KitsuVp commited on
Commit
2e9702e
·
verified ·
1 Parent(s): 96ab828

Update modeling_neollm.py

Browse files
Files changed (1) hide show
  1. modeling_neollm.py +12 -3
modeling_neollm.py CHANGED
@@ -5200,10 +5200,15 @@ class NeoLLMDecoderLayer(GradientCheckpointingLayer):
5200
  self.use_jtokm = config.use_jtokm
5201
  # Controls only the first pre-attention normalisation applied directly
5202
  # to the embedding stream. Defaults to True for checkpoint/config
5203
- # backward compatibility.
 
 
5204
  self.use_embedding_input_norm = bool(
5205
  getattr(config, "use_embedding_input_norm", True)
5206
  )
 
 
 
5207
 
5208
  self.self_attn = NeoLLMAttention(config, layer_idx)
5209
  self.mlp = (
@@ -5212,7 +5217,11 @@ class NeoLLMDecoderLayer(GradientCheckpointingLayer):
5212
  else NeoLLMMLP(config)
5213
  )
5214
  self.use_versatile_ffn = getattr(config, "use_versatile_ffn", False)
5215
- self.input_layernorm = SeeDNorm(config.hidden_size, eps=config.rms_norm_eps)
 
 
 
 
5216
  self.post_attention_layernorm = SeeDNorm(config.hidden_size, eps=config.rms_norm_eps)
5217
  self.lns_attn = LNS(layer_idx)
5218
  self.lns_mlp = LNS(layer_idx)
@@ -5506,7 +5515,7 @@ class NeoLLMDecoderLayer(GradientCheckpointingLayer):
5506
  # embedding magnitudes to attention.
5507
  # layer_idx > 0: keep the standard pre-norm Transformer flow exactly
5508
  # as before.
5509
- if self.layer_idx == 0 and not self.use_embedding_input_norm:
5510
  h_normed = h_attn
5511
  if sn_pre is not None:
5512
  # Analysis compatibility: mark the bypass as the observed
 
5200
  self.use_jtokm = config.use_jtokm
5201
  # Controls only the first pre-attention normalisation applied directly
5202
  # to the embedding stream. Defaults to True for checkpoint/config
5203
+ # backward compatibility. When False, layer 0 does not instantiate
5204
+ # input_layernorm at all, so the flag removes the corresponding
5205
+ # SeeDNorm parameters instead of merely bypassing them in forward.
5206
  self.use_embedding_input_norm = bool(
5207
  getattr(config, "use_embedding_input_norm", True)
5208
  )
5209
+ self.has_input_layernorm = not (
5210
+ self.layer_idx == 0 and not self.use_embedding_input_norm
5211
+ )
5212
 
5213
  self.self_attn = NeoLLMAttention(config, layer_idx)
5214
  self.mlp = (
 
5217
  else NeoLLMMLP(config)
5218
  )
5219
  self.use_versatile_ffn = getattr(config, "use_versatile_ffn", False)
5220
+ self.input_layernorm = (
5221
+ SeeDNorm(config.hidden_size, eps=config.rms_norm_eps)
5222
+ if self.has_input_layernorm
5223
+ else None
5224
+ )
5225
  self.post_attention_layernorm = SeeDNorm(config.hidden_size, eps=config.rms_norm_eps)
5226
  self.lns_attn = LNS(layer_idx)
5227
  self.lns_mlp = LNS(layer_idx)
 
5515
  # embedding magnitudes to attention.
5516
  # layer_idx > 0: keep the standard pre-norm Transformer flow exactly
5517
  # as before.
5518
+ if self.input_layernorm is None:
5519
  h_normed = h_attn
5520
  if sn_pre is not None:
5521
  # Analysis compatibility: mark the bypass as the observed