# gstearmit/deepseek-r1 architecture

> Architecture diagram of the GitHub repository gstearmit/deepseek-r1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gstearmit/deepseek-r1
- Repository: https://github.com/gstearmit/deepseek-r1

## Overview

##### Project’s Nature and Purpose
- The repository is primarily for releasing research, documentation, and downloadable model weights for DeepSeek-R1 and its distilled variants.
- The core purpose is to document the methodology—highlighting two reinforcement learning (RL) stages, two supervised fine-tuning (SFT) stages, and a subsequent distillation pipeline—to achieve robust reasoning performance in large language models.
- Additionally, the repository provides information on a chat website and an API platform that serve as inference endpoints for the models.

##### Break Down the Main Architectural Components
a. Model Training Pipeline Components:
- Base Model: Represent the base model (DeepSeek-V3-Base) from which DeepSeek-R1 is derived.
- Reinforcement Learning Stages: Illustrate the two RL stages:
- The first stage that produces DeepSeek-R1-Zero by exploring chain-of-thought (CoT) reasoning.
- The second RL stage that further refines reasoning during training.
- Supervised Fine-Tuning (SFT) Components: Indicate the two SFT stages that are incorporated – one to provide a seed for non-reasoning behavior and another to stabilize the reasoning output.
- Distillation Pipeline: Show the process by which large models (671B total parameters, 37B activated) are used to generate reasoning data for fine-tuning smaller distilled models (ranging from 1.5B up to 70B).

b. Evaluation and Benchmarking:
- How the evaluation results feed back into refining the model training process.

c. Deployment and Serving Infrastructure:
- Chat Website: Represent the frontend or user interface (chat.deepseek.com) where users interact with DeepSeek-R1.
- API Platform: Include an API endpoint (platform.deepseek.com) that supports OpenAI-compatible requests.
- Model Serving Frameworks: Illustrate tools like vLLM or SGLang as part of the deployment that allows for dynamic model serving (indicate configuration options like tensor parallel size, max model length, etc.).

d. External Resources and Documentation:
- Presence of a research paper (DeepSeek_R1.pdf) and figures (in the figures directory) as well as community links (Hugging Face, Discord, Twitter) which play into the ecosystem around the model.

##### Component Relationships
- On the deployment side, illustrate how trained/distilled models are loaded into model serving frameworks, and then integrated with the Chat Website and API Platform for end-user interaction.
- Optionally, indicate feedback loops from benchmarking/evaluation back to the training components to show iterative improvement.

##### Architectural Patterns and Technologies
- Following:
- Reinforcement Learning as a primary training paradigm to incentivize chain-of-thought reasoning.
- Supervised Fine-Tuning to refine and correct the model’s behavior.
- Model Distillation, which is central for producing efficient dense models.
- The use of MoE (Mixture of Experts) as referenced in the readme (for both DeepSeek-V3 and DeepSeek-R1 architectures).
- Deployment specifics such as vLLM and SGLang for inference, along with guidance for setting configurations (temperature, context length, etc.).

##### Final Assembly
- Start from the left (perhaps the data/training phase) to the right (deployment and serving).

- Training Pipeline: Base Model → RL Stages → SFT Refinements → Distillation Process.
- Evaluation & Benchmarking: Metrics and feedback loops.
- Serving Infrastructure: Chat website, API platform, and model serving tools.
- External Integration: Research paper, community and documentation resources.

This approach will provide a clear, comprehensive view of the project’s architecture tailored to its purpose and structure as described in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Training Pipeline"
        Base["Base Model – DeepSeek-V3-Base"]:::training
        RL1["RL Stage 1 (CoT Exploration) producing DeepSeek-R1-Zero"]:::training
        RL2["RL Stage 2 (Refinement)"]:::training
        SFT["Supervised Fine-Tuning (Seed & Stabilize)"]:::training
        DS1["DeepSeek-R1"]:::training
        Distill["Model Distillation"]:::training
        Distilled["Distilled Models (1.5B-70B)"]:::training
        Base -->|"training_data"| RL1
        RL1 -->|"exploration"| RL2
        RL2 -->|"refinement"| SFT
        SFT -->|"fine-tuning"| DS1
        DS1 -->|"distillation_process"| Distill
        Distill -->|"generates"| Distilled
    end

    subgraph "Evaluation & Benchmarking"
        Eval["Evaluation & Benchmarking\n(Metrics: English,Code,Math,Chinese)"]:::eval
    end

    subgraph "Serving Infrastructure"
        Serve["Model Serving Framework\n(vLLM/SGLang)"]:::serve
        Chat["Chat Website\n(chat.deepseek.com)"]:::serve
        API["API Platform\n(platform.deepseek.com)"]:::serve
    end

    subgraph "External Resources"
        Paper["Research Paper"]:::external
        Figures["Figures & Diagrams"]:::external
        Docs["Documentation"]:::external
    end

    DS1 -->|"evaluation"| Eval
    Eval -->|"feedback"| SFT

    Distilled -->|"loaded_into"| Serve
    Serve -->|"handles_chat_requests"| Chat
    Serve -->|"handles_API_calls"| API

    DS1 ---|"documented_in"| Docs
    Paper -.->|"reference"| DS1
    Figures -.->|"illustrates"| DS1

    click Paper "https://github.com/gstearmit/deepseek-r1/blob/main/DeepSeek_R1.pdf"
    click Figures "https://github.com/gstearmit/deepseek-r1/tree/main/figures/"
    click Docs "https://github.com/gstearmit/deepseek-r1/blob/main/README.md"

    classDef training fill:#a3d2ca,stroke:#000,stroke-width:2px;
    classDef eval fill:#ffdac1,stroke:#000,stroke-width:2px;
    classDef serve fill:#f6d186,stroke:#000,stroke-width:2px;
    classDef external fill:#f9c74f,stroke:#000,stroke-width:2px;
```
