← all modules

Std.Ai.Train

Std.Ai.Train

Types
  type alias SnapshotFile = { path : String , sha256 : String }
  type alias Snapshot = { repo : String , revision : String , files : List SnapshotFile }
  type alias BaseModelPayload = { id : String , mlx : Maybe Snapshot , unsloth : Maybe Snapshot , serving : Local.ModelRef }
  type BaseModel
  type alias ParsedBase = { id : String , snapshot : Snapshot }
  type Backend = Mlx | Unsloth | Vertex | Fake
  type alias Batch = { perDevice : Int , accumulate : Int }
  type alias Settings = { name : String , baseId : String , serving : String , format : String , dataset : String , datasetDigest : String , dataFile : String , trainRows : Int , evalRows : Int , quantBits : Int , memoryCap : Int , rank : Int , alpha : Int , layers : Int , targets : List String , learningRate : Float , epochs : Int , maxSteps : Int , batch : Batch , sequenceLength : Int , seed : Int , checkpointEvery : Int , evalEvery : Int , backend : Maybe Backend , ggufExport : Bool , mergedExport : Bool , workDir : String , maxRelaunches : Int , watchWindowMs : Int , fakeCrashAt : Int , fakeStepMs : Int , cloud : Cloud , budget : Maybe Money , prices : Maybe MachinePriceBook , image : String , serviceAccount : String , maxRuntimeMinutes : Int , spot : Bool , keepStaging : Bool , labels : List ( String, String ) }
  type alias JobPayload = { s : Settings , base : BaseModel , registry : Maybe Registry.Registry }
  type Job
  type alias Cloud = { project : String , region : String , machine : String , staging : String }
  type alias MachineRate = { machine : String , region : String , perHour : String }
  type MachinePriceBook
  type alias PriceBook = { currency : Money.Currency , version : String , rates : List PricedRate , problems : List String }
  type alias PricedRate = { machine : String , region : String , perHour : Money }
  type alias Host = { os : String , arch : String , totalBytes : Int , availableBytes : Int , accelerator : String }
  type alias ModelShape = { architecture : String , layers : Int , hidden : Int , intermediate : Int , qDim : Int , kvDim : Int , heads : Int , vocab : Int , parameters : Int }
  type alias Setting = { key : String , name : String , value : String , source : String }
  type alias TrainCode = { sequenceLength : String , batch : String , rank : String , quantBits : String , memoryCap : String }
  type alias Plan = { runId : String , backend : String , backendSource : String , host : Host , shape : ModelShape , steps : Int , trainRows : Int , evalRows : Int , estimateBytes : Int , availableBytes : Int , capBytes : Int , settings : List Setting , cloud : Maybe CloudPlan }
  type alias RawSetting = { key : String , name : String , value : String , source : String }
  type Status = Queued | Provisioning | Running | Relaunching | Converting | Registering | Done | Failed | Cancelled
  type alias LossPoint = { step : Int , value : Float }
  type alias Progress = { runId : String , status : Status , backend : String , step : Int , totalSteps : Int , loss : Maybe Float , valLoss : Maybe Float , tokensPerSecond : Float , attempt : Int , relaunches : Int , resumedFrom : Int , lastCheckpoint : Int , peakBytes : Int , losses : List LossPoint , valLosses : List LossPoint , message : String }
  type alias HelloPayload = { backend : String , attempt : Int , resumeFrom : Int , totalSteps : Int }
  type alias StepProgressPayload = { step : Int , total : Int , loss : Float , tokensPerSecond : Float , footprintBytes : Int , peakBytes : Int }
  type alias MetricPayload = { step : Int , name : String , value : Float }
  type alias CheckpointPayload = { step : Int , path : String }
  type alias ArtefactPayload = { kind : String , path : String , sha256 : String }
  type alias DoneEventPayload = { step : Int , trainLoss : Float , valLoss : Float }
  type alias CancelledEventPayload = { step : Int }
  type alias DriverErrorPayload = { code : String , message : String , peakBytes : Int , capBytes : Int }
  type Event = Hello HelloPayload | StepProgress StepProgressPayload | Metric MetricPayload | Checkpoint CheckpointPayload | Artefact ArtefactPayload | DoneEvent DoneEventPayload | CancelledEvent CancelledEventPayload | DriverError DriverErrorPayload
  type alias Artefact = { path : String , sha256 : String }
  type alias Adapter = { name : String , runId : String , baseId : String , serving : String , dataset : String , datasetDigest : String , backend : String , toolchain : String , method : String , seed : Int , steps : Int , peft : Artefact , gguf : Maybe Artefact , merged : Maybe Artefact , trainLoss : Float , valLoss : Float , relaunches : Int , resumedFrom : Int , registered : Maybe String , job : String }
  type alias RawStaged = { train : Int , eval : Int }
  type alias RawTokenized = { train : Int , eval : Int , steps : Int }
  type alias RawVersion = { name : String , version : String }
  type alias ToolchainVersion = RawVersion
  type alias Toolchain = { name : String , id : String , python : String , driverDir : String , dir : String , versions : List ToolchainVersion , packages : Int , installed : Bool , trainer : String }
  type alias RawLaunched = { pid : Int , attempt : Int , resumeFrom : Int , startedAtMs : Int , attached : Bool }
  type alias RawWatched = { offset : Int , lines : List String , alive : Bool , cancelRequested : Bool , stderrTail : String }
  type alias RawCheckpoint = { step : Int , path : String }
  type alias RawRunState = { exists : Bool , launched : Bool , converted : Bool , size : Int , attemptOffset : Int , lines : List String , alive : Bool , attempt : Int , pid : Int , cancelRequested : Bool , result : String , stderrTail : String , generation : Int }
  type alias RawConverted = { path : String , sha256 : String , tensors : Int , architecture : String }
  type alias RawRun = { runId : String , dir : String , modifiedMs : Int }
  type alias RawDigest = { sha256 : String , size : Int }
  type alias RunRequest = { runId : String , job : String }
  type alias Tool = { name : String , id : String , python : String , driverDir : String , trainer : String }
  type alias Origin = { attempt : Int , alive : Bool , finished : Bool , offset : Int }
  type alias Seen = { offset : Int , outcome : String , step : Int , code : String , message : String , trainLoss : Float , valLoss : Float , peft : String , relaunches : Int , resumedFrom : Int , peakBytes : Int , capBytes : Int }
  type alias Setup = { backend : String , shape : ModelShape , tool : Tool , weights : String , capBytes : Int }
  type alias CloudSettings = { project : String , region : String , machine : String , staging : String , image : String , serviceAccount : String , budget : Money , perHour : Money , priceBook : String , accelerator : String , acceleratorCount : Int , labels : List ( String, String ) , sources : List RawSetting }
  type alias CloudPlan = { project : String , region : String , machine : String , accelerator : String , acceleratorCount : Int , image : String , staging : String , steps : Int , estimateMinutes : Int , timeoutSeconds : Int , perHour : Money , estimate : Money , budget : Money , priceBook : String , bucketLocation : String , quotaLimit : Maybe Int , quotaNote : String }
  type alias RawCloudCode = { project : String , region : String , machine : String , staging : String , budget : String , image : String , serviceAccount : String , labels : String }
  type alias CloudRun = { settings : CloudSettings , key : String }
  type alias RawCloud = { project : String , region : String , machine : String , staging : String , image : String , serviceAccount : String , budget : String , perHour : String , priceBook : String , accelerator : String , acceleratorCount : Int , labels : List ( String, String ) }
  type alias CloudWatch = { segment : String , state : String , outcome : String , step : Int , code : String , message : String , trainLoss : Float , valLoss : Float , peft : String , resumedFrom : Int , spentMinor : Decimal.Decimal , errorCode : Int , errorMessage : String , relaunches : Int , ranSeconds : Int }
  type alias CloudOrigin = { attempt : Int , job : String , live : Bool , finished : Bool , spentMinor : Decimal.Decimal }
  type alias CloudFile = { job : String , state : String , attempt : Int , staging : String , runKey : String , spentMinor : Decimal.Decimal , runningSinceMs : Int }
  type alias CloudStatus = { job : String , state : String , attempt : Int , region : String , machine : String , spent : Money , budget : Money }

