Fix: CUDA OOM issue after training before inference#96
Open
Hongbin10 wants to merge 1 commit intoTIO-IKIM:mainfrom
Open
Fix: CUDA OOM issue after training before inference#96Hongbin10 wants to merge 1 commit intoTIO-IKIM:mainfrom
Hongbin10 wants to merge 1 commit intoTIO-IKIM:mainfrom
Conversation
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.
Problem:
When running run_cpp_net.py, training and inference are executed sequentially in the same process.
On hardware with limited GPU memory (tested on NVIDIA L40S, 48GB VRAM), GPU memory allocated reached ~97% by the end of training. The experiment object — including the model, optimizer states, and gradients — was not explicitly released before inference was initiated, leaving insufficient VRAM for the inference model to load.
This caused a torch.OutOfMemoryError at the start of inference:
Root Cause
In both the checkpoint and casual run branches of run_cpp_net.py, inference = InferenceCellViTCPP(...) was called immediately after experiment.run_experiment() without releasing the training objects from GPU memory first.
Fix
Added explicit GPU memory cleanup between training and inference in both branches:
Result
Training and inference now run successfully end-to-end in a single job without CUDA OOM errors.