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

Shell out to model handlers to collect byte sizes #28182

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

damccorm
Copy link
Contributor

Right now, we're not calculating batch sizes correctly for keyed examples in the per key model handler implementation; we should be shelling out to the underlying model handler which can do this more effectively. This adds support to do this.

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.

@damccorm
Copy link
Contributor Author

R: @tvalentyn

@github-actions
Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #28182 (5b920ad) into master (e26735d) will increase coverage by 0.01%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #28182      +/-   ##
==========================================
+ Coverage   72.29%   72.31%   +0.01%     
==========================================
  Files         678      678              
  Lines       99848    99855       +7     
==========================================
+ Hits        72189    72208      +19     
+ Misses      26084    26072      -12     
  Partials     1575     1575              
Flag Coverage Δ
python 82.90% <100.00%> (+0.02%) ⬆️

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 95.09% <100.00%> (+0.07%) ⬆️

... and 10 files with indirect coverage changes

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


def test_keyed_model_handler_multiple_models_get_num_bytes(self):
mhs = [
base.KeyMhMapping(['key1'], FakeModelHandler(num_bytes_per_element=10)),
Copy link
Contributor

Choose a reason for hiding this comment

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

do you still plan to change the name of KeyMhMapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm waiting until I don't have in flight PRs around this to change it to avoid conflicts (right now #28026 uses KeyMhMapping)

return batch_bytes + self._unkeyed.get_num_bytes(unkeyed_batch)

batch_by_key = defaultdict(list)
for pair in batch:
Copy link
Contributor

@tvalentyn tvalentyn Aug 28, 2023

Choose a reason for hiding this comment

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

nit: consider using mnemonic names for readability if pair can be unpacked:

    for key, examples in batch:
      batch_by_key[key].append(examples)

Copy link
Contributor

Choose a reason for hiding this comment

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

also there is conflation of batch of keyed prediction inputs vs a batch of elements for a single key. not sure how to clarify, could use a courtesy variable like:

    if self._single_model:
      return batch_bytes + self._unkeyed.get_num_bytes(unkeyed_batch)
    else:
      keyed_batches = batch

    for key, examples in keyed_batches:
      ...

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 updated to use key/examples.

also there is conflation of batch of keyed prediction inputs vs a batch of elements for a single key. not sure how to clarify, could use a courtesy variable like:

I don't think this is right. batches means batch of keyed prediction inputs in all contexts here, batch_by_key represents batches of elements per key.

@damccorm damccorm merged commit 252c713 into apache:master Aug 28, 2023
91 checks passed
@damccorm damccorm deleted the users/damccorm/per-key-metrics branch August 28, 2023 19:03
zechenj18 pushed a commit to zechenj18/beam that referenced this pull request Aug 29, 2023
* Shell out to model handlers to collect byte sizes

* naming
lostluck pushed a commit to lostluck/beam that referenced this pull request Aug 30, 2023
* Shell out to model handlers to collect byte sizes

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

Successfully merging this pull request may close these issues.

2 participants