Skip to content

Add @torch.inference_mode() to pipeline __call__ methods#170

Open
garrick99 wants to merge 1 commit intoLightricks:mainfrom
garrick99:fix/add-inference-mode-to-call
Open

Add @torch.inference_mode() to pipeline __call__ methods#170
garrick99 wants to merge 1 commit intoLightricks:mainfrom
garrick99:fix/add-inference-mode-to-call

Conversation

@garrick99
Copy link

Summary

Fixes #152 — Pipeline __call__ methods are not wrapped in torch.inference_mode(), causing OOM when called from Python code (not CLI).

Problem

All 7 pipeline classes were missing @torch.inference_mode() on their __call__ method. The main() functions had the decorator, so CLI usage worked fine. But when calling pipelines from Python (the API use case), torch retains autograd graphs — the text encoder's ~37 GB of activations aren't freed before the transformer loads, causing OOM.

Only ti2vid_two_stages_hq.py already had the decorator on __call__.

Fix

Added @torch.inference_mode() to __call__ in all 7 pipeline classes:

  • a2vid_two_stage.py
  • distilled.py
  • ic_lora.py
  • keyframe_interpolation.py
  • retake.py
  • ti2vid_one_stage.py
  • ti2vid_two_stages.py

7 files, 7 lines added. No behavioral change for CLI users (already covered by main()'s decorator).

🤖 Generated with Claude Code

…ricks#152)

All 7 pipeline classes were missing the decorator on __call__, causing
torch to retain autograd graphs when called from Python (not CLI).
This leads to OOM — the text encoder's ~37 GB of activations aren't
freed before the transformer loads.

Only ti2vid_two_stages_hq.py already had the decorator. The main()
functions in each file had inference_mode, but __call__ did not —
so CLI usage worked but Python API usage OOMed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pipeline __call__ functions are not in inference mode decorators → OOM when used externally from Python

1 participant