mxguru1 commited on
Commit
71d613e
Β·
verified Β·
1 Parent(s): 4853598

Path B v3: full test set + same-protocol refs (6.5482 / 7.3814)

Browse files
quantization/hsaq/awq_path_b_clip.py CHANGED
@@ -239,8 +239,10 @@ def apply_quantization(model, name_to_bits: dict[str, int],
239
 
240
  # ── Eval ────────────────────────────────────────────────────────────────
241
 
242
- def evaluate_ppl(model, tokenizer, ctx_len: int = 2048, n_samples: int = 40) -> float:
243
- """Same wikitext PPL protocol as HSAQ baseline."""
 
 
244
  from datasets import load_dataset
245
  ds = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")
246
  text = "\n\n".join(ds["text"])
@@ -250,7 +252,9 @@ def evaluate_ppl(model, tokenizer, ctx_len: int = 2048, n_samples: int = 40) ->
250
  nlls = []
251
  stride = ctx_len
252
  prev_end = 0
253
- for i in range(0, min(input_ids.size(1), n_samples * stride), stride):
 
 
254
  begin = max(i + stride - ctx_len, 0)
255
  end = min(i + stride, input_ids.size(1))
256
  trg_len = end - prev_end
@@ -261,7 +265,8 @@ def evaluate_ppl(model, tokenizer, ctx_len: int = 2048, n_samples: int = 40) ->
261
  out = model(ids, labels=target)
262
  nlls.append(out.loss.float() * trg_len)
263
  prev_end = end
264
- return torch.exp(torch.stack(nlls).sum() / end).item()
 
265
 
266
  # ── Upload ──────────────────────────────────────────────────────────────
267
 
@@ -358,13 +363,15 @@ def main():
358
  logger.info("Stage 5/5: PPL eval")
359
  if tokenizer.pad_token is None:
360
  tokenizer.pad_token = tokenizer.eos_token
361
- ppl = evaluate_ppl(model, tokenizer)
 
362
  report["eval"] = {
363
  "ppl": ppl,
364
- "ppl_bf16_baseline_ref": 8.756,
365
- "ppl_hsaq_baseline_ref": 10.013,
366
- "pct_above_bf16": (ppl - 8.756) / 8.756 * 100,
367
- "pct_above_hsaq": (ppl - 10.013) / 10.013 * 100,
 
368
  }
369
  report["status"] = "success"
370
  logger.info("PPL: %.4f (%.2f%% above bf16, %.2f%% vs HSAQ baseline)",
 
239
 
240
  # ── Eval ────────────────────────────────────────────────────────────────
241
 
242
+ def evaluate_ppl(model, tokenizer, ctx_len: int = 2048, n_samples: int | None = None) -> tuple[float, int]:
243
+ """Same wikitext PPL protocol as awq_validation_runs.py.
244
+ n_samples=None evaluates FULL test set (per web-Claude review 2026-05-20).
245
+ Returns (ppl, n_windows_evaluated)."""
246
  from datasets import load_dataset
247
  ds = load_dataset("wikitext", "wikitext-2-raw-v1", split="test")
248
  text = "\n\n".join(ds["text"])
 
252
  nlls = []
253
  stride = ctx_len
254
  prev_end = 0
255
+ max_pos = input_ids.size(1) if n_samples is None else min(input_ids.size(1), n_samples * stride)
256
+ n_windows = 0
257
+ for i in range(0, max_pos, stride):
258
  begin = max(i + stride - ctx_len, 0)
259
  end = min(i + stride, input_ids.size(1))
260
  trg_len = end - prev_end
 
265
  out = model(ids, labels=target)
266
  nlls.append(out.loss.float() * trg_len)
267
  prev_end = end
268
+ n_windows += 1
269
+ return torch.exp(torch.stack(nlls).sum() / end).item(), n_windows
270
 
271
  # ── Upload ──────────────────────────────────────────────────────────────
272
 
 
363
  logger.info("Stage 5/5: PPL eval")
364
  if tokenizer.pad_token is None:
365
  tokenizer.pad_token = tokenizer.eos_token
366
+ ppl, n_windows = evaluate_ppl(model, tokenizer)
367
+ # bf16 / HSAQ refs from awq-validation-20260520_122419 (same protocol, full test set)
368
  report["eval"] = {
369
  "ppl": ppl,
370
+ "n_windows": n_windows,
371
+ "ppl_bf16_baseline_ref": 6.5482,
372
+ "ppl_hsaq_baseline_ref": 7.3814,
373
+ "pct_above_bf16": (ppl - 6.5482) / 6.5482 * 100,
374
+ "pct_above_hsaq": (ppl - 7.3814) / 7.3814 * 100,
375
  }
376
  report["status"] = "success"
377
  logger.info("PPL: %.4f (%.2f%% above bf16, %.2f%% vs HSAQ baseline)",