mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-11 05:49:55 +00:00
[Tensor] init a tp network training unittest (#849)
This commit is contained in:
@@ -1 +1 @@
|
||||
from . import repeated_computed_layer, resnet, nested_model, bert, no_leaf_module
|
||||
from . import repeated_computed_layer, resnet, nested_model, bert, no_leaf_module, simple_net
|
||||
|
44
tests/components_to_test/simple_net.py
Normal file
44
tests/components_to_test/simple_net.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
from colossalai.nn import CheckpointModule
|
||||
from .utils.dummy_data_generator import DummyDataGenerator
|
||||
from .registry import non_distributed_component_funcs
|
||||
|
||||
|
||||
class SimpleNet(CheckpointModule):
|
||||
"""
|
||||
In this no-leaf module, it has subordinate nn.modules and a nn.Parameter.
|
||||
"""
|
||||
|
||||
def __init__(self, checkpoint=False) -> None:
|
||||
super().__init__(checkpoint=checkpoint)
|
||||
self.proj1 = nn.Linear(4, 8)
|
||||
self.proj2 = nn.Linear(8, 4)
|
||||
|
||||
def forward(self, x):
|
||||
x = self.proj1(x)
|
||||
x = self.proj2(x)
|
||||
return x
|
||||
|
||||
|
||||
class DummyDataLoader(DummyDataGenerator):
|
||||
|
||||
def generate(self):
|
||||
data = torch.rand(16, 4)
|
||||
label = torch.randint(low=0, high=2, size=(16,))
|
||||
return data, label
|
||||
|
||||
|
||||
@non_distributed_component_funcs.register(name='simple_net')
|
||||
def get_training_components():
|
||||
|
||||
def model_builder(checkpoint=True):
|
||||
return SimpleNet(checkpoint)
|
||||
|
||||
trainloader = DummyDataLoader()
|
||||
testloader = DummyDataLoader()
|
||||
|
||||
criterion = torch.nn.CrossEntropyLoss()
|
||||
from colossalai.nn.optimizer import HybridAdam
|
||||
return model_builder, trainloader, testloader, HybridAdam, criterion
|
Reference in New Issue
Block a user