• 文档 >
  • 量化 >
  • 量化 API 参考 >
  • 嵌入包
快捷键

嵌入包 ¶

class torch.ao.nn.quantized.EmbeddingBag(num_embeddings, embedding_dim, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, mode='sum', sparse=False, _weight=None, include_last_offset=False, dtype=torch.quint8)[source][source]

一个量化嵌入包模块,以量化打包权重作为输入。我们采用与 torch.nn.EmbeddingBag 相同的接口,请参阅 https://pytorch.org/docs/stable/generated/torch.nn.EmbeddingBag.html 以获取文档。

类似于 EmbeddingBag ,属性将在模块创建时随机初始化,之后将被覆盖

变量:

weight(张量)- 模块的非可学习量化权重,形状为 (num_embeddings,embedding_dim)(\text{num\_embeddings}, \text{embedding\_dim})

示例::
>>> m = nn.quantized.EmbeddingBag(num_embeddings=10, embedding_dim=12, include_last_offset=True, mode='sum')
>>> indices = torch.tensor([9, 6, 5, 7, 8, 8, 9, 2, 8, 6, 6, 9, 1, 6, 8, 8, 3, 2, 3, 6, 3, 6, 5, 7, 0, 8, 4, 6, 5, 8, 2, 3])
>>> offsets = torch.tensor([0, 19, 20, 28, 28, 32])
>>> output = m(indices, offsets)
>>> print(output.size())
torch.Size([5, 12])
classmethod from_float(mod, use_precomputed_fake_quant=False)[source][source]

从浮点模块创建量化 embedding_bag 模块

参数:

mod(模块)- 一个浮点模块,可以是 torch.ao.quantization 工具生成的,也可以由用户提供


© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

查看 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源