KitsuVp commited on
Commit
9658d5e
·
verified ·
1 Parent(s): 34f5c41

Update configuration_neollm.py

Browse files
Files changed (1) hide show
  1. configuration_neollm.py +97 -100
configuration_neollm.py CHANGED
@@ -194,13 +194,36 @@ class NeoLLMConfig(PretrainedConfig):
194
  tied input/output embeddings and for the Leviathan generator path so
195
  it does not break parameter sharing or wrap a non-matrix generator.
196
  use_seednorm (:obj:`bool`, *optional*, defaults to ``True``):
197
- Use SeeDNorm as the model's main Transformer normalisation operator.
198
- When ``True``, the pre-attention, pre-MLP, final and Q/K
199
- normalisations use ``SeeDNorm``. When ``False``, those same backbone
200
- normalisation sites instantiate standard ``nn.RMSNorm`` instead,
201
- removing SeeDNorm's ``alpha`` and ``beta`` parameters and dynamic
202
- rescaling path. MEA output normalisation is controlled separately by
203
  ``mea_norm_type``.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  use_embedding_input_norm (:obj:`bool`, *optional*, defaults to ``True``):
205
  Controls only the first pre-attention normalisation applied to the
206
  raw embedding stream. When ``True``, layer 0 instantiates and applies
@@ -363,50 +386,6 @@ class NeoLLMConfig(PretrainedConfig):
363
  Reference: Rabe, Clymo & Dong (2026). *Spelling Bee Embeddings for
364
  Language Modeling.* arXiv:2601.18030.
365
 
366
- use_yurii_spelling_velocity (:obj:`bool`, *optional*, defaults to ``False``):
367
- Enable the price-quality YuriiFormer × Spelling Bee variant used in
368
- ``modeling_neollm.py``. The original Spelling Bee embedding is kept
369
- unchanged:
370
-
371
- .. math::
372
- X_0(t)=\frac{1}{2}\left(E_{\text{tok}}[t]+S_x(t)\right)
373
-
374
- and an additional byte table builds a spelling-only velocity seed:
375
-
376
- .. math::
377
- V_0(t)=\frac{\lambda_v}{2}\left(S_x(t)+S_v(t)\right)
378
-
379
- where ``S_x`` is the existing Spelling Bee character embedding and
380
- ``S_v`` is built from a new ``256 × hidden_size`` byte table. The
381
- decoder then uses the Nesterov + Lie--Trotter update from
382
- YuriiFormer, the article's best loss/price variant because it keeps
383
- one attention call and one MLP call per block while adding only a
384
- velocity stream, learned scalar coefficients and velocity LayerNorms.
385
- This avoids YuriiFormer's full vocabulary velocity table
386
- ``vocab_size × hidden_size``.
387
-
388
- Requires ``use_spelling_bee_embeddings=True`` because the velocity
389
- branch intentionally reuses the original Spelling Bee spelling table
390
- ``S_x`` instead of replacing it.
391
-
392
- yurii_spelling_velocity_scale (:obj:`float`, *optional*, defaults to ``0.10``):
393
- Multiplicative scale ``λ_v`` applied to the initial spelling
394
- velocity. Keep this small when combining with the original SBE path
395
- because ``S_x`` contributes to both ``X_0`` and ``V_0``.
396
-
397
- yurii_mu_init (:obj:`float`, *optional*, defaults to ``0.50``):
398
- Initial value for the learned Nesterov lookahead coefficients
399
- ``μ`` in the attention and MLP substeps. Stored as logits and
400
- constrained to ``(0, 1)`` during forward.
401
-
402
- yurii_beta_init (:obj:`float`, *optional*, defaults to ``0.90``):
403
- Initial value for the learned velocity carry coefficients ``β``.
404
- Stored as logits and constrained to ``(0, 1)`` during forward.
405
-
406
- yurii_gamma_init (:obj:`float`, *optional*, defaults to ``1.00``):
407
- Initial value for the positive learned oracle scale coefficients
408
- ``γ``. Stored through an inverse-softplus parameterization.
409
-
410
  use_hadamard_o_proj (:obj:`bool`, *optional*, defaults to ``False``):
411
  Replace the dense ``W_O ∈ R^{d×d}`` output projection in every
412
  multi-head attention block with a fixed Walsh–Hadamard Transform
@@ -567,17 +546,13 @@ class NeoLLMConfig(PretrainedConfig):
567
  - ``use_spelling_bee_embeddings=True`` requires calling
