DeepSeek-R1

repository·main·Indexed 13 days ago

https://github.com/deepseek-ai/deepseek-r1

A series of first-generation reasoning models designed for math, code, and complex reasoning tasks. The series includes the large-scale DeepSeek-R1 and DeepSeek-R1-Zero models (671B parameters), as well as distilled versions based on Qwen and Llama architectures ranging from 1.5B to 70B parameters. Supports commercial use under the MIT License and provides an OpenAI-compatible API.

Tokens
1.7K
Snippets
3
Records
8
Agent score
50%

What's inside DeepSeek-R1

  1. Official prompt templates for File Upload and Web Search

    main

    DeepSeek uses specific prompt templates for advanced features. Note that the official web/app uses a temperature of 0.6 and does not use system prompts.

    File Upload Template

    Use this template to provide file context to the model. Arguments: {file_name}, {file_content}, and {question}.

    Web Search Templates

    Use these templates to provide search results. Arguments: {search_results}, {cur_date}, and {question}. There are specific templates for Chinese and English queries to ensure proper citation formatting (e.g., [citation:X]) and response structure.

    # File Upload Template
    file_template = \
    """[file name]: {file_name}
    [file content begin]
    {file_content}
    [file content end]
    {question}"""
  2. Understanding DeepSeek-R1 Model Variants

    main

    DeepSeek-R1 consists of two main types of models: pure reinforcement learning models and distilled models.

    DeepSeek-R1-Zero vs. DeepSeek-R1

    • DeepSeek-R1-Zero: Trained via large-scale reinforcement learning (RL) without supervised fine-tuning (SFT). While it shows strong reasoning, it can suffer from endless repetition, poor readability, and language mixing.
    • DeepSeek-R1: Incorporates "cold-start" data (SFT) before the RL stage. This improves readability and reasoning performance, making it comparable to OpenAI-o1.

    Distilled Models

    DeepSeek-R1's reasoning patterns can be distilled into smaller, dense models. These models (ranging from 1.5B to 70B parameters) are fine-tuned using reasoning samples generated by the larger DeepSeek-R1 model. They often outperform larger models in specific benchmarks relative to their size.

  3. DeepSeek-R1 series licensing and commercial use

    main

    The DeepSeek-R1 series supports commercial use, including modifications and derivative works (such as distillation for training other LLMs).

    License Dependencies:

    • DeepSeek-R1-Distill-Qwen series: Derived from Qwen-2.5 (Apache 2.0 License).
    • DeepSeek-R1-Distill-Llama-8B: Derived from Llama3.1-8B-Base (Llama3.1 license).
    • DeepSeek-R1-Distill-Llama-70B: Derived from Llama3.3-70B-Instruct (Llama3.3 license).

    The repository and weights are licensed under the MIT License.

  4. Download DeepSeek-R1 and Distilled Models

    main

    DeepSeek-R1 provides several model variants available for download on Hugging Face.

    DeepSeek-R1 Models

    These are the large-scale reasoning models trained on the DeepSeek-V3-Base architecture.

    • DeepSeek-R1-Zero: 671B total params (37B activated), 128K context length.
    • DeepSeek-R1: 671B total params (37B activated), 128K context length.

    DeepSeek-R1-Distill Models

    These are smaller, dense models fine-tuned using reasoning data generated by DeepSeek-R1. They are based on the Qwen and Llama series. Note: These models have slightly modified configurations and tokenizers; you should use the specific settings provided by DeepSeek to run them correctly.

    ModelBase ModelHugging Face Link
    DeepSeek-R1-Distill-Qwen-1.5BQwen2.5-Math-1.5BLink
    DeepSeek-R1-Distill-Qwen-7BQwen2.5-Math-7BLink
    DeepSeek-R1-Distill-Llama-8BLlama-3.1-8BLink
    DeepSeek-R1-Distill-Qwen-14BQwen2.5-14BLink
    DeepSeek-R1-Distill-Qwen-32BQwen2.5-32BLink
    DeepSeek-R1-Distill-Llama-70BLlama-3.3-70B-InstructLink
  5. Run DeepSeek-R1-Distill models locally with vLLM or SGLang

    main

    DeepSeek-R1-Distill models can be run using standard inference engines like vLLM or SGLang, similar to Qwen or Llama models.

    Note: For the full DeepSeek-R1 models, refer to the DeepSeek-V3 repository. Hugging Face's Transformers is not yet directly supported for the main R1 models.

    # Using vLLM
    vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --tensor-parallel-size 2 --max-model-len 32768 --enforce-eager
    
    # Using SGLang
    python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --trust-remote-code --tp 2
  6. Recommended configurations for DeepSeek-R1 series models

    main

    To achieve expected performance and prevent issues like endless repetition or bypassed reasoning, follow these usage recommendations:

    1. Temperature: Set between 0.5 and 0.7 (recommended: 0.6).
    2. System Prompts: Avoid using system prompts. All instructions should be placed directly within the user prompt.
    3. Mathematical Reasoning: For math problems, include a directive such as: "Please reason step by step, and put your final answer within \boxed{}."
    4. Reasoning Enforcement: To ensure the model engages in thorough reasoning and doesn't bypass the thinking pattern, force the model to start its response with \<think>\n.
  7. Reference: Web Search prompt templates (English and Chinese)

    main

    The following templates are used for Web Search functionality to manage citations and response quality.

    # Chinese Web Search Template
    search_answer_zh_template = \
    '''# 以下内容是基于用户发送的消息的搜索结果:
    {search_results}
    ... (instructions for citation [citation:X], date {cur_date}, and response style) ...
    # 用户消息为:
    {question}'''
    
    # English Web Search Template
    search_answer_en_template = \
    '''# The following contents are the search results related to the user's message:
    {search_results}
    ... (instructions for citation [citation:X], date {cur_date}, and response style) ...
    # The user's message is:
    {question}'''