-
Notifications
You must be signed in to change notification settings - Fork 8
[Feature]: Generalize Prediction pipeline for Lightning CLI models #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6571cfb
changes moved from https://github.com/ChEB-AI/python-chebai/pull/135
aditya0by0 1997d9f
fix pipeline
aditya0by0 7e1143e
make classification labels to be in ckpt file mandatory
aditya0by0 ac863cd
avoid generated dummy labels for each smiles
aditya0by0 9daa712
add vs extensions setting for the projects
aditya0by0 c584284
fix model device error + config fp
aditya0by0 2ef9cc8
Change Python type checking mode to 'basic'
aditya0by0 5e9d5e9
use execute for predict step
aditya0by0 c7b3a86
Update .vscode/settings.json
aditya0by0 7f094c3
fix type
sfluegel05 e30513a
fix file path in comment
sfluegel05 1d33f65
add migration script
aditya0by0 55def66
copilot comments
aditya0by0 9084374
model hparms required
aditya0by0 3b46ac2
use load_checkpoint to load model as it loads weights too
aditya0by0 fea402e
Update chebai/preprocessing/migration/migrate_checkpoints.py
aditya0by0 679a5cb
Fix review comments: type hints, error handling, and documentation (#…
Copilot 6148667
update to instantiate a predictor from mlp model
aditya0by0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,7 +175,7 @@ chebai.egg-info | |
| lightning_logs | ||
| logs | ||
| .isort.cfg | ||
| /.vscode | ||
| /.vscode/launch.json | ||
|
|
||
| *.out | ||
| *.err | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "recommendations": [ | ||
| "ms-python.python", | ||
| "ms-python.vscode-pylance", | ||
| "charliermarsh.ruff", | ||
| "usernamehw.errorlens" | ||
| ], | ||
| "unwantedRecommendations": [ | ||
| "ms-python.vscode-python2" | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "python.testing.unittestArgs": [ | ||
| "-v", | ||
| "-s", | ||
| "./tests", | ||
| "-p", | ||
| "test*.py" | ||
| ], | ||
| "python.testing.pytestEnabled": false, | ||
| "python.testing.unittestEnabled": true, | ||
| "python.analysis.typeCheckingMode": "basic", | ||
| "editor.formatOnSave": true, | ||
| "[python]": { | ||
| "editor.defaultFormatter": "charliermarsh.ruff" | ||
| } | ||
| } |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """ | ||
| Docstring for chebai.preprocessing.migration.migrate_checkpoints | ||
|
|
||
| This script migrates lightning checkpoints created before python-chebai | ||
| version 1.2.1 to be compatible with the new version. | ||
|
|
||
| The main change is the addition of a new key "classification_labels" in the checkpoint, | ||
| which is required for the new version of python-chebai from version 1.2.1 onwards. | ||
|
|
||
| For more details, see the pull request: https://github.com/ChEB-AI/python-chebai/pulls | ||
| """ | ||
|
|
||
| import sys | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| def add_class_labels_to_checkpoint(input_path, classes_file_path): | ||
| print(f"Loading checkpoint from {input_path}...") | ||
| print(f"Loading class labels from {classes_file_path}...") | ||
|
|
||
| with open(classes_file_path, "r") as f: | ||
| class_labels = [line.strip() for line in f.readlines()] | ||
|
|
||
| assert len(class_labels) > 0, "The classes file is empty." | ||
|
|
||
| # 1. Load the checkpoint | ||
| checkpoint = torch.load( | ||
| input_path, map_location=torch.device("cpu"), weights_only=False | ||
| ) | ||
|
|
||
| if "classification_labels" in checkpoint: | ||
| print( | ||
| "Warning: 'classification_labels' key already exists in the checkpoint and will be overwritten." | ||
| ) | ||
|
|
||
| # 2. Add your custom key/value pair | ||
| checkpoint["classification_labels"] = class_labels | ||
|
|
||
| # 3. Save the modified checkpoint | ||
| output_path = input_path.replace(".ckpt", "_modified.ckpt") | ||
| torch.save(checkpoint, output_path) | ||
| print(f"Successfully added classification_labels and saved to {output_path}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) < 3: | ||
| print("Usage: python migrate_checkpoints.py <input_checkpoint> <classes_file>") | ||
| sys.exit(1) | ||
|
|
||
| input_ckpt = sys.argv[1] | ||
| classes_file = sys.argv[2] | ||
|
|
||
| add_class_labels_to_checkpoint( | ||
| input_path=input_ckpt, classes_file_path=classes_file | ||
| ) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.