Skip to content

Commit

Permalink
Merge pull request abetlen#178 from Stonelinks/document-presence-freq…
Browse files Browse the repository at this point in the history
…uency-penalty

Document presence frequency penalty
  • Loading branch information
abetlen authored May 10, 2023
2 parents d957422 + 02e8a01 commit 3c96b43
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions llama_cpp/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ def get_llama():
+ "Repeat penalty is a hyperparameter used to penalize the repetition of token sequences during text generation. It helps prevent the model from generating repetitive or monotonous text. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient.",
)

presence_penalty_field = Field(
default=0.0,
ge=-2.0,
le=2.0,
description="Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.",
)

frequency_penalty_field = Field(
default=0.0,
ge=-2.0,
le=2.0,
description="Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
)

class CreateCompletionRequest(BaseModel):
prompt: Optional[str] = Field(
Expand All @@ -175,13 +188,13 @@ class CreateCompletionRequest(BaseModel):
ge=0,
description="The number of logprobs to generate. If None, no logprobs are generated.",
)
presence_penalty: Optional[float] = presence_penalty_field
frequency_penalty: Optional[float] = frequency_penalty_field

# ignored or currently unsupported
model: Optional[str] = model_field
n: Optional[int] = 1
logprobs: Optional[int] = Field(None)
presence_penalty: Optional[float] = 0
frequency_penalty: Optional[float] = 0
best_of: Optional[int] = 1
logit_bias: Optional[Dict[str, float]] = Field(None)
user: Optional[str] = Field(None)
Expand Down Expand Up @@ -269,12 +282,12 @@ class CreateChatCompletionRequest(BaseModel):
top_p: float = top_p_field
stop: Optional[List[str]] = stop_field
stream: bool = stream_field
presence_penalty: Optional[float] = presence_penalty_field
frequency_penalty: Optional[float] = frequency_penalty_field

# ignored or currently unsupported
model: Optional[str] = model_field
n: Optional[int] = 1
presence_penalty: Optional[float] = 0
frequency_penalty: Optional[float] = 0
logit_bias: Optional[Dict[str, float]] = Field(None)
user: Optional[str] = Field(None)

Expand Down

0 comments on commit 3c96b43

Please sign in to comment.