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

Clean up linear_int8_dynamic_activation_intx_weight_subclass #1553

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

metascroy
Copy link
Contributor

@metascroy metascroy commented Jan 11, 2025

Summary:
Cleans up layout and quantization API:

int8_dynamic_activation_intx_weight(
    weight_dtype=torch.int4,
    granularity=PerGroup(128),
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight. By passing bit_width=4, has_weight_zeros=false, and layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939

Copy link

pytorch-bot bot commented Jan 11, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1553

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f04f3b2 with merge base de5c6e1 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 11, 2025
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

@@ -60,15 +60,15 @@ from torchao.quantization.quant_api import quantize_
quantize_(
my_model,
int8_dynamic_activation_intx_weight(
bit_width=4,
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be updated to using real dtype now if you can use torch nightly btw, both torch.uintx and torch.intx are available in nightly (2.6 and later I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed bit_width to weight_dtype

Copy link
Contributor

Choose a reason for hiding this comment

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

please change README as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated readme

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

metascroy added a commit to metascroy/ao that referenced this pull request Jan 13, 2025
…#1553)

Summary:
Pull Request resolved: pytorch#1553

Cleans up layout and quantization API:

```
int8_dynamic_activation_intx_weight(
    group_size: int = 128,
    bit_width: int = 4,
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)
```

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight.  By passing bit_width=4, has_weight_zeros=false, and  layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939
@metascroy metascroy added the topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) label Jan 13, 2025
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

metascroy added a commit to metascroy/ao that referenced this pull request Jan 13, 2025
…#1553)

Summary:
Pull Request resolved: pytorch#1553

Cleans up layout and quantization API:

```
int8_dynamic_activation_intx_weight(
    group_size: int = 128,
    bit_width: int = 4,
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)
```

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight.  By passing bit_width=4, has_weight_zeros=false, and  layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

metascroy added a commit to metascroy/ao that referenced this pull request Jan 13, 2025
…#1553)

Summary:
Pull Request resolved: pytorch#1553

Cleans up layout and quantization API:

```
int8_dynamic_activation_intx_weight(
    group_size: int = 128,
    bit_width: int = 4,
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)
```

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight.  By passing bit_width=4, has_weight_zeros=false, and  layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

metascroy added a commit to metascroy/ao that referenced this pull request Jan 13, 2025
…#1553)

Summary:
Pull Request resolved: pytorch#1553

Cleans up layout and quantization API:

```
int8_dynamic_activation_intx_weight(
    group_size: int = 128,
    bit_width: int = 4,
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)
```

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight.  By passing bit_width=4, has_weight_zeros=false, and  layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939
@metascroy metascroy requested a review from jerryzh168 January 13, 2025 21:07
+ " Alternatively, use layout=PlainLayout() with int8_dynamic_activation_intx_weight, but note that doing so will result in much slower performance."
)

dtype_to_bit_width = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not pass this around to layout as well?

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 think for layout, bit_width is more convenient a more to use because I can then do something like this to call the kernel:

getattr(torch.ops.torchao, f"_pack_8bit_act_{layout.bit_width}bit{wzp_suffix}_weight")(*args)

I can change, though, if you think it's better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, depending on whether there could be cases of uintx as well I think, if not, then it's fine since it's not user facing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's leave it as bitwidth then. The quantizer is specifically for intx, not uintx, and the layout is not user facing.

Copy link
Contributor

@jerryzh168 jerryzh168 Jan 14, 2025

Choose a reason for hiding this comment

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

sg, also we have a util here:

_DTYPE_TO_BIT_WIDTH.update(

…#1553)

Summary:
Pull Request resolved: pytorch#1553

Cleans up layout and quantization API:

```
int8_dynamic_activation_intx_weight(
    group_size: int = 128,
    bit_width: int = 4,
    has_weight_zeros: bool = False,
    weight_mapping_type=MappingType.ASYMMETRIC,
    act_mapping_type=MappingType.ASYMMETRIC,
    layout=PackedLinearInt8DynamicActivationIntxWeightLayout(),
)
```

int8_dynamic_activation_intx_weight is now very similar to int8_dynamic_activation_int4_weight.  By passing bit_width=4, has_weight_zeros=false, and  layout=PlainLayout(), it should be numerically identical (but slower).

The fallback option is removed and instead relies on using PlainLayout().

Reviewed By: jerryzh168

Differential Revision: D67821939
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D67821939

@metascroy metascroy requested a review from jerryzh168 January 14, 2025 17:36
Comment on lines +589 to +590
quant_min = -(1 << (bit_width - 1))
quant_max = (1 << (bit_width - 1)) - 1
Copy link
Contributor

Choose a reason for hiding this comment

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

we also have utils here:

_SUB_BYTE_INT_BOUNDS.update(

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@facebook-github-bot facebook-github-bot merged commit 0bc5b00 into pytorch:main Jan 14, 2025
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants