Sampling: Add adaptive-P params

This commit is contained in:
turboderp
2026-01-20 19:09:54 +01:00
parent 8a824cb127
commit 0985c7f7b7
4 changed files with 29 additions and 0 deletions

View File

@@ -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)

View File

@@ -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()])

View File

@@ -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."""

View File

@@ -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