Skip to content

Commit 00520ae

Browse files
authored
Merge pull request #17 from NVIDIA/fix-bugs
Fix bugs
2 parents 275c6fb + 5acca23 commit 00520ae

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

example_notebooks/vllm/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import os
12
import vllm
23

4+
# vLLM V1 does not currently accept logits processor so we need to disable it
5+
# https://docs.vllm.ai/en/latest/getting_started/v1_user_guide.html#deprecated-features
6+
os.environ["VLLM_USE_V1"] = "0"
7+
38

49
class vLLMRunner:
510
def __init__(self, model_name="Qwen/Qwen2.5-1.5B-Instruct"):

logits_processor_zoo/transformers/cite_prompt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ def __init__(self, tokenizer: PreTrainedTokenizer, boost_factor: float = 1.0, bo
4141
self.boost_eos = boost_eos
4242

4343
def _process(self, input_ids: List[int], scores: torch.Tensor) -> torch.Tensor:
44+
voc_size = scores.shape[1]
4445
for i in range(scores.shape[0]):
4546
tokens = set(self.prompt_token_ids[i])
4647
if self.boost_eos:
4748
tokens.add(self.eos_token_id)
4849

49-
tokens = list(tokens)
50+
tokens = [t for t in tokens if t < voc_size]
5051
scores[i, tokens] += self.boost_factor
5152
return scores

logits_processor_zoo/vllm/cite_prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ def __call__(self, prompt_tokens_ids: List[int], past_token_ids: List[int], scor
4646
if self.boost_eos:
4747
tokens.add(self.eos_token_id)
4848

49-
tokens = list(tokens)
49+
tokens = [t for t in tokens if t < scores.shape[0]]
5050
scores[tokens] += self.boost_factor
5151
return scores

logits_processor_zoo/vllm/generation_length.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class GenLengthLogitsProcessor:
3939
def __init__(self, tokenizer: PreTrainedTokenizer, boost_factor: float,
4040
p: int = 2, complete_sentences: bool = False, boost_token_str: str = None):
4141
self.boost_token = tokenizer.eos_token_id
42+
self.boost_token_str = boost_token_str
4243
if boost_token_str is not None:
4344
self.boost_token = text_to_token(tokenizer, boost_token_str, last=False)
4445
self.boost_factor = boost_factor

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "logits-processor-zoo"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "A collection of LogitsProcessors to customize and enhance LLM behavior for specific tasks."
55
authors = ["Ahmet Erdem", "Ivan Sorokin", "Maximilian Jeblick", "Darragh Hanley", "David Austin"]
66
readme = "README.md"

0 commit comments

Comments
 (0)