Giter VIP home page Giter VIP logo

Comments (5)

drakitLiu avatar drakitLiu commented on May 24, 2024

发现即使没有scale文件,但也可以将量化后的静态图合并成onnx模型文件,使用的命令是:
paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file quant_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend onnxruntime --enable_onnx_checker True
但是失真度太大了!
于是我尝试改用这个量化方法:

 quant_recon_static(
        executor=exe,
        model_dir=args__.model_path,
        quantize_model_path=args__.save_path + 'quant_recon_static/',
        data_loader=data_loader,
        model_filename=args__.model_filename,
        params_filename=args__.params_filename,
        batch_size=32,
        batch_nums=256,
        region_weights_names=None,
        onnx_format=args__.onnx_format,
        recon_level='region-wise',
        is_full_quantize=args__.is_full_quantize,
        bias_correction=args__.bias_correction,
    )

官方说是这个方法会很耗时,没想到不仅耗时,而且压根不会成功,跑了4天了,epoch使用的是默认值20,程序跑完20个epoch后又会从0开始跑,然后没完没了,第五天报错了:
屏幕截图 2024-02-15 140658
此时此刻很想雨!

from paddleslim.

xiaoluomi avatar xiaoluomi commented on May 24, 2024

你好,首先回答下你提到的这个scale文件,在使用paddleslim压缩静态图模型后得到的只有model.pdmodel和model.pdiparams两个文件,你所描述的这个scale文件是calibration.cache文件,这个文件是在GPU上使用Tensorrt部署时,指令paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file float_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend tensorrt --enable_onnx_checker True生成的。
关于精度损失的问题,quant_post_static和quant_recon_static属于比较老的接口,可能在某些模型使用上存在部分问题,这边建议去使用paddleslim的新接口,自动压缩接口,可参照https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/auto_compression
里面包括了训练后量化和量化训练,静态图模型适合使用此接口。
以下面是简单的接口示例:
ac = AutoCompression(
model_dir="./MobileNetV1_infer",
model_filename="inference.pdmodel",
params_filename="inference.pdiparams",
save_dir="MobileNetV1_quant",
config={"QuantPost": {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}},
train_dataloader=train_loader,
eval_dataloader=train_loader)
ac.compress()

from paddleslim.

xiaoluomi avatar xiaoluomi commented on May 24, 2024

你好,首先回答下你提到的这个scale文件,在使用paddleslim压缩静态图模型后得到的只有model.pdmodel和model.pdiparams两个文件,你所描述的这个scale文件是calibration.cache文件,这个文件是在GPU上使用Tensorrt部署时,指令paddle2onnx --model_dir ./ --model_filename model.pdmodel --params_filename model.pdiparams --save_file float_model.onnx --opset_version 13 --enable_dev_version True --deploy_backend tensorrt --enable_onnx_checker True生成的。
关于精度损失的问题,quant_post_static和quant_recon_static属于比较老的接口,可能在某些模型使用上存在部分问题,这边建议去使用paddleslim的新接口,自动压缩接口,可参照https://github.com/PaddlePaddle/PaddleSlim/tree/develop/example/auto_compression
里面包括了训练后量化和量化训练,静态图模型适合使用此接口。
以下面是简单的接口示例:
ac = AutoCompression(
model_dir="./MobileNetV1_infer",
model_filename="inference.pdmodel",
params_filename="inference.pdiparams",
save_dir="MobileNetV1_quant",
config={"QuantPost": {}, "HyperParameterOptimization": {'ptq_algo': ['avg'], 'max_quant_count': 3}},
train_dataloader=train_loader,
eval_dataloader=train_loader)
ac.compress()

from paddleslim.

xiaoluomi avatar xiaoluomi commented on May 24, 2024

此外提醒一下onnx_format这个参数设置为True,便于导出的pdmodel是paddle的新格式,也便于后续转成onnx文件。

from paddleslim.

xiaoluomi avatar xiaoluomi commented on May 24, 2024

如果问题解决了的话,麻烦关闭该issue,谢谢

from paddleslim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.