mario-rc commited on
Commit
a0ab671
·
verified ·
1 Parent(s): af05824

Add usage example to model card

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -55,6 +55,51 @@ Preference accuracy by domain:
55
  | Empathy | 94.3606 |
56
  | Multicultural | 76.2950 |
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  ## Limitations
59
 
60
  This is a reward model, not a standalone chat assistant. Scores are intended for
 
55
  | Empathy | 94.3606 |
56
  | Multicultural | 76.2950 |
57
 
58
+ ## Usage Example
59
+
60
+ This checkpoint uses the project's custom `RewardModelWithGating` class. Run the
61
+ example from an environment where `multidomain_model/modeling_custom.py` is
62
+ importable.
63
+
64
+ ```python
65
+ import torch
66
+ from transformers import AutoTokenizer
67
+ from modeling_custom import RewardModelWithGating
68
+
69
+ model_id = "mario-rc/multi-domain-rm-fsfairx-llama-3-8b-it"
70
+ dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
71
+ device_map = {"": 0} if torch.cuda.is_available() else None
72
+
73
+ tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)
74
+ model = RewardModelWithGating.from_pretrained(
75
+ model_id,
76
+ device_map=device_map,
77
+ dtype=dtype,
78
+ ).eval()
79
+ device = next(model.parameters()).device
80
+
81
+ messages = [
82
+ {"role": "user", "content": "I failed an important exam and feel awful."},
83
+ {"role": "assistant", "content": "I'm sorry. That is a hard setback, but it does not define your ability. Take a little time to recover, then we can make a concrete study plan for the next attempt."},
84
+ ]
85
+
86
+ encoded = tokenizer.apply_chat_template(
87
+ messages,
88
+ return_tensors="pt",
89
+ padding=True,
90
+ truncation=True,
91
+ max_length=4096,
92
+ )
93
+ inputs = {"input_ids": encoded.to(device)} if isinstance(encoded, torch.Tensor) else {
94
+ key: value.to(device) for key, value in encoded.items()
95
+ }
96
+
97
+ with torch.no_grad():
98
+ score = model(**inputs).score.float().item()
99
+
100
+ print(score)
101
+ ```
102
+
103
  ## Limitations
104
 
105
  This is a reward model, not a standalone chat assistant. Scores are intended for