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

Add ability to run per key inference #27857

Merged
merged 6 commits into from
Aug 11, 2023

Conversation

damccorm
Copy link
Contributor

@damccorm damccorm commented Aug 4, 2023

This builds on top of #27603 to add support for running inference against a cohort of different models using the KeyedModelHandler. Full design is here - https://docs.google.com/document/d/1kj3FyWRbJu1KhViX07Z0Gk0MU0842jhYRhI-DMhhcv4/edit#heading=h.wskna8eurvjv

This piece adds basic support. In future prs we will need to cover:

  • Example + an E2E test (I have run this in an E2E pipeline, but decided to split the example out from this pr for size reasons)
  • Limiting the maximum number of models that can be held in memory
  • Model updates support
  • Metrics improvements
  • Docs

Given these gaps, I don't think we should merge before the release cut on Wednesday, but we can get this in after and iterate with small PRs

Part of #27628


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions github-actions bot added the python label Aug 4, 2023
@codecov
Copy link

codecov bot commented Aug 4, 2023

Codecov Report

Merging #27857 (10d3319) into master (887560b) will increase coverage by 0.03%.
Report is 108 commits behind head on master.
The diff coverage is 95.41%.

@@            Coverage Diff             @@
##           master   #27857      +/-   ##
==========================================
+ Coverage   70.89%   70.92%   +0.03%     
==========================================
  Files         861      861              
  Lines      105040   105053      +13     
==========================================
+ Hits        74463    74511      +48     
+ Misses      29015    28980      -35     
  Partials     1562     1562              
Flag Coverage Δ
python 79.89% <95.41%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
sdks/python/apache_beam/ml/inference/base.py 94.80% <95.41%> (+0.08%) ⬆️

... and 20 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2023

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @AnandInguva for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@AnandInguva
Copy link
Contributor

assign to next reviewer

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @tvalentyn for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@damccorm
Copy link
Contributor Author

damccorm commented Aug 9, 2023

@tvalentyn FYI, here's an integration test built on top of this PR - #27880

I'm keeping it separate for now to keep this one easier to review

sdks/python/apache_beam/ml/inference/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Outdated Show resolved Hide resolved
# Use a dataclass instead of named tuple because NamedTuples and generics don't
# mix well across the board for all versions:
# https://github.com/python/typing/issues/653
class KeyMhMapping(Generic[KeyT, ExampleT, PredictionT, ModelT]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other possible names: KeyModelEntry, KeyModelMapping, KeyMH

Also please add a docstring for this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a docstring, I don't think anything that doesn't have a ModelHandler reference is right though since they're mapping keys to model handlers

Copy link
Contributor

@tvalentyn tvalentyn Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's less precise; but ultimately users care about the key->model mapping, and MH is an intermediary. I was trying to come up with a more readable and speakable name , esp since it's public api; also it's more common in python to cap all letters in the acronym (e.g. HTTP vs Http, but i i'd rather have MhM than MHM in this case i think...). i don't have a better name though. Maybe others have ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I ended up with in the design doc so I think I'll stick with it for now. If we come up with something better we do have 6 weeks before the next cut

sdks/python/apache_beam/ml/inference/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Outdated Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Show resolved Hide resolved
sdks/python/apache_beam/ml/inference/base.py Outdated Show resolved Hide resolved
@damccorm damccorm merged commit a5f1347 into apache:master Aug 11, 2023
76 checks passed
@damccorm damccorm deleted the users/damccorm/keyedManyModels branch August 11, 2023 22:49
def __init__(
self,
unkeyed: Union[ModelHandler[ExampleT, PredictionT, ModelT],
List[KeyMhMapping[KeyT, ExampleT, PredictionT, ModelT]]]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyToModelMapping? or KeyModelMapping?

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

Successfully merging this pull request may close these issues.

4 participants