refactor: remove redundant .to(device) in StageNet and convert assert to ValueError#966
Open
haoyu-haoyu wants to merge 2 commits intosunlabuiuc:masterfrom
Open
refactor: remove redundant .to(device) in StageNet and convert assert to ValueError#966haoyu-haoyu wants to merge 2 commits intosunlabuiuc:masterfrom
haoyu-haoyu wants to merge 2 commits intosunlabuiuc:masterfrom
Conversation
… to ValueError Remove 9 redundant .to(device) calls from StageNet step() loop and convert input-validation assertions to ValueError in splitter, tasks, and calibration modules. Assisted-by: Claude Code
The assert-to-ValueError conversion in the previous commit left two docstrings still referencing AssertionError. Assisted-by: Claude Code
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.
Summary
.to(device)calls fromStageNet.step()loop (called T times per forward pass)assertstatements toValueErrorin user-facing modulesChanges
Performance:
stagenet_mha.pyThe
step()method is called once per timestep in the forward loop. It contained 9.to(device=device)calls on intermediate tensors that already inherit device from their inputs. Removing them eliminates ~9T unnecessary operations per forward pass.Code quality:
assert→ValueErrorConverted input-validation assertions to proper
ValueErrorexceptions in:datasets/splitter.pycalib/calibration/hb.pytasks/readmission_prediction.pytasks/sleep_staging.pytasks/benchmark_ehrshot.pytasks/covid19_cxr_classification.pytasks/in_hospital_mortality_mimic4.pytasks/medical_transcriptions_classification.pyInternal invariants (red-black tree, model framework checks) are intentionally left as
assert.Test plan
python -m pytest tests/passes