Repository navigation
Follow the paper's fine-tuning schedule in the LaBraM TUH example - #1805
Conversation
Add a 5-epoch warm-up and cosine decay to 1e-6, an effective batch size of 512 by gradient accumulation, and label smoothing 0.1 on TUEV, as in Table 5 of the paper. Report the test scores obtained with this recipe.
Test CoverageTotal: 89.44% (69268 / 77448 lines) No modified files under |
|
Thanks for the TUH results and the schedule fix. I've labeled it |
|
/review |
| kwargs.setdefault("label_smoothing", smoothing) | ||
| return plain_loss(logits, y_true, **kwargs) | ||
|
|
||
| processor.loss = loss |
There was a problem hiding this comment.
[medium] Label smoothing wraps the library processor's loss; the description does not name this link
smooth_training_loss replaces the loss method of the model's label processor (processor.loss = loss). On TUEV that processor is a MultiClassLabelProcessor from pyhealth/processors/label_processor.py:353, a concrete library component, so the example now wraps its method and depends on its **kwargs pass-through to F.cross_entropy. The PR description says TUEV trains with label smoothing 0.1 but does not say the example wraps a shared processor. Either state in the description that the example wraps the processor's loss and why, or keep the example self-contained and say so. This is the author's choice.
| return np.concatenate((warmup, decay)) | ||
|
|
||
|
|
||
| class AccumulatingAdamW(torch.optim.AdamW): |
There was a problem hiding this comment.
[medium] New optimizer and LR schedule have no tests
AccumulatingAdamW (update counting, skipped steps, gradient averaging, zero_grad gating) and cosine_schedule are new non-trivial logic that decides the reported scores. The only checks are the doctests in this file, and I found no doctest collection in the repo's pytest or CI configuration, so nothing runs them. The author's 6-epoch equivalence test against the wrapper and the 587-updates check are not in the repository. tests/core/test_tcga_rna_seq.py already loads an example script by path for tests, so the pattern exists. Add a test that loads this example and checks the schedule values and the update count, and that accumulated batches give the same weights as one batch of the effective size.
| softmax head on TUAB instead of one sigmoid logit, and a validation part | ||
| drawn with this script's seed. | ||
|
|
||
| Test scores with seed 0 on one RTX 3060 Laptop GPU (paper, Tables 1 and |
There was a problem hiding this comment.
[low] Reported scores come from a wrapper, not from this script
The PR description says the 50-epoch runs used the same optimizer through a wrapper around the example. The docstring presents the scores as results of this script with seed 0. Say which script produced them, or rerun the committed script and report that.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It brings the LaBraM TUH example in line with the paper's fine-tuning recipe: a 5-epoch warm-up, a cosine decay, an effective batch of 512 through gradient accumulation, and label smoothing on TUEV. The reported TUAB scores now exceed the paper's, and TUEV moves from 0.5826 to 0.6134 balanced accuracy.
It looks ready to merge. The change is confined to the example script and touches no library code. The AccumulatingAdamW gating (stepping every 8th batch, dropping the incomplete trailing batch, and clearing gradients only after an update) is consistent with how the Trainer calls step() and zero_grad(). The loss wrapper applies smoothing only while gradients are enabled, so evaluation still uses the plain loss. The schedule length matches the number of updates per epoch.
Coverage: no files under pyhealth/ changed, so there is no per-file figure to check. The repository total is 89.44%, above the 60% bar.
Optional suggestions:
- The example wraps the model's label processor
lossto add smoothing. Say in the description that this is intentional, for example "done in the example so the library stays unchanged". - Consider a small test for
cosine_scheduleandAccumulatingAdamW(update count and schedule values). Your doctests and local equivalence check would make a good starting point, since CI may not run doctests. - The module docstring is now long with benchmark numbers. You could move the score table to the PR description or a docs page.
- The reported scores came from a wrapper around the example rather than the committed script. A short note on how to reproduce them with the committed script would help readers.
Reviewed commit 4ea9bc9
Closes #1731.
The TUH example trained LaBraM at a constant rate of 5e-4 with an update every 64 samples, since the
Trainerhas no scheduler. On TUEV the model stayed on the majority class for the first epochs and ended at 0.5826 test balanced accuracy, against 0.6409 in the paper.This PR follows Table 5 of the paper inside the example only.
AccumulatingAdamWaccumulates 8 batches of 64 per update (batch 512) and sets the rate from a 5-epoch warm-up and a cosine decay to 1e-6, the values of the officialcosine_scheduler. TUEV also trains with label smoothing 0.1. No library code changes.Test scores, seed 0, one RTX 3060 Laptop GPU (paper in brackets):
Checks: doctests pass; the schedule matches the official one within 1e-12. The 50-epoch runs used the same optimizer through a wrapper around the example; a local test gives identical weights for both over 6 epochs. A short run of this branch on TUAB starts with the expected 587 updates per epoch.
Limits: one seed, no mixed precision, TUEV still 2.75 points below the paper.