Skip to content
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

Merged
merged 10 commits into from
Nov 4, 2024
Merged

Fix huggingface response caching bug #659

merged 10 commits into from
Nov 4, 2024

Conversation

bkorycki
Copy link
Contributor

The huggingface chat_completions API returns a dataclass/dict object ChatCompletionOutput. It inherits from dict, 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.

@bkorycki bkorycki requested a review from a team as a code owner October 31, 2024 20:52
Copy link

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

Copy link
Contributor

@rogthefrog rogthefrog left a 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"]
Copy link
Contributor

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).

Copy link
Contributor

@wpietri wpietri left a 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.

@bkorycki bkorycki merged commit da6662f into main Nov 4, 2024
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants