KitsuVp commited on
Commit
27e5303
·
verified ·
1 Parent(s): 1adbe02

Update configuration_neollm.py

Browse files
Files changed (1) hide show
  1. configuration_neollm.py +47 -0
configuration_neollm.py CHANGED
@@ -126,6 +126,24 @@ class NeoLLMConfig(PretrainedConfig):
126
  Epsilon for the denominator of the XSA projection to prevent
127
  division by zero: ``‖v_ref‖² + xsa_eps``. Ignored when
128
  ``use_xsa=False``.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  fan_ratio (:obj:`float`, *optional*, defaults to 0.125):
130
  Ratio controlling the periodic-dimension size in FANformer attention.
131
  The transformed representation has dimension
@@ -444,6 +462,8 @@ class NeoLLMConfig(PretrainedConfig):
444
  - ``use_laurel=True`` is incompatible with ``use_attn_res=True``.
445
  - When ``use_laurel=True``, at least one of ``use_laurel_rw`` or
446
  ``use_laurel_lr`` must be ``True``.
 
 
447
 
448
  Examples::
449
 
@@ -552,6 +572,12 @@ class NeoLLMConfig(PretrainedConfig):
552
  # ── Attention Residuals (Kimi Team, 2026) ─────────────────────────
553
  use_attn_res=False,
554
  attn_res_num_blocks=4,
 
 
 
 
 
 
555
  # ── ResFormer cross-layer FAN residual (He et al., 2023) ─────────
556
  use_fan_residual=False,
557
  fan_ratio=0.125,
@@ -694,6 +720,20 @@ class NeoLLMConfig(PretrainedConfig):
694
  "Set `use_laurel_rw=True` and/or `use_laurel_lr=True`."
695
  )
696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
  super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
698
 
699
  # ── Core Transformer ──────────────────────────────────────────────
@@ -748,6 +788,13 @@ class NeoLLMConfig(PretrainedConfig):
748
  # O(num_layers × batch × seq × hidden).
749
  self.use_attn_res = use_attn_res
750
  self.attn_res_num_blocks = attn_res_num_blocks
 
 
 
 
 
 
 
751
  rope_config_validation(self)
752
 
753
  # ── FANformer periodicity ─────────────────────────────────────────
 
126
  Epsilon for the denominator of the XSA projection to prevent
127
  division by zero: ``‖v_ref‖² + xsa_eps``. Ignored when
128
  ``use_xsa=False``.
129
+ use_stack_memory (:obj:`bool`, *optional*, defaults to ``False``):
130
+ Enable the StackMemory / STACKTRANS hidden-state stack between
131
+ decoder layers (Zhang et al., NeurIPS 2025). The module keeps the
132
+ standard attention path intact and applies differentiable soft
133
+ ``push``, ``pop`` and ``no-op`` stack updates to the layer input
134
+ before the attention block.
135
+ stack_d_model (:obj:`int`, *optional*, defaults to ``32``):
136
+ Low-rank stack width ``d_s`` used by StackMemory. Hidden states are
137
+ projected ``hidden_size → stack_d_model`` before stack operations
138
+ and projected back afterwards.
139
+ num_mem_heads (:obj:`int`, *optional*, defaults to ``8``):
140
+ Number of independent stack heads. Must divide ``stack_d_model``.
141
+ stack_slots (:obj:`int`, *optional*, defaults to ``16``):
142
+ Number of slots kept by each differentiable stack head.
143
+ stack_memory_cache_size (:obj:`int`, *optional*, defaults to ``2048``):
144
+ Cache length kept for parity with the released StackTrans source.
145
+ The default training path keeps this cache disabled.
146
+
147
  fan_ratio (:obj:`float`, *optional*, defaults to 0.125):
148
  Ratio controlling the periodic-dimension size in FANformer attention.
149
  The transformed representation has dimension
 
462
  - ``use_laurel=True`` is incompatible with ``use_attn_res=True``.
463
  - When ``use_laurel=True``, at least one of ``use_laurel_rw`` or
464
  ``use_laurel_lr`` must be ``True``.
465
+ - ``stack_d_model`` must be divisible by ``num_mem_heads`` when
466
+ ``use_stack_memory=True``.
467
 
468
  Examples::
469
 
 
572
  # ── Attention Residuals (Kimi Team, 2026) ─────────────────────────
573
  use_attn_res=False,
574
  attn_res_num_blocks=4,
575
+ # ── StackMemory / STACKTRANS (Zhang et al., NeurIPS 2025) ───────
576
+ use_stack_memory=True,
577
+ stack_d_model=32, # H * d_s = 4 * 16
578
+ num_mem_heads=4, # H = 4
579
+ stack_slots=16, # S = 24
580
+ stack_memory_cache_size=2048,
581
  # ── ResFormer cross-layer FAN residual (He et al., 2023) ─────────
582
  use_fan_residual=False,
583
  fan_ratio=0.125,
 
720
  "Set `use_laurel_rw=True` and/or `use_laurel_lr=True`."
721
  )
722
 
723
+ # ── StackMemory: source-code shape constraints ────────────────────
724
+ if use_stack_memory:
725
+ if stack_d_model <= 0:
726
+ raise ValueError(f"`stack_d_model` must be > 0, got {stack_d_model}.")
727
+ if num_mem_heads <= 0:
728
+ raise ValueError(f"`num_mem_heads` must be > 0, got {num_mem_heads}.")
729
+ if stack_slots <= 0:
730
+ raise ValueError(f"`stack_slots` must be > 0, got {stack_slots}.")
731
+ if stack_d_model % num_mem_heads != 0:
732
+ raise ValueError(
733
+ f"`stack_d_model` must be divisible by `num_mem_heads`, "
734
+ f"got stack_d_model={stack_d_model}, num_mem_heads={num_mem_heads}."
735
+ )
736
+
737
  super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
738
 
739
  # ── Core Transformer ──────────────────────────────────────────────
 
788
  # O(num_layers × batch × seq × hidden).
789
  self.use_attn_res = use_attn_res
790
  self.attn_res_num_blocks = attn_res_num_blocks
791
+
792
+ # ── StackMemory / STACKTRANS ──────────────────────────────────────
793
+ self.use_stack_memory = use_stack_memory
794
+ self.stack_d_model = stack_d_model
795
+ self.num_mem_heads = num_mem_heads
796
+ self.stack_slots = stack_slots
797
+ self.stack_memory_cache_size = stack_memory_cache_size
798
  rope_config_validation(self)
799
 
800
  # ── FANformer periodicity ─────────────────────────────────────────