568
  ``model.model.spelling_bee.set_byte_table(tokenizer)`` before
569
  training (handled automatically by ``setup_model``).
570
- - ``use_yurii_spelling_velocity=True`` requires
571
- ``use_spelling_bee_embeddings=True`` and uses the same tokenizer byte
572
- table through ``model.model.spelling_bee``. It is mutually exclusive
573
- with DCA, AttnRes, LAuReL and StackMemory because it changes the
574
- residual update rule into a two-stream YuriiFormer update.
575
  - ``repo_start_layer`` must satisfy
576
  ``0 <= repo_start_layer < num_hidden_layers`` when
577
  ``use_repo=True``, ``use_repo_grape=True`` or
578
  ``use_repo_goat_prior=True``.
579
- - At most one of ``use_dca=True``, ``use_laurel=True``, ``use_attn_res=True`` or
580
- ``use_stack_memory=True`` may be active.
 
581
  - When ``use_laurel=True``, at least one of ``use_laurel_rw`` or
582
  ``use_laurel_lr`` must be ``True``.
583
  - ``stack_d_model`` must be divisible by ``num_mem_heads`` when
@@ -627,6 +602,9 @@ class NeoLLMConfig(PretrainedConfig):
627
  ... )
628
 
629
  References:
 
 
 
630
  Bae, J. et al. (2026). *Affine-Scaled Attention: Towards Flexible and
631
  Stable Transformer Attention.* arXiv:2602.23057.
632
 
@@ -723,6 +701,10 @@ class NeoLLMConfig(PretrainedConfig):
723
  use_embedding_multipliers=False,
724
  # ── Normalization controls ────────────────────────────────────────
725
  use_seednorm=False,
 
 
 
 
726
  # ── Embedding input normalization ─────────────────────────────────
727
  use_embedding_input_norm=True,
728
  # ── Leviathan continuous token generator ──────────────────────────
@@ -747,12 +729,6 @@ class NeoLLMConfig(PretrainedConfig):
747
  polynorm_exclusive=False,
748
  # ── Spelling Bee Embeddings (Rabe et al., 2026) ───────────────────
749
  use_spelling_bee_embeddings=True,
750
- # ── YuriiFormer × Spelling Bee velocity seed (Zimin et al., 2026) ──
751
- use_yurii_spelling_velocity=True,
752
- yurii_spelling_velocity_scale=0.03,
753
- yurii_mu_init=0.25,
754
- yurii_beta_init=0.70,
755
- yurii_gamma_init=0.5,
756
  # ── Context Re-Positioning (Li et al., 2026) ──────────────────────
757
  use_repo=True,
758
  repo_start_layer=None,
@@ -782,6 +758,50 @@ class NeoLLMConfig(PretrainedConfig):
782
  iha_sliding_window=None, # auto = N // (2*P^2) usando la longitud real del batch
783
  **kwargs,
784
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785
  # ── Generator / tying consistency ─────────────────────────────────
786
  if use_token_generator and tie_word_embeddings:
787
  logger.warning(
@@ -831,30 +851,6 @@ class NeoLLMConfig(PretrainedConfig):
831
  f"got jtokm_top_k={jtokm_top_k}, jtokm_num_experts={jtokm_num_experts}."
832
  )
833
 
834
- # ── YuriiFormer × Spelling Bee velocity consistency ───────────────
835
- if use_yurii_spelling_velocity and not use_spelling_bee_embeddings:
836
- raise ValueError(
837
- "`use_yurii_spelling_velocity=True` requires "
838
- "`use_spelling_bee_embeddings=True`. The velocity seed is "
839
- "defined as V0 = λ/2 · (S_x + S_v), so the original Spelling "
840
- "Bee character table S_x must remain active."
841
- )
842
- if yurii_spelling_velocity_scale < 0.0:
843
- raise ValueError(
844
- f"`yurii_spelling_velocity_scale` must be >= 0, "
845
- f"got {yurii_spelling_velocity_scale}."
846
- )
847
- for _name, _value in {
848
- "yurii_mu_init": yurii_mu_init,
849
- "yurii_beta_init": yurii_beta_init,
850
- }.items():
851
- if not (0.0 < float(_value) < 1.0):
852
- raise ValueError(f"`{_name}` must satisfy 0 < value < 1, got {_value}.")
853
- if float(yurii_gamma_init) <= 0.0:
854
- raise ValueError(
855
- f"`yurii_gamma_init` must be > 0, got {yurii_gamma_init}."
856
- )
857
-
858
  # ── DCA: validate k-DCA source selection ──────────────────────────
