Skip to content

Commit 3d80cb3

Browse files
authored
Add TriggerPhraseLogitsProcessor for vllm and transformers (#8)
* Add TriggerPhraseLogitsProcessor for vllm * Add <think> utility for genLengthLogitsProcessor for vllm * Update vllm notebooks * Update transformers notebooks * Fix ignoring immediate trigger bug
1 parent 91702e4 commit 3d80cb3

20 files changed

+1389
-320
lines changed

example_notebooks/transformers/cite_prompt_logits_processor.ipynb

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "28ed6952",
77
"metadata": {},
8-
"outputs": [],
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"/home/aerdem/projects/nvidia/logits-processor-zoo\n"
14+
]
15+
}
16+
],
917
"source": [
1018
"%cd ../.."
1119
]
1220
},
1321
{
1422
"cell_type": "code",
15-
"execution_count": null,
23+
"execution_count": 2,
1624
"id": "a85f8503",
1725
"metadata": {},
1826
"outputs": [],
@@ -54,6 +62,13 @@
5462
"id": "cbf4c2d5",
5563
"metadata": {},
5664
"outputs": [
65+
{
66+
"name": "stderr",
67+
"output_type": "stream",
68+
"text": [
69+
"The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
70+
]
71+
},
5772
{
5873
"name": "stdout",
5974
"output_type": "stream",
@@ -65,11 +80,16 @@
6580
" \n",
6681
"\n",
6782
"LLM response:\n",
68-
"The user seems to think that the product is worth its high price. They describe it as \"very soft\" and \"colorful,\" suggesting that these features contribute positively to their overall impression of the item. The phrase \"deserves its price\" indicates satisfaction with the value for money. Additionally, they mention that the product is \"stylish,\" which adds another positive aspect to their opinion.\n",
83+
"The user seems to have mixed feelings about the price of the product. They find it \"expensive,\" which might be due to several factors:\n",
6984
"\n",
70-
"Overall, the user appears to have a favorable view of the product despite its higher cost, appreciating both its quality and design.\n",
71-
"-----END-----\n",
85+
"1. **Quality and Quality Control**: If the product is described as \"very soft\" and \"colorful,\" it suggests that it may be of high quality or unique in some way.\n",
86+
"\n",
87+
"2. **Design and Design Elements**: Describing the design as \"stylish\" indicates that the product has an appealing aesthetic appeal, which can sometimes come at a higher cost.\n",
88+
"\n",
89+
"3. **Brand Reputation**: The fact that the product is described as \"deserving its price\" implies that it represents good value for money, suggesting that it offers more than just basic functionality; perhaps it also provides additional features or materials that justify the higher price point.\n",
7290
"\n",
91+
"Overall, while the user appreciates the product's appearance and style, they seem to feel that the price is too high relative to these positive attributes. This could mean there might not be enough information provided to determine if the price reflects the true value of the product. It would help to know more details about the product's features, materials used, and any other relevant specifications to better understand their perspective on pricing.\n",
92+
"-----END-----\n",
7393
"\n",
7494
"Prompt: \n",
7595
" Retrieved information:\n",
@@ -81,9 +101,8 @@
81101
" \n",
82102
"\n",
83103
"LLM response:\n",
84-
"A Pokémon is a fictional creature that exists within the Pokémon media franchise. These creatures have unique abilities or characteristics that allow them to interact with their environment and other Pokémon. They can be trained by players through various means such as battling, collecting, or participating in events. Pokémon are often depicted as having magical or supernatural powers, though they may also possess more mundane attributes depending on the specific type of Pokémon.\n",
104+
"A Pokémon is a fictional creature that exists within the Pokémon media franchise. These creatures have unique abilities or characteristics that allow them to interact with their environment and other characters in various ways. Pokémon can be found in different types of habitats such as forests, mountains, rivers, and cities, and they often serve as companions or allies for trainers who embark on adventures. Each Pokémon has its own distinct appearance, moveset, and personality traits, making them beloved figures in popular culture.\n",
85105
"-----END-----\n",
86-
"\n",
87106
"\n"
88107
]
89108
}
@@ -117,10 +136,9 @@
117136
" \n",
118137
"\n",
119138
"LLM response:\n",
120-
"The user's opinion about the product's price is that it is worth the cost, as they describe the product as \"very soft, colorful, expensive but deserves its price.\" This indicates that the user believes the product is of high quality and is not overpriced for its features, despite its higher price point.\n",
139+
"The user seems to have mixed feelings about the price of the product. They find it expensive, but they also appreciate its softness, colorfulness, and style, which suggests that the product is well-made and worth the cost.\n",
121140
"-----END-----\n",
122141
"\n",
123-
"\n",
124142
"Prompt: \n",
125143
" Retrieved information:\n",
126144
" Pokémon is a Japanese media franchise consisting of video games, animated series and films, a trading card game, and other related media. \n",
@@ -131,9 +149,8 @@
131149
" \n",
132150
"\n",
133151
"LLM response:\n",
134-
"A Pokémon is a fictional creature that exists within the Pokémon media franchise, including video games, animated series, films, trading cards, and other related media. These creatures have unique abilities or characteristics, often derived from the environment they inhabit, and can be trained by players or collectors for various purposes, such as battling opponents, participating in competitions, or simply collecting them as collectibles.\n",
152+
"A Pokémon is a fictional creature in the Pokémon franchise, which is a Japanese media franchise consisting of video games, animated series, films, a trading card game, and other related media. The franchise takes place in a shared universe where humans coexist with Pokémon, a large variety of species endowed with special powers. The franchise's target audience is children aged 5 to 12, but it is known to attract people of all ages.\n",
135153
"-----END-----\n",
136-
"\n",
137154
"\n"
138155
]
139156
}
@@ -170,9 +187,10 @@
170187
" \n",
171188
"\n",
172189
"LLM response:\n",
173-
"The user seems to think that while the product might be more expensive than other options available in the market (described as \"very soft\" and \"colorful\"), it still warrants this higher cost due to its quality and style. The phrase \"deserves its price\" indicates that they believe the item provides good value for money. Therefore, their overall impression of the product’s pricing seems positive; despite being costly, they consider it worth purchasing because of its appealing features like colorfulness and style.\n",
174-
"-----END-----\n",
190+
"The reviewer seems to have mixed feelings towards the pricing of the product. They describe it as \"expensive\" and \"deserves its price,\" which suggests that they find it worth paying for its quality or unique features. The use of words like \"stylish\" further emphasizes their positive impression.\n",
175191
"\n",
192+
"So in summary, while they appreciate the design and style of the product, they also acknowledge that it might be quite pricey. Therefore, their overall sentiment can be described as **mixed**, with appreciation for both aspects (quality and style).\n",
193+
"-----END-----\n",
176194
"\n",
177195
"Prompt: \n",
178196
" Retrieved information:\n",
@@ -184,9 +202,12 @@
184202
" \n",
185203
"\n",
186204
"LLM response:\n",
187-
"A Pokémon is a fictional creature that exists within the Pokémon media franchise. These creatures have unique abilities or characteristics that allow them to interact with their environment and other Pokémon. They can be trained by players through various means such as battling against each other or participating in events. Pokémon are often depicted as having magical or supernatural powers and are commonly associated with adventure stories and gameplay experiences.\n",
188-
"-----END-----\n",
205+
"A Pokémon is an imaginary creature that exists within the fictional world of the Pokémon franchise. These creatures have unique abilities or characteristics that allow them to interact with their environment or engage in battles against each other.\n",
206+
"\n",
207+
"Pokémon can be found throughout various regions on Earth (or \"Gym Leaders\") where trainers can catch them using Poké Balls or capture them through battle encounters. Each type of Pokémon has specific attributes such as strength, speed, or ability to use certain moves.\n",
189208
"\n",
209+
"The concept behind Pokémon revolves around the idea that these magical beings exist alongside human society, providing entertainment through gameplay experiences like battling or collecting cards representing different types of Pokémon. This blend of fantasy elements combined with interactive gaming mechanics makes the Pokémon franchise appealing across diverse age groups due to its accessibility for young audiences while also attracting older fans who appreciate the depth and complexity of the character designs and storylines.\n",
210+
"-----END-----\n",
190211
"\n"
191212
]
192213
}
@@ -201,7 +222,7 @@
201222
],
202223
"metadata": {
203224
"kernelspec": {
204-
"display_name": ".venv",
225+
"display_name": "Python 3 (ipykernel)",
205226
"language": "python",
206227
"name": "python3"
207228
},
@@ -215,7 +236,7 @@
215236
"name": "python",
216237
"nbconvert_exporter": "python",
217238
"pygments_lexer": "ipython3",
218-
"version": "3.12.7"
239+
"version": "3.10.13"
219240
}
220241
},
221242
"nbformat": 4,

