MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / __init__

Method __init__

bitsandbytes/nn/modules.py:54–99  ·  view source on GitHub ↗

Args: num_embeddings (`int`): 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 g

(
        self,
        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: Optional[Tensor] = None,
        device=None,
        dtype=None,
    )

Source from the content-addressed store, hash-verified

52 """
53
54 def __init__(
55 self,
56 num_embeddings: int,
57 embedding_dim: int,
58 padding_idx: Optional[int] = None,
59 max_norm: Optional[float] = None,
60 norm_type: float = 2.0,
61 scale_grad_by_freq: bool = False,
62 sparse: bool = False,
63 _weight: Optional[Tensor] = None,
64 device=None,
65 dtype=None,
66 ) -> None:
67 """
68 Args:
69 num_embeddings (`int`):
70 The number of unique embeddings (vocabulary size).
71 embedding_dim (`int`):
72 The dimensionality of the embedding.
73 padding_idx (`Optional[int]`):
74 Pads the output with zeros at the given index.
75 max_norm (`Optional[float]`):
76 Renormalizes embeddings to have a maximum L2 norm.
77 norm_type (`float`, defaults to `2.0`):
78 The p-norm to compute for the `max_norm` option.
79 scale_grad_by_freq (`bool`, defaults to `False`):
80 Scale gradient by frequency during backpropagation.
81 sparse (`bool`, defaults to `False`):
82 Computes dense gradients. Set to `True` to compute sparse gradients instead.
83 _weight (`Optional[Tensor]`):
84 Pretrained embeddings.
85 """
86 super().__init__(
87 num_embeddings,
88 embedding_dim,
89 padding_idx,
90 max_norm,
91 norm_type,
92 scale_grad_by_freq,
93 sparse,
94 _weight,
95 device,
96 dtype,
97 )
98 self.norm = torch.nn.LayerNorm(embedding_dim, device=device)
99 GlobalOptimManager.get_instance().register_module_override(self, "weight", {"optim_bits": 32})
100
101 def reset_parameters(self) -> None:
102 torch.nn.init.xavier_uniform_(self.weight)

Callers

nothing calls this directly

Calls 3

__init__Method · 0.45
get_instanceMethod · 0.45

Tested by

no test coverage detected