Skip to content
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

feat(l2g): better l2g training, evaluation, and integration #576

Merged
merged 36 commits into from
Jun 24, 2024
Merged

Conversation

ireneisdoomed
Copy link
Contributor

@ireneisdoomed ireneisdoomed commented Apr 17, 2024

✨ Context

L2G training and prediction rewrite to use Scikit instead of pyspark.ml.

The main points that made me do this were:

  • Evaluation of the model was really slow. Even though I was persisting the L2G feature matrix and model, any time that we interacted with the model, this was triggering a retraining. This led to runtimes of ~2h if we wanted to run the pipeline end to end.
  • I don't think using Spark is necessary for training. We have a simple model. Testing the approach to scikit made training and predicting possible in seconds.
  • Using scikit brings many niceties: bigger support from community, more control, native integration with W&B (panel is more informative now), the model is easier to share, and we can upload it to the Hugging Face Hub.

Training end to end is now 18mins - job
Predicting is also 18 mins - job

This basically reassures me that annotating features is practically the entirety of the pipeline, which is consistent with my tests.

🛠 What does this PR implement

I've deprecated almost its entirety, so it's easier if i describe what this inclu
However, the L2G workflow is very similar to the previous one. This is just a change in the implementation that optimises the process.

  • LocusToGeneStep.run_train creates a L2GModel based on a GradientBoostingClassifier. The model is trained, exported to Hugging Face and saved locally.
  • LocusToGeneStep.run_predict downloads the model from the hub by default, and extracts scores.
  • The W&B and Hugging Face secrets are now accessed from the Secret Manager. So this part is now fully integrated in the pipeline.
    • Added the copy_to_gcs util to move the L2G model local file into a GCS destination.
  • The only particularity in LocusToGeneTrainer is the addition of hyperparameter_tuning. This function uses Weights&Biases Sweeps, to sweep over all parameters provided in a grid, train a model, evaluate the results and upload them in a group. For example:
    image
    (interesting that the metrics are the same) This is not part of the pipeline, only useful in development stages.
  • L2GFeatureMatrix have 2 new attributes fixed_cols, to complement the columns that are not features, and mode. Both are connected, on train mode the fixed columns are studyLocusId, geneId and the target column (goldStandardSet); on predict mode, we don't have the latter one.
  • LocusToGeneModel gain 3 attributes: hyperparameters, training_data (to store the input feature matrix and log it to W&B), label_encoder. Features_list is no longer necessary.

🙈 Missing

  • Bug in the logging of the feature matrix that don't show the feature labels
  • Cross validation to have a more accurate evaluation of the model.
  • Testing for the Training functions
  • When the model is public, we could upload the predictions dataset to the HF Hub to link a dataset with a model.

🚦 Before submitting

  • Do these changes cover one single feature (one change at a time)?
  • Did you read the contributor guideline?
  • Did you make sure to update the documentation with your changes?
  • Did you make sure there is no commented out code in this PR?
  • Did you follow conventional commits standards in PR title and commit messages?
  • Did you make sure the branch is up-to-date with the dev branch?
  • Did you write any new necessary tests?
  • Did you make sure the changes pass local tests (make test)?
  • Did you make sure the changes pass pre-commit rules (e.g poetry run pre-commit run --all-files)?

@github-actions github-actions bot removed the airflow label Jun 17, 2024
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jun 17, 2024
@ireneisdoomed ireneisdoomed changed the title perf(l2g): change l2g implementation to scikit-learn feat(l2g): better l2g training, evaluation, and integration Jun 18, 2024
@ireneisdoomed ireneisdoomed marked this pull request as ready for review June 18, 2024 10:47
pyproject.toml Outdated Show resolved Hide resolved
src/gentropy/common/utils.py Outdated Show resolved Hide resolved
src/gentropy/config.py Show resolved Hide resolved
src/gentropy/config.py Outdated Show resolved Hide resolved
src/gentropy/dataset/l2g_feature_matrix.py Show resolved Hide resolved
src/gentropy/dataset/l2g_prediction.py Outdated Show resolved Hide resolved
src/gentropy/dataset/l2g_prediction.py Show resolved Hide resolved
src/gentropy/l2g.py Show resolved Hide resolved
src/gentropy/l2g.py Show resolved Hide resolved
tests/gentropy/method/test_locus_to_gene.py Show resolved Hide resolved
@ireneisdoomed ireneisdoomed merged commit 0d9160f into dev Jun 24, 2024
4 checks passed
@ireneisdoomed ireneisdoomed deleted the il-3263 branch June 24, 2024 16:21
project-defiant pushed a commit that referenced this pull request Jul 12, 2024
* chore: checkpoint

* chore: checkpoint

* chore: deprecate spark evaluator

* chore: checkpoint

* chore: resolve conflicts with dev

* chore: resolve conflicts with dev

* chore(model): add parameters class property

* feat: add module to export model to hub

* refactor: make model agnostic of features list

* chore: add wandb to gitignore

* feat: download model from hub

* chore(model): adapt predict method

* feat(trainer): add hyperparameter tuning

* chore: deprecate trainer tests

* refactor: modularise step

* feat: download model from hub by default

* fix: convert omegaconfig defaults to python objects

* fix: write serialised model to disk and then upload to gcs

* fix(matrix): drop goldStandardSet when in predict mode

* chore: pass token to access private model

* chore: pass token to access private model

* fix: pass right schema

* chore: pre-commit auto fixes [...]

* chore: fix mypy issues

* build: remove xgboost

* chore: merge

* chore: pre-commit auto fixes [...]

* chore: address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dataset documentation Improvements or additions to documentation Feature Method size-XL Step
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants