lodrick-the-lafted commited on
Commit
c734331
1 Parent(s): 6539b1d

move tensor if necessary (like device_map: auto with >1 gpu)

Browse files
Files changed (1) hide show
  1. modeling_internlm2.py +4 -0
modeling_internlm2.py CHANGED
@@ -1880,6 +1880,10 @@ class InternLM2ForRewardModel(InternLM2PreTrainedModel):
1880
  # get end reward token's score
1881
  ends = attention_mask.cumsum(dim=1).argmax(dim=1).view(-1,1)
1882
 
 
 
 
 
1883
  reward_scores = torch.gather(hidden_states.squeeze(-1), 1, ends)
1884
 
1885
  loss = None
 
1880
  # get end reward token's score
1881
  ends = attention_mask.cumsum(dim=1).argmax(dim=1).view(-1,1)
1882
 
1883
+ # move tensor if on different device so auto_map works
1884
+ if ends.device != hidden_states.device:
1885
+ ends = ends.to(hidden_states.device)
1886
+
1887
  reward_scores = torch.gather(hidden_states.squeeze(-1), 1, ends)
1888
 
1889
  loss = None