Buckets:
Embedding
The embedding class is used to store and retrieve word embeddings from their indices. There are two types of embeddings in bitsandbytes, the standard PyTorch Embedding class and the StableEmbedding class.
The StableEmbedding class was introduced in the 8-bit Optimizers via Block-wise Quantization paper to reduce gradient variance as a result of the non-uniform distribution of input tokens. This class is designed to support quantization.
Embedding[[bitsandbytes.nn.Embedding]]
class bitsandbytes.nn.Embeddingbitsandbytes.nn.Embedding
Embedding class to store and retrieve word embeddings from their indices.
initbitsandbytes.nn.Embedding.initint) --
The number of unique embeddings (vocabulary size).
- embedding_dim (
int) -- The dimensionality of the embedding. - padding_idx (
Optional[int]) -- Pads the output with zeros at the given index. - max_norm (
Optional[float]) -- Renormalizes embeddings to have a maximum L2 norm. - norm_type (
float, defaults to2.0) -- The p-norm to compute for themax_normoption. - scale_grad_by_freq (
bool, defaults toFalse) -- Scale gradient by frequency during backpropagation. - sparse (
bool, defaults toFalse) -- Computes dense gradients. Set toTrueto compute sparse gradients instead. - _weight (
Optional[Tensor]) -- Pretrained embeddings.0
StableEmbedding[[bitsandbytes.nn.StableEmbedding]]
class bitsandbytes.nn.StableEmbeddingbitsandbytes.nn.StableEmbeddingtorch.nn.LayerNorm) -- Layer normalization applied after the embedding.0
Custom embedding layer designed to improve stability during training for NLP tasks by using 32-bit optimizer states. It is designed to reduce gradient variations that can result from quantization. This embedding layer is initialized with Xavier uniform initialization followed by layer normalization.
Example:
# Initialize StableEmbedding layer with vocabulary size 1000, embedding dimension 300
embedding_layer = StableEmbedding(num_embeddings=1000, embedding_dim=300)
# Reset embedding parameters
embedding_layer.reset_parameters()
# Perform a forward pass with input tensor
input_tensor = torch.tensor([1, 2, 3])
output_embedding = embedding_layer(input_tensor)
Methods: reset_parameters(): Reset embedding parameters using Xavier uniform initialization. forward(input: Tensor) -> Tensor: Forward pass through the stable embedding layer.
initbitsandbytes.nn.StableEmbedding.initint) --
The number of unique embeddings (vocabulary size).
- embedding_dim (
int) -- The dimensionality of the embedding. - padding_idx (
Optional[int]) -- Pads the output with zeros at the given index. - max_norm (
Optional[float]) -- Renormalizes embeddings to have a maximum L2 norm. - norm_type (
float, defaults to2.0) -- The p-norm to compute for themax_normoption. - scale_grad_by_freq (
bool, defaults toFalse) -- Scale gradient by frequency during backpropagation. - sparse (
bool, defaults toFalse) -- Computes dense gradients. Set toTrueto compute sparse gradients instead. - _weight (
Optional[Tensor]) -- Pretrained embeddings.0
Xet Storage Details
- Size:
- 6.92 kB
- Xet hash:
- 05142ee59ae3d550e9f3f4a828b44898f418213d2c929991a6963d58a2611b2c
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.