@@ -46,180 +46,15 @@ GPT OSS models are supported via the Bridge system with specialized configuratio
4646- ** Bias in Linear Layers** : Linear layers include bias terms
4747- ** Activation Clamping** : Output activations clamped to [ -7.0, 7.0] for numerical stability
4848
49- ## Conversion with 🤗 Hugging Face
50-
51- ### Load HF → Megatron
52- ``` python
53- from megatron.bridge import AutoBridge
54-
55- # Example: GPT OSS 20B
56- bridge = AutoBridge.from_hf_pretrained(" openai/gpt-oss-20b" )
57- provider = bridge.to_megatron_provider()
58-
59- # Configure parallelism before instantiating the model
60- provider.tensor_model_parallel_size = 2
61- provider.pipeline_model_parallel_size = 4
62- provider.expert_model_parallel_size = 4
63- provider.sequence_parallel = True
64-
65- model = provider.provide_distributed_model(wrap_with_ddp = False )
66-
67- provider.finalize()
68-
69- # For GPT OSS 120B:
70- # bridge = AutoBridge.from_hf_pretrained("openai/gpt-oss-120b")
71- ```
72-
73- ### Export Megatron → HF
74- ``` python
75- # Convert from a Megatron checkpoint directory to HF format
76- bridge.export_ckpt(
77- megatron_path = " /results/gpt_oss_120b/checkpoints/iter_0500000" ,
78- hf_path = " ./gpt-oss-hf-export" ,
79- )
80- ```
81-
8249## Examples
8350
84- - Checkpoint conversion: [ examples/conversion/convert_checkpoints.py] ( https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/main/examples/conversion/convert_checkpoints.py )
85-
86- ## Pretrain recipes
87-
88- ### Example usage (GPT OSS 20B)
89- ``` python
90- from megatron.bridge.recipes.gpt_oss import gpt_oss_20b_pretrain_config
91-
92- cfg = gpt_oss_20b_pretrain_config(
93- name = " gpt_oss_20b_pretrain" ,
94- data_paths = [" /path/to/dataset.nvjsonl" ],
95- dir = " /results/gpt_oss_20b" ,
96- train_iters = 500_000 ,
97- global_batch_size = 512 ,
98- seq_length = 4096 ,
99- )
100- ```
101-
102- ### Example usage (GPT OSS 120B)
103- ``` python
104- from megatron.bridge.recipes.gpt_oss import gpt_oss_120b_pretrain_config
105-
106- cfg = gpt_oss_120b_pretrain_config(
107- name = " gpt_oss_120b_pretrain" ,
108- data_paths = [" /path/to/dataset.nvjsonl" ],
109- dir = " /results/gpt_oss_120b" ,
110- train_iters = 500_000 ,
111- global_batch_size = 512 ,
112- seq_length = 4096 ,
113- )
114- ```
115-
116- ### Key configuration options
117- - ** Parallelism (20B)** : Default TP=2, PP=4, EP=4 for efficient MoE training
118- - ** Parallelism (120B)** : Default TP=2, PP=4, EP=16 for large-scale training
119- - ** Sequence parallel** : Enabled by default for memory efficiency
120- - ** Context parallel** : Supports CP for long sequences (131K tokens)
121- - ** Manual GC** : Aggressive garbage collection (interval=100) for stable memory usage
122- - ** MoE optimizations** : Grouped GEMM and permute fusion enabled by default
123-
124- ## Finetuning recipes
125-
126- ### Example usage (GPT OSS 20B - LoRA finetuning)
127- ``` python
128- from megatron.bridge.recipes.gpt_oss import gpt_oss_20b_finetune_config
129-
130- cfg = gpt_oss_20b_finetune_config(
131- hf_path = " openai/gpt-oss-20b" ,
132- name = " gpt_oss_20b_lora_finetune" ,
133- pretrained_checkpoint = " path/to/gpt_oss/checkpoint" ,
134- peft = " lora" , # or "dora" for DoRA
135- train_iters = 1000 ,
136- global_batch_size = 128 ,
137- finetune_lr = 1e-4 ,
138- )
139- ```
140-
141- ### Example usage (GPT OSS 20B - Full SFT)
142- ``` python
143- cfg = gpt_oss_20b_finetune_config(
144- hf_path = " openai/gpt-oss-20b" ,
145- name = " gpt_oss_20b_full_sft" ,
146- pretrained_checkpoint = " path/to/gpt_oss/checkpoint" ,
147- peft = None , # Full supervised finetuning
148- train_iters = 1000 ,
149- global_batch_size = 128 ,
150- finetune_lr = 5e-6 , # Lower LR for full SFT
151- )
152- ```
153-
154- ### Example usage (GPT OSS 120B - LoRA finetuning)
155- ``` python
156- from megatron.bridge.recipes.gpt_oss import gpt_oss_120b_finetune_config
157-
158- cfg = gpt_oss_120b_finetune_config(
159- hf_path = " openai/gpt-oss-120b" ,
160- name = " gpt_oss_120b_lora_finetune" ,
161- pretrained_checkpoint = " path/to/gpt_oss/checkpoint" ,
162- peft = " lora" ,
163- train_iters = 1000 ,
164- global_batch_size = 128 ,
165- finetune_lr = 1e-4 ,
166- )
167- ```
168-
169- ### Default configurations
170-
171- #### GPT OSS 20B
172-
173- ** LoRA/DoRA (1 node, 8 GPUs)**
174- - TP=1, PP=1, EP=1, LR=1e-4
175- - Optimized for parameter-efficient training
176- - Lower memory footprint
177-
178- ** Full SFT (1 node, 8 GPUs)**
179- - TP=1, PP=1, EP=8, LR=5e-6
180- - Full model training with expert parallelism
181- - Higher throughput with distributed experts
182-
183- #### GPT OSS 120B
184-
185- ** LoRA/DoRA (2 nodes, 16 GPUs)**
186- - TP=1, PP=4, EP=8, LR=1e-4
187- - Optimized for parameter-efficient training
188- - Pipeline parallelism for memory efficiency
189-
190- ** Full SFT (2 nodes, 16 GPUs)**
191- - TP=1, PP=1, EP=8, LR=5e-6
192- - Full model training with expert parallelism
193- - Requires more memory per GPU
51+ For checkpoint conversion, inference, finetuning recipes, and step-by-step training guides, see the [ GPT-OSS Examples] ( https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/main/examples/models/gpt_oss/README.md ) .
19452
19553## API reference
19654
19755- GPT OSS recipes: [ bridge.recipes.gpt_oss] ( ../../apidocs/bridge/bridge.recipes.gpt_oss.md )
19856- GPT OSS model provider: [ bridge.models.gpt_oss.GPTOSSProvider] ( ../../apidocs/bridge/bridge.models.gpt_oss.md )
19957
200- ## Performance optimizations
201-
202- ### Memory efficiency
203- - ** Manual GC** : Aggressive garbage collection (interval=100) for stable memory usage
204- - ** Precision-aware optimizer** : BF16 gradients and optimizer states
205- - ** Expert parallelism** : Distributes experts across GPUs (EP=4 for 20B, EP=16 for 120B)
206- - ** Sequence parallel** : Reduces activation memory across tensor parallel ranks
207- - ** Context parallel** : Splits long sequences across multiple GPUs
208-
209- ### Compute efficiency
210- - ** MoE permute fusion** : Fuses expert permutation operations
211- - ** Grouped GEMM** : Optimized expert computation with grouped matrix multiplications
212- - ** AllToAll dispatcher** : Efficient token routing across expert parallel ranks
213- - ** Bias activation fusion** : Fuses bias addition with activation functions
214- - ** Gradient overlapping** : Overlaps gradient all-reduce with backward computation
215-
216- ### Attention optimizations
217- - ** Sliding window attention** : Reduces attention computation with 128-token windows
218- - ** Window attention skip frequency** : Alternates between windowed and full attention every 2 layers
219- - ** Sink attention** : Learnable softmax offsets for improved attention stability
220- - ** Flash Attention** : FlashAttention-2 support via Transformer Engine
221- - ** Activation clamping** : Prevents numerical instability with [ -7.0, 7.0] clamping
222-
22358## Hugging Face model cards
22459
22560### GPT OSS 20B
@@ -234,4 +69,3 @@ cfg = gpt_oss_120b_finetune_config(
23469- Training configuration: [ Configuration overview] ( ../../training/config-container-overview.md )
23570- Training entry points: [ Entry points] ( ../../training/entry-points.md )
23671- Attention optimizations: [ Attention optimizations] ( ../../training/attention-optimizations.md )
237-
0 commit comments