mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-14 15:57:27 +00:00
Sampling: Add adaptive-P params
This commit is contained in:
@@ -918,6 +918,10 @@ class ExllamaV3Container(BaseModelContainer):
|
||||
if params.temperature_last:
|
||||
sampler_builder.temperature(params.temperature)
|
||||
|
||||
# Apply adaptive-P
|
||||
if params.adaptive_target < 1.0:
|
||||
sampler_builder.adaptive_p(params.adaptive_target, params.adaptive_decay)
|
||||
|
||||
# Build the sampler
|
||||
# Set greedy if temperature is 0
|
||||
sampler = sampler_builder.build(params.temperature == 0)
|
||||
|
||||
@@ -11,6 +11,7 @@ from exllamav3.generator.sampler import (
|
||||
SS_TopP,
|
||||
SS_Sample,
|
||||
SS_Base,
|
||||
SS_AdaptiveP
|
||||
)
|
||||
|
||||
|
||||
@@ -43,9 +44,16 @@ class ExllamaV3SamplerBuilder:
|
||||
def greedy(self):
|
||||
self.stack.append(SS_Argmax())
|
||||
|
||||
def adaptive_p(self, adaptive_target, adaptive_decay):
|
||||
self.stack.append(SS_AdaptiveP(adaptive_target, adaptive_decay))
|
||||
|
||||
def build(self, greedy):
|
||||
"""Builds the final sampler from stack."""
|
||||
|
||||
# Adaptive-P does categorical sampling already
|
||||
if len(self.stack) and isinstance(self.stack[-1], SS_AdaptiveP):
|
||||
return CustomSampler(self.stack)
|
||||
|
||||
# Use greedy if temp is 0
|
||||
if greedy:
|
||||
return CustomSampler([SS_Argmax()])
|
||||
|
||||
@@ -275,6 +275,15 @@ class BaseSamplerRequest(BaseModel):
|
||||
ge=0,
|
||||
)
|
||||
|
||||
adaptive_target: Optional[float] = Field(
|
||||
default_factory=lambda: get_default_sampler_value("adaptive_target", 1.0)
|
||||
)
|
||||
|
||||
adaptive_decay: Optional[float] = Field(
|
||||
default_factory=lambda: get_default_sampler_value("adaptive_decay", 0.9)
|
||||
)
|
||||
|
||||
|
||||
@field_validator("top_k", mode="before")
|
||||
def convert_top_k(cls, v):
|
||||
"""Fixes instance if Top-K is -1."""
|
||||
|
||||
@@ -156,3 +156,11 @@ cfg_scale:
|
||||
negative_prompt:
|
||||
override:
|
||||
force: false
|
||||
|
||||
# MARK: Adaptive-P
|
||||
adaptive_target:
|
||||
override: 1.0
|
||||
force: false
|
||||
adaptive_decay:
|
||||
override: 0.9
|
||||
force: false
|
||||
|
||||
Reference in New Issue
Block a user