[Bug]: Excessive memory allocation during CUDA graph capture in Eagle3 flow
System Info
Applicable to all hardware in eagle3 flow.
Description
During CUDA graph capture in the Eagle3 flow, additional memory equal to (max_num_tokens x hidden_size × num_layers_to_capture) is allocated per graph capture, refer code here. This accumulates significant GPU memory overhead and leaves less free memory available when the server starts.
Expected Behavior
The buffer used during CUDA graph capture should be reused across graph captures rather than allocating a new one each time.
Proposed Fix
Reuse the buffer for every graph capture instead of allocating a new one, reducing the total memory footprint at server startup.
@achartier aware of this issue, working with him on this PR bug fix.
Who can help?
No response
Information
- [ ] The official example scripts
- [ ] My own modified scripts
Tasks
- [ ] An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - [ ] My own task or dataset (give details below)
Reproduction
You can add a logging in cuda graph capture here, to show allocated/free memory per graph capture and should be able to see constant increase of (max_num_tokens x hidden_size × num_layers_to_capture) per graph capture
print(
f"[Memory-Debug][rank={self.config.mapping.rank}][cuda_graph:capture] "
f"key={key} is_draft_model={self.config.is_draft_model} "
f"graphs_so_far={len(self.graphs)} "
f"torch_allocated_before={torch.cuda.memory_allocated()/1024**3:.2f}GiB"
)
Expected behavior
Create the tensor outside the graph capture and re-use.
actual behavior
Per graph capture, ideally memory should be flat.
additional notes
Will send a PR for this bug fix.
Before submitting a new issue...
- [x] Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.