859
  if use_dca and dca_past_layers_k < 1:
860
  raise ValueError(
@@ -937,22 +933,23 @@ class NeoLLMConfig(PretrainedConfig):
937
  )
938
 
939
  # ── Residual-flow mechanism mutex ─────────────────────────────────
940
- # DCA, AttnRes, LAuReL and StackMemory all alter cross-layer residual
941
- # routing during training. Keep exactly one experimental residual-flow
942
- # mechanism active at a time so ablations remain interpretable.
 
943
  _residual_flow_flags = {
944
  "use_dca": bool(use_dca),
945
  "use_laurel": bool(use_laurel),
946
  "use_attn_res": bool(use_attn_res),
947
  "use_stack_memory": bool(use_stack_memory),
948
- "use_yurii_spelling_velocity": bool(use_yurii_spelling_velocity),
949
  }
950
  _active_residual_flow = [name for name, enabled in _residual_flow_flags.items() if enabled]
951
  if len(_active_residual_flow) > 1:
952
  raise ValueError(
953
  "Enable at most one residual-flow mechanism among "
954
  "`use_dca`, `use_laurel`, `use_attn_res`, `use_stack_memory`, "
955
- "and `use_yurii_spelling_velocity`. "
956
  f"Active flags: {_active_residual_flow}."
957
  )
958
 
@@ -1058,7 +1055,14 @@ class NeoLLMConfig(PretrainedConfig):
1058
  self.use_embedding_multipliers = use_embedding_multipliers
1059
 
1060
  # ── Normalization controls ────────────────────────────────────────
1061
- self.use_seednorm = bool(use_seednorm)
 
 
 
 
 
 
 
1062
 
1063
  # ── Embedding input normalization ─────────────────────────────────
1064
  # True preserves the previous layer-0 pre-norm path, using the active
@@ -1096,13 +1100,6 @@ class NeoLLMConfig(PretrainedConfig):
1096
  # ── Spelling Bee Embeddings (Rabe et al., 2026) ───────────────────
1097
  self.use_spelling_bee_embeddings = use_spelling_bee_embeddings
1098
 
1099
- # ── YuriiFormer × Spelling Bee velocity seed (Zimin et al., 2026) ──
1100
- self.use_yurii_spelling_velocity = bool(use_yurii_spelling_velocity)
1101
- self.yurii_spelling_velocity_scale = float(yurii_spelling_velocity_scale)
1102
- self.yurii_mu_init = float(yurii_mu_init)
1103
- self.yurii_beta_init = float(yurii_beta_init)
1104
- self.yurii_gamma_init = float(yurii_gamma_init)
1105
-
1106
  # ── Context Re-Positioning (Li et al., 2026) ──────────────────────
1107
  self.use_repo = use_repo
1108
  self.repo_start_layer = repo_start_layer
 
194
  tied input/output embeddings and for the Leviathan generator path so
195
  it does not break parameter sharing or wrap a non-matrix generator.
196
  use_seednorm (:obj:`bool`, *optional*, defaults to ``True``):
197
+ Backward-compatible boolean selector for the model's main
198
+ Transformer normalisation operator. When ``norm_type`` is left as
199
+ ``None``, ``use_seednorm=True`` resolves to ``norm_type="seednorm"``
200
+ and ``use_seednorm=False`` resolves to ``norm_type="rmsnorm"``.
201
+ MEA output normalisation is still controlled separately by
 
202
  ``mea_norm_type``.
