我使用英特尔lpot(neural compressor)成功地量化了一个用于huggingface文本分类的pytorch模型。
现在,我的机器中有了原始的fp32模型和量化的int8模型。为了进行推断,我用以下代码加载了量化的lpot模型
model = AutoModelForSequenceClassification.from_pretrained('fp32/model/path')
from lpot.utils.pytorch import load
modellpot = load("path/to/lpotmodel/", model)我能够看到时间上的各种改进,但我想确认模型权重是否确实被量化,并使用数据类型,如int8,fp16等,这应该是理想的加速原因。我迭代了模型权重并打印权重的dtype,但我看到所有权重都是fp32类型
for param in modellpot.parameters():
print(param.data.dtype)输出
torch.float32
torch.float32
torch.float32
torch.float32
torch.float32
torch.float32
torch.float32
..
...如何验证我的pytorch模型是否已被量化?
发布于 2021-10-11 04:31:36
使用print(modellpot)检查模型是否已量化。例如,线性层图层将转换为QuantizedLinear 。实际上,只有PyTorch支持的图层才会被转换为量化图层,所以并不是所有的参数都是int8/uint8。
当在输出中打印每个模型时,您将能够看到数据类型,例如,如果在打印模型时执行了int8量化,则模型输出将显示dtype为qint8。
https://stackoverflow.com/questions/69376098
复制相似问题