Spaces:
Sleeping
Sleeping
Commit ·
6538c21
1
Parent(s): 3247744
Fix for Transformers v5
Browse files- app.py +3 -2
- solution.py +4 -2
app.py
CHANGED
|
@@ -66,9 +66,10 @@ def compute_mean_logprob(prompt_text, generated_text):
|
|
| 66 |
# Always use chat template: the model is an instruct model, so
|
| 67 |
# logprobs are meaningful only in the chat context.
|
| 68 |
message = [{"role": "user", "content": prompt_text}]
|
| 69 |
-
|
| 70 |
message, add_generation_prompt=True, return_tensors="pt"
|
| 71 |
-
)
|
|
|
|
| 72 |
gen_ids = tokenizer.encode(
|
| 73 |
generated_text, add_special_tokens=False, return_tensors="pt"
|
| 74 |
).to(model.device)
|
|
|
|
| 66 |
# Always use chat template: the model is an instruct model, so
|
| 67 |
# logprobs are meaningful only in the chat context.
|
| 68 |
message = [{"role": "user", "content": prompt_text}]
|
| 69 |
+
encoded = tokenizer.apply_chat_template(
|
| 70 |
message, add_generation_prompt=True, return_tensors="pt"
|
| 71 |
+
)
|
| 72 |
+
prompt_ids = (encoded if isinstance(encoded, torch.Tensor) else encoded["input_ids"]).to(model.device)
|
| 73 |
gen_ids = tokenizer.encode(
|
| 74 |
generated_text, add_special_tokens=False, return_tensors="pt"
|
| 75 |
).to(model.device)
|
solution.py
CHANGED
|
@@ -29,7 +29,8 @@ class LaDisparition:
|
|
| 29 |
def __call__(self, prompt, max_tokens=20, beam_width=5):
|
| 30 |
# Option 2: we use self.tokenizer.apply_chat_template to tokenize the prompt
|
| 31 |
message = [{"role": "user", "content": prompt}]
|
| 32 |
-
|
|
|
|
| 33 |
prompt_len = input_ids.shape[1]
|
| 34 |
|
| 35 |
# Beam search: maintain multiple hypotheses
|
|
@@ -155,7 +156,8 @@ class ToulouseSequence:
|
|
| 155 |
def __call__(self, prompt, max_tokens=20):
|
| 156 |
# Option 2: we use self.tokenizer.apply_chat_template to tokenize the prompt
|
| 157 |
message = [{"role": "user", "content": prompt}]
|
| 158 |
-
|
|
|
|
| 159 |
prompt_length = inputs.shape[1]
|
| 160 |
|
| 161 |
# Generate tokens one by one
|
|
|
|
| 29 |
def __call__(self, prompt, max_tokens=20, beam_width=5):
|
| 30 |
# Option 2: we use self.tokenizer.apply_chat_template to tokenize the prompt
|
| 31 |
message = [{"role": "user", "content": prompt}]
|
| 32 |
+
encoded = self.tokenizer.apply_chat_template(message, add_generation_prompt=True, return_tensors="pt")
|
| 33 |
+
input_ids = (encoded if isinstance(encoded, torch.Tensor) else encoded["input_ids"]).to(self.model.device)
|
| 34 |
prompt_len = input_ids.shape[1]
|
| 35 |
|
| 36 |
# Beam search: maintain multiple hypotheses
|
|
|
|
| 156 |
def __call__(self, prompt, max_tokens=20):
|
| 157 |
# Option 2: we use self.tokenizer.apply_chat_template to tokenize the prompt
|
| 158 |
message = [{"role": "user", "content": prompt}]
|
| 159 |
+
encoded = self.tokenizer.apply_chat_template(message, add_generation_prompt=True, return_tensors="pt")
|
| 160 |
+
inputs = (encoded if isinstance(encoded, torch.Tensor) else encoded["input_ids"]).to(self.model.device)
|
| 161 |
prompt_length = inputs.shape[1]
|
| 162 |
|
| 163 |
# Generate tokens one by one
|