mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-26 01:08:52 +00:00
Model: Add CFG support
CFG, or classifier-free guidance helps push a model in different directions based on what the user provides. Currently, CFG is ignored if the negative prompt is blank (it shouldn't be used in that way anyways). Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -75,6 +75,7 @@ class CommonCompletionRequest(BaseModel):
|
||||
add_bos_token: Optional[bool] = True
|
||||
ban_eos_token: Optional[bool] = False
|
||||
logit_bias: Optional[Dict[int, float]] = Field(default=None, examples=[[{"1": 10}]])
|
||||
negative_prompt: Optional[str] = None
|
||||
|
||||
# Aliased variables
|
||||
penalty_range: Optional[int] = Field(
|
||||
@@ -86,6 +87,10 @@ class CommonCompletionRequest(BaseModel):
|
||||
),
|
||||
)
|
||||
|
||||
cfg_scale: Optional[float] = Field(
|
||||
default=1.0, validation_alias=AliasChoices("cfg_scale", "guidance_scale")
|
||||
)
|
||||
|
||||
def to_gen_params(self):
|
||||
"""Converts to internal generation parameters."""
|
||||
# Convert stop to an array of strings
|
||||
@@ -115,4 +120,6 @@ class CommonCompletionRequest(BaseModel):
|
||||
"mirostat": self.mirostat_mode == 2,
|
||||
"mirostat_tau": self.mirostat_tau,
|
||||
"mirostat_eta": self.mirostat_eta,
|
||||
"cfg_scale": self.cfg_scale,
|
||||
"negative_prompt": self.negative_prompt,
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ class ModelLoadRequest(BaseModel):
|
||||
cache_mode: Optional[str] = "FP16"
|
||||
prompt_template: Optional[str] = None
|
||||
num_experts_per_token: Optional[int] = None
|
||||
use_cfg: Optional[bool] = None
|
||||
draft: Optional[DraftModelLoadRequest] = None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user