"lib/mocker/vscode:/vscode.git/clone" did not exist on "e5850e2385542ff5076da8b0de8e8420b63801dc"
Unverified Commit 980bae03 authored by zhongdaor-nv's avatar zhongdaor-nv Committed by GitHub
Browse files

chore: add request validation and better error message for n > 1 and temperature=0 (#3914)


Signed-off-by: default avatarzhongdaor <zhongdaor@nvidia.com>
parent 9bb1af33
......@@ -305,6 +305,8 @@ impl ValidateRequest for NvCreateChatCompletionRequest {
validate::validate_repetition_penalty(self.get_repetition_penalty())?;
validate::validate_min_p(self.get_min_p())?;
validate::validate_top_k(self.get_top_k())?;
// Cross-field validation
validate::validate_n_with_temperature(self.inner.n, self.inner.temperature)?;
Ok(())
}
......
......@@ -396,6 +396,8 @@ impl ValidateRequest for NvCreateCompletionRequest {
validate::validate_repetition_penalty(self.get_repetition_penalty())?;
validate::validate_min_p(self.get_min_p())?;
validate::validate_top_k(self.get_top_k())?;
// Cross-field validation
validate::validate_n_with_temperature(self.inner.n, self.inner.temperature)?;
Ok(())
}
......
......@@ -249,6 +249,27 @@ pub fn validate_n(n: Option<u8>) -> Result<(), anyhow::Error> {
Ok(())
}
/// Validates n and temperature interaction
/// When n > 1, temperature must be > 0 to ensure diverse outputs
pub fn validate_n_with_temperature(
n: Option<u8>,
temperature: Option<f32>,
) -> Result<(), anyhow::Error> {
if let Some(n_value) = n
&& n_value > 1
{
let temp = temperature.unwrap_or(1.0);
if temp == 0.0 {
anyhow::bail!(
"When n > 1, temperature must be greater than 0 to ensure diverse outputs. Got n={}, temperature={}",
n_value,
temp
);
}
}
Ok(())
}
/// Validates model parameter
pub fn validate_model(model: &str) -> Result<(), anyhow::Error> {
if model.trim().is_empty() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment