Supporting inference when called within an asyncio loop - #2816
Conversation
|
@shanmugamr1992 @santhnm2 I am continuing this discussion in a separate thread. This is the Pythonic way to implement this fix: #2831. Here are the differences between #2816 and #2831.
After thinking about this yesterday, I decided on this current #2816 for its simplicity. |
|
/ok to test ef4b760 |
oyilmaz-nvidia
left a comment
There was a problem hiding this comment.
Can you please change the https://github.com/shanmugamr1992/Megatron-LM/blob/fix_asyncio_issue/megatron/core/inference/contexts/dynamic_context.py to something like
if not isinstance(m, torch.Tensor):
m = torch.as_tensor(m, device=self.request_metadata[label].device, dtype=self.request_metadata[label].dtype)
self.request_metadata[label][current_id] = m
?
I just tested this in the nvcr.io/nvidian/nemo:26.02.rc1 and it works after this update.
|
/ok to test 12abb38 |
oyilmaz-nvidia
left a comment
There was a problem hiding this comment.
Tested with triton based deployment and it's working. Thanks!
|
/ok to test 3c7a941 |
Export-Deploy faced this issue
This is a known issue with Python asyncio - you cannot call run_until_complete() from within an already running event loop. The error occurs because:
PyTriton runs its own async event loop internally
When it calls Megatron's generate() → step_modern(), the code tries to run self._loop.run_until_complete(self.async_step())
This fails because Python's asyncio doesn't allow nested run_until_complete() calls