-
-
Notifications
You must be signed in to change notification settings - Fork 122
Output from generate is a tuple, rather than a string #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I noticed it today as well I will take a look |
The second part of the Tuple contains useful information, so no problem with keeping it and adjusting the various type annotations accordingly. Some examples would need alignment too, I suppose. |
Further investigation shows that return text, usage_stats while def generate(
model: nn.Module,
processor: PreTrainedTokenizer,
prompt: str,
image: Union[str, List[str]] = None,
verbose: bool = False,
**kwargs,
) -> str: This seems to have been introduce through the FastAPI PR 321. So a simple fix would be to correct this return type. However, there are other options. @dataclass
class GenerationResult:
text: str
token: Optional[int]
logprobs: Optional[List[float]]
prompt_tokens: int
generation_tokens: int
prompt_tps: float
generation_tps: float
peak_memory: float After all, it is what Finally, while we get If you decide to return an enhanced type (and I think that that would be useful), the documentation and examples would need to follow. |
Gemma 2.5 Pro identifies the mismatch!
More generally, I don't klnow what ruff settings you use, but there are a good few bits of cruft such as unused or duplicate imports and functions, odd references to |
Got it, thanks this is really helpful! Will fix it over the weekend |
Yes, it was introduced here: I'm thinking probably best to return a dataclass instead of a tuple. Where users will need to index into .text to access the output. What do you think? |
Yes, that would be good. There is already a GenerationResult class that could be suitable, particularly if it was augmented with the other memory use metrics that mix offers. |
I must be doing something wrong, but the output string that I get back from
generate
is a tuple with both the model output and some stats. I always set the verbose parameter. When it is set to false, I get, eg:and with a bit more debugging output:
which checks.
Truing the verbose parameter:
I am obviously making a schoolboy error of some sort, but I can't see what it is. Suggestions ... ?
The text was updated successfully, but these errors were encountered: