siliconflow / onediff

OneDiff: An out-of-the-box acceleration library for diffusion models.
https://github.com/siliconflow/onediff/wiki
Apache License 2.0
1.7k stars 104 forks source link

Found a small problem with the calculation #893

Closed songh11 closed 6 months ago

songh11 commented 6 months ago

Describe the bug

A clear and concise description of what the bug is.

我在看代码的时候,发现这里在求 scale 的时候,权重最大值并未取绝对值最大值,这里不考虑负数可能会导致负数超出的地方被截断吧,另外想请问下 weight_acc 是什么作用呢,一般不是只要 weight_scale 和 zero_point 就足够了

https://github.com/siliconflow/onediff/blob/2249010f8cfdbf2229bdf84134b5398541b2d6fe/onediff_comfy_nodes/modules/oneflow/utils/model_patcher.py#L470

Your environment

OS

OneDiff git commit id

OneFlow version info

Run python -m oneflow --doctor and paste it here.

How To Reproduce

Steps to reproduce the behavior(code or script):

The complete error message

Additional context

Add any other context about the problem here.

hjchen2 commented 6 months ago

这里确实应该先计算weight的abs再计算max,此处确实存在bug。

weight_acc的作用是为了方便将输出的反量化操作与int8 matmul或者int8 conv进行融合,因为对于activation是非对称量化来说,最终需要的输出为

截屏2024-05-21 22 22 23

weight_acc即weight按k维累加的结果,可以提前计算得到。

songh11 commented 6 months ago

这里确实应该先计算weight的abs再计算max,此处确实存在bug。

weight_acc的作用是为了方便将输出的反量化操作与int8 matmul或者int8 conv进行融合,因为对于activation是非对称量化来说,最终需要的输出为

截屏2024-05-21 22 22 23

weight_acc即weight按k维累加的结果,可以提前计算得到。

这里确实应该先计算weight的abs再计算max,此处确实存在bug。

weight_acc的作用是为了方便将输出的反量化操作与int8 matmul或者int8 conv进行融合,因为对于activation是非对称量化来说,最终需要的输出为

截屏2024-05-21 22 22 23

weight_acc即weight按k维累加的结果,可以提前计算得到。

感谢答复~