example_notebooks/transformers/force_last_phrase_logits_processor.ipynb

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "28ed6952",
77
"metadata": {},
8-
"outputs": [],
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"/home/aerdem/projects/nvidia/logits-processor-zoo\n"
14+
]
15+
}
16+
],
917
"source": [
1018
"%cd ../.."
1119
]
1220
},
1321
{
1422
"cell_type": "code",
15-
"execution_count": null,
23+
"execution_count": 2,
1624
"id": "a85f8503",
1725
"metadata": {},
1826
"outputs": [],
@@ -51,6 +59,13 @@
5159
"id": "cbf4c2d5",
5260
"metadata": {},
5361
"outputs": [
62+
{
63+
"name": "stderr",
64+
"output_type": "stream",
65+
"text": [
66+
"The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n"
67+
]
68+
},
5469
{
5570
"name": "stdout",
5671
"output_type": "stream",
@@ -67,15 +82,12 @@
6782
" \n",
6883
"\n",
6984
"LLM response:\n",
70-
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in Pocket Monsters: Red and Green (Pokémon Red and Blue outside Japan). As a Grass and Poison-type Pokémon, Bulbasaur is considered to be one of the most iconic characters in the franchise.\n",
85+
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in the original Pokémon games, specifically in Pokémon Red and Blue outside of Japan. As a Grass and Poison-type Pokémon, Bulbasaur serves as the starting Pokémon for players to catch and train.\n",
7186
"\n",
72-
"Since its debut, Bulbasaur has been featured in numerous sequels, spin-off games, related merchandise, and animated and printed adaptations of the franchise. In the Pokémon anime, it serves as a central character, being one of Ash Ketchum's main Pokémon for the first season. Later on, another Pokémon named May obtains a different Bulbasaur as her own.\n",
87+
"Throughout the series, Bulbasaur has been featured in numerous sequels, spin-offs, related merchandise, and animated and printed adaptations of the franchise. It plays an important role in the Pokémon anime, where it is one of Ash Ketchum's main Pokémon during the first season. Later on, another Pokémon named May obtains a different version of Bulbasaur as her own.\n",
7388
"\n",
74-
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga series, including those written by Satoshi Hoshino. Furthermore, it is owned by the protagonist Red in the Pokémon Adventures game.\n",
75-
"\n",
76-
"Overall, Bulbasaur is an important part of the Pokémon universe and continues to be popular among fans of the franchise.\n",
89+
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga stories and is owned by the protagonist Red in the Pokémon Adventures game. The Pokémon has become a beloved character within the franchise due to its enduring popularity across multiple platforms and generations of fans.\n",
7790
"-----END-----\n",
78-
"\n",
7991
"\n"
8092
]
8193
}
@@ -114,17 +126,14 @@
114126
" \n",
115127
"\n",
116128
"LLM response:\n",
117-
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in Pocket Monsters: Red and Green (Pokémon Red and Blue outside Japan). As a Grass and Poison-type Pokémon, Bulbasaur is considered to be one of the most iconic characters in the franchise.\n",
129+
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in the original Pokémon games, specifically in Pokémon Red and Blue outside of Japan. As a Grass and Poison-type Pokémon, Bulbasaur serves as the starting Pokémon for players to catch and train.\n",
118130
"\n",
119-
"Since its debut, Bulbasaur has been featured in numerous sequels, spin-off games, related merchandise, and animated and printed adaptations of the franchise. In the Pokémon anime, it serves as a central character, being one of Ash Ketchum's main Pokémon for the first season. Later on, another Pokémon named May obtains a different Bulbasaur as her own.\n",
131+
"Throughout the series, Bulbasaur has been featured in numerous sequels, spin-offs, related merchandise, and animated and printed adaptations of the franchise. It plays an important role in the Pokémon anime, where it is one of Ash Ketchum's main Pokémon during the first season. Later on, another Pokémon named May obtains a different version of Bulbasaur as her own.\n",
120132
"\n",
121-
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga series, including those written by Satoshi Hoshino. Furthermore, it is owned by the protagonist Red in the Pokémon Adventures game.\n",
122-
"\n",
123-
"Overall, Bulbasaur is an important part of the Pokémon universe and continues to be popular among fans of the franchise.\n",
133+
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga stories and is owned by the protagonist Red in the Pokémon Adventures game. The Pokémon has become a beloved character within the franchise due to its enduring popularity across multiple platforms and generations of fans.\n",
124134
"\n",
125135
"References: Wikipedia article on Bulbasaur.\n",
126136
"-----END-----\n",
127-
"\n",
128137
"\n"
129138
]
130139
}
@@ -169,17 +178,14 @@
169178
" \n",
170179
"\n",
171180
"LLM response:\n",
172-
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in Pocket Monsters: Red and Green (Pokémon Red and Blue outside Japan). As a Grass and Poison-type Pokémon, Bulbasaur is considered to be one of the most iconic characters in the franchise.\n",
181+
"Bulbasaur is a fictional Pokémon species that appears in the Pokémon franchise. It was designed by Atsuko Nishida and first appeared in the original Pokémon games, specifically in Pokémon Red and Blue outside of Japan. As a Grass and Poison-type Pokémon, Bulbasaur serves as the starting Pokémon for players to catch and train.\n",
173182
"\n",
174-
"Since its debut, Bulbasaur has been featured in numerous sequels, spin-off games, related merchandise, and animated and printed adaptations of the franchise. In the Pokémon anime, it serves as a central character, being one of Ash Ketchum's main Pokémon for the first season. Later on, another Pokémon named May obtains a different Bulbasaur as her own.\n",
183+
"Throughout the series, Bulbasaur has been featured in numerous sequels, spin-offs, related merchandise, and animated and printed adaptations of the franchise. It plays an important role in the Pokémon anime, where it is one of Ash Ketchum's main Pokémon during the first season. Later on, another Pokémon named May obtains a different version of Bulbasaur as her own.\n",
175184
"\n",
176-
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga series, including those written by Satoshi Hoshino. Furthermore, it is owned by the protagonist Red in the Pokémon Adventures game.\n",
185+
"In addition to its appearances in the anime, Bulbasaur also features prominently in various manga stories and is owned by the protagonist Red in the Pokémon Adventures game. The Pokémon has become a beloved character within the franchise due to its enduring popularity across multiple platforms and generations of fans.\n",
177186
"\n",
178-
"Overall, Bulbasaur is an important part of the Pokémon universe and continues to be popular among fans of the franchise.\n",
179-
"\n",
180-
"Thanks for trying our RAG application! If you have more questions about Bulbasaur or any other topic, feel free to ask. We're here to help!\n",
187+
"Thanks for trying our RAG application! If you have more questions about Bulbasaur or any other topic, feel free to ask!\n",
181188
"-----END-----\n",
182-
"\n",
183189
"\n"
184190
]
185191
}
@@ -196,7 +202,7 @@
196202
],
197203
"metadata": {
198204
"kernelspec": {
199-
"display_name": ".venv",
205+
"display_name": "Python 3 (ipykernel)",
200206
"language": "python",
201207
"name": "python3"
202208
},
@@ -210,7 +216,7 @@
210216
"name": "python",
211217
"nbconvert_exporter": "python",
212218
"pygments_lexer": "ipython3",
213-
"version": "3.12.7"
219+
"version": "3.10.13"
214220
}
215221
},
216222
"nbformat": 4,

0 commit comments

Comments
 (0)