Skip to content

Tranche 1 stats: GPU identity, run-stats collector and the remaining run-stats fields - #59

Draft
rianfyi wants to merge 3 commits into
tranche1_final-demosfrom
tranche1_final-stats
Draft

rianfyi wants to merge 3 commits into
tranche1_final-demosfrom
tranche1_final-stats

Conversation

@rianfyi

@rianfyi rianfyi commented Nov 27, 2026 •

Copy link
Copy Markdown

Draft. The run-stats layer for Tranche 1, in 3 small commits, stacked on the experiment-driver PR #58 (tranche1_final-demos). This diff holds only these 3 commits. Upstream master has since moved to 0181aa2f; this layer stays on 59890580 for review.

Items 1 and 2 record GPU identity and peak VRAM in run metrics, and add the collector. Item 3 records the remaining run-stats fields the collector reported as missing. Please use the Commits tab: each commit makes one change and has its own tests.

Commits

# Commit Subject Behaviour change
1 1c3c2ab Record GPU identity, thread pinning, and peak VRAM in run metrics metrics.json gains a hardware object
2 4eaeb52 Add a run-stats collector New script; collects one standard-schema row per run directory
3 26190ba Record the remaining run-stats fields run_config.json and metrics gain the remaining fields (null where not applicable)

Please read before reviewing

  • Item 3: positive_rate adds one pass over the dataset, outside the timed sections. peak_pss_mb is null on macOS by design.
  • Item 3: tree_sha and dirty are null outside a git checkout. dirty is true when git status --porcelain reports any change, including untracked files.

Verification

  • CI rules: tools/check_pr_rules.py passes on each commit (exit 0, ruff 0.17.6), each run with that commit checked out.
  • Per commit: cumulative series counts: 242 passed at item 1, 249 at item 2 and 255 at item 3, with no failures.
  • Full suite, CPU, against upstream 59890580: upstream 16 failed, 4165 passed; 50a56042: 13 failed, 4372 passed. 50a56042 is this tip before one test fix for CI, and differs from it only in that test. The failing-test diff has no new failures. The only differences are the three upstream tests/core/test_lime.py failures (TestLimeExplainerStageNet), which pass on this tip. LIME is randomized and flaky in both directions (see Tranche 1: 29 commits for commit-by-commit review #56).
  • CI fix: test_empty_cache_runs_before_reset (item 1) now runs with --epochs 0. With torch.cuda.is_available mocked to True, newer CUDA-build torch makes a real CUDA call in the optimizer step. That failed on CI, which has no GPU driver. Reproduced on a CUDA build with no visible GPU before the fix; after it, the test passes and tests/core/test_unified_e2e_runner.py passes in full (16 tests).
  • Real data: the collector's missing-field list has not been checked on a real run (pending: the rebase real-data smoke has no free GPU yet).

Not in this PR

https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95

The collector judges comparability on protocol and hardware fields, but
the runner never wrote the hardware half: every pair of real runs came
out UNVERIFIABLE. metrics.json now carries a hardware object with the
GPU model (torch device name, "cpu" on a CPU run), the GPU count the
run used (1, not the number visible), thread pinning (OMP_NUM_THREADS,
or "unset"), and the CUDA allocated/reserved peaks in MB (null on CPU).
Peaks come from the torch.cuda counters, never nvidia-smi: the run's
--device reaches max_memory_allocated, max_memory_reserved and
reset_peak_memory_stats, so --device cuda:2 records that GPU's peaks
(None keeps the current device). At the start of run(), gc.collect()
then torch.cuda.empty_cache() clear the allocator's carried-over cache
before the reset, because driver arms share one process and the
reserved peak would otherwise be inherited. An unset --drop-modality
is recorded as [] (matching the driver full arm), not null, so
collected rows can compare on it.

Sources: the missing-field half of the collector comparability review.
Tests: doctest in _collect_hardware (CPU branch), the updated demo
metrics key pin (metrics.json gains hardware), and mock-patch tests
(the run device reaches all three calls; empty_cache runs before the
reset); GPU branch and collector end covered by the cluster run.
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
Collects one standard-schema row per run directory (CSV + Markdown),
leaves absent fields missing, and flags pairs that fail the
comparability rules. Reads the runner's run_config.json,
test_metrics.json, CPU seconds/util fields, and the hardware object
(GPU model/count, thread pinning, VRAM peaks) when present. The row and
the compare fields also carry drop_modality, lr, adam_eps,
max_grad_norm, dev, split_mode, eval_split, and cache_frozen_text, so an
--lr change (or any other protocol change) compares non-comparable by
name instead of silently passing. Code identity is run_config.json's
source_sha256 (the pyhealth package only, not examples/), which is
written on git and archive trees alike, so it replaces tree_sha in the
compare fields and the pair verdicts run on every tree. Covered
against two real demo-fixture run directories (same config compares;
--lr differs and names lr) as well as synthetic ones.

Tests: tests/core/test_collect_run_stats.py (7 passed: 5 synthetic,
2 real-run, CPU, seconds; verdicts run on every tree now).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
A real run still left nine fields missing for the run-stats collector.
Record each where tools/collect_run_stats.py reads it:

- cache_bytes: tensor storage of the frozen [CLS] cache, in
  frozen_text_cache.bytes.
- peak_rss_mb: ru_maxrss of the trainer process, in MiB (bytes on macOS,
  KiB on Linux, both converted).
- peak_pss_mb: peak PSS of the process tree, sampled every 0.2 s. Linux
  only; null where psutil has no PSS (macOS).
- note_length and text_encoder: max_length and tokenizer_model of the
  admission-note processor. Null for labs-only tasks.
- positive_rate: positives over every sample the run built, before the
  train/val/test split, to 4 decimals.
- val_pr_auc_best: the trainer's best monitored validation score, from
  the new Trainer.best_score. Null when no epoch ran.
- tree_sha and dirty: already written by write_run_config from git. They
  are null outside a git checkout, as the _git_revision docstring now says.

Sources: prs/analysis/X4_stats_standard.md sections 1, 2 and 4.
Tests: tests/core/test_run_stats_fields.py, tests/core/test_unified_e2e_runner.py.

Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
@rianfyi
rianfyi force-pushed the tranche1_final-stats branch from 50a5604 to 26190ba Compare November 27, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant