FlagScale Train Upgrade: Synchronization with Megatron-LM Core0.17.0#1193
Merged
Conversation
….15.0rc7 → core_v0.16.1) Resolved 66+ merge conflicts across 9 files in flagscale/train/megatron/: - training.py (22 conflicts): _STARTUP_TIMESTAMPS, TECudaGraphHelper, RL sequence packing, cur_platform stream - arguments.py (24 conflicts): print_rank_0, CUDA graph expansion, hetero guards, FP8/FP4 args - checkpointing.py (9 conflicts): dp_cp_group, distributed quant summary, convert_to_ep - initialize.py (4 conflicts): set_global_writers, cur_platform stream, hetero CPU comm, dualpipev - utils.py (7 conflicts): cu_seqlens, max_seqlen, local_cp_size, cur_platform - global_vars.py: disable_jit_fuser + set_global_writers - dist_signal_handler.py: SIGNAL_MAP dict, string-based signal constructor - biencoder_dataset_utils.py: cur_platform import - __init__.py: clean merge Preserved all FlagScale customizations: cur_platform abstractions, hetero support, dualpipev pipeline parallelism, engram embedding, spiky loss detection, extra validation datasets, FlagScale marker blocks.
…device() in training.py and utils.py Stage 5 multi-platform compliance: converted 12 torch.cuda.current_device() calls and 1 hardcoded device='cuda' to cur_platform equivalents. Remaining torch.cuda calls are CUDA-specific profiler/memory APIs with no platform abstraction.
…form compliance in train_engram.py - Add lazy import for StableLM2SchedulerConfig at usage site to avoid circular import - Replace 5 torch.cuda.current_device() + 5 .cuda() calls in train_engram.py with cur_platform Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add FlagScale-specific files that were missing from dev-train: - arguments_fs.py, extra_valid.py, fs_theoretical_memory_usage.py - spiky_loss.py, stablelm2_scheduler.py, peft/ - datasets/concated_indexed_dataset.py, datasets/sft_dataset_fs.py - tokenizer/rwkv_tokenization.py, tokenizer/tokenization_utils.py - SYNC_REPORT.md
…dd_argument calls Upstream core_v0.16.1 moved many manual add_argument calls to ArgumentGroupFactory (TransformerConfig, TrainingConfig, LoggerConfig, etc.). The three-way merge kept the old manual calls, causing argparse.ArgumentError: conflicting option string at runtime. Rebuilt arguments.py from upstream and re-applied FlagScale customizations: - imports: arguments_fs, platform abstraction - hetero parallelism support in validate_args - FFN hidden size with multiple_of/hidden_dim_multiplier - cur_platform.get_device_capability() for GroupedGEMM - engram config support - flagcx distributed backend - FlagScale tokenizer types Moved FlagScale-only arg (inference-wandb-logging-step-interval) to arguments_fs.py. Removed 6 args from arguments_fs.py that are now auto-generated by ArgumentGroupFactory(TransformerConfig): cpu-offloading-num-layers, fp8/fp4-quantizer-factory, moe-flex-dispatcher-backend, moe-hybridep-num-sms, moe-router-padding-for-quantization. Also removed duplicate muon-momentum (now in upstream).
…from arguments_fs.py These args are now auto-generated by ArgumentGroupFactory(TransformerConfig) via inheritance from ModelParallelConfig. Manual add_argument calls caused argparse.ArgumentError at runtime.
…ry exclude list Prevents duplicate CLI argument generation for fields now defined in TransformerConfig: use_dualpipev, moe_fb_overlap, te_fl_prefer, qk_layernorm_hidden_dim, recompute_*_per_stage_micro_batch, peft_type, lora_* fields.
…ramGroupOverride get_standard_config_overrides() returns ParamGroupOverride dicts which are incompatible with _get_param_groups() that expects OptimizerConfig dataclass instances. Reverted to old-style config_overrides construction using copy.deepcopy(config) for decoupled_lr support.
get_batch_on_this_tp_rank now returns 8 keys (added cu_seqlens, max_seqlen, local_cp_size) but forward_step only needs 5. Return explicit keys instead of batch.values().
All training YAMLs that had eval_iters but no eval_interval would crash with 'unsupported operand type(s) for //: int and NoneType' at training.py:3838 because args.eval_interval defaults to None. Fixed across: aquila, deepseek_v3, llava_onevision, qwen2_5, qwen2_5_vl, qwen3, qwen3_vl, qwq, robobrain_x0
Three-way merge of FlagScale patches (from pre-replacement commit e0c9233) onto upstream 0.17.0 base for all training/ and legacy/model/ files. Key merge decisions: - arguments.py: keep FlagScale args (hetero, auto_tune, flagcx, etc.) + upstream new args - checkpointing.py: keep platform plugin + upstream deletion process tracking - initialize.py: keep pre/post validate_args, spiky_loss; drop fused_kernels (removed in 0.17.0); use upstream init_persistent_async_worker(args.rank, 'forkserver') signature - training.py: combine auto_tune guard + upstream skip_train check; update cuda graph API names - utils.py: drop old cu_seqlens broadcast (removed upstream); keep optimizer config + has_nvrx - common_config.py: add flagcx to distributed_backend Literal - tokenizer/: restore FlagScale-patched tokenizer files (removed in 0.17.0, still needed) - legacy/model/: clean merges for all 7 files
…0.17.0 - Remove legacy_tokenizer: true from all training YAML configs - Update tokenizer imports: use megatron.training.tokenizer instead of megatron.core.tokenizers.text.utils - Simplify tokenizer logic: remove legacy_tokenizer branch in train_gpt/train_engram - Delete deprecated tokenizer files: bert_tokenization, multimodal_tokenizer, sft_tokenizer, tokenization_utils - Refactor tokenizer.py to be a thin FlagScale extension layer over upstream build_tokenizer - Update auto_tuner and global_vars imports
…0.17.0 - Remove old get_megatron_optimizer_config from utils.py (used MuonOptimizerConfig, shadowed by the upstream-aligned version in training.py) - Remove MuonOptimizerConfig/AdamOptimizerConfig/SGDOptimizerConfig/ParamKey imports from utils.py (not in upstream) - Remove _add_regularization_args from arguments_fs.py (--muon-matched-adamw-rms, --muon-ns-steps, --no-muon-nesterov duplicated/conflicted with upstream args) - Remove stale 'from megatron.training.utils import get_megatron_optimizer_config' from training.py Muon optimizer now fully uses upstream core 0.17.0 implementation via megatron.core.optimizer.muon with args defined in arguments.py.
…re_v0.17.0 - gpt_builders.py: add experimental_attention_variant handling, fix MTP logic to use get_gpt_decoder_layer_specs, preserve FlagScale hetero support - model_provider.py: update OOM observer to use torch.cuda.memory._dump_snapshot - train_gpt.py: full sync with upstream pretrain_gpt.py (packed seq, MTP, hybrid CP, FIM, startup timing, get_embedding_ranks) - train_aquila_sft.py, train_engram.py, train_qwen2_5_vl.py, train_qwen3_vl.py, train_robobrain_x0.py, train_rwkv.py: replace stale modelopt_args_enabled() with getattr(args, 'modelopt_enabled', False), add missing pretrain import
…actory dispatch - Rewrite tokenizer.py with _TOKENIZER_FACTORY_REGISTRY and register_tokenizer_factory() - Each FlagScale tokenizer type owns its special token definitions internally - build_tokenizer checks FlagScale registry first, falls through to upstream - Add unique_identifiers property to _FlagScaleTokenizerBase for dataset serialization - Update train_gpt.py to import build_tokenizer from FlagScale's shim - Verified: Qwen3-32b training completes 30 iterations successfully
…loss at iter 2 The upstream is_first_iteration flag sets should_reset=False for iteration 1, which prevents the advanced_iters counter from resetting. However, the loss tensor values were unconditionally zeroed after printing. This mismatch caused iteration 2 to report actual_loss/2 because the counter was 2 but only one iteration's loss was accumulated. Now both the loss tensor zeroing and the counter reset are conditional on should_reset, keeping them in sync.
…ipeline_layer_split The dataclass types in ModelParallelConfig (str for enable_hetero, bare list for hetero_pipeline_layer_split) are incompatible with ArgumentGroupFactory auto-generation. Add them to the exclude list and restore the original manual definitions (store_true for enable_hetero, nargs=* type=int for hetero_pipeline_layer_split). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…for hetero mode In validate_args, data_parallel_size and expert_tensor_parallel_size were being unconditionally recalculated from mesh-local TP/PP values, overwriting the correct values set by pre_validate_args in hetero mode. Guard both assignments with 'if not enable_hetero'. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- engram_builder.py: remove moe_use_legacy_grouped_gemm param and args - train_aquila_sft.py: remove moe_use_legacy_grouped_gemm from layer spec calls - arguments_fs.py: use getattr for moe_use_legacy_grouped_gemm assertion
…le training/models Replace hardcoded torch.cuda.* calls with megatron.plugin.platform abstraction (cur_platform) for multi-platform support (CUDA, NPU, MUSA). Files modified: - flagscale/train/processor/device_processor.py (is_available) - flagscale/train/utils/random_utils.py (is_available, get/set_rng_state) - flagscale/train/megatron/training/training.py (use_mem_pool, empty_cache) - flagscale/train/train_pi.py (current_device) - flagscale/models/megatron/engram/engram.py (Stream, stream, Event, etc.) - flagscale/models/megatron/engram/engram_model.py (Stream, stream, etc.) - flagscale/models/megatron/engram/multi_head_embedding.py (current_device, nvtx) - flagscale/models/megatron/qwen3_vl/language_model.py (current_device) - flagscale/models/megatron/qwen2_5_vl/tensor_parallel.py (current_device) Skipped: CUDA debug internals (memory._snapshot, check_error/cudart), docstring-only references, and commented-out lines.
aoyulong
reviewed
Apr 21, 2026
Contributor
There was a problem hiding this comment.
Should we delete this file?
GroupedMLP was removed in upstream core_r0.17.0 (replaced by TEGroupedMLP), so moe_use_legacy_grouped_gemm no longer exists as an arg. The getattr fallback always returned False, making this assertion dead code.
…anges - 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
zhaoyinglia
reviewed
Apr 22, 2026
| ######### FlagScale Begin ######### | ||
| # Use FlagScale's tokenizer shim which handles FlagScale-specific tokenizer | ||
| # types (QwenTokenizerFS, etc.) and delegates standard types to upstream. | ||
| from megatron.training.tokenizer import build_tokenizer |
Collaborator
There was a problem hiding this comment.
move from megatron.training.tokenizer import build_tokenizer to line 65, put “flagscale import” togather
| # In RL inference-only mode, train_iters must still be set despite having no optimizer. | ||
| if args.perform_rl_step: | ||
| update_train_iters(args) | ||
| else: | ||
| config, config_overrides = get_megatron_optimizer_config(args) |
Collaborator
There was a problem hiding this comment.
add if para_ctx is not None: banch
LiJunscs
reviewed
Apr 22, 2026
Collaborator
There was a problem hiding this comment.
All files of engram have no problem. LGTM
49f837c to
02cb070
Compare
| self.video_token = '<|video_pad|>' | ||
| self.vision_start_token = '<|vision_start|>' | ||
| self.vision_end_token = '<|vision_end|>' | ||
| class _Qwen2VLTokenizer(_FlagScaleTokenizerBase): |
Collaborator
There was a problem hiding this comment.
Only need to replace the class _Qwen2VLTokenizer(MegatronLegacyTokenizer): using class _Qwen2VLTokenizer(_FlagScaleTokenizerBase):. Otherwise, an error will be reported.
Without eval_interval, training.py crashes with TypeError when computing eval_samples: args.train_iters // args.eval_interval where eval_interval is None.
aoyulong
approved these changes
May 6, 2026
zhaoyinglia
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FlagScale Training Upgrade
Sync FlagScale training layer with upstream Megatron-LM core_r0.17.0. Key changes: