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

torch compile config standardization update #3166

Merged
merged 22 commits into from
Jun 11, 2024

Conversation

agunapal
Copy link
Collaborator

@agunapal agunapal commented May 30, 2024

Description

This PR standardizes how TorchServe would be supporting any PyTorch 2.x APIs config

Define the following structure for a PyTorch 2.x feature config in model-config.yaml

pt2:
  <API name>:
    enable: True
    option1:  value1
    optionN:  valueN

or

pt2:
  <API name>:
    <feature 1>:
      enable: True
      option1:  value1
      optionN:  valueN

For torch.compile, we would specify the following options

pt2:
  compile:
    enable: True
    backend: "inductor"
    mode: "max-autotune"

This PR also fixes the issues with torch compile pytests

Fixes #(
issue1
issue2
issue3
)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

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 -v test_torch_compile.py
================================================================================== test session starts ===================================================================================
platform linux -- Python 3.10.14, pytest-7.3.1, pluggy-1.0.0 -- /home/ubuntu/anaconda3/envs/torchserve/bin/python
cachedir: .pytest_cache
rootdir: /home/ubuntu/serve
plugins: cov-4.1.0, mock-3.14.0, timeout-2.3.1
collected 8 items                                                                                                                                                                        

test_torch_compile.py::TestTorchCompile::test_archive_model_artifacts PASSED                                                                                                       [ 12%]
test_torch_compile.py::TestTorchCompile::test_start_torchserve PASSED                                                                                                              [ 25%]
test_torch_compile.py::TestTorchCompile::test_server_status PASSED                                                                                                                 [ 37%]
test_torch_compile.py::TestTorchCompile::test_registered_model PASSED                                                                                                              [ 50%]
test_torch_compile.py::TestTorchCompile::test_serve_inference SKIPPED (Test failing on regression runner)                                                                          [ 62%]
test_torch_compile.py::TestTorchCompile::test_compile_inference_enable_true_default PASSED                                                                                         [ 75%]
test_torch_compile.py::TestTorchCompile::test_compile_inference_enable_true PASSED                                                                                                 [ 87%]
test_torch_compile.py::TestTorchCompile::test_compile_inference_enable_false PASSED                                                                                                [100%]

==================================================================================== warnings summary ====================================================================================
test_torch_compile.py:12
  /home/ubuntu/serve/test/pytest/test_torch_compile.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    from pkg_resources import packaging

../../../anaconda3/envs/torchserve/lib/python3.10/site-packages/pkg_resources/__init__.py:2832
../../../anaconda3/envs/torchserve/lib/python3.10/site-packages/pkg_resources/__init__.py:2832
  /home/ubuntu/anaconda3/envs/torchserve/lib/python3.10/site-packages/pkg_resources/__init__.py:2832: 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
======================================================================= 7 passed, 1 skipped, 3 warnings in 35.29s ========================================================================

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?

@agunapal agunapal marked this pull request as ready for review June 3, 2024 16:59
@agunapal agunapal requested a review from mreso June 3, 2024 16:59
@agunapal agunapal added this to the v0.12.0 milestone Jun 3, 2024
Copy link
Collaborator

@mreso mreso left a comment

Choose a reason for hiding this comment

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

LGTM, just left some nits

@@ -23,7 +23,7 @@ Ex: `cd examples/image_classifier/resnet_18`
In this example , we use the following config

```
echo "pt2 : {backend: inductor, mode: reduce-overhead}" > model-config.yaml
echo "pt2:\n compile:\n enable: True\n backend: inductor\n mode: reduce-overhead" > model-config.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you just use multiple lines people will be able to visualize the new format much better:

echo "pt2:
  compile:
    enable: True
    backend: inductor
    mode: reduce-overhead" > model-config.yaml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Done

@@ -19,7 +19,7 @@ Ex: `cd examples/pt2/torch_compile`
In this example , we use the following config

```
echo "pt2 : {backend: inductor, mode: reduce-overhead}" > model-config.yaml
echo "pt2:\n compile:\n enable: True" > model-config.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above regarding multiline echo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Done

@@ -76,7 +76,7 @@ After a few iterations of warmup, we see the following
#### Measure inference time with `torch.compile`

```
echo "pt2: {backend: inductor, mode: reduce-overhead}" > model-config.yaml && \
echo "pt2:\n compile:\n enable: True\n backend: inductor\n mode: reduce-overhead" > model-config.yaml && \
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. Done

@@ -146,3 +176,90 @@ def test_serve_inference(self):
"Compiled model with backend inductor, mode reduce-overhead"
in model_log
)

def test_compile_inference_enable_true_default(self, chdir_example):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should parametrize these tests to make it more obvious what is the difference between them. See

@pytest.mark.parametrize(("compile"), ("false", "true"))
for an example

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is cool. Done

@agunapal agunapal enabled auto-merge June 11, 2024 18:14
@agunapal agunapal added this pull request to the merge queue Jun 11, 2024
Merged via the queue into master with commit d29059f Jun 11, 2024
11 of 12 checks passed
@agunapal agunapal deleted the feature/torch_compile_config branch June 11, 2024 20:14
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.

2 participants