+
Skip to content

Conversation

namgyu-youn
Copy link
Contributor

@namgyu-youn namgyu-youn commented Oct 10, 2025

Summary:
Add quantized parameter choosing algorithm for int4 weight-only quantization (int4_choose_qparams_algorithm) test

Related Issue/PR: #3106 (comment)

Test plan:
test/prototype/test_awq.py

Copy link

pytorch-bot bot commented Oct 10, 2025

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit ad15bb9 with merge base 2fe0ca0 (image):

NEW FAILURES - The following jobs have failed:

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

@meta-cla meta-cla 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 Oct 10, 2025
Int4WeightOnlyConfig(group_size=128, int4_packing_format="tile_packed_to_4d"),
Int4WeightOnlyConfig(
group_size=128,
int4_packing_format="tile_packed_to_4d",
Copy link
Contributor Author

@namgyu-youn namgyu-youn Oct 10, 2025

Choose a reason for hiding this comment

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

nit: How about using packing_format instead of int4_packing_format, and choose_qparams_algorithm instead of int4_choose_qparams_algorithm? The current name seems too long and not generalized.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is intentional actually since we don't want to introduce global abstractions that is only used by a single dtype

Comment on lines 1159 to 1164
if isinstance(self.int4_packing_format, str):
self.int4_packing_format = Int4PackingFormat(self.int4_packing_format)
if isinstance(self.int4_choose_qparams_algorithm, str):
self.int4_choose_qparams_algorithm = Int4ChooseQParamsAlgorithm(
self.int4_choose_qparams_algorithm
)
Copy link
Contributor

Choose a reason for hiding this comment

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

these are not needed actually since we use str Enum

Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove this? I guess we can just add the config and it works.

@jerryzh168
Copy link
Contributor

wait, no fix is needed? does the test of int4 hqq config work? I remember it's failing for me

@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Oct 10, 2025

wait, no fix is needed? does the test of int4 hqq config work? I remember it's failing for me

Not sure for the true reason, but it failed and was overridden to Int4Tensor, not Int4TilePackedTo4dTensor, and generates dispatch error.

@namgyu-youn
Copy link
Contributor Author

And Int4WeightOnlyConfig(int4_packing_format="tile_packed_to_4d", int4_choose_qparams_algorithm=Int4ChooseQParamsAlgorithm.HQQ) did work.

@jerryzh168
Copy link
Contributor

And Int4WeightOnlyConfig(int4_packing_format="tile_packed_to_4d", int4_choose_qparams_algorithm=Int4ChooseQParamsAlgorithm.HQQ) did work.

you mean the test_awq_functionality failed right?

@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Oct 10, 2025

And Int4WeightOnlyConfig(int4_packing_format="tile_packed_to_4d", int4_choose_qparams_algorithm=Int4ChooseQParamsAlgorithm.HQQ) did work.

you mean the test_awq_functionality failed right?

No, it worked. For test_awq_functionality case, it can be summarized to:

  • Old: Fail (override to Int4Tensor, not Int4TilePackedTo4dTensor)
  • Int4WeightOnlyConfig(int4_packing_format="tile_packed_to_4d", int4_choose_qparams_algorithm=Int4ChooseQParamsAlgorithm.HQQ): No fail; Int4TilePackedTo4dTensor is loaded
  • New (in this PR): No fail

@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Oct 10, 2025

The reason why Int4Tensor generates a dispatch error seems to be that they use different kernels:

@jerryzh168
Copy link
Contributor

for the script:

import torch
from torchao.quantization import Int4WeightOnlyConfig
from torchao.utils import _is_fbgemm_gpu_genai_available, torch_version_at_least

devices = ["cpu", "cuda"]
device_to_base_configs = {
    "cuda": [
        Int4WeightOnlyConfig(group_size=128),
        # Note: the functionality unit test doesn't work for hqq
        Int4WeightOnlyConfig(group_size=128, int4_packing_format="tile_packed_to_4d"),
        Int4WeightOnlyConfig(
            group_size=128,
            int4_packing_format="tile_packed_to_4d",
            int4_choose_qparams_algorithm="hqq",
        ),
    ],
}

for i, cfg in enumerate(device_to_base_configs["cuda"]):
    print(f"Config {i}:")
    print(f"  packing_format: {cfg.int4_packing_format}")
    print(f"  choose_qparams: {cfg.int4_choose_qparams_algorithm}")

I get:

Config 0:
  packing_format: Int4PackingFormat.PLAIN
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 1:
  packing_format: tile_packed_to_4d
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 2:
  packing_format: tile_packed_to_4d
  choose_qparams: hqq

and it seems to be running locally, the test_awq_functionality works for the hqq algorithm as well

@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Oct 10, 2025

for the script:

import torch
from torchao.quantization import Int4WeightOnlyConfig
from torchao.utils import _is_fbgemm_gpu_genai_available, torch_version_at_least

devices = ["cpu", "cuda"]
device_to_base_configs = {
    "cuda": [
        Int4WeightOnlyConfig(group_size=128),
        # Note: the functionality unit test doesn't work for hqq
        Int4WeightOnlyConfig(group_size=128, int4_packing_format="tile_packed_to_4d"),
        Int4WeightOnlyConfig(
            group_size=128,
            int4_packing_format="tile_packed_to_4d",
            int4_choose_qparams_algorithm="hqq",
        ),
    ],
}

for i, cfg in enumerate(device_to_base_configs["cuda"]):
    print(f"Config {i}:")
    print(f"  packing_format: {cfg.int4_packing_format}")
    print(f"  choose_qparams: {cfg.int4_choose_qparams_algorithm}")

I get:

Config 0:
  packing_format: Int4PackingFormat.PLAIN
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 1:
  packing_format: tile_packed_to_4d
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 2:
  packing_format: tile_packed_to_4d
  choose_qparams: hqq

and it seems to be running locally, the test_awq_functionality works for the hqq algorithm as well

Yeah it returns no fail for test_awq.py locally. We don't have to debug them, and can just add that test case, right?

Hmm... I truly remember getting the following error:

torchao/prototype/awq/core.py:91: in calculate_qparams
    q_out = F.linear(acc / scales, w, self.bias)
    ↓
torchao/quantization/quantize_/workflows/int4/int4_tensor.py:161
    res = torch.ops.fbgemm.bf16i4bf16_rowwise(...)
    ↓
RuntimeError: cutlass cannot initialize

But everything is resolved without any change...? Mamma mia 😕

@jerryzh168
Copy link
Contributor

for the script:

import torch
from torchao.quantization import Int4WeightOnlyConfig
from torchao.utils import _is_fbgemm_gpu_genai_available, torch_version_at_least

devices = ["cpu", "cuda"]
device_to_base_configs = {
    "cuda": [
        Int4WeightOnlyConfig(group_size=128),
        # Note: the functionality unit test doesn't work for hqq
        Int4WeightOnlyConfig(group_size=128, int4_packing_format="tile_packed_to_4d"),
        Int4WeightOnlyConfig(
            group_size=128,
            int4_packing_format="tile_packed_to_4d",
            int4_choose_qparams_algorithm="hqq",
        ),
    ],
}

for i, cfg in enumerate(device_to_base_configs["cuda"]):
    print(f"Config {i}:")
    print(f"  packing_format: {cfg.int4_packing_format}")
    print(f"  choose_qparams: {cfg.int4_choose_qparams_algorithm}")

I get:

Config 0:
  packing_format: Int4PackingFormat.PLAIN
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 1:
  packing_format: tile_packed_to_4d
  choose_qparams: Int4ChooseQParamsAlgorithm.TINYGEMM
Config 2:
  packing_format: tile_packed_to_4d
  choose_qparams: hqq

and it seems to be running locally, the test_awq_functionality works for the hqq algorithm as well

Yeah it returns no fail for test_awq.py locally. We don't have to debug them, and can just add that test case, right?

Hmm... I truly remember getting the following error:

torchao/prototype/awq/core.py:91: in calculate_qparams
    q_out = F.linear(acc / scales, w, self.bias)
    ↓
torchao/quantization/quantize_/workflows/int4/int4_tensor.py:161
    res = torch.ops.fbgemm.bf16i4bf16_rowwise(...)
    ↓
RuntimeError: cutlass cannot initialize

But everything is resolved without any change...? Mamma mia 😕

yeah it runs for me locally without any changes. not sure why you get the error, seems like some env issues, are you using an H100 machine? fbgemm is only available in H100.

@jerryzh168 jerryzh168 added the topic: not user facing Use this tag if you don't want this PR to show up in release notes label Oct 10, 2025
@namgyu-youn namgyu-youn changed the title Fix enum backend for int4 choosing qprams algorithm Add int4 choosing qprams algorithm test for AWQ Oct 10, 2025
@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Oct 10, 2025

yeah it runs for me locally without any changes. not sure why you get the error, seems like some env issues, are you using an H100 machine? fbgemm is only available in H100.

Yes I use H100 for only allocated time (luckily now) and mostly use A100. Updated title and context for this change.

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. topic: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载