Skip to main content
A sampler generates completions from a base model or a published checkpoint. Each run can have a paired sampler that serves the weights the run publishes, for RL rollouts or evaluation during training. To sample without a trainer, such as after a run ends, create a standalone sampler.

Sample published weights

Request a sampling client from a training client with save_weights_and_get_sampling_client(). It publishes the current weights and returns a client for them. To sample from weights you saved with save_weights_for_sampler(), pass the returned path to TrainingClient.create_sampling_client(). Then call sample() with a tokenized prompt. To generate one completion from the saved weights and print it, run:
The script prints the generated reply. For a complete script and its output, see Sample from the checkpoint. By default, the run creates its paired sampler at the first sampling request. To have the sampler ready for that request, set with_sampler=True in create_lora_training_client(), and the run creates its paired sampler with the trainer. Leave it off for runs that only train, so the run doesn’t provision a sampler.

Weight sync

Publishing sampler weights makes a checkpoint available to the run’s paired sampler. What a sampling client serves afterward depends on the availability mode:
  • Serverless: Loops pins the client to the published checkpoint. Publish again and use the returned client to sample from later weights. Each publish needs a name the run hasn’t used; see Save a checkpoint.
  • Dedicated: The client serves the published weights or later ones. The paired sampler loads newly published weights without restarting, so the client doesn’t stay on an exact snapshot.
In the dedicated mode, TrainingClient.policy_version reports the trainer’s optimizer-step count, which is the policy version that a client tracks. The serverless mode doesn’t support it. A paired sampler accepts checkpoints with the run’s LoRA configuration. To sample from a checkpoint with a different LoRA configuration, create a standalone sampler.

Next steps