Datasets:
Rebuild: QAD phase memory logging + skip-checkpoint
Browse files- kit_manifest.json +3 -3
- scripts/eval_quantized.py +6 -0
- scripts/qad_finetune.py +36 -2
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",
|
|
@@ -24,8 +24,8 @@
|
|
| 24 |
"scripts/yaqa_calibration.py": "5fbee3f3594d6d15cd67e5aa9cba20572db5aef698568e8982a101aeaab5b073",
|
| 25 |
"scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
|
| 26 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 27 |
-
"scripts/eval_quantized.py": "
|
| 28 |
-
"scripts/qad_finetune.py": "
|
| 29 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 30 |
"scripts/run_lane.py": "eef3be44e5d711995b6993e3e9ff36aa6007b593b44357041e08d6fa4c0d024e",
|
| 31 |
"scripts/make_sweep_spec.py": "dc31ec026c89e7db316a185575a4423bca988c2ac6cf08ef6df8f955328cda69",
|
|
|
|
| 1 |
{
|
| 2 |
+
"built_from_commit": "06b0717a82dcc99730c21cdf81cc57b489617141",
|
| 3 |
"capabilities": [
|
| 4 |
"rht_int4_convert.layer_filter",
|
| 5 |
"eval_quantized.dtype",
|
|
|
|
| 24 |
"scripts/yaqa_calibration.py": "5fbee3f3594d6d15cd67e5aa9cba20572db5aef698568e8982a101aeaab5b073",
|
| 25 |
"scripts/merge_language_hessians.py": "a6385caaa0d7190024b4e47ded59d1ab662e771ce81e18de94b30c8846829b4e",
|
| 26 |
"scripts/merge_calibration_groups.py": "58a347ff40c47f629c073c23aea54e215c1e75c052737e5b4a48ff81946d8060",
|
| 27 |
+
"scripts/eval_quantized.py": "5b4e5454630724c116d14fbc64061ffdd6066f4a458e228d372354d3eb32c5b0",
|
| 28 |
+
"scripts/qad_finetune.py": "5cd719d7b2f5251bd1c9903a403f75ae86e4da82ec0d18298bf092c212c86b96",
|
| 29 |
"scripts/compute_bpc.py": "2b55fd1df406d54b40daeeca2ecaf2efb35981655f5bf5e0cc10c057ce796256",
|
| 30 |
"scripts/run_lane.py": "eef3be44e5d711995b6993e3e9ff36aa6007b593b44357041e08d6fa4c0d024e",
|
| 31 |
"scripts/make_sweep_spec.py": "dc31ec026c89e7db316a185575a4423bca988c2ac6cf08ef6df8f955328cda69",
|
scripts/eval_quantized.py
CHANGED
|
@@ -275,6 +275,12 @@ def main() -> None:
|
|
| 275 |
"corpus": str(args.corpus),
|
| 276 |
"config": eval_config,
|
| 277 |
"config_hash": config_hash,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
"chunks": len(chunks),
|
| 279 |
"tokens": total_positions,
|
| 280 |
"chars": char_total,
|
|
|
|
| 275 |
"corpus": str(args.corpus),
|
| 276 |
"config": eval_config,
|
| 277 |
"config_hash": config_hash,
|
| 278 |
+
# dtype changes absolute PPL (0.8B runs float32 on CPU/T4, 4B/9B run
|
| 279 |
+
# bfloat16 on A100), so it must travel with the number.
|
| 280 |
+
"eval_dtype": args.dtype,
|
| 281 |
+
# CPU float32 and GPU float32 agree to 0.02%, but recording the device
|
| 282 |
+
# makes every number self-describing.
|
| 283 |
+
"device": jax.devices()[0].device_kind if jax.devices() else "unknown",
|
| 284 |
"chunks": len(chunks),
|
| 285 |
"tokens": total_positions,
|
| 286 |
"chars": char_total,
|
scripts/qad_finetune.py
CHANGED
|
@@ -40,6 +40,18 @@ from pathlib import 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 |
|
|
@@ -653,29 +665,51 @@ def main() -> None:
|
|
| 653 |
flush=True,
|
| 654 |
)
|
| 655 |
completed_steps = step + 1
|
| 656 |
-
if args.save_every and (step + 1) % args.save_every == 0:
|
|
|
|
| 657 |
save_checkpoint(step + 1, params, opt_state, rng)
|
|
|
|
| 658 |
last_saved_step = step + 1
|
| 659 |
|
| 660 |
if stop_reason:
|
| 661 |
completed_text = f"final step {completed_steps}" if completed_steps >= args.steps else f"step {completed_steps}"
|
| 662 |
print(f"early stop at {completed_text}: {stop_reason}", flush=True)
|
| 663 |
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
save_checkpoint(completed_steps, params, opt_state, rng)
|
|
|
|
| 666 |
|
|
|
|
| 667 |
if args.master_dtype != "bfloat16":
|
| 668 |
params = {key: value.astype(master_dtypes.get(key, value.dtype)) for key, value in params.items()}
|
| 669 |
trained = inject_params(student, params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
trained = map_nodes_of_type_with_path(
|
| 671 |
HybridMatrix,
|
| 672 |
lambda path, matrix: matrix.switch_implementation(CompressionImplementation.INFERENCE),
|
| 673 |
trained,
|
| 674 |
)
|
|
|
|
| 675 |
args.output_dir.mkdir(parents=True, exist_ok=True)
|
| 676 |
trained.save(args.output_dir)
|
|
|
|
| 677 |
rewrite(args.output_dir / "model.safetensors")
|
| 678 |
normalize(args.output_dir)
|
|
|
|
| 679 |
print(f"saved QAD model -> {args.output_dir}")
|
| 680 |
|
| 681 |
|
|
|
|
| 40 |
os.environ.setdefault("JAX_PLATFORM_NAME", "cpu")
|
| 41 |
|
| 42 |
|
| 43 |
+
def peak_rss_mb() -> float:
|
| 44 |
+
"""Peak resident memory of this process, in MB.
|
| 45 |
+
|
| 46 |
+
A silent death right after the last step (no traceback in the log, no
|
| 47 |
+
checkpoint) looks like the OOM killer; this number says which phase grew.
|
| 48 |
+
"""
|
| 49 |
+
import resource
|
| 50 |
+
|
| 51 |
+
usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
| 52 |
+
return usage / (1024 * 1024) if sys.platform == "darwin" else usage / 1024
|
| 53 |
+
|
| 54 |
+
|
| 55 |
def early_stop_decision(bad_val_evals: int, patience: int, step: int, steps: int) -> str:
|
| 56 |
"""Decide what to do after a non-improving validation.
|
| 57 |
|
|
|
|
| 665 |
flush=True,
|
| 666 |
)
|
| 667 |
completed_steps = step + 1
|
| 668 |
+
if args.save_every and (step + 1) % args.save_every == 0 and not args.skip_checkpoint:
|
| 669 |
+
print(f"checkpoint {step + 1} start peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 670 |
save_checkpoint(step + 1, params, opt_state, rng)
|
| 671 |
+
print(f"checkpoint {step + 1} done peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 672 |
last_saved_step = step + 1
|
| 673 |
|
| 674 |
if stop_reason:
|
| 675 |
completed_text = f"final step {completed_steps}" if completed_steps >= args.steps else f"step {completed_steps}"
|
| 676 |
print(f"early stop at {completed_text}: {stop_reason}", flush=True)
|
| 677 |
|
| 678 |
+
print(f"training done peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 679 |
+
if (
|
| 680 |
+
args.steps > 0
|
| 681 |
+
and completed_steps > 0
|
| 682 |
+
and completed_steps > last_saved_step
|
| 683 |
+
and not args.skip_checkpoint
|
| 684 |
+
):
|
| 685 |
+
print(f"final checkpoint start peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 686 |
save_checkpoint(completed_steps, params, opt_state, rng)
|
| 687 |
+
print(f"final checkpoint done peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 688 |
|
| 689 |
+
print(f"export start peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 690 |
if args.master_dtype != "bfloat16":
|
| 691 |
params = {key: value.astype(master_dtypes.get(key, value.dtype)) for key, value in params.items()}
|
| 692 |
trained = inject_params(student, params)
|
| 693 |
+
del params
|
| 694 |
+
opt_state = None
|
| 695 |
+
try:
|
| 696 |
+
import jax
|
| 697 |
+
|
| 698 |
+
jax.clear_caches()
|
| 699 |
+
except Exception: # noqa: BLE001 - freeing memory must never break export
|
| 700 |
+
pass
|
| 701 |
trained = map_nodes_of_type_with_path(
|
| 702 |
HybridMatrix,
|
| 703 |
lambda path, matrix: matrix.switch_implementation(CompressionImplementation.INFERENCE),
|
| 704 |
trained,
|
| 705 |
)
|
| 706 |
+
print(f"export injected peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 707 |
args.output_dir.mkdir(parents=True, exist_ok=True)
|
| 708 |
trained.save(args.output_dir)
|
| 709 |
+
print(f"export saved peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 710 |
rewrite(args.output_dir / "model.safetensors")
|
| 711 |
normalize(args.output_dir)
|
| 712 |
+
print(f"export done peak_rss={peak_rss_mb():.0f}MB", flush=True)
|
| 713 |
print(f"saved QAD model -> {args.output_dir}")
|
| 714 |
|
| 715 |
|