EmbeddingBag¶
- 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]¶
具有量化打包权重作为输入的量化 EmbeddingBag 模块。我们采用与 torch.nn.EmbeddingBag 相同的接口,请参见 https://pytorch.ac.cn/docs/stable/generated/torch.nn.EmbeddingBag.html 获取文档。
类似于
EmbeddingBag
,属性将在模块创建时随机初始化,并将在之后被覆盖。- 变量
weight (Tensor) – 模块的不可学习量化权重,形状为 .
- 示例:
>>> 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])