e93507a09c
Lockfile supply-chain audit / lockfile supply-chain audit (push) Has been cancelled
Windows Studio GGUF CI / GPU prebuilt resolves without Visual Studio (push) Has been cancelled
Windows Studio GGUF CI / setup.ps1 unit tests (VS 2026 / CMake guard) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2022) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-2025-vs2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-latest) (push) Has been cancelled
Windows Studio Update CI / Studio Updating Tests (push) Has been cancelled
Wheel CI / Wheel build + content sanity + import smoke (push) Has been cancelled
Lint CI / Source lint (Python + shell + YAML + JSON + safety nets) (push) Has been cancelled
MLX CI on Mac M1 / dispatch (push) Has been cancelled
Security audit / advisory audit (pip + npm + cargo) (push) Has been cancelled
Security audit / pip scan-packages :: extras (push) Has been cancelled
Security audit / pip scan-packages :: studio (push) Has been cancelled
Security audit / pip scan-packages :: hf-stack (push) Has been cancelled
Security audit / npm scan-packages (Studio frontend tarballs) (push) Has been cancelled
Security audit / workflow-trigger lint (pull_request_target / cache-poisoning) (push) Has been cancelled
Security audit / pytest tests/security (push) Has been cancelled
Security audit / npm provenance + new install-script diff (push) Has been cancelled
Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Backend CI / (Python 3.10) (push) Has been cancelled
Backend CI / (Python 3.11) (push) Has been cancelled
Backend CI / (Python 3.12) (push) Has been cancelled
Backend CI / (Python 3.13) (push) Has been cancelled
Backend CI / Repo tests (CPU) (push) Has been cancelled
Frontend CI / Frontend build + bundle sanity (push) Has been cancelled
Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Mac Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Mac Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-14) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15-intel) (push) Has been cancelled
Mac Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26-intel) (push) Has been cancelled
Mac Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Tauri CI / Tauri Linux debug build (no codesign) (push) Has been cancelled
Mac Studio Update CI / Studio Updating Tests (push) Has been cancelled
Studio UI CI / Chat UI Tests (push) Has been cancelled
Windows Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Windows Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Update CI / Studio Updating Tests (push) Has been cancelled
Core / Core (HF=default + TRL=default) (push) Has been cancelled
Core / Core (HF=4.57.6 + TRL<1) (push) Has been cancelled
Core / Core (HF=latest + TRL=latest) (push) Has been cancelled
Core / llama.cpp build + smoke (push) Has been cancelled
Windows Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Windows Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Windows Studio GGUF CI / JSON, images (push) Has been cancelled
Windows Studio GGUF CI / Studio install + inference without Visual Studio (push) Has been cancelled
Studio export capability / capability (macos-latest) (push) Has been cancelled
Studio export capability / capability (ubuntu-latest) (push) Has been cancelled
Studio export capability / capability (windows-latest) (push) Has been cancelled
Cross-platform parity / parity (macos-latest) (push) Has been cancelled
Cross-platform parity / parity (windows-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Studio load-orchestrator CI / test (push) Has been cancelled
137 lines
4.5 KiB
Python
137 lines
4.5 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
|
|
|
|
"""Pin TrainingStartRequest hyperparameter caps at the at-cap / over-cap boundary."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
_BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(_BACKEND_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(_BACKEND_ROOT))
|
|
|
|
from models.training import (
|
|
_MAX_BATCH_SIZE,
|
|
_MAX_LORA_ALPHA,
|
|
_MAX_LORA_R,
|
|
_MAX_SEQ_LENGTH,
|
|
_MAX_VISION_IMAGE_SIZE,
|
|
_MIN_VISION_IMAGE_SIZE,
|
|
)
|
|
|
|
|
|
def _check_field(field_name: str, value):
|
|
"""Run the field validator without building a full TrainingStartRequest."""
|
|
from models.training import TrainingStartRequest
|
|
|
|
schema_field = TrainingStartRequest.model_fields[field_name]
|
|
return TrainingStartRequest.__pydantic_validator__.validate_assignment(
|
|
TrainingStartRequest.model_construct(),
|
|
field_name,
|
|
value,
|
|
)
|
|
|
|
|
|
class TestSeqLengthCap:
|
|
def test_at_cap_accepts(self):
|
|
_check_field("max_seq_length", _MAX_SEQ_LENGTH)
|
|
assert _MAX_SEQ_LENGTH == 2_000_000
|
|
|
|
def test_over_cap_rejects(self):
|
|
with pytest.raises(ValidationError) as exc:
|
|
_check_field("max_seq_length", _MAX_SEQ_LENGTH + 1)
|
|
assert "max_seq_length" in str(exc.value)
|
|
|
|
def test_below_min_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("max_seq_length", 0)
|
|
|
|
|
|
class TestBatchSizeCap:
|
|
def test_at_cap_accepts(self):
|
|
_check_field("batch_size", _MAX_BATCH_SIZE)
|
|
assert _MAX_BATCH_SIZE == 4096
|
|
|
|
def test_over_cap_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("batch_size", _MAX_BATCH_SIZE + 1)
|
|
|
|
def test_below_min_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("batch_size", 0)
|
|
|
|
|
|
class TestVisionImageSizeCap:
|
|
def test_none_accepts_model_default(self):
|
|
_check_field("vision_image_size", None)
|
|
|
|
@pytest.mark.parametrize(
|
|
"value",
|
|
[_MIN_VISION_IMAGE_SIZE, 640, 1000, _MAX_VISION_IMAGE_SIZE],
|
|
)
|
|
def test_in_range_accepts(self, value):
|
|
_check_field("vision_image_size", value)
|
|
assert _MIN_VISION_IMAGE_SIZE == 256
|
|
assert _MAX_VISION_IMAGE_SIZE == 2048
|
|
|
|
@pytest.mark.parametrize(
|
|
"value",
|
|
[_MIN_VISION_IMAGE_SIZE - 1, _MAX_VISION_IMAGE_SIZE + 1, 640.5, True],
|
|
)
|
|
def test_invalid_rejects(self, value):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("vision_image_size", value)
|
|
|
|
@pytest.mark.parametrize("value", [True, False])
|
|
def test_bool_error_says_integer_not_range(self, value):
|
|
# Regression guard: bools say "integer or null", not "in [256, 2048]".
|
|
with pytest.raises(ValidationError) as exc:
|
|
_check_field("vision_image_size", value)
|
|
assert "integer or null" in str(exc.value)
|
|
|
|
@pytest.mark.parametrize("value", ["++512", "--256", "+-+512", "+", "-"])
|
|
def test_multi_sign_string_says_integer_not_raw(self, value):
|
|
# Regression guard: multi-sign strings say "integer or null", not int()'s raw message.
|
|
with pytest.raises(ValidationError) as exc:
|
|
_check_field("vision_image_size", value)
|
|
assert "integer or null" in str(exc.value)
|
|
assert "invalid literal" not in str(exc.value)
|
|
|
|
@pytest.mark.parametrize("value", ["512", "٥١٢", "१०२४"])
|
|
def test_unicode_digit_string_rejected(self, value):
|
|
# Reject non-ASCII (full-width/Arabic-Indic/Devanagari) digits.
|
|
with pytest.raises(ValidationError) as exc:
|
|
_check_field("vision_image_size", value)
|
|
assert "integer or null" in str(exc.value)
|
|
|
|
|
|
class TestLoraRCap:
|
|
def test_at_cap_accepts(self):
|
|
_check_field("lora_r", _MAX_LORA_R)
|
|
assert _MAX_LORA_R == 16_384
|
|
|
|
def test_over_cap_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("lora_r", _MAX_LORA_R + 1)
|
|
|
|
def test_below_min_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("lora_r", 0)
|
|
|
|
|
|
class TestLoraAlphaCap:
|
|
def test_at_cap_accepts(self):
|
|
_check_field("lora_alpha", _MAX_LORA_ALPHA)
|
|
assert _MAX_LORA_ALPHA == 32_768
|
|
|
|
def test_over_cap_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("lora_alpha", _MAX_LORA_ALPHA + 1)
|
|
|
|
def test_below_min_rejects(self):
|
|
with pytest.raises(ValidationError):
|
|
_check_field("lora_alpha", 0)
|