We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
get_asyncio_loop
1 parent 2dac593 commit 15eca05Copy full SHA for 15eca05
megatron/core/utils.py
@@ -2001,11 +2001,12 @@ def unwrap_model(model, module_instances=None):
2001
return unwrapped_model
2002
2003
2004
-def get_asyncio_loop():
+def get_asyncio_loop(loop: asyncio.AbstractEventLoop | None = None) -> asyncio.AbstractEventLoop:
2005
"""Creates an asyncio loop if necessary and then returns the current asyncio loop."""
2006
- try:
2007
- loop = asyncio.get_running_loop()
2008
- except RuntimeError as e:
2009
- loop = asyncio.new_event_loop()
2010
- asyncio.set_event_loop(loop)
+ if loop is None:
+ try:
+ loop = asyncio.get_running_loop()
+ except RuntimeError as e:
+ loop = asyncio.new_event_loop()
2011
+ asyncio.set_event_loop(loop)
2012
return loop
0 commit comments