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

Allow Metric.score to work within an existing asyncio loop #1161

Merged
merged 6 commits into from
Aug 5, 2024

Conversation

abramowskia
Copy link
Contributor

I got errors when running metrics within an existing asyncio loop, the asyncio.run part makes the code fail in those cases. Submitting a bugfix.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 2, 2024
@@ -96,7 +96,8 @@ def score(self: t.Self, row: t.Dict, callbacks: Callbacks = None) -> float:
callbacks = callbacks or []
rm, group_cm = new_group(self.name, inputs=row, callbacks=callbacks)
try:
score = asyncio.run(self._ascore(row=row, callbacks=group_cm))
loop = asyncio.get_event_loop()
score = loop.run_until_complete(self._ascore(row=row, callbacks=group_cm))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will still fail in jupyter notebook envs right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry my bad!

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 5, 2024
@jjmachan
Copy link
Member

jjmachan commented Aug 5, 2024

added a few tests but thanks a lot for this PR ❤️

@jjmachan jjmachan merged commit d2486f1 into explodinggradients:main Aug 5, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants