eth-sri / lmql

A language for constraint-guided and efficient LLM programming.
https://lmql.ai
Apache License 2.0
3.65k stars 197 forks source link

RuntimeError: There is no current event loop in thread 'MainThread'. #6

Closed lambdaofgod closed 1 year ago

lambdaofgod commented 1 year ago

When I run lmql run on your joke example, or using lml playground I get that RuntimeError.

BTW thanks for a great initiative.

lambdaofgod commented 1 year ago

Error details when running lml run with a file:

Exception ignored in: <function AsyncOpenAIAPI.__del__ at 0x7faf6116aa70>
Traceback (most recent call last):
  File "/home/kuba/Projects/forks/lmql/src/lmql/runtime/bopenai/batched_openai.py", line 553, in __del__
  File "/etc/conda/envs/lmql/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
RuntimeError: There is no current event loop in thread 'MainThread'.
lbeurerkellner commented 1 year ago

Thanks for reporting this. Does the query otherwise finish execution, or does it not execute at all?

lambdaofgod commented 1 year ago

Query finishes. In app the problem is that every next call does not work.

lbeurerkellner commented 1 year ago

I think I have observed this before on Linux systems specifically. This is very likely a asyncio clean-up issue. I will investigate this.

When you say "next call", what exactly do you mean? Once the query finishes, lmql run should have terminated, right?

lambdaofgod commented 1 year ago

I mean in web app.

lbeurerkellner commented 1 year ago

Okay, thank. I will investigate further and report back here. If you run locally, the playground will actually re-run a new lmql process on each query. So it seems odd that it would block the next call.

Paethon commented 1 year ago

Seeing the exact same problem here as well (running on Arch Linux)

lbeurerkellner commented 1 year ago

I just released a bug fix release lmql==0.0.4.2, where this issue should be fixed. It would be really cool, if anyone who has experienced this bug, could briefly report back, if this is fixed.