Skip to content

Conversation

@jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented Jul 31, 2025

Summary:

Current torchao integration quantizes the weights by wrapping weights in a top level linear module and use quantize_ to quantize it, this works for quantization methods that do inplace changes to the weight itself, such as int4, float8, since these only do inplace changes to the linear module itself

but there are quantization configs that would need module swap, such as awq, that's not supported, in order to support these, we wrap the linear in nn.Sequential so it is no longer a top level module and can be swapped to another module.

Test Plan:
uplodated an awq checkpoint: https://huggingface.co/torchao-testing/Phi-4-mini-instruct-int4wo-awq-0.13-dev and we test by loading the checkpoint

python tests/quantization/test_torchao.py

Reviewers:

Subscribers:

Tasks:

Tags:

@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from d9ce8c2 to 4de8f17 Compare July 31, 2025 01:58
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables support for torchao quantization methods that require module swaps, like AWQ, by wrapping the linear layer in an nn.Sequential. The change is well-contained and accompanied by a relevant test case. I've suggested one improvement to make the code more robust against future changes in torchao or different quantization configurations.

Comment on lines +171 to +168
Copy link
Contributor

Choose a reason for hiding this comment

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

high

After quantization, the module may have been swapped. Instead of directly accessing dummy_linear[0].weight, retrieve the weight by inspecting the module's parameters. This avoids making fragile assumptions about the internal structure of the quantized module, which may change in future torchao versions.

    dummy_linear[0].weight = param
    quantize_(dummy_linear, torchao_config)
    # After quantization, the module may have been swapped.
    # We retrieve the single parameter, which is the quantized weight.
    params = list(dummy_linear.parameters())
    assert len(params) == 1, (
        "Expected the dummy module to have exactly one parameter after "
        f"quantization, but found {len(params)}."
    )
    return params[0].data

@github-actions
Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from 4de8f17 to f1473ee Compare July 31, 2025 03:47
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me, thanks!

@mgoin mgoin enabled auto-merge (squash) July 31, 2025 20:13
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 31, 2025
Copy link
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Looks good.

@DarkLight1337
Copy link
Member

Can you merge from main to fix the CI failures?

auto-merge was automatically disabled August 1, 2025 18:27

Head branch was pushed to by a user without write access

@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch 2 times, most recently from a3112b0 to f511cfd Compare August 1, 2025 23:36
@jerryzh168
Copy link
Contributor Author

jerryzh168 commented Aug 2, 2025

the current error is because we just landed AWQ updates in torchao recently and it's not picked up by nightly yet
there is actually one more update to awq I plan to do next week, we can land this one after that

@jerryzh168 jerryzh168 changed the title [torchao] Support quantization configs using module support [torchao] Support quantization configs using module swap Aug 9, 2025
@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from f511cfd to 204bc03 Compare September 10, 2025 04:46
@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch 3 times, most recently from 4bfe2c8 to 0e6ab4c Compare September 10, 2025 05:37
Copy link
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

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

LGTM, please also fix the pre-commit issue so we can get this landed

@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch 2 times, most recently from fdd7402 to 970d460 Compare September 10, 2025 20:27
@mergify mergify bot added the ci/build label Sep 10, 2025
@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from 970d460 to 5a4d4a1 Compare September 10, 2025 20:29
@jerryzh168
Copy link
Contributor Author

jerryzh168 commented Sep 10, 2025

failure in buildkite/ci/pr is not related to this PR, it's a distributed test error and also appears in other merged PRs such as: https://buildkite.com/vllm/ci/builds/30238/steps/canvas

another basic_model test error also failed in other PRs already merged: https://buildkite.com/vllm/ci/builds/30254/steps/canvas?jid=019935cb-2260-4165-a2c0-589306ca583c

@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from feb6aed to 3086d73 Compare September 10, 2025 22:30
… swap

Summary:
Current torchao integration quantizes the weights by wrapping weights
in a top level linear module and use quantize_ to quantize it, this works
for quantization methods that do inplace changes to the weight itself, such as
int4, float8, but there are quantization configs that would need module swap,
such as awq, that's not supported, in order to support these, we wrap the linear
in nn.Sequential so it is no longer a top level module and can be swapped to another module.

Test Plan:
uplodated an awq checkpoint: https://huggingface.co/torchao-testing/Phi-4-mini-instruct-int4wo-awq-0.13-dev
and we test by loading the checkpoint

```
python tests/quantization/test_torchao.py
```

Reviewers:

Subscribers:

Tasks:

Tags:
Signed-off-by: Jerry Zhang <[email protected]>
@jerryzh168 jerryzh168 force-pushed the allow-torchao-module-swap-config branch from aeb2766 to ef05f84 Compare September 10, 2025 22:46
@vllm-bot vllm-bot merged commit 2048c4e into vllm-project:main Sep 11, 2025
69 of 72 checks passed
skyloevil pushed a commit to skyloevil/vllm that referenced this pull request Sep 13, 2025
dsxsteven pushed a commit to dsxsteven/vllm_splitPR that referenced this pull request Sep 15, 2025
FeiDaLI pushed a commit to FeiDaLI/vllm that referenced this pull request Sep 25, 2025
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 10, 2025
xuebwang-amd pushed a commit to xuebwang-amd/vllm that referenced this pull request Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build quantization ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants