評價此頁

Embedding#

class torch.ao.nn.quantized.Embedding(num_embeddings, embedding_dim, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False, _weight=None, dtype=torch.quint8)[原始碼]#

一個量化的 Embedding 模組,以量化的打包權重作為輸入。我們採用與 torch.nn.Embedding 相同的介面,請參閱 https://pytorch.com.tw/docs/stable/generated/torch.nn.Embedding.html 獲取文件。

Embedding 類似,屬性將在模組建立時隨機初始化,之後會被覆蓋。

變數

weight (Tensor) – 模組的非可學習量化權重,形狀為 (num_embeddings,embedding_dim)(\text{num\_embeddings}, \text{embedding\_dim})

示例:
>>> m = nn.quantized.Embedding(num_embeddings=10, embedding_dim=12)
>>> indices = torch.tensor([9, 6, 5, 7, 8, 8, 9, 2, 8])
>>> output = m(indices)
>>> print(output.size())
torch.Size([9, 12])
classmethod from_float(mod, use_precomputed_fake_quant=False)[原始碼]#

從浮點模組建立量化嵌入模組。

引數

mod (Module) – 一個浮點模組,可以由 torch.ao.quantization 工具生成,也可以由使用者提供。