Fix NameError in download_weights.py and add GPU memory cleanup in gradio_app.py#96
Open
fox3nox wants to merge 1 commit into
Open
Conversation
- Fix critical bug where `args.models` was referenced inside `main()` but only defined in the `__main__` block, causing a NameError on any import. `models` is now passed as an explicit parameter to `main()`. - Replace bare `assert` with a proper `ValueError` for invalid model names. - Add `torch.cuda.OutOfMemoryError` handling in `generate_video` to surface a clear message and free GPU memory instead of silently returning None. - Clean up temp files on error and call `torch.cuda.empty_cache()` + `gc.collect()` in a `finally` block to prevent VRAM leaks between generations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
download_weights.pyreferencedargs.modelsinsidemain(), butargsis only defined in the__main__block — this caused aNameErrorwhenevermain()was called programmatically or imported. Fixed by passingmodelsas an explicit parameter tomain().assertfor invalid model names with a properValueErrorand a descriptive error message.gradio_app.pynow handlestorch.cuda.OutOfMemoryErrorseparately with a user-friendly message and immediately frees VRAM viatorch.cuda.empty_cache()+gc.collect(). Afinallyblock ensures cleanup runs after every generation, preventing VRAM leaks between calls.Test plan
python download_weights.py --models 720x720_5s— should download without errormainfromdownload_weightsin a Python shell and call it directly — noNameError--models invalid) — should raiseValueErrorwith a clear messagegradio_app.py(e.g. very high resolution) — should log a clear message and not leave temp files behind🤖 Generated with Claude Code