Skip to content

Commit

Permalink
Model: Fix logit bias handling
Browse files Browse the repository at this point in the history
If the token doesn't exist, gracefully warn instead of erroring out.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
kingbri1 committed Feb 18, 2024
1 parent aa34b2e commit 7def32e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion backends/exllamav2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,13 @@ def generate_gen(self, prompt: str, **kwargs):

# Map logits to the tensor with their biases
for token, bias in logit_bias.items():
gen_settings.token_bias[token] = bias
if token in gen_settings.token_bias:
gen_settings.token_bias[token] = bias
else:
logger.warning(
f"Logit bias: Token {token} not present "
"in the model's vocab. Skipping."
)

# Ban the EOS token if specified. If not, append to stop conditions
# as well.
Expand Down
2 changes: 1 addition & 1 deletion common/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class BaseSamplerRequest(BaseModel):

logit_bias: Optional[Dict[int, float]] = Field(
default_factory=lambda: get_default_sampler_value("logit_bias"),
examples=[[{"1": 10}]],
examples=[{"1": 10, "2": 50}],
)

negative_prompt: Optional[str] = Field(
Expand Down

0 comments on commit 7def32e

Please sign in to comment.