Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions bitsandbytes/nn/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(
scale_grad_by_freq: bool = False,
sparse: bool = False,
_weight: Optional[Tensor] = None,
device=None,
dtype=None,
) -> None:
super(StableEmbedding, self).__init__(
num_embeddings,
Expand All @@ -48,8 +50,10 @@ def __init__(
scale_grad_by_freq,
sparse,
_weight,
device,
dtype,
)
self.norm = torch.nn.LayerNorm(embedding_dim)
self.norm = torch.nn.LayerNorm(embedding_dim, device=device)
GlobalOptimManager.get_instance().register_module_override(
self, "weight", {"optim_bits": 32}
)
Expand Down Expand Up @@ -81,7 +85,10 @@ def forward(self, input: Tensor) -> Tensor:
self.sparse,
)

return self.norm(emb)
# always apply layer norm in full precision
emb = emb.to(torch.get_default_dtype())

return self.norm(emb).to(self.weight.dtype)


class Embedding(torch.nn.Embedding):
Expand Down