Overview
DeploymentSampler handles client-side tokenization via a HuggingFace tokenizer and returns structured SampledCompletion objects with token IDs, logprobs, and completion metadata. Use it in training scripts that need token-level outputs (e.g. GRPO, DPO).
Constructor
Concurrency Control
sample_with_tokens(n=K) fans out into K individual streaming requests. Without concurrency control, all requests fire simultaneously, which can overload the server. Two controllers are available:
AdaptiveConcurrencyController (recommended)
Auto-tunes the concurrency window using AIMD (Additive Increase / Multiplicative Decrease) based on the server’sprefill_queue_duration:
prefill_queue_duration from server response metrics. When the queue is below target, the window grows proportionally. When above, it halves (multiplicative decrease). By default, it adjusts after every 32 completed requests and at step boundaries. Set adjustment_interval=0 to adjust only at step boundaries.
FixedConcurrencyController
Static semaphore — use when you know the right concurrency for your deployment:sample_with_tokens(...)
Sample completions and return structured results with token IDs. This method is async, so call it with await or wrap it with asyncio.run(...) from synchronous code:
Retrieving inference logprobs
For GRPO importance sampling, passlogprobs=True:
Sequence length filtering
sample_with_tokens supports max_seq_len for automatic filtering:
- Prompt pre-filter: If the tokenized prompt already meets or exceeds
max_seq_len, the method returns an empty list immediately — no inference call is made. - Completion post-filter: After sampling, any completion whose full token sequence (prompt + completion) exceeds
max_seq_lenis silently dropped.
SampledCompletion
Each completion returned bysample_with_tokens:
Related guides
- FiretitanServiceClient — create SDK-managed deployment samplers
- Training and Sampling — end-to-end workflow
- Cookbook RL recipe — GRPO with sampling pipeline