contracts.py
python
sha256:1d3182b1c5c2833c8ab0d437e03eeadfd3ad6679a2877a6baab8d17442d38936
Bootstrap Scooling Lab repository
Human
patch
42 days ago
| 1 | """Typed contracts for Scooling Lab training job boundaries.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from dataclasses import dataclass |
| 6 | from enum import Enum |
| 7 | from typing import Literal |
| 8 | |
| 9 | |
| 10 | class TrainingJobStatus(str, Enum): |
| 11 | """Lifecycle states exposed by the training boundary.""" |
| 12 | |
| 13 | QUEUED = "queued" |
| 14 | RUNNING = "running" |
| 15 | SUCCEEDED = "succeeded" |
| 16 | FAILED = "failed" |
| 17 | CANCELLED = "cancelled" |
| 18 | |
| 19 | |
| 20 | AdapterKind = Literal["lora", "qlora"] |
| 21 | ModelLocationPolicy = Literal["local", "cloud_policy"] |
| 22 | |
| 23 | |
| 24 | @dataclass(frozen=True, slots=True) |
| 25 | class TrainingDatasetRef: |
| 26 | """Reviewed dataset reference approved by the main Scooling app.""" |
| 27 | |
| 28 | dataset_id: str |
| 29 | workspace_id: str |
| 30 | source_commit: str |
| 31 | approved_by: str |
| 32 | |
| 33 | |
| 34 | @dataclass(frozen=True, slots=True) |
| 35 | class TrainingJobRequest: |
| 36 | """Server-side request accepted by Scooling Lab after approval gates pass.""" |
| 37 | |
| 38 | job_id: str |
| 39 | dataset: TrainingDatasetRef |
| 40 | base_model: str |
| 41 | adapter_kind: AdapterKind |
| 42 | location_policy: ModelLocationPolicy |
| 43 | |
| 44 | |
| 45 | def validate_training_job_request(request: TrainingJobRequest) -> tuple[str, ...]: |
| 46 | """Return deterministic validation errors for a training request.""" |
| 47 | |
| 48 | errors: list[str] = [] |
| 49 | |
| 50 | if request.job_id.strip() == "": |
| 51 | errors.append("job_id is required") |
| 52 | if request.dataset.dataset_id.strip() == "": |
| 53 | errors.append("dataset.dataset_id is required") |
| 54 | if request.dataset.workspace_id.strip() == "": |
| 55 | errors.append("dataset.workspace_id is required") |
| 56 | if request.dataset.source_commit.strip() == "": |
| 57 | errors.append("dataset.source_commit is required") |
| 58 | if request.dataset.approved_by.strip() == "": |
| 59 | errors.append("dataset.approved_by is required") |
| 60 | if request.base_model.strip() == "": |
| 61 | errors.append("base_model is required") |
| 62 | |
| 63 | return tuple(errors) |
File History
1 commit
sha256:1d3182b1c5c2833c8ab0d437e03eeadfd3ad6679a2877a6baab8d17442d38936
Bootstrap Scooling Lab repository
Human
patch
42 days ago