Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: reject a NaN weight_decay in a training request (#14721)

Vineeth Sai Varikuntla01dcfef95b58
diff --git a/studio/backend/models/training.py b/studio/backend/models/training.py
index 3f9b638e332..96c76c642b8 100644
--- a/studio/backend/models/training.py
+++ b/studio/backend/models/training.py
@@ -555,7 +555,8 @@ class TrainingStartRequest(BaseModel):
warmup_ratio: Optional[float] = Field(None, description = "Warmup ratio")
max_steps: Optional[int] = Field(None, description = "Maximum training steps")
save_steps: int = Field(100, description = "Steps between checkpoints")
- weight_decay: float = Field(0.001, description = "Weight decay")
+ # NaN clears _check_weight_decay's 0..10 range check (every comparison with it is False), so it is refused here.
+ weight_decay: float = Field(0.001, allow_inf_nan = False, description = "Weight decay")
# Finite as well as non-negative: JSON 1e309 floats to inf, which clears ge=0 but never binds, so
# the run would train unclipped while reporting a threshold.
max_grad_norm: Optional[float] = Field(
diff --git a/studio/backend/tests/test_training_weight_decay_finite.py b/studio/backend/tests/test_training_weight_decay_finite.py
new file mode 100644
index 00000000000..9761c50527b
--- /dev/null
+++ b/studio/backend/tests/test_training_weight_decay_finite.py
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""weight_decay must be a finite number in [0, 10]; NaN used to slip through the range check."""
+
+import pytest
+from pydantic import ValidationError
+
+from models.training import TrainingStartRequest
+
+
+def _request(**overrides):
+ return TrainingStartRequest(
+ model_name = "unsloth/test",
+ training_type = "LoRA/QLoRA",
+ format_type = "auto",
+ **overrides,
+ )
+
+
[email protected]("value", [float("nan"), float("inf"), float("-inf"), -0.1, 10.5])
+def test_weight_decay_rejects_non_finite_and_out_of_range(value):
+ with pytest.raises(ValidationError):
+ _request(weight_decay = value)
+
+
[email protected]("value", [0, 0.001, 10])
+def test_weight_decay_accepts_range(value):
+ assert _request(weight_decay = value).weight_decay == value