-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][fix] fix: resolve GPU memory imbalance in concurrent weight loading #6472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| from torch.utils._pytree import tree_any_only | ||
| from tqdm import tqdm | ||
|
|
||
| from tensorrt_llm._utils import mpi_rank | ||
| from tensorrt_llm.lora_manager import HfLoraLoader | ||
| from tensorrt_llm.models.convert_utils import split_matrix_tp | ||
|
|
||
|
|
@@ -844,6 +845,7 @@ def _load_weights_impl(model: Union[nn.Module, DecoderModelForCausalLM], | |
| } | ||
|
|
||
| def load_single_module(name, module): | ||
| torch.cuda.set_device(mpi_rank()) | ||
| if len(module._parameters) > 0: | ||
| # skip load weights if module is in skip_modules | ||
| if any(skip_module in name for skip_module in skip_modules): | ||
|
|
@@ -940,6 +942,7 @@ def _load_weights_impl_v2(model: Union[nn.Module, DecoderModelForCausalLM], | |
| logger.info(f"Renamed weights with params_map: {params_map}") | ||
|
|
||
| def load_single_module(name, module): | ||
| torch.cuda.set_device(mpi_rank()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consistent fix applied to v2 implementation - good practice. This change mirrors the fix in Consider consolidating the error handling by extracting the device setting logic into a helper function: +def _set_cuda_device_for_worker():
+ """Set CUDA device to current MPI rank with error handling."""
+ try:
+ torch.cuda.set_device(mpi_rank())
+ except (RuntimeError, ValueError) as e:
+ logger.warning(f"Failed to set CUDA device to MPI rank {mpi_rank()}: {e}")
+ # Handle appropriately based on requirementsThen use this helper in both
🤖 Prompt for AI Agents |
||
| if len(module._parameters) > 0: | ||
| if weight_mapper.should_skip_module(name): | ||
| return | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.