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

Class EmptyTailModel

tests/unit/runtime/zero/test_zero_numel_param_shape.py:78–89  ·  view source on GitHub ↗

A trainable parameter with no elements, kept in the autograd graph by the loss.

Source from the content-addressed store, hash-verified

76
77
78class EmptyTailModel(torch.nn.Module):
79 """A trainable parameter with no elements, kept in the autograd graph by the loss."""
80
81 def __init__(self, hidden=HIDDEN):
82 super().__init__()
83 self.dense = torch.nn.Linear(hidden, hidden, bias=False)
84 self.empty = torch.nn.Linear(hidden, 0, bias=False)
85
86 def forward(self, x):
87 hidden = self.dense(x)
88 # `empty(hidden)` is (batch, 0); summing it keeps the parameter in the graph.
89 return hidden.sum() + self.empty(hidden).sum()
90
91
92def _engine(case):

Callers 1

_engineFunction · 0.85

Calls

no outgoing calls

Tested by 1

_engineFunction · 0.68