-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix huggingface response caching bug #659
Conversation
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I bet this one was a bear to debug.
) -> SUTResponse: | ||
completions = [] | ||
for choice in response.choices: | ||
text = choice.message.content | ||
text = choice["message"]["content"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to try the benedict library. It wraps dict
and gives you convenient functionality like accessing elements via dot notation or dict notation interchangeably (choice["message"]
or choice.message
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sorting this out.
The huggingface chat_completions API returns a dataclass/dict object
ChatCompletionOutput
. It inherits fromdict
, which is a "typeable" data structure and thus allows it to be cached. However, there was a bug when running this SUT on a prompt that has been previously cached. Because it's a dataclass and not a plain dict, the deserialization produced an error.This PR addresses this bug by putting the response object into pydantic form before returning it in evaluate.
I also added some testing to make sure all SUTs are cacheable.