zhan1206 commited on
Commit
36e31c4
·
1 Parent(s): 1c801e3

fix(v8): S1 lora vocab sync, M1 test_sbla tuple unpack, N1 dead code removal

Browse files

- lora_finetune.py: add vocab_size_override param, sync after tokenizer creation
- full_finetune.py: remove redundant post-init vocab_size override (dead code)
- test_sbla.py: fix output unpack to (output, cache) tuple for v6 signature

All remaining audit items resolved.

tests/test_sbla.py CHANGED
@@ -4,19 +4,21 @@ sys.path.insert(0, ".")
4
  import torch
5
 
6
  print("[TEST] Testing SBLA Attention...")
7
- sbla = __import__("models.sbla_attention", fromlist=["SBLAttention"]).SBLAttention(
8
- hidden_size=128,
 
 
9
  num_heads=4,
10
- block_size=16,
11
- latent_dim=32,
12
  window_size=16,
13
  mode="pure_sbla",
14
  )
15
 
16
- batch_size, seq_len = 2, 48
17
- hidden_states = torch.randn(batch_size, seq_len, 128)
18
- attention_mask = torch.ones(batch_size, 1, 1, seq_len)
19
 
20
- output = sbla.forward(hidden_states=hidden_states, attention_mask=attention_mask)
21
- print(f"OK: shape={output.shape}, no NaN={not torch.isnan(output).any()}")
22
- print("[PASS] SBLA Attention working!")
 
4
  import torch
5
 
6
  print("[TEST] Testing SBLA Attention...")
7
+ from models.sbla_attention import SBLAttention
8
+
9
+ sbla = SBLAttention(
10
+ hidden_size=64,
11
  num_heads=4,
12
+ block_size=8,
13
+ latent_dim=8,
14
  window_size=16,
15
  mode="pure_sbla",
16
  )
17
 
18
+ batch_size, seq_len = 2, 16
19
+ hidden_states = torch.randn(batch_size, seq_len, 64)
20
+ attention_mask = torch.ones(batch_size, seq_len)
21
 
22
+ output, cache = sbla(hidden_states=hidden_states, attention_mask=attention_mask)
23
+ print(f"OK: shape={output.shape}, no NaN={not torch.isnan(output).any()}, cache={cache}")
24
+ print("[PASS] SBLA Attention working!")
train/full_finetune.py CHANGED
@@ -151,11 +151,6 @@ def create_local_model(
151
 
152
  config = FusionConfig(**config_dict, **common_config)
153
 
154
- # S3-fix: sync vocab_size to actual tokenizer if provided
155
- if vocab_size_override is not None and vocab_size_override != config.vocab_size:
156
- logger.warning(f"[S3-fix] Overriding model vocab_size: {config.vocab_size} -> {vocab_size_override}")
157
- config.vocab_size = vocab_size_override
158
-
159
  logger.info(f"[create_local_model] 创建 Fusion-{model_size}(随机初始化)")
160
  logger.info(f" hidden_size={config.hidden_size}, layers={config.num_hidden_layers}, "
161
  f"heads={config.num_attention_heads}")
 
151
 
152
  config = FusionConfig(**config_dict, **common_config)
153
 
 
 
 
 
 
154
  logger.info(f"[create_local_model] 创建 Fusion-{model_size}(随机初始化)")
155
  logger.info(f" hidden_size={config.hidden_size}, layers={config.num_hidden_layers}, "
156
  f"heads={config.num_attention_heads}")
train/lora_finetune.py CHANGED
@@ -131,6 +131,7 @@ def create_local_model(
131
  load_in_4bit: bool = False,
132
  load_in_8bit: bool = False,
133
  ):
 
134
  """
135
  创建本地 FusionModel(无需预训练权重)
136
 
@@ -139,6 +140,7 @@ def create_local_model(
139
  quantize: 是否量化
140
  load_in_4bit: 4-bit 量化(NF4)
141
  load_in_8bit: 8-bit 量化
 
142
  """
143
  # 模型配置(基于尺寸)
144
  model_configs = {
@@ -157,6 +159,10 @@ def create_local_model(
157
 
158
  config_dict = model_configs[model_size]
159
 
 
 
 
 
160
  # 通用配置
161
  common_config = dict(
162
  block_size=512,
@@ -262,12 +268,16 @@ def train(args):
262
  "0.5B": 32000, "1.5B": 32000, "8B": 100000, "14B": 100000
263
  }.get(args.model_size, 32000))
264
 
 
 
 
265
  # 2. 创建模型(本地随机初始化)
266
  model, config = create_local_model(
267
  model_size=args.model_size,
268
  quantize=args.quantize,
269
  load_in_4bit=args.load_in_4bit,
270
  load_in_8bit=args.load_in_8bit,
 
271
  )
272
 
273
  # 3. 应用 LoRA
 
131
  load_in_4bit: bool = False,
132
  load_in_8bit: bool = False,
133
  ):
134
+ """
135
  """
136
  创建本地 FusionModel(无需预训练权重)
137
 
 
140
  quantize: 是否量化
141
  load_in_4bit: 4-bit 量化(NF4)
142
  load_in_8bit: 8-bit 量化
143
+ vocab_size_override: S3 fix - sync vocab to actual tokenizer size
144
  """
145
  # 模型配置(基于尺寸)
146
  model_configs = {
 
159
 
160
  config_dict = model_configs[model_size]
161
 
162
+ # S3 fix: override vocab_size to match actual tokenizer
163
+ if vocab_size_override is not None:
164
+ config_dict['vocab_size'] = vocab_size_override
165
+
166
  # 通用配置
167
  common_config = dict(
168
  block_size=512,
 
268
  "0.5B": 32000, "1.5B": 32000, "8B": 100000, "14B": 100000
269
  }.get(args.model_size, 32000))
270
 
271
+ # S3 fix: sync vocab_size to actual tokenizer
272
+ actual_vocab_size = len(tokenizer)
273
+
274
  # 2. 创建模型(本地随机初始化)
275
  model, config = create_local_model(
276
  model_size=args.model_size,
277
  quantize=args.quantize,
278
  load_in_4bit=args.load_in_4bit,
279
  load_in_8bit=args.load_in_8bit,
280
+ vocab_size_override=actual_vocab_size,
281
  )
282
 
283
  # 3. 应用 LoRA