Text Classification
Transformers
Safetensors
English
Chinese
internlm2
feature-extraction
reward model
custom_code
Instructions to use internlm/internlm2-20b-reward with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm2-20b-reward with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="internlm/internlm2-20b-reward", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("internlm/internlm2-20b-reward", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
move tensor if necessary (like device_map: auto with >1 gpu)
#2
by lodrick-the-lafted - opened
- 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
|