This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3cff679
commit 20e1677
Showing
8 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
import pytest | ||
import torch | ||
import bitsandbytes as bnb | ||
|
||
from itertools import product | ||
|
||
from bitsandbytes import functional as F | ||
|
||
|
||
@pytest.mark.parametrize("embcls", [bnb.nn.Embedding, bnb.nn.StableEmbedding], ids=['Embedding', 'StableEmbedding']) | ||
def test_embeddings(embcls): | ||
bnb.optim.GlobalOptimManager.get_instance().initialize() | ||
emb1 = torch.nn.Embedding(100, 512).cuda() | ||
emb2 = embcls(100, 512).cuda() | ||
|
||
adam1 = bnb.optim.Adam8bit(emb1.parameters()) | ||
adam2 = bnb.optim.Adam8bit(emb2.parameters()) | ||
|
||
batches = torch.randint(1, 100, size=(100, 4, 32)).cuda() | ||
|
||
for i in range(100): | ||
batch = batches[i] | ||
|
||
embedded1 = emb1(batch) | ||
embedded2 = emb2(batch) | ||
|
||
l1 = embedded1.mean() | ||
l2 = embedded2.mean() | ||
|
||
l1.backward() | ||
l2.backward() | ||
|
||
adam1.step() | ||
adam2.step() | ||
|
||
adam1.zero_grad() | ||
adam2.zero_grad() | ||
|
||
assert adam1.state[emb1.weight]['state1'].dtype == torch.uint8 | ||
assert adam2.state[emb2.weight]['state1'].dtype == torch.float32 | ||
|
||
|