Training and serving
This architecture takes a model from raw data to a live endpoint. A pipeline of tasks prepares data, trains, and evaluates. An app then loads the trained weights from object storage and serves them.
flowchart LR
subgraph pipeline ["Training pipeline (tasks)"]
D["driver<br/>CPU"] --> P["prepare data<br/>CPU, cached"]
P --> T["train<br/>GPU or multi-node"]
T --> E["evaluate<br/>small GPU or CPU"]
end
E --> W[("model weights<br/>object storage")]
W --> A["serving app<br/>GPU"]
C["clients"] --> A
Components
| Box | Construct | Details |
|---|---|---|
| driver | A CPU flyte.TaskEnvironment with the other environments in depends_on |
Model training |
| prepare data | A flyte.TaskEnvironment with cache="auto" |
Caching |
| train, one node | A flyte.TaskEnvironment with GPUs in flyte.Resources |
Resources |
| train, several nodes | flyte.clustered.ClusteredTaskEnvironment |
Clustered task environment |
| evaluate | A task that compares the new model with a baseline | Evaluation |
| model weights | A flyte.io.Dir or flyte.io.File returned by the training task |
Files and directories |
| serving app | VLLMAppEnvironment, SGLangAppEnvironment, or FastAPIAppEnvironment |
Deploy trained models |
How the pieces connect
- The driver calls the data, training, and evaluation tasks in order. It can branch on the evaluation result, for example to stop before publishing a model that scores below the baseline.
- The training task saves the weights and returns them as a
flyte.io.Dir. The weights stay in object storage, and only a reference passes between tasks. - The serving app names the training task’s output as a parameter. When you deploy the app, it resolves that reference and mounts the weights.
In Flyte, pass the training task’s output to the app with
flyte.app.RunOutput, naming the task with task_name or a specific run with run_name.Variations
- Long or preemptible training: save progress with
flyte.Checkpointso a retried attempt resumes from its last checkpoint. The platform retries a preempted task without using itsretries; setretriesto also recover from errors in your own code. See Durable training. - Hyperparameter search: have the driver fan out one training task per trial. See Hyperparameter optimization.
- Fine-tuning a pretrained LLM: replace the training stage with SFT, LoRA, or preference tuning. See Post-training.
Gotchas
- The app serves the model it resolved at deploy time. A model trained after you deploy doesn’t reach the endpoint until you deploy the app again.
- Run the training task before you deploy the app. With
flyte.app.RunOutput(task_name=...), the app uses the latest successful run of that task, and the deploy fails if there is none. - vLLM and SGLang load only formats they support. Save the weights in a format the engine can load. See Deploy trained models.