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 int8 quantization support #3058

Merged
merged 13 commits into from
Aug 28, 2024
Merged

add int8 quantization support #3058

merged 13 commits into from
Aug 28, 2024

Conversation

lanluo-nvidia
Copy link
Collaborator

Description

Add int8 quantization support

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

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

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@lanluo-nvidia lanluo-nvidia self-assigned this Aug 3, 2024
@lanluo-nvidia lanluo-nvidia added WIP Work is in progress, pull request should not be merged yet and removed cla signed labels Aug 3, 2024
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Aug 3, 2024
@github-actions github-actions bot requested a review from apbose August 3, 2024 23:45
@github-actions github-actions bot requested a review from zewenli98 August 4, 2024 00:11
@peri044
Copy link
Collaborator

peri044 commented Aug 7, 2024

consider adding modelopt as optional dependency with the correct version

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-21 23:27:44.130840+00:00
+++ /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-21 23:28:02.118758+00:00
@@ -14,13 +14,15 @@
        x = self.linear1(x)
        x = torch.nn.ReLU()(x)
        x = self.linear2(x)
        return x

+
def calibrate_loop(model):
    """Simple calibration function for testing."""
    model(input_tensor)
+

input_tensor = torch.randn(1, 6).cuda()
model = SimpleNetwork().eval().cuda()
print(f"model before quantize: {model}")

@lanluo-nvidia lanluo-nvidia marked this pull request as ready for review August 21, 2024 23:28
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-21 23:28:32.341283+00:00
+++ /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-21 23:28:50.802608+00:00
@@ -14,13 +14,15 @@
        x = self.linear1(x)
        x = torch.nn.ReLU()(x)
        x = self.linear2(x)
        return x

+
def calibrate_loop(model):
    """Simple calibration function for testing."""
    model(input_tensor)
+

input_tensor = torch.randn(1, 6).cuda()
model = SimpleNetwork().eval().cuda()
print(f"model before quantize: {model}")

@lanluo-nvidia
Copy link
Collaborator Author

@dheerajperi @narendasan ready for review
tested with modelopt source from main with this PR, it is working for both int8 and fp8.

however in the testcase I has to change fromtorch.export.export()to torch.export._trace._export()
otherwise got the following error:
RuntimeError: Attempting to use FunctionalTensor on its own. Instead, please use it with a corresponding FunctionalTensorMode()
here is the slack discussion with Wei-Ming Chen from modelopt team: https://nvidia.slack.com/archives/C06K7JPMXE1/p1724280167574089

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-22 00:07:47.982949+00:00
+++ /home/runner/work/TensorRT/TensorRT/examples/dynamo/simple_int8_ptq.py	2024-08-22 00:08:05.777701+00:00
@@ -14,13 +14,15 @@
        x = self.linear1(x)
        x = torch.nn.ReLU()(x)
        x = self.linear2(x)
        return x

+
def calibrate_loop(model):
    """Simple calibration function for testing."""
    model(input_tensor)
+

input_tensor = torch.randn(1, 6).cuda()
model = SimpleNetwork().eval().cuda()
print(f"model before quantize: {model}")

@lanluo-nvidia lanluo-nvidia removed the WIP Work is in progress, pull request should not be merged yet label Aug 22, 2024
tests/py/dynamo/models/test_models_export.py Outdated Show resolved Hide resolved
examples/dynamo/simple_int8_ptq.py Outdated Show resolved Hide resolved
from torch.export._trace import _export

exp_program = _export(model, (input_tensor,))
if args.quantize_type == "int8":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldnt these be joined with a default set like enabled_precisions = {torch.float, torch.half}

Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

Seems good to me, one small optional idea for the docs

@lanluo-nvidia lanluo-nvidia merged commit b3a8cdd into main Aug 28, 2024
50 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants