[bugfix] skip full-size cat copy when single shard (TP==1) to avoid OOM#152
Merged
Conversation
…OM in colocate sync
There was a problem hiding this comment.
Code Review
This pull request optimizes tensor concatenation in gpt_bridge.py by skipping torch.concat when there is only a single shard (length of 1) to prevent Out-Of-Memory (OOM) errors during colocate sync. The reviewer suggested simplifying the handling of mg_scale_inv by removing a redundant type check, as it is already guaranteed to be a list if not None.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Jintao-Huang
approved these changes
Jul 21, 2026
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.
What does this PR do?
This PR fixes an OOM (out-of-memory) issue that occurs during colocate sync when tensor parallelism size is 1 (single shard).
Problem
In
_get_weight,torch.concat(tensor, dim=0)was always called regardless of the number of shards. When there is only a single shard (TP==1), this still allocates a new full-size tensor copy, causing unnecessary peak GPU memory spikes that lead to OOM in the colocate sync path.Fix
Skip the
torch.concatcopy when the shard list contains a single element:tensor: directly usetensor[0]whenlen(tensor) == 1, otherwise concatenate as before.mg_scale_inv: apply the same single-shard shortcut (only when it is a list/tuple of length 1).This removes one redundant full-size tensor copy in the TP==1 path, reducing peak GPU memory usage.
Changes
src/mcore_bridge/bridge/gpt_bridge.py: updated the shard-merging logic in_get_weightto short-circuit on single-shard inputs.