michaelbzhu commited on
Commit
9f3f5bb
·
verified ·
1 Parent(s): 434d756

add torch autocast to modeling

Browse files
Files changed (1) hide show
  1. 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
- x = self.embed(x)
145
- for block in self.blocks:
146
- x = block(x)
147
- x = self.out_head(self.norm(x))
148
- return CausalLMOutput(logits=x)
 
 
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)