FakeQuantizedEmbedding¶
- class torchao.quantization.qat.FakeQuantizedEmbedding(num_embeddings: int, embedding_dim: int, padding_idx: Optional[int] = None, max_norm: Optional[float] = None, norm_type: float = 2.0, scale_grad_by_freq: bool = False, sparse: bool = False, weight_config: Optional[FakeQuantizeConfig] = None, *args, **kwargs)[source]¶
General embedding layer with fake quantized weights.
Specific target dtypes, granularity, schemes etc. are specified through separate configs for weights and activations.
Example usage:
weight_config = FakeQuantizeConfig( dtype=torch.int4, group_size=8, symmetric=True, ) fq_embedding = FakeQuantizedEmbedding(5, 10, weight_config) fq_embedding(torch.LongTensor([3]))
- forward(x: Tensor) Tensor [source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.