MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / SimpleModel

Class SimpleModel

tests/unit/simple_model.py:20–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class SimpleModel(torch.nn.Module):
21
22 def __init__(self, hidden_dim, empty_grad=False, nlayers=1):
23 super(SimpleModel, self).__init__()
24 self.linears = torch.nn.ModuleList([torch.nn.Linear(hidden_dim, hidden_dim) for i in range(nlayers)])
25 if empty_grad:
26 self.linear2 = torch.nn.Linear(hidden_dim, hidden_dim)
27 self.cross_entropy_loss = torch.nn.CrossEntropyLoss()
28 self.empty_grad = empty_grad
29
30 def forward(self, x, y):
31 if len(self.linears) == 1:
32 x = self.linears[0](x)
33 else:
34 for i, l in enumerate(self.linears):
35 x = self.linears[i // 2](x) + l(x)
36 return self.cross_entropy_loss(x, y)
37
38
39class SimpleFrozenModel(torch.nn.Module):

Callers 15

testMethod · 0.90
testMethod · 0.90
test_ns_method_stage3Method · 0.90
testMethod · 0.90
test_on_deviceMethod · 0.90
test_modelMethod · 0.90
testMethod · 0.90
_initMethod · 0.90

Calls

no outgoing calls

Tested by 15

testMethod · 0.72
testMethod · 0.72
test_ns_method_stage3Method · 0.72
testMethod · 0.72
test_on_deviceMethod · 0.72
test_modelMethod · 0.72
testMethod · 0.72
_initMethod · 0.72