# How to Adjust Temperature for DeepSeek-R1 on Specific Tasks: A Complete Guide

> Learn how to adjust temperature for DeepSeek-R1 on specific tasks. Discover the optimal default setting of 0.6 for balanced creativity and coherence, plus recommended ranges.

- Repository: [DeepSeek/DeepSeek-R1](https://github.com/deepseek-ai/DeepSeek-R1)
- Tags: how-to-guide
- Published: 2026-02-27

---

**Set the temperature between 0.5 and 0.7 for most tasks, with 0.6 being the optimal default that balances creativity and coherence while preventing endless repetitions.**

The `deepseek-ai/DeepSeek-R1` repository provides specific guidance on tuning the **temperature** hyper-parameter to optimize the model’s reasoning and generation quality. Temperature controls the randomness of token sampling, directly impacting whether outputs are deterministic and precise or creative and varied. This guide explains the official recommendations from the [`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) and shows how to implement task-specific settings across different deployment environments.

## Understanding Temperature in DeepSeek-R1

### What is Temperature?

**Temperature** is a scaling factor applied to the logits (raw model outputs) before the softmax function converts them to probabilities. A lower temperature (closer to 0) makes the distribution sharper, favoring high-probability tokens and producing more deterministic, focused outputs. A higher temperature increases randomness, enabling more diverse but potentially less coherent generation.

### Default and Recommended Settings

According to the [`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) in the `deepseek-ai/DeepSeek-R1` repository, the evaluation scripts and official implementations use specific baseline values:

- **Default sampling temperature**: The paper’s evaluation scripts use a temperature of **0.6** as the baseline for most benchmarks ([`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) line 102).
- **General recommendation**: For most use-cases, maintain the temperature between **0.5 and 0.7**, with **0.6** identified as the sweet spot that avoids endless repetitions while permitting diverse reasoning paths ([`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) line 190).
- **Web-app consistency**: The official DeepSeek web and mobile applications also run at **0.6**, confirming this value works reliably for interactive chat scenarios ([`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) line 199).

## Task-Specific Temperature Recommendations

Different tasks require different balances of creativity and precision. Based on the repository’s guidance and the model’s reinforcement learning (RL) training characteristics, use the following ranges:

| Task Type | Desired Behavior | Recommended Temperature |
|-----------|------------------|-------------------------|
| **Mathematical reasoning / Step-by-step proofs** | Consistent, deterministic reasoning without random drift | 0.5 – 0.6 |
| **Code generation** | Accurate syntax, reduced hallucination of APIs | 0.5 – 0.6 |
| **Fact-focused QA** | Precise answers, minimal hallucination | 0.5 – 0.6 |
| **Creative writing / Brainstorming** | Higher diversity, novel ideas and phrasing | 0.6 – 0.7 (up to 0.8 for maximum variance) |
| **Open-ended dialogue** | Balanced creativity vs. coherence | 0.6 – 0.7 |

Adjust the temperature **per request** rather than globally. The model respects the supplied value for each generation call, allowing you to switch between precise coding tasks (0.5) and creative brainstorming (0.7) within the same session.

## How to Set Temperature in Different Deployment Environments

### OpenAI-Compatible API

When using the OpenAI-compatible API endpoint, include the `temperature` field in your JSON payload. This is the standard method for the official DeepSeek API and most third-party hosting providers.

```python
import openai

client = openai.OpenAI(
    base_url="https://api.deepseek.com/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-R1",
    messages=[{"role": "user", "content": "Explain the Riemann hypothesis step by step."}],
    temperature=0.55,
    max_tokens=2048,
)

print(response.choices[0].message.content)

```

### vLLM Deployment

When serving DeepSeek-R1 with **vLLM**, you can set a default temperature via command-line arguments. Clients can override this value per request, but the CLI flag establishes the baseline for the server.

```bash
vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-32B \
  --tensor-parallel-size 2 \
  --max-model-len 32768 \
  --enforce-eager \
  --temperature 0.58

```

### SGLang Server

**SGLang** allows you to specify temperature when launching the server. You can also override it dynamically using the Python client for specific tasks requiring different randomness levels.

Launch server with baseline temperature:

```bash
python -m sglang.launch_server \
  --model deepseek-ai/DeepSeek-R1-Distill-Qwen-32B \
  --trust-remote-code \
  --tp 2 \
  --temperature 0.6

```

Override per request using the Python client:

```python
from sglang import SGLangClient

client = SGLangClient("http://localhost:30000")
result = client.generate(
    prompt="Summarize the plot of Macbeth.",
    temperature=0.65,
    max_new_tokens=200,
)
print(result.text)

```

## Summary

- **Default temperature**: Use **0.6** as your baseline, matching the official DeepSeek web app and evaluation scripts ([`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) lines 102, 190, 199).
- **Task-specific ranges**: Use **0.5–0.6** for math, coding, and factual QA to ensure deterministic outputs; use **0.6–0.7** (up to 0.8) for creative writing and brainstorming.
- **Implementation**: Set temperature via the OpenAI-compatible API JSON payload, vLLM CLI flags (`--temperature`), or SGLang server parameters and client overrides.
- **Flexibility**: Adjust temperature per request rather than globally to switch between precision tasks and creative generation within the same session.

## Frequently Asked Questions

### What is the default temperature for DeepSeek-R1?

The default temperature is **0.6**. According to the [`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md) in the `deepseek-ai/DeepSeek-R1` repository, this value is used in the paper’s evaluation scripts (line 102) and powers the official DeepSeek web and mobile applications (line 199). This setting balances creativity with coherence while preventing the endless repetition loops that can occur at lower temperatures.

### Why does lowering temperature improve math and coding accuracy?

Lowering the temperature to **0.5–0.6** sharpens the probability distribution over tokens, causing the model to consistently select the highest-likelihood next token. For mathematical reasoning and code generation, this reduces "random drift" where the model might otherwise select syntactically unusual or mathematically inconsistent tokens. As noted in the repository’s guidance, this range helps the model stick to correct patterns and precise reasoning chains.

### Can I change temperature mid-conversation?

Yes. Temperature is a **per-request parameter**, not a persistent session setting. When using the OpenAI-compatible API, vLLM, or SGLang, you specify the temperature in each individual API call or generation request. This allows you to alternate between low temperatures (0.5) for precise coding tasks and higher temperatures (0.7) for creative brainstorming within the same conversation thread.

### What happens if I set temperature above 0.8?

Setting temperature above **0.8** increases token sampling randomness significantly, which can lead to more diverse but less coherent outputs. While the repository suggests that **0.6–0.7** is the sweet spot for most tasks, exceeding 0.8 may cause the model to generate less relevant reasoning steps, hallucinate facts more frequently, or produce stylistically inconsistent text. For production use cases requiring reliability, it is recommended to stay within the 0.5–0.7 range documented in the [`README.md`](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/README.md).