KitsuVp commited on
Commit
630571d
·
verified ·
1 Parent(s): f2e13d6

Update configuration_neollm.py

Browse files
Files changed (1) hide show
  1. configuration_neollm.py +124 -2
configuration_neollm.py CHANGED
@@ -364,14 +364,19 @@ class NeoLLMConfig(PretrainedConfig):
364
  Each token's UTF-8 encoding (up to 16 bytes) is embedded through a
365
  shared ``nn.Embedding(256, d)`` table. Byte embeddings are
366
  position-encoded with RoPE using intra-token byte positions (not
367
- sequence positions), summed and normalised by ``√byte_len``, then
368
  averaged with the standard token embedding:
369
 
370
  .. math::
371
  e_{\\text{bee}}(t) = \\frac{1}{2}\\left(e_{\\text{tok}}(t) +
372
- \\frac{1}{\\sqrt{|t|}}\\sum_{i=1}^{16}
373
  \\text{RoPE}(e_{\\text{byte}}[b_i], i)\\right)
374
 
 
 
 
 
 
375
  Adds ``256 × hidden_size`` parameters (≈0.13M for d=512).
376
  Zero inference overhead when ``bake_inference_table()`` is called
377
  after training.
@@ -569,6 +574,40 @@ class NeoLLMConfig(PretrainedConfig):
569
  tweo_eps (:obj:`float`, *optional*, defaults to ``1e-6``):
570
  Numerical stability epsilon added to the TWEO denominator.
571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
  Constraints:
573
  - ``use_jtokm=True`` requires ``use_token_generator=True``.
574
  - ``1 ≤ jtokm_top_k < jtokm_num_experts`` when ``use_jtokm=True``.
@@ -585,6 +624,7 @@ class NeoLLMConfig(PretrainedConfig):
585
  ``use_laurel_lr`` must be ``True``.
586
  - ``stack_d_model`` must be divisible by ``num_mem_heads`` when
587
  ``use_stack_memory=True``.
 
588
 
589
  Examples::
590
 
@@ -783,6 +823,22 @@ class NeoLLMConfig(PretrainedConfig):
783
  nitp_target_layer=None,
784
  nitp_loss_weight=1.0,
785
  nitp_projector_intermediate_size=None,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
  # ── NextLat: Next-Latent Prediction (Teoh et al., 2026) ───────────
787
  use_nextlat=False,
788
  nextlat_horizon=1,
@@ -1039,6 +1095,52 @@ class NeoLLMConfig(PretrainedConfig):
1039
  f"got {nitp_projector_intermediate_size}."
1040
  )
1041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1042
  # ── NextLat: resolve paper-faithful defaults and validate ─────────
1043
  # Teoh et al. train a latent dynamics model p_psi(h_t, x_{t+1}) to
1044
  # recursively predict final-layer hidden states with Smooth L1 and KL
@@ -1236,6 +1338,26 @@ class NeoLLMConfig(PretrainedConfig):
1236
  self.nitp_loss_weight = float(nitp_loss_weight)
1237
  self.nitp_projector_intermediate_size = int(nitp_projector_intermediate_size)
1238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1239
  # ── NextLat: Next-Latent Prediction ──────────────────────────────
1240
  self.use_nextlat = bool(use_nextlat)
1241
  self.nextlat_horizon = int(nextlat_horizon)
 
364
  Each token's UTF-8 encoding (up to 16 bytes) is embedded through a
365
  shared ``nn.Embedding(256, d)`` table. Byte embeddings are
366
  position-encoded with RoPE using intra-token byte positions (not
367
+ sequence positions), averaged over the fixed 16 byte slots, then
368
  averaged with the standard token embedding:
369
 
370
  .. math::
371
  e_{\\text{bee}}(t) = \\frac{1}{2}\\left(e_{\\text{tok}}(t) +
372
+ \\frac{1}{16}\\sum_{i=1}^{16}
373
  \\text{RoPE}(e_{\\text{byte}}[b_i], i)\\right)
374
 
375
+ The active configuration follows the reference fixed-length mean.
376
+ A separate theoretical variant would mask padded positions and use
377
+ ``1 / sqrt(|t|)`` over valid bytes; it is intentionally not active
378
+ in this training configuration.
379
+
380
  Adds ``256 × hidden_size`` parameters (≈0.13M for d=512).
381
  Zero inference overhead when ``bake_inference_table()`` is called
382
  after training.
 
574
  tweo_eps (:obj:`float`, *optional*, defaults to ``1e-6``):
575
  Numerical stability epsilon added to the TWEO denominator.
576
 
577
+ use_nitp_temporal (:obj:`bool`, *optional*, defaults to ``False``):
578
+ Instantiate the NITP temporal-transition extension. The module is
579
+ a separate bias-free SwiGLU residual updater and does not reuse the
580
+ existing ``NextLatDynamicsModel``. Given final state
581
+ :math:`h_t^L` and teacher-forced next-token embedding
582
+ :math:`E(x_{t+1})`, it predicts :math:`\hat h_{t+1}^L` and may be
583
+ composed for ``nitp_temporal_horizon`` local rollout steps. It
584
+ never materializes an additional vocabulary projection.
585
+ nitp_temporal_apply_loss (:obj:`bool`, *optional*, defaults to ``True``):
586
+ When ``True``, add the weighted temporal state and identification
587
+ losses to the model loss. When ``False``, keep the transition
588
+ parameters instantiated and compute all temporal metrics under
589
+ ``torch.no_grad()``, allowing a monitoring-only NTP+NITP baseline.
590
+ nitp_temporal_horizon (:obj:`int`, *optional*, defaults to ``4``):
591
+ Number :math:`W` of teacher-forced latent rollout steps.
592
+ nitp_temporal_dynamics_weight (:obj:`float`, *optional*, defaults to ``1.0``):
593
+ Weight applied to the average Smooth-L1 alignment between each
594
+ predicted final state and the stop-gradient real final state at
595
+ the same temporal offset.
596
+ nitp_temporal_identification_weight (:obj:`float`, *optional*, defaults to ``0.1``):
597
+ Weight applied to the symmetric listwise temporal-identification
598
+ objective over the local :math:`W\times W` cosine matrix.
599
+ nitp_temporal_intermediate_size (:obj:`int`, *optional*):
600
+ SwiGLU width of the transition module. ``None`` resolves to
601
+ ``2 * hidden_size``. At ``hidden_size=512`` this branch adds
602
+ ``2,622,464`` parameters, in addition to the NITP projector.
603
+ nitp_temporal_similarity_temperature (:obj:`float`, *optional*, defaults to ``0.1``):
604
+ Temperature applied to predicted cosine similarities before the
605
+ listwise temporal-identification softmax.
606
+ nitp_temporal_target_temperature (:obj:`float`, *optional*, defaults to ``0.5``):
607
+ Temperature controlling temporal label smoothing. Smaller values
608
+ make the correct diagonal step more nearly one-hot, while retaining
609
+ limited tolerance for genuinely similar adjacent states.
610
+
611
  Constraints:
612
  - ``use_jtokm=True`` requires ``use_token_generator=True``.
613
  - ``1 ≤ jtokm_top_k < jtokm_num_experts`` when ``use_jtokm=True``.
 
624
  ``use_laurel_lr`` must be ``True``.
625
  - ``stack_d_model`` must be divisible by ``num_mem_heads`` when
626
  ``use_stack_memory=True``.
627
+ - ``use_nitp_temporal=True`` requires ``use_nitp=True``.
628
 
629
  Examples::
630
 
 
823
  nitp_target_layer=None,
824
  nitp_loss_weight=1.0,
825
  nitp_projector_intermediate_size=None,
826
+ # ── NITP temporal transition / identification extension ──────────
827
+ # This is deliberately a NITP-side module, not the existing NextLat
828
+ # implementation. It learns a teacher-forced latent update
829
+ # (h_t^L, E[x_{t+1}]) -> h_{t+1}^L
830
+ # and a local temporal-identification objective over the rollout.
831
+ # `nitp_temporal_apply_loss=False` keeps the module instantiated and
832
+ # computes every diagnostic metric, but does not add its objective to
833
+ # the model loss. This is the requested monitoring-only ablation.
834
+ use_nitp_temporal=True,
835
+ nitp_temporal_apply_loss=False,
836
+ nitp_temporal_horizon=4,
837
+ nitp_temporal_dynamics_weight=1.0,
838
+ nitp_temporal_identification_weight=0.1,
839
+ nitp_temporal_intermediate_size=None,
840
+ nitp_temporal_similarity_temperature=0.1,
841
+ nitp_temporal_target_temperature=0.5,
842
  # ── NextLat: Next-Latent Prediction (Teoh et al., 2026) ───────────
843
  use_nextlat=False,
844
  nextlat_horizon=1,
 
1095
  f"got {nitp_projector_intermediate_size}."
1096
  )
1097
 
1098
+ # ── NITP temporal transition / identification ────────────────────
1099
+ # The extension is intentionally anchored to the active NITP branch:
1100
+ # it reuses NITP's final hidden states, shallow target states and
1101
+ # projector for diagnostics, but owns a separate SwiGLU transition
1102
+ # module so enabling it genuinely increases the parameter count.
1103
+ if use_nitp_temporal and not use_nitp:
1104
+ raise ValueError(
1105
+ "`use_nitp_temporal=True` requires `use_nitp=True` because "
1106
+ "the temporal branch is defined as an extension of NITP."
1107
+ )
1108
+ if int(nitp_temporal_horizon) < 1:
1109
+ raise ValueError(
1110
+ "`nitp_temporal_horizon` must be >= 1, "
1111
+ f"got {nitp_temporal_horizon}."
1112
+ )
1113
+ if nitp_temporal_dynamics_weight < 0.0:
1114
+ raise ValueError(
1115
+ "`nitp_temporal_dynamics_weight` must be >= 0, "
1116
+ f"got {nitp_temporal_dynamics_weight}."
1117
+ )
1118
+ if nitp_temporal_identification_weight < 0.0:
1119
+ raise ValueError(
1120
+ "`nitp_temporal_identification_weight` must be >= 0, "
1121
+ f"got {nitp_temporal_identification_weight}."
1122
+ )
1123
+ if nitp_temporal_intermediate_size is None:
1124
+ # For d=512 this resolves to 1024. With the NITP-style SwiGLU
1125
+ # transition below, the branch adds 10d^2 + 2d = 2,622,464
1126
+ # trainable parameters (including the affine RMSNorm scale).
1127
+ nitp_temporal_intermediate_size = 2 * hidden_size
1128
+ if int(nitp_temporal_intermediate_size) <= 0:
1129
+ raise ValueError(
1130
+ "`nitp_temporal_intermediate_size` must be positive, "
1131
+ f"got {nitp_temporal_intermediate_size}."
1132
+ )
1133
+ if nitp_temporal_similarity_temperature <= 0.0:
1134
+ raise ValueError(
1135
+ "`nitp_temporal_similarity_temperature` must be > 0, "
1136
+ f"got {nitp_temporal_similarity_temperature}."
1137
+ )
1138
+ if nitp_temporal_target_temperature <= 0.0:
1139
+ raise ValueError(
1140
+ "`nitp_temporal_target_temperature` must be > 0, "
1141
+ f"got {nitp_temporal_target_temperature}."
1142
+ )
1143
+
1144
  # ── NextLat: resolve paper-faithful defaults and validate ─────────
1145
  # Teoh et al. train a latent dynamics model p_psi(h_t, x_{t+1}) to
1146
  # recursively predict final-layer hidden states with Smooth L1 and KL
 
1338
  self.nitp_loss_weight = float(nitp_loss_weight)
1339
  self.nitp_projector_intermediate_size = int(nitp_projector_intermediate_size)
1340
 
1341
+ # ── NITP temporal transition / identification ────────────────────
1342
+ self.use_nitp_temporal = bool(use_nitp_temporal)
1343
+ self.nitp_temporal_apply_loss = bool(nitp_temporal_apply_loss)
1344
+ self.nitp_temporal_horizon = int(nitp_temporal_horizon)
1345
+ self.nitp_temporal_dynamics_weight = float(
1346
+ nitp_temporal_dynamics_weight
1347
+ )
1348
+ self.nitp_temporal_identification_weight = float(
1349
+ nitp_temporal_identification_weight
1350
+ )
1351
+ self.nitp_temporal_intermediate_size = int(
1352
+ nitp_temporal_intermediate_size
1353
+ )
1354
+ self.nitp_temporal_similarity_temperature = float(
1355
+ nitp_temporal_similarity_temperature
1356
+ )
1357
+ self.nitp_temporal_target_temperature = float(
1358
+ nitp_temporal_target_temperature
1359
+ )
1360
+
1361
  # ── NextLat: Next-Latent Prediction ──────────────────────────────
1362
  self.use_nextlat = bool(use_nextlat)
1363
  self.nextlat_horizon = int(nextlat_horizon)