203
+ norm_type (:obj:`str`, *optional*):
204
+ Main normalisation topology. Valid values are ``"seednorm"``,
205
+ ``"rmsnorm"`` and ``"siamesenorm"``. ``"seednorm"`` and
206
+ ``"rmsnorm"`` keep the original single-stream Pre-Norm topology.
207
+ ``"siamesenorm"`` activates the two-stream SiameseNorm topology
208
+ from Li et al. (2026): an X stream with Hybrid/Post-like scaled
209
+ residual updates and a Y stream with Pre-Norm-like identity
210
+ accumulation. The heavy Attention/MLP modules are shared.
211
+ use_siamesenorm (:obj:`bool`, *optional*, defaults to ``False``):
212
+ Convenience flag. When ``True``, it forces
213
+ ``norm_type="siamesenorm"``. This flag exists so training scripts can
214
+ turn SiameseNorm on without also changing the legacy
215
+ ``use_seednorm`` field.
216
+ siamese_norm_base_type (:obj:`str`, *optional*, defaults to ``"rmsnorm"``):
217
+ Local normaliser used inside the SiameseNorm streams. The paper
218
+ treats LN generically and the released OLMo configs use RMS-style
219
+ normalization, so ``"rmsnorm"`` is the default. ``"seednorm"`` is
220
+ allowed for NeoLLM ablations, but it is not the paper-faithful
221
+ baseline.
222
+ siamese_depth_scaling (:obj:`bool`, *optional*, defaults to ``True``):
223
+ Apply the paper's depth-wise residual scaling to the X stream:
224
+ residual updates are divided by
225
+ ``sqrt(2 * (layer_idx + 1))``. The Y stream keeps the clean
226
+ unscaled Pre-Norm residual update.
227
  use_embedding_input_norm (:obj:`bool`, *optional*, defaults to ``True``):
228
  Controls only the first pre-attention normalisation applied to the
229
  raw embedding stream. When ``True``, layer 0 instantiates and applies
 
386
  Reference: Rabe, Clymo & Dong (2026). *Spelling Bee Embeddings for
387
  Language Modeling.* arXiv:2601.18030.
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  use_hadamard_o_proj (:obj:`bool`, *optional*, defaults to ``False``):
390
  Replace the dense ``W_O ∈ R^{d×d}`` output projection in every
391
  multi-head attention block with a fixed Walsh–Hadamard Transform
 
546
  - ``use_spelling_bee_embeddings=True`` requires calling
547
  ``model.model.spelling_bee.set_byte_table(tokenizer)`` before
548
  training (handled automatically by ``setup_model``).
 
 
 
 
 
549
  - ``repo_start_layer`` must satisfy
550
  ``0 <= repo_start_layer < num_hidden_layers`` when
551
  ``use_repo=True``, ``use_repo_grape=True`` or
552
  ``use_repo_goat_prior=True``.
553
+ - At most one of ``use_dca=True``, ``use_laurel=True``,
554
+ ``use_attn_res=True``, ``use_stack_memory=True`` or
555
+ ``use_siamesenorm=True`` may be active.
556
  - When ``use_laurel=True``, at least one of ``use_laurel_rw`` or
557
  ``use_laurel_lr`` must be ``True``.
558
  - ``stack_d_model`` must be divisible by ``num_mem_heads`` when
 
602
  ... )
603
 
604
  References:
605
+ Li, T. et al. (2026). *SiameseNorm: Breaking the Barrier to
606
+ Reconciling Pre/Post-Norm.* arXiv:2602.08064.
607
+
608
  Bae, J. et al. (2026). *Affine-Scaled Attention: Towards Flexible and
609
  Stable Transformer Attention.* arXiv:2602.23057.
610
 
 
701
  use_embedding_multipliers=False,
702
  # ── Normalization controls ────────────────────────────────────────
703
  use_seednorm=False,
704
+ norm_type=None,
705
+ use_siamesenorm=True,
706
+ siamese_norm_base_type="rmsnorm",
707
+ siamese_depth_scaling=True,
708
  # ── Embedding input normalization ─────────────────────────────────
709
  use_embedding_input_norm=True,
710
  # ── Leviathan continuous token generator ──────────────────────────
 
729
  polynorm_exclusive=False,
730
  # ── Spelling Bee Embeddings (Rabe et al., 2026) ───────────────────
731
  use_spelling_bee_embeddings=True,
 
 
 
 
 
 
732
  # ── Context Re-Positioning (Li et al., 2026) ──────────────────────
733
  use_repo=True,
734
  repo_start_layer=None,
 
758
  iha_sliding_window=None, # auto = N // (2*P^2) usando la longitud real del batch
759
  **kwargs,
760
  ):