Values
  adapterCodec : Codec Adapter
      The JSON form of an adapter record (the run's `result.json`, the durable
  adapterRef : Adapter -> Maybe Local.ModelRef
      The GGUF adapter as a pinned file, for `Local.withAdapter`. A job without
  backendName : Backend -> String
      The backend's name, as `SKY_AI_TRAIN_BACKEND` writes it.
  baseFromReference : String -> Local.ModelRef -> Task Error BaseModel
      A base model from a reference, served by `serving`:
  baseId : BaseModel -> String
      The base's id.
  baseModel : String -> Local.ModelRef -> BaseModel
      A base model from its id and the GGUF model that serves it. Add the
  baseServing : BaseModel -> Local.ModelRef
      The GGUF model that serves the base's adapters.
  baseWeights : Backend -> BaseModel -> Maybe Snapshot
      The weights a backend trains on, if the base has them.
  cancel : Job -> Task Error Bool
      Cancel the job's run: the trainer writes a checkpoint and stops (killed
  cancelAt : String -> Task Error Bool
      Cancel the run in a run directory. A Vertex run is cancelled in the
  check : Job -> Result Error ()
      Check a job before it runs, without I/O. An empty train or eval split is
  cloudEstimate : Job -> CloudSettings -> Int -> ( Int, Money, Int )
      The estimate for a `Vertex` job, pure: `( minutes, estimate,
  cloudJobSpec : CloudSettings -> CloudPlan -> String -> Int -> Int -> Google.JobSpec
      The custom job for one attempt: the container runs the shim
  cloudSettings : Job -> Task Error CloudSettings
      Resolve and check a `Vertex` job's settings without touching the cloud:
  cloudStatus : Job -> Task Error (Maybe CloudStatus)
      The job's Vertex run, from its run directory (`Nothing` for a local run
  decodeEvent : String -> Result Error (Maybe Event)
      Decode one protocol line. A line of a type this release does not know is
  devBase : BaseModel
      The development base: Qwen2.5 0.5B Instruct (Apache-2.0). Mlx trains on
  drive : Db -> Job -> Task Error Adapter
      Train in the foreground: start the run, advance it until it ends, and
  effective : Job -> Task Error Job
      The job as it runs on this machine: the sequence length, the batch, the
  emptyProgress : String -> Progress
      The progress of a run that has written nothing yet.
  estimateMemory : ModelShape -> Job -> Int
      The memory the native trainer (`Mlx`) needs for a job, in bytes: a
  exportAt : String -> Bool -> Task Error Artefact
      Convert the finished adapter in a run directory to GGUF (and, with
  fakeCrashAt : Int -> Job -> Job
      `Fake` only: the first attempt dies after this step, as a killed trainer
  fakeStepMs : Int -> Job -> Job
      `Fake` only: the time one step takes. Default: 20.
  foldProgress : Event -> Progress -> Progress
      Fold one protocol line into a run's progress.
  host : () -> Task Error Host
      This machine.
  inputsJson : Job -> CloudSettings -> ModelShape -> String -> Store.Blob -> Store.Blob -> Result Error String
      The run's `inputs.json`: the staging location, the driver's settings for
  jobJson : Job -> String
      The job as canonical JSON: the settings that decide the adapter (not the
  lineage : Adapter -> Registry.Lineage
      The lineage a trained adapter is registered with: the serving model is the
  lora : BaseModel -> Dataset.Version Dataset.Chat -> Job
      A LoRA job on a chat dataset (the `{"messages": [...]}` format). The loss
  loraOnInstructions : BaseModel -> Dataset.Version Dataset.Instruction -> Job
      A LoRA job on an instruction dataset (`{"prompt", "completion"}`). The
  machinePrices : Money.Currency -> String -> List MachineRate -> MachinePriceBook
      A price book from its rates. A rate that does not parse as an amount of
  pinWeights : BaseModel -> Task Error BaseModel
      Pin the weight files of every snapshot the base names by commit or by
  plan : Job -> Task Error Plan
      Plan a job before it runs: resolve its settings (`effective`), check it,
  planCloud : Job -> Task Error CloudPlan
      Plan a `Vertex` job: its settings, the estimate against the budget
  poll : Db -> List Job -> Task Error Bool
      Advance the runs of these jobs that are due (one worker tick). `True`
  priceBookVersion : MachinePriceBook -> String
      The price book's version.
  progress : Job -> Task Error Progress
      The job's run's progress, from its run directory (no database needed).
  progressAt : String -> Task Error Progress
      The progress of the run in a run directory.
  provision : Backend -> Task Error Toolchain
      Install the trainer a backend trains with (`sky ai provision --train
  provisionBase : Backend -> BaseModel -> Task Error String
      Download and verify the weights a backend trains the base on, returning
  provisionSnapshot : Snapshot -> Task Error String
      Download and verify a pinned snapshot below the AI home and return its
  registryAdapter : Adapter -> Registry.Adapter
      The registry's view of a trained adapter: the GGUF file when there is
  result : Job -> Task Error (Maybe Adapter)
      The job's finished adapter: `Nothing` while the run has not finished, the
  resume : Job -> Task Error Int
      Start the run again after it failed or was cancelled: the next `start` or
  resumeAt : String -> Task Error Int
      `resume` for the run in a run directory.
  runDir : Job -> String
      The run's directory: `<workDir>/<runId>`.
  runId : Job -> String
      The run's id: the job's name and the first twelve hex digits of its
  runKey : String -> String
      The key of a run's objects in the staging bucket and of its Vertex
  runs : String -> Task Error (List Progress)
      Every run in a work directory, newest first, with its progress.
  settings : Job -> Settings
      What a job holds.
  shapeOf : BaseModel -> Task Error ModelShape
      The shape of the base's serving model (fetched if allowed).
  start : Db -> Job -> Task Error String
      Start the job's run (idempotent: a run that exists is left alone) and
  statusText : Status -> String
      A status as lower-case text.
  toolchainStatus : () -> Task Error (List Toolchain)
      Every toolchain this host can run, installed or not.
  totalSteps : Job -> Int
      The optimiser steps the job runs: `maxSteps` when set, else whole epochs
  withAlpha : Int -> Job -> Job
      The LoRA alpha (the update is scaled by alpha / rank). Default: twice
  withBackend : Backend -> Job -> Job
      Train on this backend unless `SKY_AI_TRAIN_BACKEND` says otherwise.
  withBatch : Batch -> Job -> Job
      Rows per step. Default: `{ perDevice = 4, accumulate = 1 }`.
  withBudget : Money -> Job -> Job
      The most a `Vertex` job may cost. A cloud job without a budget never
  withCheckpointEvery : Int -> Job -> Job
      Write a checkpoint every n steps (0: none). A relaunched trainer repeats
  withCloud : Cloud -> Job -> Job
      Set where a `Vertex` job runs. An empty field is left to its variable.
  withEpochs : Int -> Job -> Job
      Passes over the train split. Default: 1. `withMaxSteps` wins.
  withEvalEvery : Int -> Job -> Job
      Measure the eval split's loss every n steps (0: at the end only).
  withGgufExport : Job -> Job
      Also convert the adapter to GGUF, the format the managed llama-server
  withImage : String -> Job -> Job
      The trainer image a `Vertex` job runs, pinned by digest
  withKeepStaging : Job -> Job
      Keep the run's staging prefix (data, checkpoints, adapter) and its
  withLabels : List ( String, String ) -> Job -> Job
      Labels for the job's Vertex resources, beside Sky's own (`sky-managed`,
  withLayers : Int -> Job -> Job
      How many of the last decoder layers get adapters; `-1` for all. Default:
  withLearningRate : Float -> Job -> Job
      The learning rate (Adam). Default: 1e-4.
  withMachinePrices : MachinePriceBook -> Job -> Job
      The prices a `Vertex` job's estimate and spend use.
  withMaxRelaunches : Int -> Job -> Job
      How often a trainer that died is relaunched from its newest checkpoint
  withMaxRuntimeMinutes : Int -> Job -> Job
      A runtime ceiling in minutes for each Vertex job (each attempt), below
  withMaxSteps : Int -> Job -> Job
      Stop after this many optimiser steps.
  withMemoryCap : Int -> Job -> Job
      The most memory the trainer may use, in bytes. The plan refuses a job
  withMergedExport : Job -> Job
      Also fold the adapter into the serving model and write a merged GGUF
  withName : String -> Job -> Job
      The adapter's name: the run directory's prefix, and the registry model
  withQuantBits : Int -> Job -> Job
      The bits the base weights are held in while training: 4 or 8 quantise a
  withQuantisedBase : Job -> Job
      Mark the job QLoRA: the base weights are 4-bit (the snapshot already is,
  withRank : Int -> Job -> Job
      The LoRA rank. Default: 8. `SKY_AI_TRAIN_RANK` overrides it.
  withRegistry : Registry.Registry -> Job -> Job
      Register the finished adapter in this registry under the job's name, with
  withSeed : Int -> Job -> Job
      The seed of the adapter's initial values and of the data order. A resumed
  withSequenceLength : Int -> Job -> Job
      Tokens per row; a longer row is cut. Default: 1024.
  withServiceAccount : String -> Job -> Job
      The service account the job runs as (it needs only the staging bucket).
  withServing : Local.ModelRef -> BaseModel -> BaseModel
      The GGUF model that serves the adapter.
  withSpot : Job -> Job
      Run on Spot capacity: cheaper, and pre-emptible. A pre-empted attempt is
  withTargets : List String -> Job -> Job
      Which projections get adapters, as Hugging Face module paths
  withWatchWindow : Int -> Job -> Job
      The longest one watch of the trainer lasts, in milliseconds (at most five
  withWeights : Backend -> Snapshot -> BaseModel -> BaseModel
      The weights a backend trains on. A 4-bit snapshot (an `mlx-community`
  withWorkDir : String -> Job -> Job
      The directory that holds the run directories. Default: `.sky/ai/runs`.
  workflow : String -> Job -> Durable.WorkflowDef RunRequest Adapter
      The training workflow, registered under `name`. Each line is a
  workflows : List Job -> List Durable.RegisteredWorkflow
      The workflows of several jobs, for a worker's `Durable.poll` list.