Skip to content

Commit 7c539a8

Browse files
committed
Allow typical_p = 1.0
This value has no effect so allowing it means more possibility for misunderstanding imo, but this makes it consistent with top_p. It would be a breaking change to prohibit top_p from being 1.0.
1 parent d19245a commit 7c539a8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

router/src/grpc_server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,16 @@ fn convert_params(params: Option<Parameters>) -> Result<GenerateParameters, Vali
423423
gp.temperature = s.temperature;
424424
gp.top_k = s.top_k as i32;
425425
if s.top_p != 0.0 { gp.top_p = s.top_p }
426-
gp.typical_p = s.typical_p;
426+
if s.typical_p != 0.0 { gp.typical_p = s.typical_p }
427427
gp.seed = s.seed;
428428
}
429429
if gp.temperature == 0.0 {
430430
gp.temperature = 1.0; // sampling and temp 0 => disabled i.e. temp 1
431431
}
432432
} else if STRICT_PARAMETER_VALIDATION {
433433
if let Some(s) = p.sampling {
434-
if s.temperature != 0.0 || s.top_p != 0.0 || s.top_k != 0 || s.seed.is_some() {
434+
if s.temperature != 0.0 || s.top_p != 0.0 || s.typical_p != 0.0
435+
|| s.top_k != 0 || s.seed.is_some() {
435436
return Err(ValidationError::SampleParametersGreedy)
436437
}
437438
}

router/src/validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn validate(
184184
if params.top_p <= 0.0 || params.top_p > 1.0 {
185185
return Err(ValidationError::TopP);
186186
}
187-
if params.typical_p >= 1.0 {
187+
if params.typical_p > 1.0 {
188188
return Err(ValidationError::TypicalP);
189189
}
190190
if params.top_k < 0 {
@@ -320,7 +320,7 @@ pub enum ValidationError {
320320
TopP,
321321
#[error("top_k must be strictly positive")]
322322
TopK,
323-
#[error("typical_p must be < 1.0")]
323+
#[error("typical_p must be <= 1.0")]
324324
TypicalP,
325325
#[error("repetition_penalty must be > 0.0")]
326326
RepetitionPenalty,

0 commit comments

Comments
 (0)