add torch autocast to modeling
Browse files- modeling.py +6 -5
modeling.py
CHANGED
|
@@ -141,8 +141,9 @@ class MBZTestModelForCausalLM(PreTrainedModel):
|
|
| 141 |
self.out_head = nn.Linear(d_model, n_vocab)
|
| 142 |
|
| 143 |
def forward(self, x):
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
| 141 |
self.out_head = nn.Linear(d_model, n_vocab)
|
| 142 |
|
| 143 |
def forward(self, x):
|
| 144 |
+
with torch.autocast('cuda', dtype=torch.bfloat16):
|
| 145 |
+
x = self.embed(x)
|
| 146 |
+
for block in self.blocks:
|
| 147 |
+
x = block(x)
|
| 148 |
+
x = self.out_head(self.norm(x))
|
| 149 |
+
return CausalLMOutput(logits=x)
|