KitsuVp commited on
Commit
64480ae
·
verified ·
1 Parent(s): dc6436c

Update configuration_neollm.py

Browse files
Files changed (1) hide show
  1. configuration_neollm.py +59 -4
configuration_neollm.py CHANGED
@@ -518,6 +518,34 @@ class NeoLLMConfig(PretrainedConfig):
518
  (paper §3.3). Ignored when ``use_laurel=False`` or
519
  ``use_laurel_lr=False``.
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  Constraints:
522
  - ``use_jtokm=True`` requires ``use_token_generator=True``.
523
  - ``1 ≤ jtokm_top_k < jtokm_num_experts`` when ``use_jtokm=True``.
@@ -714,6 +742,12 @@ class NeoLLMConfig(PretrainedConfig):
714
  use_laurel_rw=False,
715
  use_laurel_lr=False,
716
  laurel_lr_rank=32,
 
 
 
 
 
 
717
  # ── NITP: Next Implicit Token Prediction (Zhang et al., 2026) ─────
718
  use_nitp=False,
719
  nitp_target_layer=None,
@@ -924,6 +958,22 @@ class NeoLLMConfig(PretrainedConfig):
924
  "Set `use_laurel_rw=True` and/or `use_laurel_lr=True`."
925
  )
926
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
927
  # ── NITP: resolve paper-faithful defaults and validate ────────────
928
  # Zhang et al. (2026) select a shallow contextualized target layer
929
  # around 20% of total depth, use cosine loss, stop-gradient targets,
@@ -961,9 +1011,7 @@ class NeoLLMConfig(PretrainedConfig):
961
  # graph-output error seen with NITP because both auxiliary branches
962
  # share final hidden states with the CCE path.
963
  if int(nextlat_horizon) < 1:
964
- raise ValueError(
965
- f"`nextlat_horizon` must be >= 1, got {nextlat_horizon}."
966
- )
967
  if nextlat_mse_weight < 0.0:
968
  raise ValueError(
969
  f"`nextlat_mse_weight` must be >= 0, got {nextlat_mse_weight}."
@@ -1131,6 +1179,13 @@ class NeoLLMConfig(PretrainedConfig):
1131
  self.use_laurel_lr = use_laurel_lr
1132
  self.laurel_lr_rank = laurel_lr_rank
1133
 
 
 
 
 
 
 
 
1134
  # ── NITP: Next Implicit Token Prediction ─────────────────────────
1135
  self.use_nitp = bool(use_nitp)
1136
  self.nitp_target_layer = int(nitp_target_layer)
@@ -1184,4 +1239,4 @@ class NeoLLMConfig(PretrainedConfig):
1184
  }
1185
 
1186
 
1187
- __all__ = ["NeoLLMConfig"]
 
518
  (paper §3.3). Ignored when ``use_laurel=False`` or
519
  ``use_laurel_lr=False``.
520
 
521
+ use_tweo (:obj:`bool`, *optional*, defaults to ``False``):
522
+ Enable Transformers Without Extreme Outliers (TWEO), a
523
+ training-only activation regularizer from Liang et al. (2026).
524
+ TWEO adds a scaled :math:`L_p` penalty over the final output
525
+ activations of every Transformer block:
526
+
527
+ .. math::
528
+ L_{total} = L_{task} + \lambda L_{TWEO}, \quad
529
+ L_{TWEO} = \frac{1}{L}\sum_l
530
+ \mathbb{E}\left[\left(\frac{|A^{(l)}|}
531
+ {\tau + \epsilon}\right)^p\right]
532
+
533
+ This is non-invasive: no architecture, inference path, or
534
+ quantization backend is changed. It is intended for FP8/low-bit
535
+ training runs where extreme activation outliers are harmful.
536
+ tweo_loss_weight (:obj:`float`, *optional*, defaults to ``0.01``):
537
+ Weight :math:`\lambda` applied to the TWEO regularizer. The paper
538
+ uses ``0.01`` in its experiments, optionally with schedule control
539
+ outside the model.
540
+ tweo_tau (:obj:`float`, *optional*, defaults to ``3.0``):
541
+ Soft activation magnitude scale :math:`\tau`. The paper reports
542
+ robust results for :math:`\tau \in [2, 5]` and defaults to ``3``.
543
+ tweo_power (:obj:`float`, *optional*, defaults to ``4.0``):
544
+ Power :math:`p` for the non-linear TWEO penalty. ``4`` preserves
545
+ small activations while sharply penalizing extreme outliers.
546
+ tweo_eps (:obj:`float`, *optional*, defaults to ``1e-6``):
547
+ Numerical stability epsilon added to the TWEO denominator.
548
+
549
  Constraints:
550
  - ``use_jtokm=True`` requires ``use_token_generator=True``.
551
  - ``1 ≤ jtokm_top_k < jtokm_num_experts`` when ``use_jtokm=True``.
 
742
  use_laurel_rw=False,
743
  use_laurel_lr=False,
744
  laurel_lr_rank=32,
745
+ # ── TWEO: Transformers Without Extreme Outliers (Liang et al., 2026)
746
+ use_tweo=False,
747
+ tweo_loss_weight=0.01,
748
+ tweo_tau=3.0,
749
+ tweo_power=4.0,
750
+ tweo_eps=1e-6,
751
  # ── NITP: Next Implicit Token Prediction (Zhang et al., 2026) ─────
752
  use_nitp=False,
753
  nitp_target_layer=None,
 
958
  "Set `use_laurel_rw=True` and/or `use_laurel_lr=True`."
959
  )
960
 
961
+ # ── TWEO: resolve paper-faithful defaults and validate ────────────
962
+ # Liang et al. (2026) regularize final output activations from all
963
+ # Transformer blocks with mean((abs(A) / (tau + eps)) ** p). The paper
964
+ # uses tau=3, p=4, lambda=0.01 and leaves scheduling of lambda(t) to
965
+ # the training loop.
966
+ if tweo_loss_weight < 0.0:
967
+ raise ValueError(
968
+ f"`tweo_loss_weight` must be >= 0, got {tweo_loss_weight}."
969
+ )
970
+ if tweo_tau <= 0.0:
971
+ raise ValueError(f"`tweo_tau` must be > 0, got {tweo_tau}.")
972
+ if tweo_power <= 0.0:
973
+ raise ValueError(f"`tweo_power` must be > 0, got {tweo_power}.")
974
+ if tweo_eps < 0.0:
975
+ raise ValueError(f"`tweo_eps` must be >= 0, got {tweo_eps}.")
976
+
977
  # ── NITP: resolve paper-faithful defaults and validate ────────────
978
  # Zhang et al. (2026) select a shallow contextualized target layer
979
  # around 20% of total depth, use cosine loss, stop-gradient targets,
 
1011
  # graph-output error seen with NITP because both auxiliary branches
1012
  # share final hidden states with the CCE path.
1013
  if int(nextlat_horizon) < 1:
1014
+ raise ValueError(f"`nextlat_horizon` must be >= 1, got {nextlat_horizon}.")
 
 
1015
  if nextlat_mse_weight < 0.0:
1016
  raise ValueError(
1017
  f"`nextlat_mse_weight` must be >= 0, got {nextlat_mse_weight}."
 
1179
  self.use_laurel_lr = use_laurel_lr
1180
  self.laurel_lr_rank = laurel_lr_rank
1181
 
1182
+ # ── TWEO: Transformers Without Extreme Outliers ──────────────────
1183
+ self.use_tweo = bool(use_tweo)
1184
+ self.tweo_loss_weight = float(tweo_loss_weight)
1185
+ self.tweo_tau = float(tweo_tau)
1186
+ self.tweo_power = float(tweo_power)
1187
+ self.tweo_eps = float(tweo_eps)
1188
+
1189
  # ── NITP: Next Implicit Token Prediction ─────────────────────────
1190
  self.use_nitp = bool(use_nitp)
1191
  self.nitp_target_layer = int(nitp_target_layer)
 
1239
  }
1240
 
1241
 
1242
+ __all__ = ["NeoLLMConfig"]