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

Micro batching example #2210

Merged
merged 27 commits into from
May 25, 2023
Merged

Micro batching example #2210

merged 27 commits into from
May 25, 2023

Conversation

mreso
Copy link
Collaborator

@mreso mreso commented Mar 31, 2023

Description

This PR introduces a new example demonstrating micro batching for a ResNet image classifier.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Feature/Issue validation/testing

Please describe the Unit or Integration tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.

  • pytest test/pytest/test_micro_batching.py
============================================================================================================================================================================= test session starts ==============================================================================================================================================================================
platform linux -- Python 3.9.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /home/ubuntu/serve
plugins: mock-3.10.0, cov-4.0.0
collected 14 items

test/pytest/test_micro_batching.py ..............                                                                                                                                                                                                                                                                                                                        [100%]

=============================================================================================================================================================================== warnings summary ===============================================================================================================================================================================
../../../opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:121
  /opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

../../../opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:2870
  /opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

../../../opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:2870
../../../opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:2870
  /opt/conda/envs/microbatching/lib/python3.9/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================================================================================= 14 passed, 4 warnings in 11.80s ========================================================================================================================================================================
  • pytest test/pytest/test_example_micro_batching.py
============================================================================================================================================================================= test session starts ==============================================================================================================================================================================
platform linux -- Python 3.9.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /home/ubuntu/serve
plugins: mock-3.10.0, cov-4.0.0
collected 3 items

test/pytest/test_example_micro_batching.py ...                                                                                                                                                                                                                                                                                                                           [100%]

============================================================================================================================================================================== 3 passed in 49.75s ==============================================================================================================================================================================

Checklist:

  • Did you have fun?
  • Have you added tests that prove your fix is effective or that this feature works?
  • Has code been commented, particularly in hard-to-understand areas?
  • Have you made corresponding changes to the documentation?

@codecov
Copy link

codecov bot commented Apr 1, 2023

Codecov Report

Merging #2210 (9022980) into master (4450287) will increase coverage by 1.24%.
The diff coverage is 95.26%.

❗ Current head 9022980 differs from pull request most recent head b3b487a. Consider uploading reports for the commit b3b487a to get more accurate results

@@            Coverage Diff             @@
##           master    #2210      +/-   ##
==========================================
+ Coverage   69.44%   70.69%   +1.24%     
==========================================
  Files          77       78       +1     
  Lines        3450     3638     +188     
  Branches       57       57              
==========================================
+ Hits         2396     2572     +176     
- Misses       1051     1063      +12     
  Partials        3        3              
Impacted Files Coverage Δ
ts/handler_utils/micro_batching.py 90.90% <90.90%> (ø)
ts/tests/unit_tests/test_micro_batching.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

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

Copy link
Collaborator

@HamidShojanazeri HamidShojanazeri left a comment

Choose a reason for hiding this comment

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

Thanks @mreso , LGTM.

Copy link
Collaborator

@lxning lxning left a comment

Choose a reason for hiding this comment

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

many users ignore TS good examples. Micro batching is a good feature to boost TPS. We need promote it to a feature announcement, not just an example.

can we move extract the core parts such as micro_batching.py and micro_batch_handler.py to handler utils so that users can easily plugged in customer handler?

def initialize(self, ctx):
super().initialize(ctx)

config_file = Path(ctx.system_properties["model_dir"], "micro_batching.json")
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use the new feature model-config.yaml to set these parameters?

all of the parameters can be accessed via ctx. model_yaml_config

Comment on lines 26 to 27
self.handle.parallelism = config["parallelism"]
self.handle.micro_batch_size = config["micro_batch_size"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

users may be thought "parallelism" and "micro_batch_size" are related to large model parallel. Can we have a good naming to differentiate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, can just call them mb_size and mb_parallelism

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Went with ["micro_batching"]["parallelism"], that should be sufficient for users to differentiate.

@mreso mreso requested a review from lxning April 5, 2023 00:43
Copy link
Collaborator

@lxning lxning left a comment

Choose a reason for hiding this comment

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

ts/handler_utils is handler utils dir. could you move utils/micro_batching.py to ts/handler_utils/microbatching?

Comment on lines 1 to 3
from .micro_batching import MicroBatching

__all__ = ["MicroBatching"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this needs to be removed.

@lxning lxning merged commit 4f85477 into master May 25, 2023
18 of 19 checks passed
@agunapal
Copy link
Collaborator

@mreso I see the MacOS CI is failing because of Resource issue. Can you please check if its because of this PR?

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

Successfully merging this pull request may close these issues.

None yet

4 participants