Understanding DeepSeek R1
Alphonse Zimpel laboja lapu 6 mēneši atpakaļ


DeepSeek-R1 is an open-source language model built on DeepSeek-V3-Base that's been making waves in the AI community. Not only does it match-or even surpass-OpenAI's o1 model in numerous standards, but it likewise features totally MIT-licensed weights. This marks it as the first non-OpenAI/Google model to provide strong thinking abilities in an open and available way.

What makes DeepSeek-R1 particularly amazing is its openness. Unlike the less-open approaches from some industry leaders, DeepSeek has actually released a detailed training method in their paper. The design is likewise incredibly economical, with input tokens costing just $0.14-0.55 per million (vs o1's $15) and output tokens at $2.19 per million (vs o1's $60).

Until ~ GPT-4, the common wisdom was that better models required more data and calculate. While that's still legitimate, designs like o1 and R1 show an option: inference-time scaling through thinking.

The Essentials

The DeepSeek-R1 paper provided multiple designs, however main amongst them were R1 and R1-Zero. Following these are a series of distilled designs that, while intriguing, I will not go over here.

DeepSeek-R1 uses two significant concepts:

1. A multi-stage pipeline where a small set of cold-start information kickstarts the model, followed by massive RL.

  1. Group Relative Policy Optimization (GRPO), a reinforcement learning method that counts on comparing several model outputs per prompt to prevent the need for a separate critic.

    R1 and R1-Zero are both thinking models. This essentially indicates they do Chain-of-Thought before addressing. For the R1 series of models, this takes type as thinking within a tag, before responding to with a final summary.

    R1-Zero vs R1

    R1-Zero uses Reinforcement Learning (RL) straight to DeepSeek-V3-Base without any supervised fine-tuning (SFT). RL is utilized to enhance the model's policy to make the most of reward. R1-Zero attains exceptional accuracy however in some cases produces confusing outputs, such as blending numerous languages in a single response. R1 repairs that by including limited monitored fine-tuning and numerous RL passes, which enhances both accuracy and readability.

    It is interesting how some languages might express certain concepts better, which leads the design to select the most expressive language for the job.

    Training Pipeline

    The training pipeline that DeepSeek published in the R1 paper is profoundly intriguing. It showcases how they developed such strong thinking designs, and what you can anticipate from each phase. This includes the problems that the resulting models from each stage have, and how they resolved it in the next phase.

    It's fascinating that their training pipeline varies from the typical:

    The normal training method: Pretraining on large dataset (train to anticipate next word) to get the base model → supervised fine-tuning → preference tuning by means of RLHF R1-Zero: Pretrained → RL R1: Pretrained → Multistage training pipeline with numerous SFT and RL stages

    Cold-Start Fine-Tuning: Fine-tune DeepSeek-V3-Base on a few thousand Chain-of-Thought (CoT) samples to make sure the RL procedure has a decent starting point. This offers a great model to start RL. First RL Stage: Apply GRPO with rule-based rewards to improve reasoning accuracy and formatting (such as forcing chain-of-thought into believing tags). When they were near convergence in the RL procedure, they moved to the next action. The result of this step is a strong thinking model but with weak basic capabilities, e.g., poor format and language blending. Rejection Sampling + basic information: Create brand-new SFT information through rejection sampling on the RL checkpoint (from action 2), combined with monitored data from the DeepSeek-V3-Base design. They gathered around 600k high-quality reasoning samples. Second Fine-Tuning: Fine-tune DeepSeek-V3-Base again on 800k total samples (600k reasoning + 200k basic jobs) for broader capabilities. This step led to a strong reasoning design with basic abilities. Second RL Stage: Add more reward signals (helpfulness, harmlessness) to fine-tune the final design, in addition to the thinking rewards. The result is DeepSeek-R1. They likewise did model distillation for a number of Qwen and Llama designs on the thinking traces to get distilled-R1 models.

    Model distillation is a technique where you use an instructor design to enhance a trainee design by creating training information for the trainee design. The teacher is typically a bigger model than the trainee.

    Group Relative Policy Optimization (GRPO)

    The standard idea behind using reinforcement knowing for LLMs is to fine-tune the design's policy so that it naturally produces more accurate and useful answers. They used a reward system that checks not just for correctness however also for correct format and language consistency, so the model gradually discovers to favor actions that satisfy these quality criteria.

    In this paper, they motivate the R1 design to generate chain-of-thought reasoning through RL training with GRPO. Instead of adding a different module at reasoning time, the training procedure itself pushes the model to produce detailed, detailed outputs-making the chain-of-thought an emergent habits of the enhanced policy.

    What makes their method particularly intriguing is its reliance on straightforward, rule-based benefit functions. Instead of depending upon costly external models or human-graded examples as in standard RLHF, the RL utilized for R1 utilizes simple requirements: it may give a greater reward if the answer is proper, if it follows the expected/ format, and if the language of the response matches that of the timely. Not relying on a reward model also implies you do not have to spend time and effort training it, and it does not take memory and calculate away from your main design.

    GRPO was presented in the DeepSeekMath paper. Here's how GRPO works:

    1. For each input timely, the model generates various responses.
  2. Each reaction gets a scalar benefit based on aspects like accuracy, format, and language consistency.
  3. Rewards are changed relative to the group's performance, essentially measuring just how much better each reaction is compared to the others.
  4. The design updates its strategy slightly to prefer responses with higher relative benefits. It only makes small adjustments-using techniques like clipping and a KL penalty-to ensure the policy does not wander off too far from its original habits.

    A cool aspect of GRPO is its versatility. You can utilize basic rule-based benefit functions-for instance, awarding a benefit when the design properly uses the syntax-to guide the training.

    While DeepSeek used GRPO, you might use alternative methods instead (PPO or PRIME).

    For those aiming to dive much deeper, Will Brown has composed rather a nice execution of training an LLM with RL using GRPO. GRPO has likewise already been contributed to the Transformer Reinforcement Learning (TRL) library, which is another great resource. Finally, Yannic Kilcher has an excellent video explaining GRPO by going through the DeepSeekMath paper.

    Is RL on LLMs the path to AGI?

    As a last note on explaining DeepSeek-R1 and larsaluarna.se the approaches they have actually presented in their paper, I desire to highlight a from the DeepSeekMath paper, based on a point Yannic Kilcher made in his video.

    These findings show that RL enhances the design's total performance by rendering the output circulation more robust, simply put, it appears that the improvement is credited to increasing the proper action from TopK rather than the enhancement of basic capabilities.

    In other words, RL fine-tuning tends to shape the output circulation so that the highest-probability outputs are most likely to be appropriate, even though the total capability (as determined by the variety of appropriate answers) is mainly present in the pretrained model.

    This suggests that support knowing on LLMs is more about refining and "forming" the existing distribution of actions rather than endowing the design with completely brand-new abilities. Consequently, while RL strategies such as PPO and GRPO can produce substantial efficiency gains, there appears to be an intrinsic ceiling figured out by the underlying design's pretrained knowledge.

    It is uncertain to me how far RL will take us. Perhaps it will be the stepping stone to the next big milestone. I'm delighted to see how it unfolds!

    Running DeepSeek-R1

    I have actually used DeepSeek-R1 by means of the main chat user interface for different issues, which it seems to resolve well enough. The extra search performance makes it even better to use.

    Interestingly, o3-mini(-high) was released as I was composing this post. From my initial screening, R1 seems more powerful at mathematics than o3-mini.

    I also leased a single H100 via Lambda Labs for $2/h (26 CPU cores, 214.7 GB RAM, 1.1 TB SSD) to run some experiments. The main objective was to see how the design would perform when released on a single H100 GPU-not to thoroughly evaluate the design's capabilities.

    671B by means of Llama.cpp

    DeepSeek-R1 1.58-bit (UD-IQ1_S) quantized model by Unsloth, with a 4-bit quantized KV-cache and partial GPU offloading (29 layers working on the GPU), running by means of llama.cpp:

    29 layers appeared to be the sweet spot provided this setup.

    Performance:

    A r/localllama user explained that they were able to overcome 2 tok/sec with DeepSeek R1 671B, without utilizing their GPU on their local gaming setup. Digital Spaceport composed a full guide on how to run Deepseek R1 671b fully in your area on a $2000 EPYC server, on which you can get ~ 4.25 to 3.5 tokens per second.

    As you can see, the tokens/s isn't quite bearable for any serious work, but it's fun to run these big designs on available hardware.

    What matters most to me is a mix of effectiveness and time-to-usefulness in these designs. Since reasoning designs require to think before answering, their time-to-usefulness is usually higher than other models, however their usefulness is also typically higher. We require to both make the most of effectiveness and reduce time-to-usefulness.

    70B via Ollama

    70.6 b params, 4-bit KM quantized DeepSeek-R1 running by means of Ollama:

    GPU usage shoots up here, as expected when compared to the mainly CPU-powered run of 671B that I showcased above.

    Resources

    DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning [2402.03300] DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models DeepSeek R1 - Notion (Building a fully local "deep scientist" with DeepSeek-R1 - YouTube). DeepSeek R1's recipe to reproduce o1 and the future of thinking LMs. The Illustrated DeepSeek-R1 - by Jay Alammar. Explainer: What's R1 & Everything Else? - Tim Kellogg. DeepSeek R1 Explained to your grandmother - YouTube

    DeepSeek

    - Try R1 at chat.deepseek.com. GitHub - deepseek-ai/DeepSeek-R 1. deepseek-ai/Janus-Pro -7 B · Hugging Face (January 2025): Janus-Pro is a novel autoregressive framework that unifies multimodal understanding and generation. It can both understand and produce images. DeepSeek-R1: Incentivizing Reasoning Capability in Large Language Models via Reinforcement Learning (January 2025) This paper presents DeepSeek-R1, an open-source thinking design that rivals the efficiency of OpenAI's o1. It presents a detailed approach for training such designs utilizing large-scale reinforcement learning methods. DeepSeek-V3 Technical Report (December 2024) This report discusses the execution of an FP8 blended accuracy training structure validated on an extremely large-scale model, attaining both sped up training and lowered GPU memory use. DeepSeek LLM: Scaling Open-Source Language Models with Longtermism (January 2024) This paper explores scaling laws and provides findings that help with the scaling of massive models in open-source configurations. It presents the DeepSeek LLM project, devoted to advancing open-source language models with a long-term viewpoint. DeepSeek-Coder: When the Large Language Model Meets Programming-The Rise of Code Intelligence (January 2024) This research study presents the DeepSeek-Coder series, disgaeawiki.info a variety of open-source code designs trained from scratch on 2 trillion tokens. The models are pre-trained on a top quality project-level code corpus and utilize a fill-in-the-blank task to boost code generation and infilling. DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model (May 2024) This paper presents DeepSeek-V2, a Mixture-of-Experts (MoE) language model identified by cost-effective training and efficient reasoning. DeepSeek-Coder-V2: Breaking the Barrier of Closed-Source Models in Code Intelligence (June 2024) This research presents DeepSeek-Coder-V2, an open-source Mixture-of-Experts (MoE) code language design that attains performance similar to GPT-4 Turbo in code-specific tasks.

    Interesting events

    - Hong Kong University reproduces R1 results (Jan 25, '25).
  5. Huggingface announces huggingface/open-r 1: Fully open recreation of DeepSeek-R1 to replicate R1, completely open source (Jan 25, '25).
  6. OpenAI researcher validates the DeepSeek team individually discovered and utilized some core ideas the OpenAI group utilized on the way to o1

    Liked this post? Join the newsletter.