Upload folder using huggingface_hub
Browse files- opd_1gpu_tb.py +21 -15
opd_1gpu_tb.py
CHANGED
|
@@ -95,21 +95,26 @@ def verify_pinned_sources(config: dict[str, Any]) -> dict[str, Any]:
|
|
| 95 |
}
|
| 96 |
|
| 97 |
|
| 98 |
-
def weight_fingerprint(model: torch.nn.Module) -> str:
|
| 99 |
-
"""
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
| 106 |
"""
|
| 107 |
digest = hashlib.sha256()
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
|
| 115 |
def device_records() -> list[dict[str, Any]]:
|
|
@@ -245,7 +250,7 @@ def run(config: dict[str, Any], output_dir: Path) -> dict[str, Any]:
|
|
| 245 |
)
|
| 246 |
|
| 247 |
writer = SummaryWriter(log_dir=str(tb_dir), flush_secs=5)
|
| 248 |
-
fingerprint_before = weight_fingerprint(student)
|
| 249 |
writer.add_text("run/evidence_class", config["evidence_class"], 0)
|
| 250 |
writer.add_text("run/source_commit", config["source_commit"], 0)
|
| 251 |
writer.add_text("run/tracking_backend", "tensorboard", 0)
|
|
@@ -454,7 +459,7 @@ def run(config: dict[str, Any], output_dir: Path) -> dict[str, Any]:
|
|
| 454 |
},
|
| 455 |
checkpoint_dir / "trainer_state.pt",
|
| 456 |
)
|
| 457 |
-
fingerprint_after = weight_fingerprint(student)
|
| 458 |
writer.add_text("run/weight_fingerprint_after", fingerprint_after, steps)
|
| 459 |
|
| 460 |
summary = {
|
|
@@ -497,6 +502,7 @@ def run(config: dict[str, Any], output_dir: Path) -> dict[str, Any]:
|
|
| 497 |
"student_weights_changed": fingerprint_after != fingerprint_before,
|
| 498 |
"weight_fingerprint_before": fingerprint_before,
|
| 499 |
"weight_fingerprint_after": fingerprint_after,
|
|
|
|
| 500 |
"total_runtime_seconds": time.perf_counter() - run_start,
|
| 501 |
"final_metrics": step_metrics[-1],
|
| 502 |
}
|
|
|
|
| 95 |
}
|
| 96 |
|
| 97 |
|
| 98 |
+
def weight_fingerprint(model: torch.nn.Module) -> tuple[str, int]:
|
| 99 |
+
"""Digest a slice of every named parameter, plus how many carry gradients.
|
| 100 |
+
|
| 101 |
+
My first version hashed `next(model.parameters())`, which for Llama is
|
| 102 |
+
`embed_tokens.weight`. That tensor receives no gradient here — the loss only
|
| 103 |
+
covers response tokens — so it never moves and the check reported
|
| 104 |
+
"weights unchanged" after ten real optimizer steps. The instrument was wrong,
|
| 105 |
+
not the run. Hashing every named parameter in a stable order covers the
|
| 106 |
+
transformer body, which does receive gradient.
|
| 107 |
"""
|
| 108 |
digest = hashlib.sha256()
|
| 109 |
+
params = sorted(model.named_parameters(), key=lambda item: item[0])
|
| 110 |
+
with_grad = sum(1 for _, param in params if param.grad is not None)
|
| 111 |
+
for name, param in params:
|
| 112 |
+
with torch.no_grad():
|
| 113 |
+
slice_ = param.detach().float().reshape(-1)[:512].cpu().numpy()
|
| 114 |
+
digest.update(name.encode("utf-8"))
|
| 115 |
+
digest.update(str(slice_.shape).encode("ascii"))
|
| 116 |
+
digest.update(slice_.tobytes())
|
| 117 |
+
return digest.hexdigest(), with_grad
|
| 118 |
|
| 119 |
|
| 120 |
def device_records() -> list[dict[str, Any]]:
|
|
|
|
| 250 |
)
|
| 251 |
|
| 252 |
writer = SummaryWriter(log_dir=str(tb_dir), flush_secs=5)
|
| 253 |
+
fingerprint_before, _ = weight_fingerprint(student)
|
| 254 |
writer.add_text("run/evidence_class", config["evidence_class"], 0)
|
| 255 |
writer.add_text("run/source_commit", config["source_commit"], 0)
|
| 256 |
writer.add_text("run/tracking_backend", "tensorboard", 0)
|
|
|
|
| 459 |
},
|
| 460 |
checkpoint_dir / "trainer_state.pt",
|
| 461 |
)
|
| 462 |
+
fingerprint_after, params_with_grad = weight_fingerprint(student)
|
| 463 |
writer.add_text("run/weight_fingerprint_after", fingerprint_after, steps)
|
| 464 |
|
| 465 |
summary = {
|
|
|
|
| 502 |
"student_weights_changed": fingerprint_after != fingerprint_before,
|
| 503 |
"weight_fingerprint_before": fingerprint_before,
|
| 504 |
"weight_fingerprint_after": fingerprint_after,
|
| 505 |
+
"parameters_with_gradients": params_with_grad,
|
| 506 |
"total_runtime_seconds": time.perf_counter() - run_start,
|
| 507 |
"final_metrics": step_metrics[-1],
|
| 508 |
}
|