Skip to content

Commit 02cb070

Browse files
committed
fix: sync arguments.py with upstream core_r0.17.0 FP4 param gather changes
- Replace fp4_param with fp4_param_gather and use graceful warning instead of hard error - Add kw_args['fp4_param'] = args.fp4_param_gather in core_transformer_config_from_args - Add --fp4-param-gather CLI argument - Reorganize TE args section (FP4/FP8/precision config) - Add fp4_param to deprecated config list
1 parent 0cb3f9f commit 02cb070

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

flagscale/train/megatron/training/arguments.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,13 @@ def validate_args(args, defaults={}):
907907
'all_gather instead, turning off fp8_param_gather',
908908
args.rank,
909909
)
910-
if args.fp4_param and not is_te_min_version("2.7.0.dev0"):
911-
raise ValueError("--fp4-param requires Transformer Engine >= 2.7.0.dev0.")
910+
if args.fp4_param_gather and not is_te_min_version("2.7.0.dev0"):
911+
args.fp4_param_gather = False
912+
warn_rank_0(
913+
'FSDP2 FP4 param gather is not supported yet in TE 2.0, will fallback to bf16'
914+
'all_gather instead, turning off fp4_param_gather',
915+
args.rank,
916+
)
912917

913918
if args.overlap_param_gather_with_optimizer_step:
914919
assert args.use_distributed_optimizer, \
@@ -948,7 +953,7 @@ def validate_args(args, defaults={}):
948953
raise ValueError("--fp4-format and --fp8-format cannot be used simultaneously. Please choose one.")
949954

950955
# FP4 param requires FP4 mode
951-
if args.fp4_param and not args.fp4:
956+
if args.fp4_param_gather and not args.fp4:
952957
raise ValueError("--fp4-param-gather must be used together with --fp4-format.")
953958

954959
# FP4 requires TE >= 2.7.0.dev0
@@ -1697,6 +1702,7 @@ def core_transformer_config_from_args(args, config_class=None):
16971702
kw_args['num_layers_in_first_pipeline_stage']= args.decoder_first_pipeline_num_layers
16981703
kw_args['num_layers_in_last_pipeline_stage']= args.decoder_last_pipeline_num_layers
16991704
kw_args['fp8_param'] = args.fp8_param_gather
1705+
kw_args['fp4_param'] = args.fp4_param_gather
17001706
if args.swiglu:
17011707
kw_args['activation_func'] = F.silu
17021708
kw_args['gated_linear_unit'] = True
@@ -1762,12 +1768,15 @@ def core_transformer_config_from_args(args, config_class=None):
17621768
def _add_transformer_engine_args(parser):
17631769
group = parser.add_argument_group(title='Transformer-Engine')
17641770

1765-
# delayed scaling only configs
1771+
# FP4 related arguments
1772+
group.add_argument('--fp4-param-gather', action='store_true',
1773+
help='Keep the compute param in fp4 (do not use any other intermediate '
1774+
'dtype) and perform the param all-gather in fp4.')
1775+
# FP8 related arguments
17661776
group.add_argument('--fp8-param-gather', action='store_true',
17671777
help='Keep the compute param in fp8 (do not use any other intermediate '
17681778
'dtype) and perform the param all-gather in fp8.')
1769-
1770-
# FP4 related arguments
1779+
# TE precision config file
17711780
group.add_argument('--te-precision-config-file', default=None,
17721781
help='Configuration file to select per-module precision overrides. '
17731782
'See TransformerEngineMixedPrecision.md')
@@ -2030,6 +2039,7 @@ def _add_network_size_args(parser):
20302039
# args uses same var with a different name
20312040
"num_moe_experts",
20322041
"fp8_param",
2042+
"fp4_param",
20332043
# incompatible defaults in dataclass
20342044
"gradient_accumulation_fusion",
20352045
"overlap_p2p_comm",

0 commit comments

Comments
 (0)