761
+ # ── Normalization topology resolution ─────────────────────────────
762
+ def _canon_norm_name(value, *, allow_siamese: bool) -> str:
763
+ raw = str(value).lower().replace("_", "").replace("-", "")
764
+ aliases = {
765
+ "rms": "rmsnorm",
766
+ "rmsnorm": "rmsnorm",
767
+ "seed": "seednorm",
768
+ "seednorm": "seednorm",
769
+ "seeednorm": "seednorm",
770
+ "siamese": "siamesenorm",
771
+ "siamesenorm": "siamesenorm",
772
+ }
773
+ out = aliases.get(raw)
774
+ valid = {"seednorm", "rmsnorm"} | ({"siamesenorm"} if allow_siamese else set())
775
+ if out not in valid:
776
+ raise ValueError(
777
+ f"Invalid normalization type {value!r}. Valid values are "
778
+ f"{sorted(valid)}."
779
+ )
780
+ return out
781
+
782
+ if norm_type is None:
783
+ norm_type = (
784
+ "siamesenorm"
785
+ if bool(use_siamesenorm)
786
+ else ("seednorm" if bool(use_seednorm) else "rmsnorm")
787
+ )
788
+ norm_type = _canon_norm_name(norm_type, allow_siamese=True)
789
+ if bool(use_siamesenorm) and norm_type != "siamesenorm":
790
+ logger.warning(
791
+ "`use_siamesenorm=True` overrides `norm_type=%s`; "
792
+ "using `norm_type='siamesenorm'`.",
793
+ norm_type,
794
+ )
795
+ norm_type = "siamesenorm"
796
+ use_siamesenorm = norm_type == "siamesenorm"
797
+ siamese_norm_base_type = _canon_norm_name(siamese_norm_base_type, allow_siamese=False)
798
+ if use_siamesenorm and not use_embedding_input_norm:
799
+ logger.warning(
800
+ "`norm_type='siamesenorm'` is enabled with "
801
+ "`use_embedding_input_norm=False`. The best SiameseNorm ablation "
802
+ "uses normalized fused inputs; keep this False only for ablation."
803
+ )
804
+
805
  # ── Generator / tying consistency ─────────────────────────────────
806
  if use_token_generator and tie_word_embeddings:
807
  logger.warning(
 
851
  f"got jtokm_top_k={jtokm_top_k}, jtokm_num_experts={jtokm_num_experts}."
852
  )
853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  # ── DCA: validate k-DCA source selection ──────────────────────────
855
  if use_dca and dca_past_layers_k < 1:
856
  raise ValueError(
 
933
  )
934
 
935
  # ── Residual-flow mechanism mutex ─────────────────────────────────
936
+ # DCA, AttnRes, LAuReL, StackMemory and SiameseNorm all alter
937
+ # cross-layer residual routing during training. Keep exactly one
938
+ # residual-flow mechanism active at a time so ablations remain
939
+ # interpretable and the Siamese two-stream invariant stays intact.
940
  _residual_flow_flags = {
941
  "use_dca": bool(use_dca),
942
  "use_laurel": bool(use_laurel),
943
  "use_attn_res": bool(use_attn_res),
944
  "use_stack_memory": bool(use_stack_memory),
945
+ "use_siamesenorm": bool(use_siamesenorm),
946
  }
947
  _active_residual_flow = [name for name, enabled in _residual_flow_flags.items() if enabled]
948
  if len(_active_residual_flow) > 1:
949
  raise ValueError(
950
  "Enable at most one residual-flow mechanism among "
951
  "`use_dca`, `use_laurel`, `use_attn_res`, `use_stack_memory`, "
952
+ "and `use_siamesenorm`. "
953
  f"Active flags: {_active_residual_flow}."
954
  )
955
 
 
1055
  self.use_embedding_multipliers = use_embedding_multipliers
1056
 
1057
  # ── Normalization controls ────────────────────────────────────────
1058
+ self.norm_type = norm_type
1059
+ self.use_siamesenorm = bool(use_siamesenorm)
1060
+ self.siamese_norm_base_type = siamese_norm_base_type
1061
+ self.siamese_depth_scaling = bool(siamese_depth_scaling)
1062
+ # Backward-compatible legacy field. It stays true only for the
1063
+ # single-stream SeeDNorm topology; SiameseNorm reads
1064
+ # ``siamese_norm_base_type`` instead.
1065
+ self.use_seednorm = norm_type == "seednorm"
1066
 
1067
  # ── Embedding input normalization ─────────────────────────────────
1068
  # True preserves the previous layer-0 pre-norm path, using the active
 
1100
  # ── Spelling Bee Embeddings (Rabe et al., 2026) ───────────────────
1101
  self.use_spelling_bee_embeddings = use_spelling_bee_embeddings
1102
 
 
 
 
 
 
 
 
1103
  # ── Context Re-Positioning (Li et al., 2026) ──────────────────────
1104
  self.use_repo = use_repo
1105
  self.repo_start_layer = repo_start_layer