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

torchao quantization integration #3309

Closed
wants to merge 9 commits into from
Closed

Conversation

agunapal
Copy link
Collaborator

@agunapal agunapal commented Sep 10, 2024

Description

This PR shows integration of torchao quantization with TorchServe

  • Adds support for autoquant API
  • Adds support for affine quantization
  • Added pytest but skipping it till we have the next stable release ( to include in developer.txt)

Fixes #(issue)

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

(torchserve) ubuntu@ip-172-31-4-205:~/serve/test/pytest$ pytest -v test_example_torchao.py 
========================================================================= test session starts ==========================================================================
platform linux -- Python 3.10.0, pytest-7.3.1, pluggy-1.5.0 -- /home/ubuntu/anaconda3/envs/torchserve/bin/python
cachedir: .pytest_cache
rootdir: /home/ubuntu/serve
plugins: cov-4.1.0, timeout-2.3.1, mock-3.14.0
collected 1 item                                                                                                                                                       

test_example_torchao.py::test_torchao_inference PASSED                                                                                                           [100%]

=========================================================================== warnings summary ===========================================================================
test/pytest/test_example_torchao.py::test_torchao_inference
  /home/ubuntu/anaconda3/envs/torchserve/lib/python3.10/site-packages/ts/torch_handler/base_handler.py:386: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
    state_dict = torch.load(model_pt_path, map_location=map_location)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
==================================================================== 1 passed, 1 warning in 15.32s =====================================================================

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 changed the title torchao integration torchao quantization integration Sep 10, 2024
@agunapal agunapal marked this pull request as ready for review September 10, 2024 20:33
@agunapal agunapal requested review from msaroufim and mreso September 10, 2024 20:33
@agunapal
Copy link
Collaborator Author

@msaroufim Would appreciate your input on the order of compile & quantization. The order in ao and diffusers is different

@msaroufim
Copy link
Member

Mind posting some perf benchmarks before and after you apply compile and ao? Also try out an LLM with int4 quantization

@agunapal
Copy link
Collaborator Author

Need to change the order for quantize_ . Also, not seeing any substantial perf improvements with bert, vit currently. Will re-open when the numbers look good.

@agunapal agunapal closed this Sep 12, 2024
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.

2 participants