> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Set sampling parameters

> Control how a Loops sampler generates: temperature, top-p and top-k cut-offs, length, seed, stop sequences, and structured outputs.

Sampling parameters apply to paired and standalone samplers alike. Pass [`SamplingParams`](https://docs.baseten.co/reference/sdk/loops/types) to [`sample()`](https://docs.baseten.co/reference/sdk/loops/sampling-client), with `num_samples` for the number of completions per prompt.

This example continues the sampling client and tokenizer from [Sample published weights](https://docs.baseten.co/loops/sample-from-a-run.md#sample-published-weights). It raises the temperature, samples from the 50 most likely tokens at each step, and prints the reply:

```python theme={"system"}
from baseten.loops import ModelInput, SamplingParams

tokens = tokenizer.encode("Explain LoRA in one sentence.", add_special_tokens=False)
response = sampling_client.sample(
    prompt=ModelInput.from_ints(tokens),
    num_samples=1,
    sampling_params=SamplingParams(temperature=1.2, top_k=50, max_tokens=128),
)
print(tokenizer.decode(response.sequences[0].tokens))
```

The script prints the generated reply. `response.sequences` holds one entry per requested sample, up to the `max_tokens` limit or the first stop sequence.

## Parameters

**temperature** `number` (default: 1)

Scales the token distribution before sampling. Lower values make output more deterministic, and higher values make it more varied.

**top\_p** `number` (default: 1)

Keep the most likely tokens until their combined probability reaches `top_p`. `1.0` turns off this cut-off. Don't use it when the samples feed an RL loss; see [Min-p sampling](https://docs.baseten.co/loops/min-p-sampling.md#match-the-cut-off-in-rl-losses).

**top\_k** `integer` (default: -1)

Sample from the `top_k` most likely tokens. Zero or a negative value turns off this cut-off.

**max\_tokens** `integer`

Maximum tokens to generate. Defaults to `None`.

**seed** `integer`

Random seed for reproducible samples. Defaults to `None`.

**stop** `string | string[] | integer[]`

Stop sequences, as strings or token IDs. Defaults to `None`.

**structured\_outputs** `object`

Constrain generation to a structure, such as a JSON schema or regular expression. Defaults to `None`, which leaves generation unconstrained. See [`SamplingParams`](https://docs.baseten.co/reference/sdk/loops/types) for the accepted format.

## Next steps

* [Min-p sampling](https://docs.baseten.co/loops/min-p-sampling.md): Sample at higher temperatures and match the cut-off in RL losses.
* [Sample from a run](https://docs.baseten.co/loops/sample-from-a-run.md): Call `sample()` on a run's paired sampler.
