Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
bitsandbytes
Commits
62d39a23
Commit
62d39a23
authored
Nov 04, 2022
by
Victor Nova
Browse files
add device and dtype parameters to StableEmbedding
parent
1efb87d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
bitsandbytes/nn/modules.py
bitsandbytes/nn/modules.py
+9
-2
No files found.
bitsandbytes/nn/modules.py
View file @
62d39a23
...
@@ -38,6 +38,8 @@ class StableEmbedding(torch.nn.Embedding):
...
@@ -38,6 +38,8 @@ class StableEmbedding(torch.nn.Embedding):
scale_grad_by_freq
:
bool
=
False
,
scale_grad_by_freq
:
bool
=
False
,
sparse
:
bool
=
False
,
sparse
:
bool
=
False
,
_weight
:
Optional
[
Tensor
]
=
None
,
_weight
:
Optional
[
Tensor
]
=
None
,
device
=
None
,
dtype
=
None
,
)
->
None
:
)
->
None
:
super
(
StableEmbedding
,
self
).
__init__
(
super
(
StableEmbedding
,
self
).
__init__
(
num_embeddings
,
num_embeddings
,
...
@@ -48,8 +50,10 @@ class StableEmbedding(torch.nn.Embedding):
...
@@ -48,8 +50,10 @@ class StableEmbedding(torch.nn.Embedding):
scale_grad_by_freq
,
scale_grad_by_freq
,
sparse
,
sparse
,
_weight
,
_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
(
GlobalOptimManager
.
get_instance
().
register_module_override
(
self
,
"weight"
,
{
"optim_bits"
:
32
}
self
,
"weight"
,
{
"optim_bits"
:
32
}
)
)
...
@@ -81,7 +85,10 @@ class StableEmbedding(torch.nn.Embedding):
...
@@ -81,7 +85,10 @@ class StableEmbedding(torch.nn.Embedding):
self
.
sparse
,
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
):
class
Embedding
(
torch
.
nn
.
Embedding
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment