feat(model): add GLM-5.3-Flash support - #6044
Draft
HollowMan6 wants to merge 1 commit into
Draft
HollowMan6 wants to merge 1 commit into
HollowMan6 wants to merge 1 commit into
Conversation
Signed-off-by: Hollow Man <hollowman@opensuse.org>
8 tasks
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.
Pending on:
What does this PR do ?
Add HF ↔ Megatron support for GLM-5.3-Flash (
model_typeglm5_next,Glm5NextForConditionalGeneration): a unified bridge, provider, and VLM wrapper for its hybrid KDA/DSA + MoE + mHC language model with a replicated HF vision tower, plus the shared conversion, PEFT, and packed-sequence pieces it needs.Changelog
GLM-5.3-Flash (
src/megatron/bridge/models/glm5next/)GLM53FlashBridge,GLM53FlashModelProvider, andGLM53FlashModel, registered forGlm5NextForConditionalGenerationwithmodel_type="glm5_next"and exported frommegatron.bridge.models.hybrid_layer_patternfrom the HFlayer_types/mlp_layer_types: each HF decoder layer becomes two physical layers (KDAKor DSADattention at2N, dense-or MoEEFFN at2N+1), withmoe_layer_freqderived per physical module andnum_hidden_layersrecovered from the pattern on export.qk_pos_emb_head_dim=0,kv_channels=v_head_dim), the kpool DSA indexer (FP8 kpool;index_kpool/index_kpool_always_select_tailread from the HF config), KDA two-stage low-rank gates withgate_lower_bound, mHC multi-stream hyper-connections with fp32 mappings, sigmoid routing with expert bias and an always-on shared expert (moe_shared_expert_gate=False), grouped GEMM with the HybridEP flex dispatcher, and a one-layerDEMTP using the repeated-layer spec.in_proj/conv1dbuilt from separate HF Q/K/V tensors with section-wise TP sharding (_ColumnParallelConcatMapping), MLA projections and indexer weights, dense and MoE FFN (grouped-GEMM and sequential expert layouts), mHChc_{attn,ffn}_{fn,base,scale}, and the MTPeh_projsplit intoe_proj/h_proj(_EhProjSplitMapping, import only).Glm5NextVisionModelon pre-process ranks, image/video features scattered into the embeddings before THD packing and the sequence-parallel scatter, text-only fallback when no pixel inputs are given, andfreeze_{language_model,vision_model,vision_projection}options.Hybrid providers
HybridMLAModelProvider(HybridModelProvider+MLATransformerConfig). Withpipeline_model_parallel_size > 1and DSA layers in the pattern, it inserts balanced|separators only before full-indexer DSA layers so IndexShare groups never cross a stage, validates user-provided separators, and rejectsnum_layers_in_first/last_pipeline_stage.scatter_embedding_sequence_paralleltoHybridModelProvider(defaultTrue, matchingHybridModel) and pass it through; the VLM provider sets it toFalseso vision features are injected before the SP scatter.Shared conversion infrastructure
HCAlphaMapping, mapping an HF[3]hc_*_scaletensor to Megatron'salpha_pre/alpha_post/alpha_res(index 0 exports all three), and migrateDeepSeekV4Bridgefrom its private_HCAlphaMapping/_HCAlphaSecondaryMappingto it with equivalent import/export behavior.InitOnlyMappingfor Megatron params with no HF counterpart (import keeps init, export is a no-op).MegatronModelBridge._prefix_mapping_registryto re-key a text-model registry under a VLM prefix while keeping nested_tp_mappingnames in sync.PEFT
in_projLoRAlinear_outweights by Q/K/V section sizes whenkda_two_stage_gatesis set, instead of the GQA-stylesplit_qkv_weightspath, so KDA LoRA adapters export correctly.Packed sequences
preprocess_packed_seqsfrommodels/qwen_vl/modelling_qwen3_vl/utils.pytotraining/utils/packed_seq_utils.py(shared by Qwen3-VL and GLM-5.3-Flash) and adduse_fp8_padding, which aligns each sequence tolcm(16, align)and the packed total toalign * 128.Tests
tests/unit_tests/models/glm5next/test_glm53flash_mapping.py: provider precision contract and multimodal config copy,language_model.prefixing of text mappings,HCAlphaMappingimport/export and wildcard resolution, section-wise KDA TP sharding round-trips (TP 1 to 16).tests/unit_tests/models/qwen_vl/modelling_qwen3_vl/test_utils.py: packed-sequence alignment and gradient flow with and without FP8 padding.tests/unit_tests/models/test_model_bridge_lora.py: KDA Q/K/V LoRAlinear_outsplit.GitHub Actions CI
See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
Glm5NextForConditionalGenerationis imported behind atry/exceptthat falls back to the class name,Glm5NextModel/Glm5NextVisionModelare imported lazily insideGLM53FlashModel.__init__, and the new unit tests usepytest.importorskipon the GLM-5.3-Flash config module.Additional Information
glm5_nextmodel family ships in transformers v5.17.0;pyproject.tomlcurrently pinstransformers<=5.15.0, so on the pinned version the bridge only resolves by class name, the VLM wrapper cannot be instantiated, and the new unit tests are skipped. The pin bump should go in a separatebuild:PR per the contributing guide.preprocess_packed_seqsmoved without a compatibility re-export from its old Qwen3-VL module.docs/models/glm/page and README / docs model tables, recipes and examples, verification card, and a functional HF ↔ Megatron round-trip test.