Skip to content

Commit debb995

Browse files
authored
Merge branch 'main' into fix/mamba-gate-shift-silu-into-ssm
2 parents e44812f + 9e98259 commit debb995

10 files changed

Lines changed: 75 additions & 74 deletions

File tree

‎examples/post_training/modelopt/convert_model.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from megatron.training import get_args
2828
from megatron.training.checkpointing import save_checkpoint
2929
from megatron.training.initialize import initialize_megatron
30+
from megatron.training.arguments import parse_and_validate_args
3031
from megatron.training.utils import print_rank_0, unwrap_model
3132
from model_provider import model_provider
3233

@@ -102,14 +103,12 @@ def check_arguments():
102103

103104

104105
if __name__ == "__main__":
105-
initialize_megatron(
106-
extra_args_provider=add_convert_args,
107-
args_defaults={
106+
parse_and_validate_args(extra_args_provider=add_convert_args, args_defaults={
108107
'tokenizer_type': 'HuggingFaceTokenizer',
109108
'no_load_rng': True,
110109
'no_load_optim': True,
111-
},
112-
)
110+
})
111+
initialize_megatron()
113112
check_arguments()
114113

115114
args = get_args()

‎examples/post_training/modelopt/export.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from megatron.post_training.model_builder import modelopt_gpt_hybrid_builder
1919
from megatron.training import get_args, get_model
2020
from megatron.training.initialize import initialize_megatron
21+
from megatron.training.arguments import parse_and_validate_args
2122
from megatron.training.utils import unwrap_model
2223
from model_provider import model_provider
2324

@@ -49,14 +50,12 @@ def add_modelopt_export_args(parser):
4950

5051

5152
if __name__ == "__main__":
52-
initialize_megatron(
53-
extra_args_provider=add_modelopt_export_args,
54-
args_defaults={
53+
parse_and_validate_args(extra_args_provider=add_modelopt_export_args, args_defaults={
5554
'tokenizer_type': 'HuggingFaceTokenizer',
5655
'no_load_rng': True,
5756
'no_load_optim': True,
58-
},
59-
)
57+
})
58+
initialize_megatron()
6059

6160
args = get_args()
6261

‎examples/post_training/modelopt/finetune.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,16 @@ def forward_step(data_iterator, model: GPTModel):
484484

485485

486486
if __name__ == "__main__":
487+
from megatron.training.arguments import parse_and_validate_args
488+
489+
parse_and_validate_args(
490+
extra_args_provider=add_finetune_args,
491+
args_defaults={"tokenizer_type": "HuggingFaceTokenizer"},
492+
)
487493
pretrain(
488494
train_valid_test_sft_datasets_provider,
489495
partial(model_provider, modelopt_gpt_hybrid_builder),
490496
ModelType.encoder_or_decoder,
491497
forward_step,
492-
extra_args_provider=add_finetune_args,
493-
args_defaults={"tokenizer_type": "HuggingFaceTokenizer"},
494498
non_loss_data_func=non_loss_data_func,
495499
)

‎examples/post_training/modelopt/generate.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from megatron.post_training.model_builder import modelopt_gpt_hybrid_builder
1818
from megatron.post_training.utils import report_current_memory_info, to_empty_if_meta
1919
from megatron.training import get_args, get_model, initialize_megatron
20+
from megatron.training.arguments import parse_and_validate_args
2021
from utils import get_hf_tokenizer
2122
from megatron.training.utils import print_rank_0, unwrap_model
2223
from model_provider import model_provider
@@ -73,14 +74,12 @@ def get_conversations(example):
7374

7475

7576
if __name__ == "__main__":
76-
initialize_megatron(
77-
extra_args_provider=add_generate_args,
78-
args_defaults={
77+
parse_and_validate_args(extra_args_provider=add_generate_args, args_defaults={
7978
'tokenizer_type': 'HuggingFaceTokenizer',
8079
'no_load_rng': True,
8180
'no_load_optim': True,
82-
},
83-
)
81+
})
82+
initialize_megatron()
8483

