Skip to content

Tranche 1 systems: run provenance, comparability guards, and resource logging - #57

Draft
rianfyi wants to merge 11 commits into
tranche1_final-commitsfrom
tranche1_final-systems
Draft

rianfyi wants to merge 11 commits into
tranche1_final-commitsfrom
tranche1_final-systems

Conversation

@rianfyi

@rianfyi rianfyi commented Nov 6, 2026 •

Copy link
Copy Markdown

Draft. The systems commits for Tranche 1, in 11 small commits, stacked on #56. The base is tranche1_final-commits, which is rebased onto upstream 59890580 (earlier base 2c9dfacf). Upstream master has since moved to 0181aa2f; this series stays on 59890580 for review. This diff holds only these 11 commits, and #56 should land first. The rebased branch tip is 4edd18ba. Please use the Commits tab: each commit makes one change and has its own tests.

Nothing here goes upstream yet. Items 1 to 6 come from earlier fork branches; item 6 is adapted from fork PR #55 and is not a verbatim copy. Each commit's Sources: line says which. Items 7 to 11 are new. Item 1 stays fork-only for now; the other ten are upstream candidates.

Commits

# Commit Subject Behaviour change
1 8aa75c2 Write run_config.json next to the metrics of a finished run New file in each run directory
2 db10bfd Keep paired runs from overwriting each other or reporting train as test Run directories include the task, plus _dev<N> for a nonzero --dev
3 91e741f Persist test metrics to disk on every run with a test split New test_metrics.json
4 e378085 Log per-epoch CPU seconds alongside wall time New metrics.json keys
5 b6e631c Make run identity window-aware Run directories gain _w<N> for a nonzero window
6 7dd49ec Report PSS alongside summed RSS in benchmark_perf New peak_pss_bytes column; peak_rss_bytes unchanged
7 0a60672 Resolve optimizer settings from the CLI only Bottleneck defaults change
8 844cd23 Refuse --amp-dtype without --use-amp Bare --amp-dtype is now a parse error
9 39456c7 Refuse the leaky by-sample fallback unless --allow-leaky-split Runs with an empty patient split now stop
10 d54772d Warn about architecture flags a backbone ignores, and record them Warning only, for non-default values
11 4edd18b Warn when a mortality run keeps the full stay Warning only, at the default window of 0

Please read before reviewing

  • Item 7: bottleneck_transformer loses its hardcoded clip of 0.5 and Adam eps of 1e-6, and now gets 1.0 and 1e-8 like every other backbone. That makes the backbones comparable, but it scored slightly lower in a single-seed rerun. To restore the old values, pass --max-grad-norm 0.5 --adam-eps 1e-6 and say so in the results. Trainer.train now always clips.
  • Item 9: this affects tiny cohorts. A --dev smoke run whose patient split comes up empty now stops with a RuntimeError. It can opt in with --allow-leaky-split, which adds _allow_leaky to the run directory, and its metrics aren't comparable to patient-split runs.
  • Item 11: the default window_hours=0 keeps the full stay through discharge (see item 28 in Tranche 1: 29 commits for commit-by-commit review #56), so a mortality run at the default now logs a warning naming --observation-window-hours. Nothing else changes.
  • Item 1: the source digest covers .py files in the pyhealth package. It doesn't cover examples/, configs or launchers.

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 tests after the rebase: 184 passed at item 1 and 215 passed at item 11, with no failures at any commit in between.
  • Targeted run (31 tests): the files that failed at the first version of Tranche 1: 29 commits for commit-by-commit review #56 item 20 now pass: 285 passed, 0 failed at this tip.
  • Full suite, CPU, same environment, against upstream 59890580: upstream 16 failed, 4165 passed. This tip 4edd18ba: 13 failed, 4332 passed. The failing-test diff has no new failures. The only differences are three upstream failures in tests/core/test_lime.py (TestLimeExplainerStageNet: initialization, target_class and values_finite) that pass on this tip. LIME is randomized and flaky in both directions (see Tranche 1: 29 commits for commit-by-commit review #56).
  • Not covered: this branch has no real-MIMIC run of its own. The full suite uses synthetic and demo data, on CPU. The rebase real-data smoke is pending.

Not in this PR

  • Lab z-score wiring: moved to later.
  • Experiment driver and run-stats collector: still local, built on top of this branch.

https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95

rianfyi and others added 11 commits November 27, 2026 12:12
metrics.json stores the score but not the conditions, so a frozen-encoder
run and a fine-tuned run were indistinguishable after the job log was gone.
write_run_config records the resolved settings plus git revision and a
source-tree digest, which keeps code identity answerable from an unpacked
cluster tarball. The runner calls it before training so the config lands
even when training crashes.

Fork-only for now, per the review discussion: it lives in pyhealth/utils.py
but is not proposed upstream.

Sources: 224e7f4 (utils part verbatim); provenance half matches the utils
part of fork #53 d45e3cc; runner call is new wiring for this series.
Tests: tests/core/test_run_config.py (new); demo-data runner test now
asserts run_config.json and its keys.
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
The run directory was {model}_seed{seed}, so --task labs and --task
notes_labs at one seed resolved to one path and the second run destroyed
the first. Predictions came from "test or val or train" with nothing
saying which, and the patient-split fallback was silent. The task is now
in the directory name, a nonzero --dev adds a _dev<N> suffix to the same
name, the split that predictions come from is named and warned about when
it is not test, and both the split mode and the eval split are recorded
in run_config.json next to the metrics. The predictions CSV carries the
eval split as a constant column, so collected files say which split they
hold.

Sources: 5def4ea (paired-run dirs, leaky-split warning, eval split; MLP,
lab-standardizer, loader and default changes left out -- the series
already carries them or they belong to Later); the eval-split naming
matches the runner half of fork #53 d45e3cc.
Tests: tests/core/test_paired_runs_eval_split.py (new; all 6 fail without
this commit).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
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
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
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
Summing RSS over forked workers counts every shared page once per
process; PSS divides it among the mappers, so the total stays additive.
peak_pss_bytes lands next to peak_rss_bytes in all 16 harnesses. Where
PSS is unavailable for any process in the tree, that sample is None, so
the column is left empty for the run rather than holding RSS. A denied
process drops the sample instead of undercounting it, while an exited one
is skipped. The peak_pss reset runs inside the sampler lock.
Additive: peak_rss_bytes keeps its meaning, so numbers already collected
stay interpretable.

Based on fork PR #55 (07355ae), not a verbatim copy. The PR falls back to
RSS when PSS is unavailable, resets the PSS peak outside the lock, and
undercounts denied processes. This commit does none of those.

Sources: fork #55 07355ae (adapted; see above).
Tests: tests/core/test_benchmark_pss.py (new; fails without this
commit -- tracker exercised where importable, structural markers
elsewhere since meds_reader is unavailable here, plus fake-process
cases: denied drops the sample, exited is skipped).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
A per-model branch gave bottleneck_transformer max_grad_norm=0.5 and
Adam eps=1e-6 while every other backbone got 1.0 and 1e-8, so a
six-backbone table that read as compute-matched was not, and the recorded
config stored the raw flag (null) instead of the value the optimizer
used. Defaults are now lr=1e-4, eps=1e-8, clip=1.0 for every model; a
backbone that needs different settings must be passed them.

Behaviour change in the runner: bottleneck_transformer loses its 0.5
clip / 1e-6 eps hardcode (it scored slightly lower in a single-seed
rerun); restore it with --max-grad-norm 0.5 --adam-eps 1e-6.

Sources: the per-model branch was found by comparing the runner against
the reference launcher configurations.
Tests: tests/core/test_optimizer_cli_only.py (new; all 3 fail without
this commit).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
The flag list says --amp-dtype "bf16" and never mentions --use-amp, so
following it literally ran fp32 while the recorded config claimed bf16.
A bare --amp-dtype is now a parse error; omitting it resolves to bf16
for the run that does pass --use-amp.

Sources: the flag/config mismatch was found against the reference
launcher configurations.
Tests: tests/core/test_amp_dtype_flag.py (new; the error case fails
without this commit, the other two pin the default).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
The fallback puts a patient with several admissions in both train and
test, inflating every metric, and used to happen with no warning at all.
A run that cannot be split correctly now stops instead of quietly
producing numbers nobody can use; smoke tests opt in explicitly. The
opt-in is marked in the run directory (_allow_leaky): it records the
config, not whether the fallback fired. Silence was the last way a run
could disagree with its own split config.

Sources: the silent patient-split fallback was found against the
reference launcher configurations.
Tests: the paired-run split tests now pin refuse-by-default plus the
allowed fallback path (both fail without this commit), and the opt-in
run directory gains _allow_leaky (fails without this commit).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
A launcher could appear to set something that never reached the model:
MLP has no dropout parameter and swallows it in **kwargs, JambaEHR
ignores --num-layers, and transformer/bottleneck/ehrmamba/jamba ignore
--hidden-dim. An ignored flag the user set to a non-default value is now
logged at startup (compared against the parser defaults, so a run at
defaults stays silent); the full ignored list is still stored as
inert_flags in run_config.json, so a table cannot misread the set flags
as settings that took effect.

Sources: map derived from this series' runner wiring; ignored flags are
recorded in run_config.json next to the metrics.
Tests: tests/core/test_inert_arch_flags.py (new; the warn and record tests
fail without this commit, and the at-defaults silence test fails on the
old always-warn code).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
window_hours=0 (the default) keeps the full stay through discharge, so
mortality features can include data up to discharge or death and the
label can leak into the inputs. A run that starts with an effective
observation window of 0 on a mortality task now logs one warning naming
--observation-window-hours; a positive window and non-mortality tasks
stay silent. Warning only: no refusal, no new flags, and no new
run_config field.

Sources: mortality --task values derived from the task classes'
output_schema (pyhealth/tasks/multimodal_mimic4.py:457 and :606, both
{"mortality": "binary"}); window semantics from the shared base task.
Tests: tests/core/test_mortality_full_stay_warning.py (new; all four
fail without this commit).
Claude-Session: https://claude.ai/code/session_011iPyPDjj4ktrHDkPbEkk95
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.

2 participants