Make the SDXL LoRA trainer reachable from the app with a small, self-contained job service and JSON routes, deliberately separate from the LLM TrainingBackend (whose lifecycle -- LLM config build, per-run SQLite rows, matplotlib plots, transfer-to-chat- inference -- is text-training specific and would mis-handle a diffusion run). core/training/diffusion_training_service.py: DiffusionTrainingService runs one job at a time -- validate the config cheaply (before any spawn), spawn the trainer subprocess (spawn context, parent-lifetime bound), pump its events (model_load_* / progress / complete / error) into an in-memory status snapshot, and support a clean stop. The subprocess context and target are injectable so the full start -> pump -> status -> complete path is unit-tested without real multiprocessing or torch. routes/training.py: POST /api/train/diffusion/start (400 on a bad config, 409 when a job is already running), POST /api/train/diffusion/stop, GET /api/train/diffusion/status (JSON poll). models/training.py: DiffusionTrainingStartRequest + response schemas mirroring DiffusionLoraConfig, so model_dump() passes straight through. Tests: test_diffusion_training.py -- service happy path, bad-config-before-spawn, concurrent-job rejection, clean stop, crash-without-terminal-event, event transitions; plus route wiring via the FastAPI TestClient (start / 422 / 400 / 409 / status / stop) with a mocked service. The diffusion trainer's progress events already use the field names this path expects.
136 lines
3.2 KiB
Python
136 lines
3.2 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
|
|
|
|
"""Pydantic models for API request/response schemas."""
|
|
|
|
from .training import (
|
|
TrainingStartRequest,
|
|
TrainingJobResponse,
|
|
TrainingStatus,
|
|
TrainingProgress,
|
|
TrainingRunSummary,
|
|
TrainingRunListResponse,
|
|
TrainingRunMetrics,
|
|
TrainingRunDetailResponse,
|
|
TrainingRunDeleteResponse,
|
|
TrainingRunUpdateRequest,
|
|
DiffusionTrainingStartRequest,
|
|
DiffusionTrainingStartResponse,
|
|
DiffusionTrainingStatusResponse,
|
|
)
|
|
from .models import (
|
|
CheckpointInfo,
|
|
ModelCheckpoints,
|
|
CheckpointListResponse,
|
|
ModelDetails,
|
|
LocalModelInfo,
|
|
LocalModelListResponse,
|
|
LoRAInfo,
|
|
LoRAScanResponse,
|
|
ModelListResponse,
|
|
)
|
|
from .auth import (
|
|
AuthLoginRequest,
|
|
RefreshTokenRequest,
|
|
AuthStatusResponse,
|
|
ChangePasswordRequest,
|
|
)
|
|
from .export import (
|
|
LoadCheckpointRequest,
|
|
ExportStatusResponse,
|
|
ExportOperationResponse,
|
|
ExportMergedModelRequest,
|
|
ExportBaseModelRequest,
|
|
ExportGGUFRequest,
|
|
ExportLoRAAdapterRequest,
|
|
)
|
|
from .users import Token
|
|
from .datasets import (
|
|
CheckFormatRequest,
|
|
CheckFormatResponse,
|
|
)
|
|
from .inference import (
|
|
LoadRequest,
|
|
UnloadRequest,
|
|
GenerateRequest,
|
|
LoadResponse,
|
|
UnloadResponse,
|
|
InferenceStatusResponse,
|
|
)
|
|
from .responses import (
|
|
TrainingStopResponse,
|
|
TrainingMetricsResponse,
|
|
LoRABaseModelResponse,
|
|
VisionCheckResponse,
|
|
EmbeddingCheckResponse,
|
|
)
|
|
from .data_recipe import (
|
|
RecipePayload,
|
|
PreviewResponse,
|
|
ValidateError,
|
|
ValidateResponse,
|
|
JobCreateResponse,
|
|
)
|
|
|
|
__all__ = [
|
|
# Training schemas
|
|
"TrainingStartRequest",
|
|
"DiffusionTrainingStartRequest",
|
|
"DiffusionTrainingStartResponse",
|
|
"DiffusionTrainingStatusResponse",
|
|
"TrainingJobResponse",
|
|
"TrainingStatus",
|
|
"TrainingProgress",
|
|
"TrainingRunSummary",
|
|
"TrainingRunListResponse",
|
|
"TrainingRunMetrics",
|
|
"TrainingRunDetailResponse",
|
|
"TrainingRunDeleteResponse",
|
|
"TrainingRunUpdateRequest",
|
|
# Model management schemas
|
|
"ModelDetails",
|
|
"LocalModelInfo",
|
|
"LocalModelListResponse",
|
|
"LoRAInfo",
|
|
"LoRAScanResponse",
|
|
"ModelListResponse",
|
|
# Auth schemas
|
|
"AuthLoginRequest",
|
|
"RefreshTokenRequest",
|
|
"AuthStatusResponse",
|
|
"ChangePasswordRequest",
|
|
# Export schemas
|
|
"CheckpointInfo",
|
|
"ModelCheckpoints",
|
|
"CheckpointListResponse",
|
|
"LoadCheckpointRequest",
|
|
"ExportStatusResponse",
|
|
"ExportOperationResponse",
|
|
"ExportMergedModelRequest",
|
|
"ExportBaseModelRequest",
|
|
"ExportGGUFRequest",
|
|
"ExportLoRAAdapterRequest",
|
|
"Token",
|
|
# Dataset schemas
|
|
"CheckFormatRequest",
|
|
"CheckFormatResponse",
|
|
# Inference schemas
|
|
"LoadRequest",
|
|
"UnloadRequest",
|
|
"GenerateRequest",
|
|
"LoadResponse",
|
|
"UnloadResponse",
|
|
"InferenceStatusResponse",
|
|
# Response schemas
|
|
"TrainingStopResponse",
|
|
"TrainingMetricsResponse",
|
|
"LoRABaseModelResponse",
|
|
"VisionCheckResponse",
|
|
"EmbeddingCheckResponse",
|
|
# Data recipe
|
|
"RecipePayload",
|
|
"PreviewResponse",
|
|
"ValidateError",
|
|
"ValidateResponse",
|
|
"JobCreateResponse",
|
|
]
|