Datasets:
Rebuild: ae708e57 (qad early-stop fix)
Browse files- kit_manifest.json +3 -3
- scripts/check_docs.py +1 -0
- scripts/qad_finetune.py +56 -14
kit_manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"built_from_commit": "
|
| 3 |
"capabilities": [
|
| 4 |
"rht_int4_convert.layer_filter",
|
| 5 |
"eval_quantized.dtype",
|
|
@@ -17,7 +17,7 @@
|
|
| 17 |
"scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
|
| 18 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 19 |
"scripts/eval_quantized.py": "703904d36ff9f096aa2d7cfbad420318908834b34c2890d10e85aa05fb4fdd28",
|
| 20 |
-
"scripts/qad_finetune.py": "
|
| 21 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 22 |
"scripts/run_lane.py": "cd74b56651cdff82b4ff12ab74fa84ecce1a658eb205c72faa1f6b770148ada6",
|
| 23 |
"scripts/make_sweep_spec.py": "dc31ec026c89e7db316a185575a4423bca988c2ac6cf08ef6df8f955328cda69",
|
|
@@ -33,7 +33,7 @@
|
|
| 33 |
"scripts/dedup_lines.py": "d7caa00dc29f0ba48bc1bdac675e2ed5d81f0514d5d9df17a8f5b2017e6ea8d4",
|
| 34 |
"scripts/dedup_calibration.py": "62ecc3c3921d307048c9e3547026634b616110115baf561f74dfb74c91e89b7d",
|
| 35 |
"scripts/check_experiment.py": "a2e7e40909f68031dfccd7013ed055dfbc0ebb21f2a619622b71e6772c685ca5",
|
| 36 |
-
"scripts/check_docs.py": "
|
| 37 |
"scripts/preflight.py": "5c2bcbe3693c8abf645fbf3f8160d96fdc1695daf09dc4961464ca8a23698e6e",
|
| 38 |
"scripts/env_fingerprint.py": "651db85ad3cdf28bc46e97010986109df60785eb6646507ee38b0fa75dce57d5",
|
| 39 |
"scripts/kaggle_slots.py": "e3baafe52347e74158c5b82fe6a2849f72a201d8ce60c0bbbf0871e47c75ae79",
|
|
|
|
| 1 |
{
|
| 2 |
+
"built_from_commit": "ae708e5753c1b50adfb5b88cb158225bc8c590ec",
|
| 3 |
"capabilities": [
|
| 4 |
"rht_int4_convert.layer_filter",
|
| 5 |
"eval_quantized.dtype",
|
|
|
|
| 17 |
"scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
|
| 18 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 19 |
"scripts/eval_quantized.py": "703904d36ff9f096aa2d7cfbad420318908834b34c2890d10e85aa05fb4fdd28",
|
| 20 |
+
"scripts/qad_finetune.py": "7381ec3178d4f94e390de6cfa34ec1c003add796b63575c6053816aee5aff140",
|
| 21 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 22 |
"scripts/run_lane.py": "cd74b56651cdff82b4ff12ab74fa84ecce1a658eb205c72faa1f6b770148ada6",
|
| 23 |
"scripts/make_sweep_spec.py": "dc31ec026c89e7db316a185575a4423bca988c2ac6cf08ef6df8f955328cda69",
|
|
|
|
| 33 |
"scripts/dedup_lines.py": "d7caa00dc29f0ba48bc1bdac675e2ed5d81f0514d5d9df17a8f5b2017e6ea8d4",
|
| 34 |
"scripts/dedup_calibration.py": "62ecc3c3921d307048c9e3547026634b616110115baf561f74dfb74c91e89b7d",
|
| 35 |
"scripts/check_experiment.py": "a2e7e40909f68031dfccd7013ed055dfbc0ebb21f2a619622b71e6772c685ca5",
|
| 36 |
+
"scripts/check_docs.py": "1d39c2bfc63459a43edb5b987efb37ebe0fcecdd52bf5e1a7fb4f3e25cd1ccf9",
|
| 37 |
"scripts/preflight.py": "5c2bcbe3693c8abf645fbf3f8160d96fdc1695daf09dc4961464ca8a23698e6e",
|
| 38 |
"scripts/env_fingerprint.py": "651db85ad3cdf28bc46e97010986109df60785eb6646507ee38b0fa75dce57d5",
|
| 39 |
"scripts/kaggle_slots.py": "e3baafe52347e74158c5b82fe6a2849f72a201d8ce60c0bbbf0871e47c75ae79",
|
scripts/check_docs.py
CHANGED
|
@@ -37,6 +37,7 @@ DEFAULT_DOCS = [
|
|
| 37 |
"docs/EVAL.md",
|
| 38 |
"docs/MODAL.md",
|
| 39 |
"docs/ENVIRONMENT.md",
|
|
|
|
| 40 |
"tests/README.md",
|
| 41 |
"antigravity/README.md",
|
| 42 |
]
|
|
|
|
| 37 |
"docs/EVAL.md",
|
| 38 |
"docs/MODAL.md",
|
| 39 |
"docs/ENVIRONMENT.md",
|
| 40 |
+
"docs/STATUS.md",
|
| 41 |
"tests/README.md",
|
| 42 |
"antigravity/README.md",
|
| 43 |
]
|
scripts/qad_finetune.py
CHANGED
|
@@ -40,6 +40,20 @@ from pathlib import Path
|
|
| 40 |
os.environ.setdefault("JAX_PLATFORM_NAME", "cpu")
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def parse_args() -> argparse.Namespace:
|
| 44 |
parser = argparse.ArgumentParser()
|
| 45 |
parser.add_argument("--teacher-dir", type=Path, required=True)
|
|
@@ -409,13 +423,18 @@ def main() -> None:
|
|
| 409 |
file.write(json.dumps(record) + "\n")
|
| 410 |
|
| 411 |
def scale_stats(current_params):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
values = [
|
| 413 |
np.asarray(value, dtype=np.float32).ravel()
|
| 414 |
for key, value in current_params.items()
|
| 415 |
if key.endswith("scales")
|
| 416 |
]
|
| 417 |
if not values:
|
| 418 |
-
return
|
| 419 |
merged = np.concatenate(values)
|
| 420 |
return float(merged.min()), float(merged.max())
|
| 421 |
|
|
@@ -424,6 +443,9 @@ def main() -> None:
|
|
| 424 |
initial_val = validation_loss(params)
|
| 425 |
best_val = initial_val
|
| 426 |
bad_val_evals = 0
|
|
|
|
|
|
|
|
|
|
| 427 |
if initial_val is not None:
|
| 428 |
progress({"step": 0, "val_loss": initial_val, "elapsed_s": 0.0})
|
| 429 |
print(f"step 0/{args.steps} val_kl={initial_val:.6f}", flush=True)
|
|
@@ -440,13 +462,16 @@ def main() -> None:
|
|
| 440 |
loss_value = float(loss)
|
| 441 |
grad_value = float(grad_norm)
|
| 442 |
scale_lo, scale_hi = scale_stats(params)
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
)
|
| 449 |
-
collapsed = initial_scale_max > scale_min * 10 and scale_hi <= scale_min * 10
|
| 450 |
if bad or collapsed:
|
| 451 |
reason = "non-finite loss/grad/scale" if bad else "scale collapse"
|
| 452 |
progress(
|
|
@@ -471,7 +496,10 @@ def main() -> None:
|
|
| 471 |
bad_val_evals = 0
|
| 472 |
else:
|
| 473 |
bad_val_evals += 1
|
| 474 |
-
|
|
|
|
|
|
|
|
|
|
| 475 |
progress(
|
| 476 |
{
|
| 477 |
"step": step + 1,
|
|
@@ -481,9 +509,16 @@ def main() -> None:
|
|
| 481 |
"elapsed_s": now - started_at,
|
| 482 |
}
|
| 483 |
)
|
| 484 |
-
|
| 485 |
-
f"
|
| 486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
)
|
| 488 |
record = {
|
| 489 |
"run_id": run_id,
|
|
@@ -499,17 +534,24 @@ def main() -> None:
|
|
| 499 |
with open(progress_path, "a", encoding="utf-8") as file:
|
| 500 |
file.write(json.dumps(record) + "\n")
|
| 501 |
val_text = "" if val_loss is None else f" val_kl={val_loss:.6f}"
|
|
|
|
| 502 |
print(
|
| 503 |
f"step {step + 1}/{args.steps} kl={loss_value:.6f}{val_text} "
|
| 504 |
-
f"grad={grad_value:.3g}
|
| 505 |
f"step_s={now - step_started:.2f} elapsed_s={now - started_at:.1f}",
|
| 506 |
flush=True,
|
| 507 |
)
|
|
|
|
| 508 |
if args.save_every and (step + 1) % args.save_every == 0:
|
| 509 |
save_checkpoint(step + 1, params, opt_state, rng)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
-
if args.steps > 0 and
|
| 512 |
-
save_checkpoint(
|
| 513 |
|
| 514 |
trained = inject_params(student, params)
|
| 515 |
trained = map_nodes_of_type_with_path(
|
|
|
|
| 40 |
os.environ.setdefault("JAX_PLATFORM_NAME", "cpu")
|
| 41 |
|
| 42 |
|
| 43 |
+
def early_stop_decision(bad_val_evals: int, patience: int, step: int, steps: int) -> str:
|
| 44 |
+
"""Decide what to do after a non-improving validation.
|
| 45 |
+
|
| 46 |
+
``step`` is 1-based. At the final step there is nothing left to stop, so a
|
| 47 |
+
non-improvement must not abort the run: aborting also skipped the checkpoint
|
| 48 |
+
save and export, which turned a completed 10-step run into a failed kernel.
|
| 49 |
+
"""
|
| 50 |
+
if patience <= 0 or bad_val_evals < patience:
|
| 51 |
+
return "continue"
|
| 52 |
+
if step >= steps:
|
| 53 |
+
return "ignore"
|
| 54 |
+
return "stop"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
def parse_args() -> argparse.Namespace:
|
| 58 |
parser = argparse.ArgumentParser()
|
| 59 |
parser.add_argument("--teacher-dir", type=Path, required=True)
|
|
|
|
| 423 |
file.write(json.dumps(record) + "\n")
|
| 424 |
|
| 425 |
def scale_stats(current_params):
|
| 426 |
+
"""Return (min, max) over scale arrays, or (None, None) when there are none.
|
| 427 |
+
|
| 428 |
+
With ``--freeze-scales`` the scales are not in the trainable dict at all.
|
| 429 |
+
Returning 0.0 there looked like a collapsed scale, so absence is explicit.
|
| 430 |
+
"""
|
| 431 |
values = [
|
| 432 |
np.asarray(value, dtype=np.float32).ravel()
|
| 433 |
for key, value in current_params.items()
|
| 434 |
if key.endswith("scales")
|
| 435 |
]
|
| 436 |
if not values:
|
| 437 |
+
return None, None
|
| 438 |
merged = np.concatenate(values)
|
| 439 |
return float(merged.min()), float(merged.max())
|
| 440 |
|
|
|
|
| 443 |
initial_val = validation_loss(params)
|
| 444 |
best_val = initial_val
|
| 445 |
bad_val_evals = 0
|
| 446 |
+
stop_reason = None
|
| 447 |
+
completed_steps = start_step
|
| 448 |
+
last_saved_step = start_step
|
| 449 |
if initial_val is not None:
|
| 450 |
progress({"step": 0, "val_loss": initial_val, "elapsed_s": 0.0})
|
| 451 |
print(f"step 0/{args.steps} val_kl={initial_val:.6f}", flush=True)
|
|
|
|
| 462 |
loss_value = float(loss)
|
| 463 |
grad_value = float(grad_norm)
|
| 464 |
scale_lo, scale_hi = scale_stats(params)
|
| 465 |
+
has_scales = scale_lo is not None and scale_hi is not None
|
| 466 |
+
bad = not (np.isfinite(loss_value) and np.isfinite(grad_value))
|
| 467 |
+
if has_scales:
|
| 468 |
+
bad = bad or not (np.isfinite(scale_lo) and np.isfinite(scale_hi))
|
| 469 |
+
collapsed = (
|
| 470 |
+
has_scales
|
| 471 |
+
and initial_scale_max is not None
|
| 472 |
+
and initial_scale_max > scale_min * 10
|
| 473 |
+
and scale_hi <= scale_min * 10
|
| 474 |
)
|
|
|
|
| 475 |
if bad or collapsed:
|
| 476 |
reason = "non-finite loss/grad/scale" if bad else "scale collapse"
|
| 477 |
progress(
|
|
|
|
| 496 |
bad_val_evals = 0
|
| 497 |
else:
|
| 498 |
bad_val_evals += 1
|
| 499 |
+
decision = early_stop_decision(
|
| 500 |
+
bad_val_evals, args.early_stop_patience, step + 1, args.steps
|
| 501 |
+
)
|
| 502 |
+
if decision == "stop":
|
| 503 |
progress(
|
| 504 |
{
|
| 505 |
"step": step + 1,
|
|
|
|
| 509 |
"elapsed_s": now - started_at,
|
| 510 |
}
|
| 511 |
)
|
| 512 |
+
stop_reason = (
|
| 513 |
+
f"val loss did not improve (best={best_val:.6f}, current={val_loss:.6f})"
|
| 514 |
+
)
|
| 515 |
+
completed_steps = step + 1
|
| 516 |
+
break
|
| 517 |
+
if decision == "ignore":
|
| 518 |
+
print(
|
| 519 |
+
"final step: val loss did not improve "
|
| 520 |
+
f"(best={best_val:.6f}, current={val_loss:.6f})",
|
| 521 |
+
flush=True,
|
| 522 |
)
|
| 523 |
record = {
|
| 524 |
"run_id": run_id,
|
|
|
|
| 534 |
with open(progress_path, "a", encoding="utf-8") as file:
|
| 535 |
file.write(json.dumps(record) + "\n")
|
| 536 |
val_text = "" if val_loss is None else f" val_kl={val_loss:.6f}"
|
| 537 |
+
scale_text = "scale=n/a" if not has_scales else f"scale=[{scale_lo:.3g},{scale_hi:.3g}]"
|
| 538 |
print(
|
| 539 |
f"step {step + 1}/{args.steps} kl={loss_value:.6f}{val_text} "
|
| 540 |
+
f"grad={grad_value:.3g} {scale_text} "
|
| 541 |
f"step_s={now - step_started:.2f} elapsed_s={now - started_at:.1f}",
|
| 542 |
flush=True,
|
| 543 |
)
|
| 544 |
+
completed_steps = step + 1
|
| 545 |
if args.save_every and (step + 1) % args.save_every == 0:
|
| 546 |
save_checkpoint(step + 1, params, opt_state, rng)
|
| 547 |
+
last_saved_step = step + 1
|
| 548 |
+
|
| 549 |
+
if stop_reason:
|
| 550 |
+
completed_text = f"final step {completed_steps}" if completed_steps >= args.steps else f"step {completed_steps}"
|
| 551 |
+
print(f"early stop at {completed_text}: {stop_reason}", flush=True)
|
| 552 |
|
| 553 |
+
if args.steps > 0 and completed_steps > 0 and completed_steps > last_saved_step:
|
| 554 |
+
save_checkpoint(completed_steps, params, opt_state, rng)
|
| 555 |
|
| 556 |
trained = inject_params(student, params)
|
| 557 |
trained = map_nodes_of_type_with_path(
|