gpt4 book ai didi

machine-learning - Pytorch 中的 int8 数据类型

转载 作者:行者123 更新时间:2023-11-30 09:43:48 24 4
gpt4 key购买 nike

在 Pytorch 中使用 int8 数据类型运行 qauntized 模型的最佳方法是什么?我知道在 pytorch 中我可以将张量定义为 int8但是,当我真正想使用 int8 时,我得到:

RuntimeError: _thnn_conv2d_forward is not implemented for type torch.CharTensor

所以我很困惑,当计算 block (例如卷积)不支持数据类型时,如何在使用 int8 的 pytorch 中运行量化模型?我使用的是 pytorch 版本 1.0.1.post2

最佳答案

取决于你的目标是什么。

  1. 如果您想模拟量化模型:

您可以坚持现有的 float 据类型,仅根据需要引入截断,即:

 x = torch.floor(x * 2**8) / 2**8

假设 x 是浮点张量。

  • 如果您想高效模拟量化模型:
  • 那么,恐怕 PyTorch 不会很有用,因为低级卷积运算符仅针对浮点类型实现。

    关于machine-learning - Pytorch 中的 int8 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55289703/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com