Commit
•
5a485b0
1
Parent(s):
6539b1d
move tensor if necessary (like device_map: auto with >1 gpu) (#2)
Browse files- move tensor if necessary (like device_map: auto with >1 gpu) (c734331ac5bf0d6e12e31525d5277688f5692fe1)
Co-authored-by: lodrick <lodrick-the-lafted@users.noreply.huggingface.co>
- 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
|