Skip to content

Commit 8a84d71

Browse files
authored
GPT-OSS 20B Verification Card (#5397)
Signed-off-by: Maanu Grover <maanug@nvidia.com>
1 parent 4ab94df commit 8a84d71

8 files changed

Lines changed: 459 additions & 1 deletion

File tree

‎examples/model_verification_cards/gpt-oss-20b/card.yaml‎

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

‎src/megatron/bridge/models/gpt_oss/gpt_oss_bridge.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def provider_bridge(self, hf_pretrained: PreTrainedCausalLM) -> GPTModelProvider
6060
provider.normalization = "RMSNorm"
6161
provider.gated_linear_unit = True
6262
provider.add_bias_linear = True
63-
provider.add_qkv_bias = False
63+
provider.add_qkv_bias = getattr(hf_pretrained.config, "attention_bias", True)
6464
provider.share_embeddings_and_output_weights = False
6565
provider.position_embedding_type = "yarn"
6666

@@ -101,6 +101,13 @@ def provider_bridge(self, hf_pretrained: PreTrainedCausalLM) -> GPTModelProvider
101101

102102
return provider
103103

104+
@classmethod
105+
def megatron_to_hf_config(cls, provider) -> dict:
106+
"""Convert Megatron provider config to a GPT-OSS Hugging Face config."""
107+
hf_config = super().megatron_to_hf_config(provider)
108+
hf_config["attention_bias"] = True
109+
return hf_config
110+
104111
def maybe_modify_loaded_hf_weight(
105112
self, hf_param: str | dict[str, str], hf_state_dict: Mapping[str, torch.Tensor]
106113
) -> torch.Tensor:

‎src/megatron/bridge/recipes/gpt_oss/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
gpt_oss_20b_pretrain_config,
2020
gpt_oss_20b_pretrain_fp8_current_scaling_config,
2121
gpt_oss_20b_pretrain_mxfp8_config,
22+
gpt_oss_20b_sft_32k_config,
2223
gpt_oss_20b_sft_config,
2324
gpt_oss_20b_sft_fp8_current_scaling_config,
2425
gpt_oss_20b_sft_mxfp8_config,
@@ -34,6 +35,7 @@
3435
"gpt_oss_20b_pretrain_fp8_current_scaling_config",
3536
"gpt_oss_120b_pretrain_config",
3637
"gpt_oss_20b_sft_config",
38+
"gpt_oss_20b_sft_32k_config",
3739
"gpt_oss_20b_sft_openmathinstruct2_thinking_packed_config",
3840
"gpt_oss_20b_sft_fp8_current_scaling_config",
3941
"gpt_oss_120b_sft_config",

‎src/megatron/bridge/recipes/gpt_oss/gpt_oss.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
from megatron.bridge.recipes.gpt_oss.h100.gpt_oss import (
3939
gpt_oss_20b_pretrain_16gpu_h100_fp8mx_config as gpt_oss_20b_pretrain_mxfp8_config,
4040
)
41+
from megatron.bridge.recipes.gpt_oss.h100.gpt_oss import (
42+
gpt_oss_20b_sft_8gpu_h100_bf16_32k_config as gpt_oss_20b_sft_32k_config,
43+
)
4144
from megatron.bridge.recipes.gpt_oss.h100.gpt_oss import (
4245
gpt_oss_20b_sft_8gpu_h100_bf16_config as gpt_oss_20b_sft_config,
4346
)
@@ -72,6 +75,7 @@
7275
"gpt_oss_20b_pretrain_fp8_current_scaling_config",
7376
"gpt_oss_20b_pretrain_mxfp8_config",
7477
"gpt_oss_20b_sft_config",
78+
"gpt_oss_20b_sft_32k_config",
7579
"gpt_oss_20b_sft_fp8_current_scaling_config",
7680
"gpt_oss_20b_sft_mxfp8_config",
7781
"gpt_oss_20b_sft_openmathinstruct2_thinking_packed_config",

‎src/megatron/bridge/recipes/gpt_oss/h100/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"gpt_oss_20b_pretrain_16gpu_h100_fp8cs_config",
2727
"gpt_oss_20b_pretrain_16gpu_h100_fp8mx_config",
2828
"gpt_oss_20b_sft_8gpu_h100_bf16_config",
29+
"gpt_oss_20b_sft_8gpu_h100_bf16_32k_config",
2930
"gpt_oss_20b_sft_8gpu_h100_bf16_openmathinstruct2_thinking_packed_config",
3031
"gpt_oss_20b_sft_8gpu_h100_fp8cs_config",
3132
"gpt_oss_20b_sft_8gpu_h100_fp8mx_config",

‎src/megatron/bridge/recipes/gpt_oss/h100/gpt_oss.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@ def gpt_oss_20b_sft_8gpu_h100_bf16_config() -> ConfigContainer:
421421
return cfg
422422

423423

424+
def gpt_oss_20b_sft_8gpu_h100_bf16_32k_config() -> ConfigContainer:
425+
"""Return the 32K-context full SFT config for GPT-OSS 20B."""
426+
cfg = gpt_oss_20b_sft_8gpu_h100_bf16_config()
427+
428+
seq_length = 32768
429+
cfg.model.seq_length = seq_length
430+
cfg.dataset.seq_length = seq_length
431+
cfg.dataset.offline_packing_specs.packed_sequence_size = seq_length
432+
cfg.train.global_batch_size = 32
433+
434+
# Keep the complete process environment visible on the recipe.
435+
cfg.env_vars = {
436+
**COMMON_RECIPE_ENV_VARS,
437+
}
438+
return cfg
439+
440+
424441
def gpt_oss_120b_sft_32gpu_h100_bf16_config() -> ConfigContainer:
425442
"""Return a full SFT config for GPT-OSS 120B.
426443
@@ -936,6 +953,7 @@ def gpt_oss_20b_sft_8gpu_h100_bf16_openmathinstruct2_thinking_packed_config() ->
936953
"gpt_oss_20b_pretrain_16gpu_h100_fp8cs_config",
937954
"gpt_oss_20b_pretrain_16gpu_h100_fp8mx_config",
938955
"gpt_oss_20b_sft_8gpu_h100_bf16_config",
956+
"gpt_oss_20b_sft_8gpu_h100_bf16_32k_config",
939957
"gpt_oss_20b_sft_8gpu_h100_bf16_openmathinstruct2_thinking_packed_config",
940958
"gpt_oss_20b_sft_8gpu_h100_fp8cs_config",
941959
"gpt_oss_20b_sft_8gpu_h100_fp8mx_config",

‎tests/unit_tests/models/gpt_oss/test_gpt_oss_bridges.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def gpt_oss_cfg(self):
4040
"vocab_size": 201088,
4141
"hidden_act": "silu",
4242
"sliding_window": 4096,
43+
"attention_bias": True,
4344
}
4445

4546
@pytest.fixture
@@ -64,6 +65,15 @@ def test_provider_bridge_maps_config(self, mock_pretrained):
6465
# Key fields mapped from HF config
6566
assert provider.num_layers == mock_pretrained.config.num_hidden_layers
6667
assert provider.num_moe_experts == mock_pretrained.config.num_local_experts
68+
assert provider.add_qkv_bias == mock_pretrained.config.attention_bias
6769
# dtype mapping
6870
assert provider.bf16 is True
6971
assert provider.params_dtype == torch.bfloat16
72+
73+
def test_megatron_to_hf_config_preserves_attention_bias(self, mock_pretrained):
74+
bridge = GPTOSSBridge()
75+
provider = bridge.provider_bridge(mock_pretrained)
76+
77+
hf_config = bridge.megatron_to_hf_config(provider)
78+
79+
assert hf_config["attention_bias"] is True

‎tests/unit_tests/recipes/test_gpt_oss_recipes.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ def test_fp8_sft_inherits_base_sft_config():
152152
assert base.model.moe_router_padding_for_fp8 is False
153153

154154

155+
def test_gpt_oss_20b_sft_32k_overrides_batch_and_sequence_length():
156+
"""gpt_oss_20b_sft_32k_config should inherit SFT defaults with a 32K context and GBS32."""
157+
from megatron.bridge.recipes.gpt_oss import gpt_oss_20b_sft_32k_config
158+
from megatron.bridge.recipes.gpt_oss.h100.gpt_oss import gpt_oss_20b_sft_8gpu_h100_bf16_32k_config
159+
160+
assert gpt_oss_20b_sft_32k_config is gpt_oss_20b_sft_8gpu_h100_bf16_32k_config
161+
162+
cfg = gpt_oss_20b_sft_32k_config()
163+
_assert_basic_config(cfg)
164+
assert cfg.model.seq_length == 32768
165+
assert cfg.dataset.seq_length == 32768
166+
assert cfg.dataset.offline_packing_specs.packed_sequence_size == 32768
167+
assert cfg.train.global_batch_size == 32
168+
assert cfg.train.micro_batch_size == 1
169+
170+
155171
def test_fp8_peft_inherits_base_peft_config():
156172
"""gpt_oss_20b_peft_fp8_current_scaling_config should inherit base PEFT settings."""
157173
from megatron.bridge.recipes.gpt_oss import (

0 commit comments

Comments
 (0)