codemaivanngu commited on
Commit
d3bf152
·
verified ·
1 Parent(s): 39e03eb

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. 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
- """sha256 of the first 4096 values of the first parameter, on CPU.
100
-
101
- Ten optimizer steps that merely logged loss-free numbers would look identical
102
- to ten that actually moved the weights. Digesting a fixed slice of the first
103
- parameter before and after makes "the student changed" a checkable claim
104
- instead of an assumption, and it costs no extra storage the way a 15 GB
105
- checkpoint comparison would.
 
106
  """
107
  digest = hashlib.sha256()
108
- first = next(model.parameters())
109
- with torch.no_grad():
110
- slice_ = first.detach().float().reshape(-1)[:4096].cpu().numpy()
111
- digest.update(slice_.tobytes())
112
- return digest.hexdigest()
 
 
 
 
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
  }