@@ -495,6 +495,30 @@ class ArchitectureConfig(BaseModelConfig):
495495 swiglu_limit : float = 0.0
496496 num_nextn_predict_layers : int = 0
497497
498+ # GLM-5.2 (``glm_moe_dsa``) DeepSeek Sparse Attention (DSA).
499+ #
500+ # ``use_dsa`` is not an upstream HF field -- it is a Mobius export-time
501+ # toggle (default True) flipped to False by ``--glm-full-attention`` /
502+ # ``config_overrides={"use_dsa": False}`` to fall back to plain dense MLA
503+ # (reusing ``DeepSeekV3TextModel`` unchanged) on runtimes that cannot yet
504+ # execute ``pkg.nxrt::IndexShare``.
505+ use_dsa : bool = True
506+ # Per-layer indexer schedule ("full" runs the indexer; "shared" reuses the
507+ # top-k selection from the closest preceding "full" layer). When the
508+ # checkpoint config omits this list, it is derived from
509+ # ``index_topk_freq`` / ``index_skip_topk_offset`` -- see
510+ # ``mobius.models.glm_moe_dsa._indexer_types``, which mirrors HF
511+ # ``GlmMoeDsaConfig.__post_init__`` exactly.
512+ indexer_types : list [str ] | None = None
513+ index_topk_freq : int | None = None
514+ index_skip_topk_offset : int | None = None
515+ indexer_rope_interleave : bool = False
516+ # Whether the (currently unexported, see ``glm_moe_dsa.py``) MTP layer is
517+ # meant to reuse the target's shared top-k indices rather than running its
518+ # own indexer pass. Recorded for round-tripping/documentation; not yet
519+ # acted on since MTP export itself is out of scope this cycle.
520+ index_share_for_mtp_iteration : bool = False
521+
498522 # Vision shared fields (accessed as top-level config.X by tasks)
499523 mm_tokens_per_image : int | None = None
500524 image_token_id : int | None = None
@@ -897,8 +921,20 @@ def from_transformers(cls, config, parent_config=None) -> ArchitectureConfig:
897921 n_group = getattr (config , "n_group" , 1 ),
898922 topk_group = getattr (config , "topk_group" , 1 ),
899923 routed_scaling_factor = getattr (config , "routed_scaling_factor" , 1.0 ),
900- scoring_func = getattr (config , "scoring_func" , "softmax" ),
901- topk_method = getattr (config , "topk_method" , "greedy" ),
924+ # ``scoring_func``/``topk_method`` are not real HF dataclass
925+ # fields on ``GlmMoeDsaConfig`` -- transformers hardcodes
926+ # sigmoid + e_score_correction_bias + (degenerate, n_group=1)
927+ # top-k routing for GLM-5.2 rather than exposing it as a config
928+ # knob. A checkpoint that omits these keys entirely (unlike the
929+ # real zai-org/GLM-5.2 config.json, which sets them explicitly)
930+ # would otherwise silently default to the wrong (softmax/greedy)
931+ # DeepSeek-V2 routing.
932+ scoring_func = getattr (
933+ config , "scoring_func" , "sigmoid" if model_type == "glm_moe_dsa" else "softmax"
934+ ),
935+ topk_method = getattr (
936+ config , "topk_method" , "noaux_tc" if model_type == "glm_moe_dsa" else "greedy"
937+ ),
902938 first_k_dense_replace = getattr (config , "first_k_dense_replace" , 0 ),
903939 n_shared_experts = getattr (config , "n_shared_experts" , None ),
904940 # Multi-head Latent Attention (MLA)
@@ -927,6 +963,21 @@ def from_transformers(cls, config, parent_config=None) -> ArchitectureConfig:
927963 ),
928964 swiglu_limit = getattr (config , "swiglu_limit" , 0.0 ),
929965 num_nextn_predict_layers = getattr (config , "num_nextn_predict_layers" , 0 ),
966+ # GLM-5.2 DSA. ``use_dsa`` has no HF equivalent -- every checkpoint
967+ # defaults to the sparse path; ``--glm-full-attention`` overrides
968+ # it afterwards via ``dataclasses.replace``/``config_overrides``.
969+ use_dsa = getattr (config , "use_dsa" , True ),
970+ indexer_types = (
971+ list (config .indexer_types )
972+ if getattr (config , "indexer_types" , None ) is not None
973+ else None
974+ ),
975+ index_topk_freq = getattr (config , "index_topk_freq" , None ),
976+ index_skip_topk_offset = getattr (config , "index_skip_topk_offset" , None ),
977+ indexer_rope_interleave = getattr (config , "indexer_rope_interleave" , False ),
978+ index_share_for_mtp_iteration = getattr (
979+ config , "index_share_for_mtp_iteration" , False
980+ ),
930981 # Encoder-specific
931982 type_vocab_size = getattr (config , "type_vocab_size" , 0 ),
932983 # Encoder-decoder
0 commit comments