sample_hash

Debug helper: hash the calibration samples each rank actually feeds to the model.

Gated by the PUZZLE_HASH_SAMPLES env var (set it to an output directory). When set, both the legacy and the AutoModel scoring paths call log_batch_hashes() right before the model forward to append a per-sample sha1 of input_ids to <dir>/<tag>_rank<global_rank>.txt. This lets us verify, independent of the scoring math, that (a) data-parallel sharding gives each dp rank a DISJOINT slice and (b) the legacy and AutoModel backends observe the SAME set of samples.

Check it with, e.g.:

# union of all automodel ranks == union of all legacy ranks (same samples)?
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
cat $DIR/automodel_rank*.txt | grep -o 'hash=[0-9a-f]*' | sort -u > "$tmp_dir/am.txt"
cat $DIR/legacy_rank*.txt    | grep -o 'hash=[0-9a-f]*' | sort -u > "$tmp_dir/lg.txt"
diff "$tmp_dir/am.txt" "$tmp_dir/lg.txt" && echo "SAME SAMPLE SET"
# per dp rank disjoint? (no hash appears for two different dp ranks)
grep -h . $DIR/automodel_rank*.txt | sed -E 's/.*(dp=[0-9]+).*(hash=[0-9a-f]+)/ /' | sort | uniq -c | sort -rn | head

Functions

log_batch_hashes

Append a per-sample sha1 of input_ids (shape [N, T]) to this rank's hash file.

samples_hashing_enabled

log_batch_hashes(input_ids, tag, step, extra='')

Append a per-sample sha1 of input_ids (shape [N, T]) to this rank’s hash file.

No-op unless PUZZLE_HASH_SAMPLES is set. tag is typically "legacy" / "automodel"; extra carries diagnostic fields (e.g. "dp=0 cp=1").

Parameters:
  • tag (str)

  • step (int)

  • extra (str)

Return type:

None

samples_hashing_enabled()
Return type:

bool