8584
check_arguments()
8685

‎examples/post_training/modelopt/mmlu.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from megatron.post_training.model_builder import modelopt_gpt_hybrid_builder
2121
from megatron.post_training.utils import report_current_memory_info
2222
from megatron.training import get_args, get_model, initialize_megatron
23+
from megatron.training.arguments import parse_and_validate_args
2324
from utils import get_hf_tokenizer
2425
from megatron.training.utils import print_rank_0, unwrap_model
2526
import modelopt.torch.quantization as mtq
@@ -133,14 +134,12 @@ def generate_prompt(test_example, dev_examples, few_shots=0, no_subject_prompt=F
133134

134135

135136
if __name__ == "__main__":
136-
initialize_megatron(
137-
extra_args_provider=add_mmlu_args,
138-
args_defaults={
137+
parse_and_validate_args(extra_args_provider=add_mmlu_args, args_defaults={
139138
'tokenizer_type': 'HuggingFaceTokenizer',
140139
'no_load_rng': True,
141140
'no_load_optim': True,
142-
},
143-
)
141+
})
142+
initialize_megatron()
144143

145144
args = get_args()
146145
cache = Cache(args.cache_dir)

‎examples/post_training/modelopt/offline_feature_extract.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ def extract_feature(dataset, model, output_dir, idx_start, idx_end):
4242
torch.distributed.barrier()
4343

4444
if __name__ == "__main__":
45-
initialize_megatron(
46-
extra_args_provider=add_extract_args,
47-
args_defaults={
45+
parse_and_validate_args(extra_args_provider=add_extract_args, args_defaults={
4846
'tokenizer_type': 'HuggingFaceTokenizer',
4947
'no_load_rng': True,
5048
'no_load_optim': True,
51-
},
52-
)
49+
})
50+
initialize_megatron()
5351

5452
args = get_args()
5553
tokenizer = get_tokenizer()

‎examples/post_training/modelopt/prune.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
report_current_memory_info,
3434
)
3535
from megatron.training import get_args, get_model, initialize_megatron
36+
from megatron.training.arguments import parse_and_validate_args
3637
from utils import get_hf_tokenizer
3738
from megatron.training.checkpointing import save_checkpoint
3839
from megatron.training.utils import print_rank_0, unwrap_model
@@ -149,14 +150,12 @@ def get_params(model):
149150

150151

151152
if __name__ == "__main__":
152-
initialize_megatron(
153-
extra_args_provider=add_prune_args,
154-
args_defaults={
153+
parse_and_validate_args(extra_args_provider=add_prune_args, args_defaults={
155154
"tokenizer_type": "HuggingFaceTokenizer",
156155
"no_load_rng": True,
157156
"no_load_optim": True,
158-
},
159-
)
157+
})
158+
initialize_megatron()
160159

161160
args = get_args()
162161
check_arguments(args)

