Repository navigation
[cp] Allow PTRR load balancer to select a mask from a dict - #3972
Merged
Merged
Conversation
jinsooihm
requested review from
fegin,
felipemello1,
tianyu-l,
wconstab and
wwwjn
as code owners
July 23, 2026 18:31
tianyu-l
reviewed
Jul 23, 2026
| - None: Disable load balancing | ||
| """ | ||
|
|
||
| context_parallel_ptrr_mask_key: str | None = None |
Contributor
There was a problem hiding this comment.
Could you test this in CI for gpt-oss:
- let's modify (in-place) this FSDP 4 to "FSDP 2 CP 2" or "CP 4", and apply global mask as the key.
Summary:
Context parallelism's PTRR load balancer previously rejected any model
whose attention masks are provided as a dict of named masks, since the
balancer can only be built from a single mask. Models like GPT-OSS with
flex attention legitimately produce multiple masks (e.g. a full-causal
mask plus a sliding-window mask), so PTRR was unusable for them.
This adds a configuration option letting the user name which mask in the
dict PTRR should build its balancer from. The resulting balancer is then
used to shard every mask in the dict as well as the inputs. When the
masks are a dict but no key is specified (or the key is invalid), we fail
loudly and list the available keys instead of silently guessing.
It also converts the gpt-oss flex integration test to run under context
parallelism (FSDP 2 x CP 2) with the ptrr balancer and the global
(basic_mask) key, so CI actually exercises the multi-mask CP path.
Test Plan:
Added integration test 'gpt_oss_pp+fsdp+cp+ep+sacop' which runs
gpt_oss_debugmodel_flex (dict of basic_mask + sliding_window_mask) under
FSDP 2 x CP 2 + PP 2 + EP 4 with ptrr and
context_parallel_ptrr_mask_key=basic_mask. Run on 8 GPUs:
python -m tests.integration_tests.run_tests <out_dir> \
--test_suite models --test_name 'gpt_oss_pp+fsdp+cp+ep+sacop' --ngpu 8
TODO: paste CI / local run results once executed.
jinsooihm
force-pushed
the
ptrr-dict-attention-masks
branch
from
July 23, 2026 22:00
4b6cbb4 to
9d9b879
Compare
Contributor
|
@wwwjn related to the dp balancing, no? |
tianyu-l
approved these changes
Jul 23, 2026
fegin
approved these changes
Jul 24, 2026
| if attention_masks is None: | ||
| raise ValueError( | ||
| "PTRRLoadBalancer requires attention_masks to be a " | ||
| "BlockMask, but got None or dict[str, BlockMask]" |
Contributor
There was a problem hiding this comment.
why removing dict[str, BlockMask]?
Contributor
Author
There was a problem hiding this comment.
Fixed the comment
Contributor
|
@felipemello1 No, this is purely CP load balancing. |
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.
Context parallelism's PTRR load balancer previously rejected any model whose attention masks are provided as a dict of named masks, since the balancer can only be built from a single mask. Models like GPT-OSS or Olmo3 (#3966) with flex attention legitimately produce multiple masks (e.g. a full-causal mask plus a sliding-window mask), so PTRR was unusable for them.
This adds a configuration option letting the user name which mask in the dict PTRR should build its balancer from. The resulting balancer is then used to shard every mask in the dict as well as the inputs. When the masks are a dict but no key is specified (or the key is invalid), we fail loudly and list the available keys instead of silently guessing.
For example,
would allow the user to choose
attention_masks["basic_mask"]to use as load balancing decision in PTRR.Justification:
Consider the models like GPT-OSS or Olmo3, that alternates between sliding window and global causal mask.
For example, say the input sequence consists of documents of length [4, 8] and sliding window size is 3.
Suppose we apply the global causal mask after every$k$ application of the sliding window mask.$r$ is $c_r := k c_r^s + c_r^g$ where $c_r^s$ is the cost for row $r$ for sliding window mask and $c_r^g$ is the cost for row $r$ for global causal mask.
Then, a reasonable cost model for work for a row
For a concrete example, let$k = 3$ as in the case of Olmo 3.
Note that the relative order of$(c_r)$ is same as the relative order of $(c_r^g)$ .$(c_r^g)$ or $(c_r)$ , we get the same output.
One can show this holds true in general when we take a weighted combination of a global causal mask and a sliding window mask.
This means that if we use a sorting based load balancing algorithm such as PTRR on the costs
Therefore, it may be reasonable to give the user a choice to still use PTRR when there are multiple masks present in the model.
Test Plan:
Loss decreases in a similarly, though not identically, in running
and
Also, tested in
tests/integration_tests/model.py.