Skip to content

Conversation

@menogrey
Copy link

@menogrey menogrey commented Jan 8, 2026

SUMMARY:
Add NPU support for llm-compressor, to accelerate the quantization on NPU devices. Related issue #2199

TEST PLAN:
Test branch: main
Tested with extra dependencies. The torch-npu add NPU support for Pytorch.

torch==2.8.0
torch_npu==2.8.0

We tested int8_w8a8 quantization on Qwen3-30B-A3B model.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @menogrey, 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 significantly expands the hardware compatibility of llm-compressor by adding support for Neural Processing Units (NPUs). This integration allows the model quantization process to leverage the specialized acceleration capabilities of NPU devices, potentially leading to faster and more efficient operations for users with such hardware. The changes ensure that the system can intelligently detect and utilize NPUs, and also provides tools for users to inspect NPU availability in their environment.

Highlights

  • NPU Support Integration: Introduced support for Neural Processing Units (NPUs) across the llm-compressor project, enabling acceleration of quantization tasks on NPU devices.
  • Device Detection Logic: Updated device detection helpers to prioritize NPU if available, falling back to XPU, CUDA, or CPU if NPU is not found.
  • Environment Information Tool: Enhanced the collect_env.py script to detect and report available NPU devices, providing better visibility into the hardware environment.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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 adds support for NPU devices to accelerate quantization, which is a valuable addition. The changes correctly detect NPU availability in gpu_if_available, dispatch_for_sequential, and the environment collection script. My main feedback is regarding code duplication for device detection logic, which is now present in two separate files. I've left a comment suggesting a refactor to centralize this logic for better maintainability. Otherwise, the changes look good.

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@menogrey
Copy link
Author

menogrey commented Jan 8, 2026

My quantization script

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier

MODEL_ID = "/shared/models/Qwen3-30B-A3B-Instruct-2507"

model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID, dtype=torch.bfloat16, trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)

recipe = QuantizationModifier(
    targets="Linear",
    scheme="INT8",
    ignore=["lm_head", "re:.*mlp.gate$"],
)

oneshot(
    model=model,
    recipe=recipe,
    trust_remote_code_model=True,
)

# Save to disk in compressed-tensors format.
SAVE_DIR = "./Qwen3-30B-A3B-Instruct-2507-int8-w8a8"
model.save_pretrained(SAVE_DIR, save_compressed=True)
tokenizer.save_pretrained(SAVE_DIR)

The output:

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████| 16/16 [00:02<00:00,  6.52it/s]
2026-01-07T07:57:50.749398+0000 | reset | INFO - Compression lifecycle reset
2026-01-07T07:57:50.802931+0000 | moe_calibration_context | INFO - Found 48 MoE modules to replace
Replacing MoE modules for calibration: 100%|██████████████████████████████████████| 48/48 [00:00<00:00, 20474.58it/s]
2026-01-07T07:57:50.806102+0000 | moe_calibration_context | INFO - Replaced 48 MoE modules for calibration
2026-01-07T07:57:50.806202+0000 | moe_calibration_context | INFO - 48/48 modules will be restored after calibration
2026-01-07T07:57:50.806336+0000 | from_modifiers | INFO - Creating recipe from modifiers
2026-01-07T07:57:53.827993+0000 | initialize | INFO - Compression lifecycle initialized for 1 modifiers
2026-01-07T07:57:53.828463+0000 | IndependentPipeline | INFO - Inferred `DataFreePipeline` for `QuantizationModifier`
Updating global scales: 100%|██████████████████████████████████████████████| 18624/18624 [00:00<00:00, 408496.37it/s]
Fusing global scales: 49975it [00:00, 328875.86it/s]
Calibrating weights: 100%|████████████████████████████████████████████████████| 18624/18624 [00:54<00:00, 342.32it/s]
2026-01-07T07:58:53.740272+0000 | finalize | INFO - Compression lifecycle finalized for 1 modifiers
2026-01-07T07:58:54.397827+0000 | post_process | WARNING - Optimized model is not saved. To save, please provide`output_dir` as input arg.Ex. `oneshot(..., output_dir=...)`
2026-01-07T07:58:54.403417+0000 | get_model_compressor | INFO - skip_sparsity_compression_stats set to True. Skipping sparsity compression statistic calculations. No sparsity compressor will be applied.
Compressing model: 18624it [14:36, 21.25it/s]

Co-authored-by: LHXuuu <[email protected]>
Signed-off-by: menogrey <[email protected]>
Copy link
Collaborator

@brian-dellabetta brian-dellabetta left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! looks good to me

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants