Skip to content

[CPU][INT4] Add AWQ frontend support for CPU #8225

Open
jianan-gu wants to merge 34 commits intosgl-project:mainfrom
jianan-gu:cpu_int4_frontend
Open

[CPU][INT4] Add AWQ frontend support for CPU #8225
jianan-gu wants to merge 34 commits intosgl-project:mainfrom
jianan-gu:cpu_int4_frontend

Conversation

@jianan-gu
Copy link
Contributor

@jianan-gu jianan-gu commented Jul 21, 2025

This PR implements AWQ int4 frontends support for CPU, and is calling the CPU sgl-kernels in #8226

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.

Summary of Changes

Hello @jianan-gu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive support for running AWQ (Activation-aware Weight Quantization) Linear layers on CPU, specifically targeting INT4 precision. The primary goal is to enable efficient inference of quantized models on CPU architectures, leveraging specialized CPU kernels for optimized performance.

Highlights

  • CPU INT4 AWQ Integration: Implemented the necessary logic within AWQLinearMethod to enable AWQ quantized linear layers to run on CPU, leveraging Intel AMX capabilities for accelerated INT4 operations.
  • Weight Pre-processing for CPU: Added new utility functions (_autoawq_to_int4pack, _amx_process_int4_packed_qweight_after_loading) in amx_utils.py to convert and pack AWQ weights into a CPU-optimized INT4 format, including support for a W4A8 (Weight 4-bit, Activation 8-bit) scheme via an environment variable.
  • Dynamic Kernel Dispatch: Modified the AWQLinearMethod.apply method to dynamically select and utilize appropriate CPU INT4 matrix multiplication kernels (int4_scaled_mm_cpu, int4_scaled_mm_cpu_with_quant) when the model is running on a CPU with AMX support.
  • bfloat16 Activation Support: Extended the AWQConfig to declare torch.bfloat16 as a supported activation data type, which is crucial for efficient CPU inference with quantized models.
  • Flexible Quantization Configuration: Updated update_config.py to allow group_size to be used in quantization configurations, providing more flexibility for block-wise quantization schemes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 introduces AWQ Linear frontend support for CPU, including updates to configs and amx utils. The changes involve conditional logic based on the SGLANG_USE_CPU_INT4_W4A8 environment variable and the availability of Intel AMX. The review focuses on adding comments to improve code clarity.

@jianan-gu jianan-gu marked this pull request as ready for review July 22, 2025 05:03
@jianan-gu jianan-gu requested a review from kushanam as a code owner July 30, 2025 05:34
@jianan-gu jianan-gu changed the title [CPU][INT4] Add AWQ Linear frontend support for CPU [CPU][INT4] Add AWQ frontend support for CPU Jul 30, 2025
@mingfeima mingfeima marked this pull request as draft August 1, 2025 00:07
@mingfeima mingfeima added intel cpu cpu backend performance optimization labels Aug 1, 2025
Co-authored-by: Ma Mingfei <mingfei.ma@intel.com>
@mingfeima
Copy link
Collaborator

@jianan-gu rebase.

@jianan-gu jianan-gu requested a review from Fridge003 as a code owner November 13, 2025 07:57
@jianan-gu jianan-gu requested a review from AniZpZ as a code owner November 19, 2025 07:18
@jianan-gu jianan-gu requested a review from Alcanderian December 5, 2025 08:17
@jianan-gu
Copy link
Contributor Author

/rerun-failed-ci

2 similar comments
@jianan-gu
Copy link
Contributor Author

/rerun-failed-ci

@jianan-gu
Copy link
Contributor Author

/rerun-failed-ci

@jianan-gu
Copy link
Contributor Author

/rerun-failed-ci

1 similar comment
@jianan-gu
Copy link
Contributor Author

/rerun-failed-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpu cpu backend performance optimization intel run-ci sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments