How to inference with smoothquant quantized model with pytorch?

SmoothQuant can only run on GPUs with Cutlass support.

There are many models quantized with SmoothQuant on Hugging Face. I want to run inference with them on an ARM CPU-only server, performance notwithstanding. I have struggled for a long time but haven’t found a viable way to achieve this.

  • Should I modify SmoothQuant or Torch-int?
  • PyTorch supports quantization with QNNPACK, and it provides both module (e.g., quantized_linear, with unspecified input tensor datatype) and functional interfaces (e.g., linear, with input as quint8 and weight as qint8). These do not match the interface with Cutlass in Torch-int.

I would greatly appreciate it if someone could provide thoughts, workflows, or example code/pseudo code.

Unless i am mistaken, smoothquant is just input-weight equalization applied to a quantized linear with dynamic quantization of some kind on the activation. Let me know if you want something different.

we have input-weight equalization for fx quantization

and we have dynamic quant with fx
Quantization — PyTorch 2.1 documentation which looks like it works for qnnpack. I think you’re stuck with per-tensor quantizaiton on the activation though.

those two are intended to compose so let us know if that doesn’t work.

also i think you’re looking at the wrong quantized linear op, what you’d want is

1 Like

Thank you for your responses to both of my questions.

Actually, what I’m interested in is solely the inference of LLM with PyTorch. There are many quantized LLM models with SmoothQuant on Hugging Face (e.g., opt-125m-smoothquant). I want to run a test on one or a few of them on an ARM CPU-only platform. But, I believe I haven’t found the correct method yet.

Here’s what I’ve tried: I wanted to run the model with SmoothQuant, but it calls Torch-int, which is built on Cutlass. I wanted to replace all quantization interfaces on Torch-int or SmoothQuant, but found that quantized linear in Torch-int supports qint8 for activation. I only found quint8 for activation in the PyTorch backend.

I haven’t found the correct location to eliminate Cutlass while also supporting the correct interface in PyTorch.

When you say you want to do smoothquant do you mean something you can define mathematically or a particular repo?

Smoothquant is a technique from that can be reproduced as outlined above on cpu or from a variety of repos on cuda.

the Repo GitHub - mit-han-lab/smoothquant: [ICML 2023] SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models is geared towards cuda as far as i can tell, if you want to use that on cpu you’re kind of fitting a round peg in a square hole and that’s reflected in the interface difference you’re seeing. I also think the function you’re looking at isn’t a drop in replacement. Its doing static quantization rather than dynamic quantization that smoothquant needs (mathematically)

What I’m interested in is a particular repository, as mentioned above - the SmoothQuant repository based on CUDA. However, instead of focusing on the quantization of a model, what I’m really concerned with is how to run inference with an already SmoothQuant-quantized model on an Arm CPU server. I discovered that I can only replace the Cutlass interface that SmoothQuant calls through torch-int, such as linear_a8_w8_bfp32_ofp32. Therefore, my course of action should be to either find a replacement for the interface in QNNPACK or implement them by myself. Is this correct?