CompressedGemma commited on
Commit
8668eaf
·
verified ·
1 Parent(s): ca34b06

Upload slimshard.py

Browse files
Files changed (1) hide show
  1. slimshard.py +21 -2
slimshard.py CHANGED
@@ -1061,7 +1061,7 @@ def _run_deepseek_v41_forward(
1061
  del emb_w
1062
 
1063
  # Cache layer weights if multiple layers are identical (e.g. single-shard anchor recovery)
1064
- cached_layer_ signature = None
1065
  cached_layer_data = None
1066
 
1067
  for lidx in range(num_layers):
@@ -1270,6 +1270,19 @@ def _synthesize_embed_tokens_checkfree(
1270
  t = f_handle.get_tensor(cand).to(dev, dtype=torch.float32)
1271
  if t.ndim == 2 and t.shape[1] == hidden:
1272
  in_mats.append(t[: min(384, t.shape[0])])
 
 
 
 
 
 
 
 
 
 
 
 
 
1273
  k_dim = min(128, hidden)
1274
  if in_mats:
1275
  cat_in = torch.cat(in_mats, dim=0)
@@ -1411,13 +1424,19 @@ def _write_lm_head_calibrated_chunked(
1411
  (
1412
  "self_attn.o_proj.weight",
1413
  "attn.o_proj.weight",
 
1414
  "attention.wo.weight",
1415
  "shared_experts.down_proj.weight",
 
1416
  "mlp.down_proj.weight",
1417
  "feed_forward.w2.weight",
1418
  )
1419
  ):
1420
- t = f_handle.get_tensor(cand).to(dev, dtype=torch.float32)
 
 
 
 
1421
  if t.ndim == 2 and t.shape[0] == hidden:
1422
  out_mats.append(t[:, : min(384, t.shape[1])].T)
1423
  if out_mats:
 
1061
  del emb_w
1062
 
1063
  # Cache layer weights if multiple layers are identical (e.g. single-shard anchor recovery)
1064
+ cached_layer_signature = None
1065
  cached_layer_data = None
1066
 
1067
  for lidx in range(num_layers):
 
1270
  t = f_handle.get_tensor(cand).to(dev, dtype=torch.float32)
1271
  if t.ndim == 2 and t.shape[1] == hidden:
1272
  in_mats.append(t[: min(384, t.shape[0])])
1273
+ if not in_mats:
1274
+ for cand in sorted(present):
1275
+ if cand.endswith(".weight") and ".experts." not in cand:
1276
+ sl = f_handle.get_slice(cand)
1277
+ shp = tuple(sl.get_shape())
1278
+ if len(shp) == 2 and shp[1] == hidden:
1279
+ t = f_handle.get_tensor(cand).to(dev)
1280
+ sc_key = cand[:-7] + ".scale"
1281
+ if str(t.dtype).endswith("e4m3fn") and sc_key in present:
1282
+ t = _ds4_dequant_fp8_32x32(t, f_handle.get_tensor(sc_key).to(dev))
1283
+ in_mats.append(t.float()[: min(384, t.shape[0])])
1284
+ if len(in_mats) >= 4:
1285
+ break
1286
  k_dim = min(128, hidden)
1287
  if in_mats:
1288
  cat_in = torch.cat(in_mats, dim=0)
 
1424
  (
1425
  "self_attn.o_proj.weight",
1426
  "attn.o_proj.weight",
1427
+ "attn.wo_b.weight",
1428
  "attention.wo.weight",
1429
  "shared_experts.down_proj.weight",
1430
+ "shared_experts.w2.weight",
1431
  "mlp.down_proj.weight",
1432
  "feed_forward.w2.weight",
1433
  )
1434
  ):
1435
+ t = f_handle.get_tensor(cand).to(dev)
1436
+ sc_key = cand[:-7] + ".scale"
1437
+ if str(t.dtype).endswith("e4m3fn") and sc_key in present:
1438
+ t = _ds4_dequant_fp8_32x32(t, f_handle.get_tensor(sc_key).to(dev))
1439
+ t = t.float()
1440
  if t.ndim == 2 and t.shape[0] == hidden:
1441
  out_mats.append(t[:, : min(384, t.shape[1])].T)
1442
  if out_mats: