Quickstart
About
This page trains a small model on one GPU in a few seconds. The job has the same parts as every d9d job: a model, a model provider, a task, a data provider and a configuration. The code is in example/guide/quickstart.
Run the Example
Install d9d (see Installation) and PyYAML, which reads the config. Then get the example from the repository and run it:
A job without parallelism runs as a single process, so it does not need torchrun. The job writes the loss and the gradient norm of every step to its log:
The job writes its results to runs/:
runs/checkpoints/quickstart/: The two latest checkpoints,save-200andsave-256.runs/export/: The trained weights as.safetensorsfiles.
If you start the job again, it loads save-256 and logs Training is already complete, nothing to do. See Running Jobs for checkpoints and resuming.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
The script has these parts:
ProjectConfig: One Pydantic model for the whole YAML file. Pydantic validates the file before the job starts. See Configuration.RegressionSample,RegressionBatch,RegressionInputandRegressionState: Dataclasses for one sample of the dataset, the microbatch thatcollate()builds, what the model receives and whatcompute_loss()needs besides the model output.RegressionDataset: A standard PyTorchDataset.AutoDataProvidershards it across data-parallel ranks, batches it with thecollatorand groups the microbatches into steps. See Data Loading.MLP: A standardnn.Module. It implementsreset_parameters(), because d9d builds the model on themetadevice and initializes it on the GPU. Itsforward()takesinputsandshared, like every pipeline stage. See Model Design.MLPProvider: Builds the model, distributes it and returns the state mappers for loading and export.parallelize_hsdp()shards the model alongdp_cp_shardand replicates it along the other dimensions of the mesh slice. A job on one GPU does not callparallelize_model_stage(). See Horizontal Parallelism and Model Definition.RegressionTask: Splits each microbatch into the model input and the state, and computes the loss. The five type parameters ofTrainTaskserve only type checking. See User Tasks.main():TrainingConfiguratorwires the parts together.configure()builds the job,train()runs it andexport()saves the weights.load_checkpoint=Falseexports the weights that are in memory after training, without loading the latest checkpoint first. See Training Loop.
The Configuration
The job makes one pass over the 65,536 samples: 256 steps of 256 samples.
trainer holds only the required fields. The other fields keep their defaults. For a first job of your own, you change these:
run.name: The name of the run and of its checkpoint directory.schedule.total_steps: The number of steps. Without it, the job makes one pass over the data.checkpointing: Where and how often the job saves checkpoints.logging.tracker: Where the logged values go.logwrites them to the log, andnulldrops them. Other providers send them to W&B, TensorBoard, MLflow or Aim and need an extra. See Experiment Tracking.
Configuration describes every field and its default.
Next Steps
- Your own job: Write Your Own Job shows what to replace in this script, and How d9d Works explains how the parts of a job fit together.
- More GPUs: Running Jobs shows how to launch the same script on several GPUs, and Choosing Parallelism points to the strategies.
- A real model: Fine-Tune a Hugging Face Model loads Qwen3 from a Hugging Face checkpoint, trains it and exports it back.