Skip to content

add olmo3 models - #3966

Closed
ruisizhang123 wants to merge 3 commits into
gh/ruisizhang123/1/basefrom
gh/ruisizhang123/1/head
Closed

ruisizhang123 wants to merge 3 commits into
gh/ruisizhang123/1/basefrom
gh/ruisizhang123/1/head

Conversation

@ruisizhang123

@ruisizhang123 ruisizhang123 commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
This was referenced Jul 22, 2026
@ruisizhang123
ruisizhang123 marked this pull request as draft July 22, 2026 00:40
fegin pushed a commit that referenced this pull request Jul 24, 2026
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,
```
--parallelism.context-parallel-load-balancer ptrr --parallelism.context-parallel-ptrr-mask-key basic_mask
```
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.
```
global causal mask                  work per row       relative order (decreasing)
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  1                     11       
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  2                     9
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  3                     7
[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]  ->  4                     5
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]  ->  1                     11
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0]  ->  2                     9
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0]  ->  3                     7
[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]  ->  4                     5
[0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0]  ->  5                     4
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0]  ->  6                     3
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0]  ->  7                     2
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]  ->  8                     1
```
```
sliding window mask                  work per row
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  1
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  2
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  2
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]  ->  2
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]  ->  1
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0]  ->  2
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]  ->  2
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]  ->  2
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0]  ->  2
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0]  ->  2
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0]  ->  2
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]  ->  2
```
Suppose we apply the global causal mask after every $k$ application of
the sliding window mask.
Then, a reasonable cost model for work for a row $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.

For a concrete example, let $k = 3$ as in the case of Olmo 3. 
```
combined cost                  work per row              relative order (decreasing)
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  1 + 3 = 4                     11
[4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  2 + 6 = 8                     9
[1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ->  3 + 6 = 9                     7
[1, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0]  ->  4 + 6 = 10                    5
[0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0]  ->  1 + 3 = 4                     11
[0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0]  ->  2 + 6 = 8                     9
[0, 0, 0, 0, 1, 4, 4, 0, 0, 0, 0, 0]  ->  3 + 6 = 9                     7
[0, 0, 0, 0, 1, 1, 4, 4, 0, 0, 0, 0]  ->  4 + 6 = 10                    5
[0, 0, 0, 0, 1, 1, 1, 4, 4, 0, 0, 0]  ->  5 + 6 = 11                    4
[0, 0, 0, 0, 1, 1, 1, 1, 4, 4, 0, 0]  ->  6 + 6 = 12                    3
[0, 0, 0, 0, 1, 1, 1, 1, 1, 4, 4, 0]  ->  7 + 6 = 13                    2
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 4, 4]  ->  8 + 6 = 14                    1
```
Note that the relative order of $(c_r)$ is same as the relative order of
$(c_r^g)$.
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 $(c_r^g)$ or $(c_r)$, we get the same output.
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 
```
MODULE=gpt_oss CONFIG=gpt_oss_debugmodel_flex ./run_train.sh --parallelism.context-parallel-degree 2
```
and 
```
MODULE=gpt_oss CONFIG=gpt_oss_debugmodel_flex ./run_train.sh --parallelism.context-parallel-degree 2 --parallelism.context-parallel-load-balancer ptrr --parallelism.context-parallel-ptrr-mask-key basic_mask
```
Also, tested in `tests/integration_tests/model.py`.
[ghstack-poisoned]
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant