huawei-noah / bolt

Bolt is a deep learning library with high performance and heterogeneous flexibility.
https://huawei-noah.github.io/bolt/
MIT License
911 stars 158 forks source link

是否能完整支持二值化卷积网络? #19

Open hattori7243 opened 3 years ago

hattori7243 commented 3 years ago

Bolt supports both XNOR-style and DoReFa-style BNN networks. Just save the binary weights as FP32 in an Onnx model, and X2bolt will automatically convert the storage to 1-bit representations. So far, the floating-point portion of the BNN network can only be FP16 operations, so pass "FP16" as the precision parameter to X2bolt. The number of output channels for BNN convolution layers should be divisible by 32. 这里提到的FP16是什么意思?是指对二值化网络的支持实际是用FP16实现的吗?为什么最后输出的通道数必须要被32整除呢?

Bil17t commented 3 years ago

多谢提问~最早bolt的浮点部分只支持FP16,因此在开发BNN算子的时候,跟其他算子衔接的数据类型也是FP16。实际算子内部还是使用位操作的,kernel为了比较好优化,我们约定BNN卷积层的输出通道要是32的倍数。您如果有训练好的模型,但是不符合32这个要求,最好能够发给我们看看,我们可以扩展一下进行一些通道补齐,计算完再砍回来。但如果您还没有训好,建议在训练的时候设定成32的倍数,普通浮点卷积则不需要这个条件。另外,XNOR的效果验证得比较好,建议使用