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

✨ Enable to override params at predict time in KedroPipelineModel #612

Merged

Conversation

Galileo-Galilei
Copy link
Owner

@Galileo-Galilei Galileo-Galilei commented Nov 22, 2024

Description

Close #445, improve #587 and generalize #580.

The goal is to support inference parameters for KedroPipeline Model, in order to be able to modify inference pipeline behaviour at runtime without retraining (e.g. retraining makes no sense just to change a threshold or the temperature)

Development notes

What have you changed, and how has this been tested?

  • Pin mlflow>=2.7.0 which is the lowest version that support params
  • Update MlflowHook to infer parameter signature from the inference pipeline of a PipelineML. this signature is passed when logging the custom model.
  • Also add a "runner" argument to the signature to enforce the ability
  • Update KedroPipelineModel.predict to propagate params and use the runner and params provided.

⚠️ Passing hooks via this mechanism is out of scope, because they should be defined at logging time and because mlflow supports only native python / pandas / numpy dtypes.

⚠️ This is heavily tested locally with mlflow==2.17. The CI test suite fails because of unrelated #613.-> Fixed with kedro-mlflow>=0.13.4.

Checklist

  • Read the contributing guidelines
  • Open this PR as a 'Draft Pull Request' if it is work-in-progress
  • Update the documentation to reflect the code changes
  • Add a description of this change and add your name to the list of supporting contributions in the CHANGELOG.md file. Please respect Keep a Changelog guidelines.
  • Add tests to cover your changes

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

  • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.

  • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorised to submit this contribution on behalf of the original creator(s) or their licensees.

  • I certify that the use of this contribution as authorised by the Apache 2.0 license does not violate the intellectual property rights of anyone else.

@Galileo-Galilei Galileo-Galilei changed the title ✨ Enable to override params at predict time in KedroPipeline… ✨ Enable to override params at predict time in KedroPipelineModel Nov 30, 2024
@Galileo-Galilei
Copy link
Owner Author

Galileo-Galilei commented Dec 1, 2024

@Calychas This should already work, can you try? If you don't have a custom signature in your pipeline ml factory, you have nothing to change: just train normally and you should see available parameters in the signature of the model in the UI. Then do:

model=mlflow.pyfunc.load_model(f"runs:/{run_id}/{artifact_path}")
model.predict(data, params={"<your_param_name>":<your_param_value>})

@Galileo-Galilei Galileo-Galilei force-pushed the 445-add-inference-params-to-kedropipelinemodel branch from b81a082 to fadd662 Compare December 22, 2024 10:57
@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.90%. Comparing base (023049b) to head (404c0d6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #612   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files          30       30           
  Lines        1054     1063    +9     
=======================================
+ Hits         1053     1062    +9     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Galileo-Galilei
Copy link
Owner Author

@Calychas We're getting very close! I haven't had a chance to work on kedro-mlflow these past 2 months, but I'm there again. I've refactored a lot the documentation so it makes the PR messy and I will likely separate it, but It's almost good to go.

specify signature at runtime with parameters

remove unused pydantic validation class

make sure that only inference params are allowed, not train ones

pass runner through params

fix change of default signature in tests

add tests

 add test for runner

pin mlflow>=2.7

fix changelog conflict

typo
@Galileo-Galilei Galileo-Galilei force-pushed the 445-add-inference-params-to-kedropipelinemodel branch 5 times, most recently from 04eca21 to 64ebfd7 Compare January 28, 2025 22:09
Update doc

up doc

fix tests

update doc

huge doc refactoring

doc refactoring

doc refactoring

finish doc

update doc
@Galileo-Galilei Galileo-Galilei force-pushed the 445-add-inference-params-to-kedropipelinemodel branch from 64ebfd7 to 404c0d6 Compare January 28, 2025 22:10
@Galileo-Galilei Galileo-Galilei marked this pull request as ready for review January 28, 2025 22:19
@Galileo-Galilei Galileo-Galilei merged commit d0fd002 into master Jan 28, 2025
15 of 17 checks passed
@Galileo-Galilei Galileo-Galilei deleted the 445-add-inference-params-to-kedropipelinemodel branch January 28, 2025 22:19
@Galileo-Galilei
Copy link
Owner Author

And... it's on PyPI : https://pypi.org/project/kedro-mlflow/ 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Add inference parameters to KedroPipelineModel
2 participants