Fix ICEBERG forward prediction on pip-install / CPU / pytorch_lightning 2.x#35
Open
hugogontijomachado wants to merge 1 commit into
Open
Conversation
…ng 2.x Three small, backward-compatible fixes so iceberg_prediction() -> dag_pred/predict_smis.py runs end-to-end outside an editable repo checkout: 1. iceberg_elucidation.py: build the subprocess command with predict_smis.py resolved relative to the package (Path(__file__).parent) instead of the cwd-relative "src/ms_pred/dag_pred/predict_smis.py", which only exists when run from the repo root (fails on a pip install). 2. predict_smis.py: use pl.seed_everything instead of pl.utilities.seed.seed_everything, which was removed in pytorch_lightning 2.0. pl.seed_everything is the public API and works in PL 1.x and 2.x. 3. predict_smis.py: guard torch.cuda.set_device(gpu_id) with `if gpu and avail_gpu_num > 0`; on CPU gpu_id is undefined (NameError) and there is no CUDA device to select.
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
Three small, backward-compatible fixes so ICEBERG forward prediction
(
iceberg_prediction()→dag_pred/predict_smis.py) runs end-to-end whenms_predispip-installed, on CPU, and with pytorch_lightning ≥ 2.0. None of them change
behavior for an editable checkout / GPU / PL 1.x.
1.
dag_pred/iceberg_elucidation.py— resolvepredict_smis.pyrelative to the packageiceberg_prediction()builds the subprocess with a cwd-relative path:That only resolves when run from the repo root. On a pip install there is no
src/, so thesubprocess fails (
can't open file '.../src/ms_pred/dag_pred/predict_smis.py') andload_pred_specthen raises on the missingpreds.hdf5. Fixed by locating the script viaPath(__file__).resolve().parent / "predict_smis.py"(the two files live side by side).2.
dag_pred/predict_smis.py—pl.seed_everythingpytorch_lightning.utilities.seed.seed_everythingwas removed in PL 2.0(
AttributeError: module 'pytorch_lightning.utilities.seed' has no attribute 'seed_everything').pl.seed_everythingis the public API and exists in both PL 1.x and 2.x.3.
dag_pred/predict_smis.py— guardtorch.cuda.set_deviceon CPUIn
producer_func,torch.cuda.set_device(gpu_id)runs unconditionally, butgpu_idisonly assigned in the GPU branch — on CPU this raises
NameError(and there is no CUDAdevice to select). Guarded with
if gpu and avail_gpu_num > 0:.How these surfaced
Predicting MS/MS from SMILES with the public MassSpecGym checkpoints on macOS (CPU) with
pytorch_lightning 2.6.5; each fix revealed the next.
Testing
After all three,
iceberg_prediction(...)runs end-to-end on CPU and producespreds.hdf5(verified by predicting glyphosate MS/MS for
[M-H]-and[M+H]+).