forked from hpcaitech/ColossalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testing] add beit model for unit testings (hpcaitech#2196)
* [testing] add beit model * [beit] fix bugs * [beit] fix bugs * [testing] fix bugs
- Loading branch information
Showing
5 changed files
with
58 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import torch | ||
from timm.models.beit import Beit | ||
|
||
from colossalai.utils.cuda import get_current_device | ||
|
||
from .registry import non_distributed_component_funcs | ||
from .utils.dummy_data_generator import DummyDataGenerator | ||
|
||
|
||
class DummyDataLoader(DummyDataGenerator): | ||
img_size = 64 | ||
num_channel = 3 | ||
num_class = 10 | ||
batch_size = 4 | ||
|
||
def generate(self): | ||
data = torch.randn((DummyDataLoader.batch_size, DummyDataLoader.num_channel, DummyDataLoader.img_size, | ||
DummyDataLoader.img_size), | ||
device=get_current_device()) | ||
label = torch.randint(low=0, | ||
high=DummyDataLoader.num_class, | ||
size=(DummyDataLoader.batch_size,), | ||
device=get_current_device()) | ||
return data, label | ||
|
||
|
||
@non_distributed_component_funcs.register(name='beit') | ||
def get_training_components(): | ||
|
||
def model_buider(checkpoint=False): | ||
model = Beit(img_size=DummyDataLoader.img_size, | ||
num_classes=DummyDataLoader.num_class, | ||
embed_dim=32, | ||
depth=2, | ||
num_heads=4) | ||
return model | ||
|
||
trainloader = DummyDataLoader() | ||
testloader = DummyDataLoader() | ||
|
||
criterion = torch.nn.CrossEntropyLoss() | ||
return model_buider, trainloader, testloader, torch.optim.Adam, criterion |
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