Repository navigation
Persist test metrics, log CPU usage, and make run identity window-aware - #54
Merged
Merged
Conversation
Four small fixes found while running the Tranche 1 sweep. 1. Test evaluation was gated on wandb. `if wandb_logger.enabled and test_loader is not None` meant a run without --wandb never computed test metrics at all -- not merely unlogged, never calculated. Ungated. 2. Test metrics are now written to test_metrics.json. metrics_history.json carries validation only and log.txt has no test lines, so the numbers that go in a paper previously lived nowhere on disk: only in stdout and W&B, recoverable afterwards only by re-scoring predictions_*.csv by hand. 3. Per-epoch CPU accounting alongside the existing VRAM and epoch_time_s: train_cpu_seconds and train_cpu_util_pct. Counts dataloader workers, since self-only time badly understates a data-loading-bound run. psutil is already present via wandb, with a resource fallback. 4. exp_name and the W&B run name now include the observation window. An observation-window arm is a different experiment from the full-stay run at the same task/model/seed, but both resolved to the same name -- so they shared an output directory and collided in W&B. Runs also now set W&B group (arm) and job_type (backbone) so a many-cell sweep is navigable. Also: create_directory used `if not exists: makedirs`, which two processes importing pyhealth for the first time can both pass, leaving one to die on FileExistsError. Seen on a shared cluster home with two concurrent jobs.
will-pang
merged commit Sep 5, 2026
0b83af8
into
ml4h-merge-tranche-1-wp-20260830
0 of 2 checks passed
rianfyi
added a commit
that referenced
this pull request
Nov 27, 2026
metrics.json carries validation only, so the test numbers worth reporting live nowhere on disk: only in stdout and W&B, recoverable afterwards only by re-scoring predictions by hand. test_metrics.json now lands next to the metrics with the eval split named. The series already evaluates test without W&B (its logger no-ops when disabled), so only the persist step was missing. create_directory uses exist_ok: the prior exists()-then-makedirs lost a race between concurrent first imports. Sources: fork #54 f4b3707 (test-metrics half verbatim; ungating already satisfied by this series; wandb group/job_type rides with the window-identity commit). Tests: tests/core/test_persist_test_metrics.py (new; the write test fails without this commit -- the makedirs-race half is not deterministically testable and rides along); demo-data runner test now asserts test_metrics.json and its eval split. Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
rianfyi
added a commit
that referenced
this pull request
Nov 27, 2026
Self-only CPU time badly understates a data-loading-bound run, since workers are separate processes, so the clock counts the process tree (psutil, resource fallback). metrics.json gains epoch_train_cpu_seconds plus train_cpu_seconds and train_cpu_util_pct next to epoch_train_seconds. Adapted to this series: its Trainer returns None and epoch wall time is measured by the runners loader, so CPU rides the same epoch boundaries instead of a trainer epoch record. Sources: fork #54 f4b3707 (_cpu_seconds verbatim; the per-epoch record half reworked onto this series loader timing). Tests: tests/core/test_trainer_cpu.py (new; both fail without this commit); demo-data runner test asserts the new metrics.json keys. Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
rianfyi
added a commit
that referenced
this pull request
Nov 27, 2026
An observation-window arm is a different experiment from the full-stay run at the same task/model/seed; without the window in the name the two share an output directory and collide in W&B. The directory and default W&B run name gain a _wN suffix when the window is nonzero, and runs set the W&B group (arm) and job_type (backbone) so a many-cell sweep stays navigable. Sources: fork #54 f4b3707 (window half, adapted: this series logger and naming differ; group/job_type stored on the logger for tests). Tests: tests/core/test_run_identity_window.py (new; all 3 fail without this commit). Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four small fixes found while running the Tranche 1 sweep. None of them change what a model computes — no numerics move.
1. Test evaluation was gated on wandb
A run without
--wandbnever computed test metrics at all — not merely unlogged, never calculated. Now ungated; the logger only decides whether they get shipped.2. Test metrics are written to disk
metrics_history.jsonholds validation only andlog.txthas no test lines, so the numbers that go in a paper lived nowhere on disk — only in stdout and W&B. If a log scrolled away, the only route back was re-scoringpredictions_*.csvby hand, which is exactly what I ended up doing to build the results table.Now
test_metrics.jsonlands next to the predictions, witheval_splitrecorded alongside so it is unambiguous which split produced them.3. Per-epoch CPU accounting
The trainer already recorded
train_vram_allocated_mb,train_vram_peak_mb, andepoch_time_s. Addedtrain_cpu_secondsandtrain_cpu_util_pctnext to them.Counts dataloader workers, not just the parent: workers are separate processes, so self-only CPU time badly understates a run whose cost is data loading — which is the interesting case for this toolkit.
psutilis already present via wandb; there is aresourcefallback, which reads low while persistent workers are still alive because it only sees reaped children.Utilisation above 100% is expected and means several cores are busy.
4. Run identity now includes the observation window
exp_namewas{task}_{model}_seed{seed}. An observation-window arm is a different experiment from the full-stay run at the same task/model/seed, but both resolved to the same name — so they shared an output directory and collided in W&B under one run name. Two runs in our project were genuinely indistinguishable except by tag.Now suffixed
_w48when a window is set. Runs also set W&Bgroup(arm) andjob_type(backbone), so a many-cell sweep is navigable instead of one flat list — 37 runs withgroup=Noneis not a project you can read.Also:
create_directoryraceTwo processes importing pyhealth for the first time both pass the check and one dies with
FileExistsError. Hit this on a shared cluster home when two jobs started together and raced on~/.cache/pyhealth/medcode/. Nowexist_ok=True.Verification
Dev split, two cells on the same tree:
--wandb)--observation-window-hours 48)labs_mlp_seed1labs_mlp_seed1_w48test_metrics.jsontrain_cpu_seconds/train_cpu_util_pctCell A is the one that matters: before this change it would have produced no test metrics at all.