Skip to content

Follow the paper's fine-tuning schedule in the LaBraM TUH example - #1805

Merged
solarsys merged 1 commit into
sunlabuiuc:masterfrom
AxelNoun:labram-example-paper-schedule
Dec 4, 2026
Merged

solarsys merged 1 commit into
sunlabuiuc:masterfrom
AxelNoun:labram-example-paper-schedule

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Closes #1731.

The TUH example trained LaBraM at a constant rate of 5e-4 with an update every 64 samples, since the Trainer has 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. AccumulatingAdamW accumulates 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 official cosine_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):

  • TUAB: balanced accuracy 0.8316 (0.8140), AUROC 0.9098 (0.9022)
  • TUEV: balanced accuracy 0.6134 (0.6409), Cohen's kappa 0.5274 (0.6637)

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.

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.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Test Coverage

Total: 89.44% (69268 / 77448 lines)

No modified files under pyhealth/.

Workflow run · 4ea9bc9

@solarsys solarsys added the status: automatic The PR will go through automatic review process. label Dec 4, 2026
@solarsys

solarsys commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the TUH results and the schedule fix. I've labeled it status: automatic: the change is a single file in examples/, no library code changes, and the new helpers carry doctests. I checked that the leftover batches at the end of an epoch are cleared by self.model.zero_grad() at the start of each epoch in pyhealth/trainer.py, so the accumulation logic holds. The build passes, so I'm requesting the AI review.

@solarsys

solarsys commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 4ea9bc9

kwargs.setdefault("label_smoothing", smoothing)
return plain_loss(logits, y_true, **kwargs)

processor.loss = loss

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 loss to 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_schedule and AccumulatingAdamW (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

@solarsys
solarsys merged commit fbddeb1 into sunlabuiuc:master Dec 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LaBraM: add fine-tuning results on TUAB and TUEV

2 participants