‎examples/post_training/modelopt/quantize.py‎

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
report_current_memory_info,
4646
)
4747
from megatron.training import get_args, get_model, initialize_megatron
48+
from megatron.training.arguments import parse_and_validate_args
4849
from utils import get_hf_tokenizer
4950
from megatron.training.checkpointing import save_checkpoint
5051
from megatron.training.utils import print_rank_0, unwrap_model
@@ -188,13 +189,10 @@ def get_first_layers_disabled_config(config, num_layers: int = 1, num_layers_to_
188189
"""
189190
config = copy.deepcopy(config)
190191
quant_cfg = config.get("quant_cfg", {})
191-
quant_cfg.update(
192-
{
193-
functools.partial(
194-
_is_first_layers, num_layers=num_layers, num_layers_to_disable=num_layers_to_disable
195-
): {"enable": False}
196-
}
192+
predicate = functools.partial(
193+
_is_first_layers, num_layers=num_layers, num_layers_to_disable=num_layers_to_disable
197194
)
195+
quant_cfg.append({"quantizer_name": predicate, "enable": False})
198196
config["quant_cfg"] = quant_cfg
199197
return config
200198

@@ -206,13 +204,10 @@ def get_last_layers_disabled_config(config, num_layers: int = 1, num_layers_to_d
206204
"""
207205
config = copy.deepcopy(config)
208206
quant_cfg = config.get("quant_cfg", {})
209-
quant_cfg.update(
210-
{
211-
functools.partial(
212-
_is_last_layers, num_layers=num_layers, num_layers_to_disable=num_layers_to_disable
213-
): {"enable": False}
214-
}
207+
predicate = functools.partial(
208+
_is_last_layers, num_layers=num_layers, num_layers_to_disable=num_layers_to_disable
215209
)
210+
quant_cfg.append({"quantizer_name": predicate, "enable": False})
216211
config["quant_cfg"] = quant_cfg
217212
return config
218213

@@ -224,28 +219,34 @@ def get_modelopt_torch_quantization_config():
224219
raise ValueError(f"Unsupported quantization config {args.export_quant_cfg}.")
225220
mtq_config = QUANT_CFG_CHOICES[args.export_quant_cfg]
226221

227-
fp8_config = {"enable": True, "num_bits": (4, 3), "axis": None}
222+
if isinstance(mtq_config["quant_cfg"], dict):
223+
# Normalize old dict format to new list format
224+
mtq_config["quant_cfg"] = mtq.normalize_quant_cfg_list(mtq_config["quant_cfg"])
225+
226+
fp8_config = {"enable": True, "cfg": {"num_bits": (4, 3), "axis": None}}
228227
fp4_config = {
229-
"num_bits": (2, 1),
230-
"block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)},
231-
"axis": None,
232228
"enable": True,
229+
"cfg": {
230+
"num_bits": (2, 1),
231+
"block_sizes": {-1: 16, "type": "dynamic", "scale_bits": (4, 3)},
232+
"axis": None,
233+
},
233234
}
234235
if args.export_quant_cfg == "FP8_DEFAULT_CFG":
235236
# Enable Medusa heads and kv-cache quantization
236-
mtq_config["quant_cfg"]["*medusa_heads**"] = fp8_config
237+
mtq_config["quant_cfg"].append({"quantizer_name": "*medusa_heads**", **fp8_config})
237238
if "FP4" in args.export_quant_cfg:
238239
# Enable Medusa heads and kv-cache quantization
239-
mtq_config["quant_cfg"]["*medusa_heads**"] = fp4_config
240+
mtq_config["quant_cfg"].append({"quantizer_name": "*medusa_heads**", **fp4_config})
240241
if "AWQ" in args.export_quant_cfg:
241-
weight_quantizer = mtq_config["quant_cfg"]["*weight_quantizer"] # type: ignore
242-
if isinstance(weight_quantizer, list):
243-
weight_quantizer = weight_quantizer[0]
244-
weight_quantizer["block_sizes"][-1] = 128
245-
242+
try:
243+
weight_quantizer = mtq.find_quant_cfg_entry_by_path(mtq_config["quant_cfg"], "*weight_quantizer")
244+
weight_quantizer["block_sizes"][-1] = 128
245+
except KeyError:
246+
weight_quantizer = None
246247
# Customization
247248
if args.disable_qkv_quant:
248-
mtq_config["quant_cfg"]["*self_attention*"] = {"enable": False}
249+
mtq_config["quant_cfg"].append({"quantizer_name": "*self_attention*", "enable": False})
249250

250251
# KV Cache Quantization
251252
enable_quant_kv_cache = args.export_kv_cache_quant != "none"
@@ -257,7 +258,7 @@ def get_modelopt_torch_quantization_config():
257258

258259
# Weight Only Quantization
259260
if args.weight_only:
260-
mtq_config["quant_cfg"]["*input_quantizer"] = {"enable": False}
261+
mtq_config["quant_cfg"].append({"quantizer_name": "*input_quantizer", "enable": False})
261262
if args.num_first_layers_to_skip_quant is not None:
262263
mtq_config = get_first_layers_disabled_config(
263264
mtq_config,
@@ -346,14 +347,12 @@ def get_calib_dataloader(
346347

347348

348349
if __name__ == "__main__":
349-
initialize_megatron(
350-
extra_args_provider=add_text_generate_ptq_args,
351-
args_defaults={
350+
parse_and_validate_args(extra_args_provider=add_text_generate_ptq_args, args_defaults={
352351
"tokenizer_type": "HuggingFaceTokenizer",
353352
"no_load_rng": True,
354353
"no_load_optim": True,
355-
},
356-
)
354+
})
355+
initialize_megatron()
357356

358357
check_arguments()
359358

‎examples/post_training/modelopt/validate.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from megatron.post_training.model_builder import modelopt_gpt_hybrid_builder
1818
from megatron.post_training.utils import get_mtbench_chat_data
1919
from megatron.training import get_args, get_model, initialize_megatron
20+
from megatron.training.arguments import parse_and_validate_args
2021
from utils import get_hf_tokenizer
2122
from megatron.training.utils import print_rank_0, unwrap_model
2223
from model_provider import model_provider
@@ -89,14 +90,12 @@ def report_current_memory_info():
8990

9091

9192
if __name__ == "__main__":
92-
initialize_megatron(
93-
extra_args_provider=add_ar_validation_args,
94-
args_defaults={
93+
parse_and_validate_args(extra_args_provider=add_ar_validation_args, args_defaults={
9594
'tokenizer_type': 'HuggingFaceTokenizer',
9695
'no_load_rng': True,
9796
'no_load_optim': True,
98-
},
99-
)
97+
})
98+
initialize_megatron()
10099

101100
check_arguments()
102101

‎skills/nightly-sync/SKILL.md‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,16 @@ the branch.
281281
in a collapsed `<details>` block. If git is too old for `--remerge-diff`,
282282
note the git version and describe the merge strategy used instead.
283283
- Save the PR number for later phases
284-
- **Add the `Run functional tests` label** to the PR immediately after
285-
creation. This ensures `/ok to test` triggers the full CI suite (unit tests
286-
+ functional/integration tests with 100-step training and golden value
287-
comparison). Without this label, only a lightweight subset runs.
284+
- **Add the `Run functional tests` and `Run MBridge tests` labels** to the
285+
PR immediately after creation. The `Run functional tests` label ensures
286+
`/ok to test` triggers the full CI suite (unit tests + functional/
287+
integration tests with 100-step training and golden value comparison).
288+
The `Run MBridge tests` label triggers the MBridge test suite. Without
289+
these labels, only a lightweight subset runs.
288290
```bash
289-
gh pr edit <PR_NUMBER> --repo $REPO --add-label "Run functional tests"
291+
gh pr edit <PR_NUMBER> --repo $REPO \
292+
--add-label "Run functional tests" \
293+
--add-label "Run MBridge tests"
290294
```
291295
292296
---
@@ -449,8 +453,10 @@ CI progresses. No separate registration poll needed.
449453
`/ok to test`. Pushing to them directly breaks the CI trigger
450454
mechanism. Always push to your own sync branch (e.g.
451455
`main2dev/<DATE>`) instead.
452-
- **Do NOT forget the `Run functional tests` label.** Without it,
453-
the internal GitLab functional tests do not run.
456+
- **Do NOT forget the `Run functional tests` and `Run MBridge tests`
457+
labels.** Without `Run functional tests`, the internal GitLab
458+
functional tests do not run; without `Run MBridge tests`, the
459+
MBridge test suite does not run.
454460

455461
### Failure Investigation
456462

0 commit comments

Comments
 (0)