Understanding DeepSeek R1
Abe Thiessen bu sayfayı düzenledi 4 ay önce


DeepSeek-R1 is an open-source language model developed on DeepSeek-V3-Base that's been making waves in the AI neighborhood. Not just does it match-or even surpass-OpenAI's o1 design in numerous criteria, but it also features completely MIT-licensed weights. This marks it as the first non-OpenAI/Google design to deliver strong reasoning capabilities in an open and available way.

What makes DeepSeek-R1 especially exciting is its transparency. Unlike the less-open approaches from some industry leaders, DeepSeek has actually published a detailed training approach in their paper. The model is likewise extremely cost-effective, 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 knowledge was that much better designs needed more information and compute. While that's still legitimate, designs like o1 and R1 show an alternative: inference-time scaling through reasoning.

The Essentials

The DeepSeek-R1 paper presented multiple designs, however main among them were R1 and R1-Zero. Following these are a series of distilled models that, while interesting, I won't discuss here.

DeepSeek-R1 utilizes two significant concepts:

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

  1. Group Relative Policy Optimization (GRPO), a reinforcement learning technique that depends on comparing multiple design outputs per timely to avoid the need for a different critic.

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

    R1-Zero vs R1

    R1-Zero applies Reinforcement Learning (RL) straight to DeepSeek-V3-Base with no supervised fine-tuning (SFT). RL is utilized to enhance the design's policy to take full advantage of benefit. R1-Zero attains outstanding accuracy but in some cases produces complicated outputs, such as mixing numerous languages in a single response. R1 repairs that by including minimal monitored fine-tuning and multiple RL passes, which improves both correctness and readability.

    It is fascinating how some languages might reveal certain ideas much better, which leads the design to select the most meaningful language for the task.

    Training Pipeline

    The training pipeline that DeepSeek published in the R1 paper is exceptionally interesting. It showcases how they produced such strong thinking designs, and what you can anticipate from each phase. This includes the issues that the resulting models from each stage have, and how they fixed it in the next stage.

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

    The usual training technique: Pretraining on big dataset (train to predict next word) to get the base design → supervised fine-tuning → choice tuning by means of RLHF R1-Zero: Pretrained → RL R1: Pretrained → Multistage training pipeline with multiple SFT and RL stages

    Cold-Start Fine-Tuning: Fine-tune DeepSeek-V3-Base on a couple of thousand Chain-of-Thought (CoT) samples to make sure the RL procedure has a good starting point. This gives a great model to start RL. First RL Stage: Apply GRPO with rule-based benefits to improve reasoning accuracy and format (such as forcing chain-of-thought into believing tags). When they were near merging in the RL process, they relocated to the next action. The result of this action is a strong thinking design but with weak basic abilities, e.g., bad format and language mixing. Rejection Sampling + basic information: Create brand-new SFT data through rejection sampling on the RL checkpoint (from step 2), combined with supervised data from the DeepSeek-V3-Base design. They collected around 600k top quality reasoning samples. Second Fine-Tuning: Fine-tune DeepSeek-V3-Base again on 800k overall samples (600k thinking + 200k general jobs) for broader capabilities. This action resulted in a strong reasoning design with basic capabilities. Second RL Stage: Add more benefit signals (helpfulness, harmlessness) to fine-tune the last design, in addition to the thinking rewards. The result is DeepSeek-R1. They likewise did model distillation for a number of Qwen and Llama models on the thinking traces to get distilled-R1 designs.

    Model distillation is a method where you utilize a teacher model to enhance a trainee design by generating training information for the trainee model. The instructor is generally a larger design than the trainee.

    Group Relative Policy Optimization (GRPO)

    The fundamental idea behind using reinforcement learning for LLMs is to tweak the design's policy so that it naturally produces more precise and useful responses. They used a benefit system that examines not only for correctness however likewise for appropriate format and language consistency, so the design gradually learns to favor reactions that meet 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 inference time, the training procedure itself nudges the model to produce detailed, detailed outputs-making the chain-of-thought an emerging behavior of the enhanced policy.

    What makes their approach especially fascinating is its dependence on straightforward, rule-based reward functions. Instead of depending upon expensive external designs or human-graded examples as in standard RLHF, the RL used for R1 utilizes easy criteria: it might provide a higher benefit if the response is appropriate, if it follows the anticipated/ formatting, and if the language of the response matches that of the timely. Not relying on a reward design likewise means you don't have to invest time and effort training it, and it doesn't take memory and calculate far from your main model.

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

    1. For each input timely, the model produces different responses.
  2. Each response gets a scalar reward based upon aspects like precision, formatting, and language consistency.
  3. Rewards are adjusted relative to the group's efficiency, basically measuring just how much better each response is compared to the others.
  4. The design updates its technique a little to prefer reactions with greater relative benefits. It only makes small adjustments-using methods like clipping and a KL penalty-to guarantee the policy does not stray too far from its original habits.

    A cool element of GRPO is its versatility. You can utilize simple rule-based benefit functions-for hikvisiondb.webcam instance, granting a benefit when the model properly utilizes the syntax-to guide the training.

    While DeepSeek used GRPO, you could utilize alternative techniques rather (PPO or PRIME).

    For those aiming to dive deeper, Will Brown has actually composed quite a nice implementation of training an LLM with RL using GRPO. GRPO has actually also currently been included to the Transformer Reinforcement Learning (TRL) library, which is another excellent resource. Finally, Yannic Kilcher has a great 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 the approaches they have actually provided in their paper, I want to highlight a passage from the DeepSeekMath paper, based on a point Yannic Kilcher made in his video.

    These findings show that RL improves the design's general performance by rendering the output circulation more robust, in other words, it appears that the improvement is credited to boosting the correct action from TopK instead of the enhancement of essential abilities.

    To put it simply, RL fine-tuning tends to shape the output distribution so that the highest-probability outputs are most likely to be correct, despite the fact that the total ability (as determined by the diversity of appropriate answers) is mainly present in the pretrained design.

    This recommends that support learning on LLMs is more about refining and "shaping" the existing circulation of reactions instead of enhancing the design with completely new capabilities. Consequently, while RL techniques such as PPO and GRPO can produce substantial performance gains, there appears to be an inherent ceiling identified by the underlying model's pretrained knowledge.

    It is uncertain to me how far RL will take us. Perhaps it will be the stepping stone to the next huge turning point. I'm thrilled to see how it unfolds!

    Running DeepSeek-R1

    I have actually utilized DeepSeek-R1 via the main chat user interface for numerous problems, which it seems to fix all right. The extra search performance makes it even better to utilize.

    Interestingly, o3-mini(-high) was released as I was composing this post. From my preliminary screening, R1 appears stronger at math than o3-mini.

    I also rented a single H100 through Lambda Labs for $2/h (26 CPU cores, 214.7 GB RAM, 1.1 TB SSD) to run some experiments. The main goal was to see how the model would carry out when deployed on a single H100 GPU-not to extensively test the design's abilities.

    671B through 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 running on the GPU), running through llama.cpp:

    29 layers appeared to be the sweet area given this configuration.

    Performance:

    A r/localllama user explained that they had the ability to overcome 2 tok/sec with DeepSeek R1 671B, without using their GPU on their local gaming setup. Digital Spaceport wrote a complete guide on how to run Deepseek R1 671b totally 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 manageable for any major work, however it's fun to run these big designs on available hardware.

    What matters most to me is a combination of usefulness and time-to-usefulness in these models. Since reasoning models require to think before responding to, their time-to-usefulness is usually higher than other designs, but their usefulness is also normally higher. We need to both optimize usefulness and lessen time-to-usefulness.

    70B via Ollama

    70.6 b params, 4-bit KM quantized DeepSeek-R1 running through Ollama:

    GPU utilization 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 by means of Reinforcement Learning [2402.03300] DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models DeepSeek R1 - Notion (Building a totally regional "deep researcher" with DeepSeek-R1 - YouTube). DeepSeek R1's dish to replicate 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 grandma - 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 an unique autoregressive structure that merges multimodal understanding and generation. It can both understand and produce images. DeepSeek-R1: Incentivizing Reasoning Capability in Large Language Models through Reinforcement Learning (January 2025) This paper introduces DeepSeek-R1, an open-source thinking model that rivals the efficiency of OpenAI's o1. It provides a detailed methodology for training such designs utilizing large-scale reinforcement knowing strategies. DeepSeek-V3 Technical Report (December 2024) This report discusses the execution of an FP8 mixed precision training structure verified on an exceptionally massive model, attaining both accelerated training and decreased GPU memory usage. DeepSeek LLM: Scaling Open-Source Language Models with Longtermism (January 2024) This paper looks into scaling laws and presents findings that assist in the scaling of large-scale designs in open-source configurations. It presents the DeepSeek LLM task, committed to advancing open-source language designs with a long-lasting perspective. DeepSeek-Coder: When the Large Language Model Meets Programming-The Rise of Code Intelligence (January 2024) This research study presents the DeepSeek-Coder series, a variety of open-source code designs trained from scratch on 2 trillion tokens. The designs 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 provides DeepSeek-V2, a Mixture-of-Experts (MoE) language design identified by economical training and efficient inference. 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 model that attains efficiency to GPT-4 Turbo in code-specific tasks.

    Interesting occasions

    - Hong Kong University duplicates R1 results (Jan 25, '25).
  5. Huggingface reveals huggingface/open-r 1: Fully open recreation of DeepSeek-R1 to reproduce R1, completely open source (Jan 25, '25).
  6. OpenAI scientist verifies the DeepSeek group separately discovered and utilized some core ideas the OpenAI group utilized en route to o1

    Liked this post? Join the newsletter.