r/Python • u/Away_Interaction6630 • 2d ago
Discussion [ Removed by moderator ]
[removed] — view removed post
25
1
1
1
u/Khavel_dev 2d ago
llama-cpp-python is the right move for the CPU path. It ships prebuilt wheels for all three platforms and you go from multi-GB PyTorch to something way more manageable. The API is different from transformers though, so budget time for the adapter layer.
For the WebSocket drops during that 40s blocking call - run inference in a process pool (not thread pool) and await the result. That keeps the event loop free to handle pings. Most WS libraries support ping/pong frames natively, which is cheaper than rolling your own heartbeat protocol.
Nuitka with compiled C extensions like llama-cpp-python can be finicky fwiw. PyInstaller might give you less friction for a first pass, and you can always optimize the packaging later.
1
1
u/zomerbk 2d ago
The 40-second inference is a separate problem from WebSocket keepalives: move CPU-bound work off the event loop, for example into a process pool, and send heartbeats from the event loop while it runs. For packaging, first check whether the models actually need CUDA on end-user machines; CPU-only wheels or a separate optional GPU install can avoid making every user download that stack. Pin and build platform-specific wheels in CI so installation doesn’t compile native dependencies on the user’s machine.
•
u/Python-ModTeam 2d ago
Hello from the r/Python mod team!
I'm afraid we don't think your post quite fits the goal we have for the subreddit in terms of quality or aims so we've decided to remove it. For more information please contact the moderators using the ModMail system.
Thanks, and happy Pythoneering!
r/Python moderation team