Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph output of export_ppq_graph is not quantized #49

Closed
fengyuentau opened this issue Apr 11, 2022 · 4 comments
Closed

Graph output of export_ppq_graph is not quantized #49

fengyuentau opened this issue Apr 11, 2022 · 4 comments

Comments

@fengyuentau
Copy link

Hello, great work!

I try to quantize some ONNX models with ppq. The ONNX model output from export_ppq_graph is not quantized at all, but I found some key parameters for quantization such as scales and zero points for different layers saved in JSON. Is this bug or feature of PPQ? How can I get the quantized ONNX model?

@ZhangZhiPku
Copy link
Collaborator

ZhangZhiPku commented Apr 11, 2022

哦豁,你需要注意到不同的后端要求的量化模型格式也不一样,你现在导出的这种带json的格式应该是open ppl需要的,这种格式所有量化参数都保存在json文件中,ppl可以直接执行。

请知悉:
如果你选择tensorRT作为导出平台,则我们将直接导出量化后的engine文件,tensorRT可以直接运行;
如果你选择snpe作为导出平台,量化参数将被写入caffe proto文件,snpe好像...可以直接运行;
如果你选择nxp作为导出格式,量化参数将被写入onnx,nxp可以直接运行;
如果你选择onnxruntime作为导出格式,我们将在网络中插入quant以及dequant节点,onnxruntime可以直接运行。
如果你选择onnxruntime OOS作为导出格式,我们将在网络中插入quant以及dequant节点,并且置换原有计算节点,onnxruntime可以直接运行。
如果你选择onnx作为导出格式,我们将导出一个ppq原生的格式,这个格式只是用来debug的。

如果你想最快速的看到结果,选择onnxruntime作为导出格式即可,你就可以在导出的onnx中看到量化结果。

所有导出平台被列举在ppq.api.文件中:
EXPORTERS = {
TargetPlatform.PPL_DSP_INT8: PPLDSPCaffeExporter,
TargetPlatform.PPL_DSP_TI_IN8: PPLDSPTICaffeExporter,
TargetPlatform.PPL_CUDA_INT8: PPLBackendExporter,
TargetPlatform.SNPE_INT8: SNPECaffeExporter,
TargetPlatform.NXP_INT8: NxpExporter,
TargetPlatform.ONNX: OnnxExporter,
TargetPlatform.ONNXRUNTIME: ONNXRUNTIMExporter,
TargetPlatform.CAFFE: CaffeExporter,
TargetPlatform.NATIVE: NativeExporter,
TargetPlatform.EXTENSION: ExtensionExporter,
# TargetPlatform.ORT_OOS_INT8: ONNXRUNTIMExporter,
TargetPlatform.ORT_OOS_INT8: ORTOOSExporter,
TargetPlatform.METAX_INT8_C: ONNXRUNTIMExporter,
TargetPlatform.METAX_INT8_T: ONNXRUNTIMExporter,
}

@fengyuentau
Copy link
Author

谢谢!请问导出平台是指TargetPlatform吗?提及的情况大概是这几行?
https://github.com/openppl-public/ppq/blob/35fb7f78b24946f6224793719603db75305e5d55/ppq/parser/__init__.py#L23-L35

@ZhangZhiPku
Copy link
Collaborator

啊对,这里面除了ONNX, NATIVE, EXTENSION都是后端实际需要的格式。

选择NATIVE会导出ppq的二进制原生格式;
选择EXTENSION没什么用,那个只是告诉你你可以重写EXTENSION类来实现自己的导出逻辑。

@fengyuentau
Copy link
Author

好的,非常感谢!

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

No branches or pull requests

2 participants