Fix scheduler stepping and label dtype handling in train.py and eval.py (#152)#221
Open
egekaya1 wants to merge 1 commit intoML4SCI:mainfrom
Open
Fix scheduler stepping and label dtype handling in train.py and eval.py (#152)#221egekaya1 wants to merge 1 commit intoML4SCI:mainfrom
egekaya1 wants to merge 1 commit intoML4SCI:mainfrom
Conversation
- scheduler.step(loss) -> scheduler.step(): CosineAnnealingWarmRestarts does not accept a metric argument; passing loss caused it to treat the loss value as an epoch override, breaking the cosine LR cycle entirely - labels.type(torch.LongTensor).to(device) -> labels.to(device, dtype=torch.long) in train.py: torch.LongTensor is CPU-specific; the old form allocated an intermediate CPU tensor before transferring to device every batch - batch_y.type(torch.LongTensor) -> batch_y.to(dtype=torch.long) in eval.py: same dtype issue, and the original had no .to(device) call at all — labels never moved to GPU, working only accidentally because logits were pulled back to CPU before metric computation eval.py was missed by all prior fix attempts (ML4SCI#156, ML4SCI#168, ML4SCI#173). Fixes ML4SCI#152 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
scheduler.step(loss) -> scheduler.step(): CosineAnnealingWarmRestarts does not accept a metric argument; passing loss caused it to treat the loss value as an epoch override, breaking the cosine LR cycle entirely
labels.type(torch.LongTensor).to(device) -> labels.to(device, dtype=torch.long) in train.py: torch.LongTensor is CPU-specific; the old form allocated an intermediate CPU tensor before transferring to device every batch
batch_y.type(torch.LongTensor) -> batch_y.to(dtype=torch.long) in eval.py: same dtype issue, and the original had no .to(device) call at all — labels never moved to GPU, working only accidentally because logits were pulled back to CPU before metric computation
While reviewing eval.py, I noticed
micro_aurocis initialised as an emptylist and never populated, so
np.mean(micro_auroc)always returns NaN. Thisis already tracked in #164 and is out of scope here, but flagging it for
whoever picks that up.
Fixes #152