Coder Social home page Coder Social logo

Comments (6)

ZhangZhiPku avatar ZhangZhiPku commented on August 29, 2024

你现在导出的reshape2算子上的shape是写死的,必须要batchsize=16,在这种情况下你不能送入其他batchsize。
你是如何导出的该模型?torch导出好像不会有这样的问题

from ppq.

lycfly avatar lycfly commented on August 29, 2024

我是通过torch.onnx转的:

input1 = torch.randn(16, 1, 40, 61).cuda()
input_names = [ "input"]
output_names = [ "output" ]
torch.onnx.export(net, input1, model_path, verbose=True, input_names=input_names, output_names=output_names)

这里确实指定了input tensor,请问应该如何导出不指定batchsize的模型呢?

from ppq.

ZhangZhiPku avatar ZhangZhiPku commented on August 29, 2024

你可以参考这个 https://blog.csdn.net/ChuiGeDaQiQiu/article/details/119065818
不过如果你是要做推理加速,我建议你导出固定尺寸的onnx模型。
你需要注意,对于不同shape的tensor,推理时选用的算法不会一样,只有比较方的shape在计算gemm和conv时会达到最高执行效率。

比如 shape: [1,3,224,224]就不太方,算的就比较慢
比如 shape: [96, 96, 48, 48],就是个方形的 tensor,计算效率就高得多。

但比如你的 shape 是[batchsize, 96, 48, 48],那我们就只能做最保守的优化了。

from ppq.

lycfly avatar lycfly commented on August 29, 2024

非常感谢,按照您的提示我的代码能正确运行了,那我是否可以这么理解:
PPQ接收的量化模型需要再训练的话,最好导出batchsize为dynamic 的onnx模型做finetune,
否则需要保证calibration dataset的数据数目是所固定的batchsize的整数倍?

from ppq.

ZhangZhiPku avatar ZhangZhiPku commented on August 29, 2024

是的,我们无法得知你的onnx模型里面那一维是batchsize,或者说那一维是可变的,对于你导出的reshape而言,它要求的输入尺寸是固定的,我们只能给你报错,因为你的模型有语义上的错误。
不过更希望你对推理部署有更深入的了解,在pytorch中我们可以随意改变batchsize,这样你的模型一直都可以跑。但是对于推理而言,batchsize=1的模型与batchsize=128的模型是不一样的,会触发不同的部署优化过程。

from ppq.

lycfly avatar lycfly commented on August 29, 2024

明白了,非常感谢!

from ppq.

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.