Skip to content

'q_config' is needed when export an INT8 model #1736

Open
@ZhangShuoAlreadyExists

Description

@ZhangShuoAlreadyExists

Hi,

I want to convert and quantize Pytorch model to ONNX model. I refer to this example https://github.com/intel/neural-compressor/blob/master/examples/pytorch/image_recognition/torchvision_models/export/fx/main.py
When calling export function, there is error "'q_config' is needed when export an INT8 model"
I don't see anything about q_config in example code. May I know how to solve this issue?

Here is my code:
if name == "main":
model = timm.create_model('resnet50.a1_in1k', pretrained=True)
model = model.eval()

val_dataset = SampleDataset('golden_image')
val_loader = torch.utils.data.DataLoader(
    val_dataset,
    batch_size=1, shuffle=False,
    num_workers=1, pin_memory=True)

conf = PostTrainingQuantConfig(approach='static')
q_model = quantization.fit(model,
                           conf,
                           calib_dataloader=val_loader) # Don't need tuning.
int8_onnx_config = Torch2ONNXConfig(
    dtype="int8",
    opset_version=14,
    quant_format="QDQ",
    example_inputs=torch.randn(1, 3, 224, 224),
    input_names=['input'],
    output_names=['output'],
    dynamic_axes={"input": {0: "batch_size"},
                    "output": {0: "batch_size"}},
)

inc_model = Model(q_model)
inc_model.export("resnet50_int8.onnx", int8_onnx_config)

Error message:
neural_compressor\experimental\export\torch2onnx.py", line 389, in torch_to_int8_onnx
assert q_config is not None, "'q_config' is needed when export an INT8 model."
AssertionError: 'q_config' is needed when export an INT8 model.

torch.version '2.2.2+cpu'
neural_compressor.version '2.6'

Metadata

Metadata

Labels

aitceAI TCE to handle it firstly

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions