Skip to content

Commit 09c397b

Browse files
authored
Merge pull request #3367 from santiagxf/santiagxf/quickstart-deepseek
New tutorial for DeepSeek-R1
2 parents 7f52988 + 75f3a0b commit 09c397b

File tree

9 files changed

+288
-2
lines changed

9 files changed

+288
-2
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
manager: nitinme
3+
ms.service: azure-ai-model-inference
4+
ms.topic: include
5+
ms.date: 1/21/2025
6+
ms.author: fasantia
7+
author: santiagxf
8+
---
9+
10+
# [Python](#tab/python)
11+
12+
```python
13+
from azure.ai.inference.models import SystemMessage, UserMessage
14+
15+
response = client.complete(
16+
messages=[
17+
UserMessage(content="How many languages are in the world?"),
18+
],
19+
model="DeepSeek-R1"
20+
)
21+
22+
print(response.choices[0].message.content)
23+
```
24+
25+
# [JavaScript](#tab/javascript)
26+
27+
```javascript
28+
var messages = [
29+
{ role: "user", content: "How many languages are in the world?" },
30+
];
31+
32+
var response = await client.path("/chat/completions").post({
33+
body: {
34+
messages: messages,
35+
model: "DeepSeek-R1"
36+
}
37+
});
38+
39+
console.log(response.choices[0].message.content)
40+
```
41+
42+
# [C#](#tab/csharp)
43+
44+
```csharp
45+
requestOptions = new ChatCompletionsOptions()
46+
{
47+
Messages = {
48+
new ChatRequestUserMessage("How many languages are in the world?")
49+
},
50+
Model = "DeepSeek-R1"
51+
};
52+
53+
response = client.Complete(requestOptions);
54+
Console.WriteLine($"Response: {response.Value.Content}");
55+
```
56+
57+
# [Java](#tab/java)
58+
59+
```java
60+
List<ChatRequestMessage> chatMessages = new ArrayList<>();
61+
chatMessages.add(new ChatRequestUserMessage("How many languages are in the world?"));
62+
63+
ChatCompletions chatCompletions = client.complete(new ChatCompletionsOptions(chatMessages, "DeepSeek-R1"));
64+
65+
for (ChatChoice choice : chatCompletions.getChoices()) {
66+
ChatResponseMessage message = choice.getMessage();
67+
System.out.println("Response:" + message.getContent());
68+
}
69+
```
70+
71+
# [REST](#tab/rest)
72+
73+
__Request__
74+
75+
```HTTP/1.1
76+
POST https://<resource>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview
77+
api-key: <api-key>
78+
Content-Type: application/json
79+
```
80+
81+
```JSON
82+
{
83+
"messages": [
84+
{
85+
"role": "user",
86+
"content": "How many languages are in the world?"
87+
}
88+
],
89+
"model": "DeepSeek-R1"
90+
}
91+
```
92+
93+
---

articles/ai-foundry/model-inference/includes/use-chat-reasoning/about-reasoning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ author: santiagxf
1111

1212
Reasoning models can reach higher levels of performance in domains like math, coding, science, strategy, and logistics. The way these models produces outputs is by explicitly using chain of thought to explore all possible paths before generating an answer. They verify their answers as they produce them which helps them to arrive to better more accurate conclusions. This means that reasoning models may require less context in prompting in order to produce effective results.
1313

14-
Such way of scaling model's performance is referred as *inference compute time* as it trades performance against higher latency and cost. It contrasts to other approaches that scale through *training compute time*.
14+
Such way of scaling model's performance is referred as *inference compute time* as it trades performance against higher latency and cost. It contrasts to other approaches that scale through *training compute time*.
1515

1616
Reasoning models then produce two types of outputs:
1717

articles/ai-foundry/model-inference/includes/use-chat-reasoning/best-practices.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ When building prompts for reasoning models, take the following into consideratio
1414
> * Built-in reasoning capabilities make simple zero-shot prompts as effective as more complex methods.
1515
> * When providing additional context or documents, like in RAG scenarios, including only the most relevant information may help preventing the model from over-complicating its response.
1616
> * Reasoning models may support the use of system messages. However, they may not follow them as strictly as other non-reasoning models.
17-
> * When creating multi-turn applications, consider only appending the final answer from the model, without it's reasoning content as explained at [Reasoning content](#reasoning-content) section.
17+
> * When creating multi-turn applications, consider only appending the final answer from the model, without it's reasoning content as explained at [Reasoning content](#reasoning-content) section.
18+
19+
Notice that reasoning models can take longer times to generate responses. They use long reasoning chains of thought that enabled deeper and more structured problem-solving. They also perform self-verification to cross-check its own answers and correct its own mistakes, showcasing emergent self-reflective behaviors.
2.39 MB
Loading
2.15 MB
Loading
1.89 MB
Loading
59.5 KB
Loading

articles/ai-foundry/model-inference/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ items:
2424
href: ./how-to/quickstart-github-models.md
2525
- name: Configure AI projects to work with Azure AI model inference
2626
href: ./how-to/quickstart-ai-project.md
27+
- name: Tutorials
28+
items:
29+
- name: Get started with DeepSeek-R1 reasoning model
30+
href: ./tutorials/get-started-deepseek-r1.md
2731
- name: Concepts
2832
items:
2933
- name: Available models
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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

Comments
 (0)