|
| 1 | +--- |
| 2 | +title: "Tutorial: Getting started with DeepSeek-R1 reasoning model in Azure AI model inference" |
| 3 | +titleSuffix: Azure AI Foundry |
| 4 | +description: Learn about the reasoning capabilities of DeepSeek-R1 in Azure AI model inference. |
| 5 | +manager: scottpolly |
| 6 | +ms.service: azure-ai-model-inference |
| 7 | +ms.topic: tutorial |
| 8 | +ms.date: 03/01/2025 |
| 9 | +ms.reviewer: fasantia |
| 10 | +ms.author: mopeakande |
| 11 | +author: msakande |
| 12 | +--- |
| 13 | + |
| 14 | +# Tutorial: Get started with DeepSeek-R1 reasoning model in Azure AI model inference |
| 15 | + |
| 16 | +In this tutorial, you learn: |
| 17 | + |
| 18 | +> [!div class="checklist"] |
| 19 | +> * How to create and configure the Azure resources to use DeepSeek-R1 model in Azure AI model inference. |
| 20 | +> * How to configure the model deployment. |
| 21 | +> * How to use DeepSeek-R1 using the Azure AI Inference SDK or REST APIs. |
| 22 | +> * How to use DeepSeek-R1 using other SDKs. |
| 23 | +
|
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +To complete this article, you need: |
| 27 | + |
| 28 | +* An Azure subscription. If you're using [GitHub Models](https://docs.github.com/en/github-models/), you can upgrade your experience and create an Azure subscription in the process. Read [Upgrade from GitHub Models to Azure AI model inference](../how-to/quickstart-github-models.md) if that's your case. |
| 29 | + |
| 30 | +[!INCLUDE [about-reasoning](../includes/use-chat-reasoning/about-reasoning.md)] |
| 31 | + |
| 32 | +## Create the resources |
| 33 | + |
| 34 | +Azure AI model inference is a capability in Azure AI Services resources in Azure. You can create model deployments under the resource to consume their predictions. You can also connect the resource to Azure AI Hubs and Projects in Azure AI Foundry to create intelligent applications if needed. The following picture shows the high level architecture. |
| 35 | + |
| 36 | +:::image type="content" source="../media/quickstart-get-started-deepseek-r1/resources-architecture.png" alt-text="A diagram showing the high level architecture of the resources created in the tutorial." lightbox="../media/quickstart-get-started-deepseek-r1/resources-architecture.png"::: |
| 37 | + |
| 38 | +To create an Azure AI project that supports model inference for DeepSeek-R1, follow these steps: |
| 39 | + |
| 40 | +> [!TIP] |
| 41 | +> You can also create the resources using [Azure CLI](../how-to/quickstart-create-resources.md?pivots=programming-language-cli) or [infrastructure as code with Bicep](../how-to/quickstart-create-resources.md?pivots=programming-language-bicep). |
| 42 | +
|
| 43 | +1. Go to [Azure AI Foundry portal](https://ai.azure.com) and log in with your account. |
| 44 | + |
| 45 | +2. On the landing page, select **Create project**. |
| 46 | + |
| 47 | +3. Give the project a name, for example "my-project". |
| 48 | + |
| 49 | +4. In this tutorial, we create a brand new project under a new AI hub, hence, select **Create new hub**. Hubs are containers for multiple projects and allow you to share resources across all the projects. |
| 50 | + |
| 51 | +5. Give the hub a name, for example "my-hub" and select **Next**. |
| 52 | + |
| 53 | +6. The wizard updates with details about the resources that are going to be created. Select **Azure resources to be created** to see the details. |
| 54 | + |
| 55 | + :::image type="content" source="../media/create-resources/create-project-with-hub-details.png" alt-text="Screenshot showing the details of the project and hub to be created." lightbox="../media/create-resources/create-project-with-hub-details.png"::: |
| 56 | + |
| 57 | +7. You can see that the following resources are created: |
| 58 | + |
| 59 | + | Property | Description | |
| 60 | + | -------------- | ----------- | |
| 61 | + | Resource group | The main container for all the resources in Azure. This helps get resources that work together organized. It also helps to have a scope for the costs associated with the entire project. | |
| 62 | + | Location | The region of the resources that you're creating. | |
| 63 | + | Hub | The main container for AI projects in Azure AI Foundry. Hubs promote collaboration and allow you to store information for your projects. | |
| 64 | + | AI Services | The resource enabling access to the flagship models in Azure AI model catalog. In this tutorial, a new account is created, but Azure AI services resources can be shared across multiple hubs and projects. Hubs use a connection to the resource to have access to the model deployments available there. To learn how, you can create connections between projects and Azure AI Services to consume Azure AI model inference you can read [Connect your AI project](../how-to/configure-project-connection.md). | |
| 65 | + |
| 66 | +8. Select **Create**. The resources creation process starts. |
| 67 | + |
| 68 | +9. Once completed, your project is ready to be configured. |
| 69 | + |
| 70 | +10. Azure AI model inference is a Preview feature that needs to be turned on in Azure AI Foundry. At the top navigation bar, over the right corner, select the **Preview features** icon. A contextual blade shows up at the right of the screen. |
| 71 | + |
| 72 | +11. Turn the feature **Deploy models to Azure AI model inference service** on. |
| 73 | + |
| 74 | + :::image type="content" source="../media/quickstart-ai-project/ai-project-inference-endpoint.gif" alt-text="An animation showing how to turn on the Azure AI model inference service deploy models feature in Azure AI Foundry portal." lightbox="../media/quickstart-ai-project/ai-project-inference-endpoint.gif"::: |
| 75 | + |
| 76 | +12. Close the panel. |
| 77 | + |
| 78 | + |
| 79 | +## Add DeepSeek-R1 model deployment |
| 80 | + |
| 81 | +Let's now create a new model deployment for DeepSeek-R1: |
| 82 | + |
| 83 | +1. Go to **Model catalog** section in [Azure AI Foundry portal](https://ai.azure.com/explore/models) and find the model [DeepSeek-R1](https://ai.azure.com/explore/models/DeepSeek-R1/version/1/registry/azureml-deepseek) model. |
| 84 | + |
| 85 | +3. You can review the details of the model in the model card. |
| 86 | + |
| 87 | +4. Select **Deploy**. |
| 88 | + |
| 89 | +5. The wizard shows the model's terms and conditions for DeepSeek-R1, which is offered as a Microsoft first party consumption service. You can review our privacy and security commitments under [Data, privacy, and Security](../../../ai-studio/how-to/concept-data-privacy.md). |
| 90 | + |
| 91 | + > [!TIP] |
| 92 | + > Review the pricing details for the model by selecting [Pricing and terms](https://aka.ms/DeepSeekPricing). |
| 93 | +
|
| 94 | +6. Accept the terms on those cases by selecting **Subscribe and deploy**. |
| 95 | + |
| 96 | + :::image type="content" source="../media/quickstart-get-started-deepseek-r1/models-deploy-agree.png" alt-text="Screenshot showing how to agree the terms and conditions of a DeepSeek-R1 model." lightbox="../media/quickstart-get-started-deepseek-r1/models-deploy-agree.png"::: |
| 97 | + |
| 98 | +7. You can configure the deployment settings at this time. By default, the deployment receives the name of the model you're deploying. The deployment name is used in the `model` parameter for request to route to this particular model deployment. This allows you to also configure specific names for your models when you attach specific configurations. |
| 99 | + |
| 100 | +8. We automatically select an Azure AI Services connection depending on your project. Use the **Customize** option to change the connection based on your needs. DeepSeek-R1 is currently offered under the **Global Standard** deployment type which offers higher throughput and performance. |
| 101 | + |
| 102 | +9. Select **Deploy**. |
| 103 | + |
| 104 | + :::image type="content" source="../media/quickstart-get-started-deepseek-r1/model-deploy.png" alt-text="Screenshot showing how to deploy the model." lightbox="../media/quickstart-get-started-deepseek-r1/model-deploy.png"::: |
| 105 | + |
| 106 | +10. Once the deployment completes, the new model is listed in the page and it's ready to be used. |
| 107 | + |
| 108 | +## Use the model in playground |
| 109 | + |
| 110 | +You can get started by using the model in the playground to have an idea of the model capabilities. |
| 111 | + |
| 112 | +1. On the deployment details page, select **Open in playground** option in the top bar. |
| 113 | + |
| 114 | +2. In the **Deployment** drop down, the deployment you created has been automatically selected. |
| 115 | + |
| 116 | +3. Configure the system prompt as needed. In general, reasoning models don't use system messages in the same way that other types of models. |
| 117 | + |
| 118 | + :::image type="content" source="../media/quickstart-get-started-deepseek-r1/playground-chat-models.png" alt-text="Screenshot showing how to select a model deployment to use in playground, configure the system message, and test it out." lightbox="../media/quickstart-get-started-deepseek-r1/playground-chat-models.png"::: |
| 119 | + |
| 120 | +4. Type your prompt and see the outputs. |
| 121 | + |
| 122 | +5. Additionally, you can use **View code** so see details about how to access the model deployment programmatically. |
| 123 | + |
| 124 | +[!INCLUDE [best-practices](../includes/use-chat-reasoning/best-practices.md)] |
| 125 | + |
| 126 | +## Use the model in code |
| 127 | + |
| 128 | +Use the Azure AI model inference endpoint and credentials to connect to the model: |
| 129 | + |
| 130 | +:::image type="content" source="../media/overview/overview-endpoint-and-key.png" alt-text="Screenshot showing how to get the URL and key associated with the resource." lightbox="../media/overview/overview-endpoint-and-key.png"::: |
| 131 | + |
| 132 | +You can use the Azure AI Inference package to consume the model in code: |
| 133 | + |
| 134 | +[!INCLUDE [code-create-chat-client](../includes/code-create-chat-client.md)] |
| 135 | + |
| 136 | +[!INCLUDE [code-chat-reasoning](../includes/code-create-chat-reasoning.md)] |
| 137 | + |
| 138 | +Reasoning may generate longer responses and consume a larger amount of tokens. You can see the [rate limits](../quotas-limits.md) that apply to DeepSeek-R1 models. Consider having a retry strategy to handle rate limits being applied. You can also [request increases to the default limits](../quotas-limits.md#request-increases-to-the-default-limits). |
| 139 | + |
| 140 | +### Reasoning content |
| 141 | + |
| 142 | +Some reasoning models, like DeepSeek-R1, generate completions and include the reasoning behind it. The reasoning associated with the completion is included in the response's content within the tags `<think>` and `</think>`. The model may select on which scenarios to generate reasoning content. You following example shows how to do it in Python: |
| 143 | + |
| 144 | +```python |
| 145 | +import re |
| 146 | + |
| 147 | +match = re.match(r"<think>(.*?)</think>(.*)", response.choices[0].message.content, re.DOTALL) |
| 148 | + |
| 149 | +print("Response:", ) |
| 150 | +if match: |
| 151 | + print("\tThinking:", match.group(1)) |
| 152 | + print("\tAnswer:", match.group(2)) |
| 153 | +else: |
| 154 | + print("\tAnswer:", response.choices[0].message.content) |
| 155 | +print("Model:", response.model) |
| 156 | +print("Usage:") |
| 157 | +print("\tPrompt tokens:", response.usage.prompt_tokens) |
| 158 | +print("\tTotal tokens:", response.usage.total_tokens) |
| 159 | +print("\tCompletion tokens:", response.usage.completion_tokens) |
| 160 | +``` |
| 161 | + |
| 162 | +```console |
| 163 | +Thinking: Okay, the user is asking how many languages exist in the world. I need to provide a clear and accurate answer. Let's start by recalling the general consensus from linguistic sources. I remember that the number often cited is around 7,000, but maybe I should check some reputable organizations.\n\nEthnologue is a well-known resource for language data, and I think they list about 7,000 languages. But wait, do they update their numbers? It might be around 7,100 or so. Also, the exact count can vary because some sources might categorize dialects differently or have more recent data. \n\nAnother thing to consider is language endangerment. Many languages are endangered, with some having only a few speakers left. Organizations like UNESCO track endangered languages, so mentioning that adds context. Also, the distribution isn't even. Some countries have hundreds of languages, like Papua New Guinea with over 800, while others have just a few. \n\nA user might also wonder why the exact number is hard to pin down. It's because the distinction between a language and a dialect can be political or cultural. For example, Mandarin and Cantonese are considered dialects of Chinese by some, but they're mutually unintelligible, so others classify them as separate languages. Also, some regions are under-researched, making it hard to document all languages. \n\nI should also touch on language families. The 7,000 languages are grouped into families like Indo-European, Sino-Tibetan, Niger-Congo, etc. Maybe mention a few of the largest families. But wait, the question is just about the count, not the families. Still, it's good to provide a bit more context. \n\nI need to make sure the information is up-to-date. Let me think – recent estimates still hover around 7,000. However, languages are dying out rapidly, so the number decreases over time. Including that note about endangerment and language extinction rates could be helpful. For instance, it's often stated that a language dies every few weeks. \n\nAnother point is sign languages. Does the count include them? Ethnologue includes some, but not all sources might. If the user is including sign languages, that adds more to the count, but I think the 7,000 figure typically refers to spoken languages. For thoroughness, maybe mention that there are also over 300 sign languages. \n\nSummarizing, the answer should state around 7,000, mention Ethnologue's figure, explain why the exact number varies, touch on endangerment, and possibly note sign languages as a separate category. Also, a brief mention of Papua New Guinea as the most linguistically diverse country. \n\nWait, let me verify Ethnologue's current number. As of their latest edition (25th, 2022), they list 7,168 living languages. But I should check if that's the case. Some sources might round to 7,000. Also, SIL International publishes Ethnologue, so citing them as reference makes sense. \n\nOther sources, like Glottolog, might have a different count because they use different criteria. Glottolog might list around 7,000 as well, but exact numbers vary. It's important to highlight that the count isn't exact because of differing definitions and ongoing research. \n\nIn conclusion, the approximate number is 7,000, with Ethnologue being a key source, considerations of endangerment, and the challenges in counting due to dialect vs. language distinctions. I should make sure the answer is clear, acknowledges the variability, and provides key points succinctly. |
| 164 | + |
| 165 | +Answer: The exact number of languages in the world is challenging to determine due to differences in definitions (e.g., distinguishing languages from dialects) and ongoing documentation efforts. However, widely cited estimates suggest there are approximately **7,000 languages** globally. |
| 166 | +Model: DeepSeek-R1 |
| 167 | +Usage: |
| 168 | + Prompt tokens: 11 |
| 169 | + Total tokens: 897 |
| 170 | + Completion tokens: 886 |
| 171 | +``` |
| 172 | + |
| 173 | + |
| 174 | +### Parameters |
| 175 | + |
| 176 | +In general, reasoning models don't support the following parameters you can find in chat completion models: |
| 177 | + |
| 178 | +* Temperature |
| 179 | +* Presence penalty |
| 180 | +* Repetition penalty |
| 181 | +* Parameter `top_p` |
| 182 | + |
| 183 | +## Related content |
| 184 | + |
| 185 | +* [Use chat reasoning models](../how-to/use-chat-reasoning.md) |
| 186 | +* [Use image embedding models](../how-to/use-image-embeddings.md) |
| 187 | +* [Azure AI Model Inference API](.././reference/reference-model-inference-api.md) |
0 commit comments