DEV Community

Cover image for Run DeepSeek-R1 Locally for Free in Just 3 Minutes!
Pavan Belagatti
Pavan Belagatti

Posted on • Edited on

2579 2 2 4 4

Run DeepSeek-R1 Locally for Free in Just 3 Minutes!

DeepSeek-R1 has been creating quite a buzz in the AI community. Developed by a Chinese AI company DeepSeek, this model is being compared to OpenAI's top models. The excitement around DeepSeek-R1 is not just because of its capabilities but also because it is open-sourced, allowing anyone to download and run it locally. In this blog, I'll guide you through setting up DeepSeek-R1 on your machine using Ollama.

Why DeepSeek-R1?

DeepSeek R1

DeepSeek-R1 stands out for several reasons. Not only is it cheaper than many other models, but it also excels in problem-solving, reasoning, and coding. Its built-in chain of thought reasoning enhances its efficiency, making it a strong contender against other models. Let's dive into how you can get this model running on your local system.

Getting Started with Ollama

ollama logo
Before we begin, let's discuss Ollama. Ollama is a free, open-source tool that allows users to run Natural Language Processing models locally. With Ollama, you can easily download and run the DeepSeek-R1 model.

Here's how you can get started:

Step 1: Install Ollama

First, you'll need to download and install Ollama. Visit the Ollama website and download the version that matches your operating system.
Follow the installation instructions provided on the site.

install ollama

Step 2: Download DeepSeek-R1

step 2 download deepseek-R1

As you can see when you go to Ollama website, you can run the different parameters of DeepSeek-R1. You can find the details of requirements here (as shown above in the screenshot)

You can run 1.5b, 7b, 8b, 14b, 32b, 70b, 671b and obviously the hardware requirements increase as you choose bigger parameter. I used 7b one in my tutorial.

Once Ollama is installed, open your terminal and type the following command to download the DeepSeek-R1 model:

DeepSeek-7b

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

This command tells Ollama to download the model. Depending on your internet speed, this might take some time. Grab a coffee while it completes!

Step 3: Verify Installation

After downloading, verify the installation by running:

ollama list
Enter fullscreen mode Exit fullscreen mode

You should see deepseek-r1 in the list of available models. If you do, great job! You're ready to run the model.

Step 4: Run DeepSeek-R1

Now, let's start the model using the command:

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

And just like that, you're interacting with DeepSeek-R1 locally. It's that simple!

Step 5: Ask a Query

ask a query

Chain-of-thought reasoning by the model.

chain of thought

The model looks good with coding tasks also. Let's check that approach too.

deepseek code generation

The detailed anwer for the above code related query.

code gen R1

Below is a complete step-by-step video of using DeepSeek-R1 for different use cases.

My first impression about DeepSeek-R1 is just mind blowing:)

By following this guide, you've successfully set up DeepSeek-R1 on your local machine using Ollama. This setup offers a powerful solution for AI integration, providing privacy, speed, and control over your applications. Enjoy experimenting with DeepSeek-R1 and exploring the potential of local AI models. BTW, having a robust database for your AI/ML applications is a must. I recommend using an all-in-one data platform like SingleStore.


Let's Build a RAG Application using DeepSeek and SingleStore

If you like to extend your learning and build a simple RAG application, you can follow this tutorial.

We will set the DeepSeek API key from NVIDIA NIM microservice (Yes, I'll show you how). NVIDIA NIM (Inference Microservices) is a set of microservices that help deploy AI models across clouds, data centers, and workstations. We will be using LangChain as our LLM framework to bind everything. We will be using SingleStore as our vector database.

Let's Get Started (Follow Along)

1. Prerequisites [All are FREE]

First thing is to create a free SingleStore account. Login to your account and create a workspace and a database for yourself.

singlestore workspace

After creating a workspace, create a database attached to that workspace. Click on create a database as shown in the dashboard screenshot to create a database.

singlestore db

Cool. Now, we created our database to store our custom documents for our RAG application.

The next step is to create a Notebook. Yes, a free notebook environment. SingleStore has this cool integrated feature where you can use their Notebooks [Just like your Google collab]

Go to Data Studio and then create a new Notebook.
SingleStore Notebooks

Give a name to your Notebook
notebook name

This is where you will land.
ss dashboard

Make sure to select your workspace and database you created from the dropdown as shown below. My workspace name is 'pavappy-workspace-1' and the database I created is 'DeepSeek'. So I have selected both.

workspace ss

Now we are all set to code our RAG application. Start adding all the below code step-by-step into the newly created notebook (make sure to run each code snippet aswell)

Start with installing all the required libraries and dependencies.

!pip install langchain --quiet
!pip install pdf2image --quiet
!pip install pdfminer.six --quiet
!pip install singlestoredb --quiet
!pip install tiktoken --quiet
!pip install --upgrade unstructured==0.10.14 --quiet
!pip install -qU pypdf langchain_community
!pip install langchain-nvidia-ai-endpoints --quiet
!pip install langchain-deepseek-official --quiet
Enter fullscreen mode Exit fullscreen mode

Import libraries

from langchain.document_loaders import PyPDFLoader
from langchain_nvidia_ai_endpoints import ChatNVIDIA
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.chains import RetrievalQA
from langchain.vectorstores import SingleStoreDB
import os
Enter fullscreen mode Exit fullscreen mode

Load your custom document [I have used a publicly available pdf, you can replace and use your own)

file_path = "https://unctad.org/system/files/official-document/wesp2023_en.pdf"
loader = PyPDFLoader(file_path)
data = loader.load()
Enter fullscreen mode Exit fullscreen mode

Split document into chunks

text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=0)
texts = text_splitter.split_documents(data)
Enter fullscreen mode Exit fullscreen mode

Set up OpenAI embeddings (for vectorization)

os.environ["OPENAI_API_KEY"] = "Add your OpenAI API key"
embedding = OpenAIEmbeddings()
Enter fullscreen mode Exit fullscreen mode

Store embeddings in SingleStore

docsearch = SingleStoreDB.from_documents(
    texts,
    embedding,
    table_name="deepseek_rag", # Replace table name with any name
    host="admin:password@host_url:3306/database_name",  # Replace with your SingleStore connection
    port=3306
)
Enter fullscreen mode Exit fullscreen mode

In the above code, admin is constant and don't change that. You can get your password from the access tab and host url can get as shown below. Go to your deployments tab, you should see your workspace, click on connect and then see the dropdown as below. Select 'SQL IDE' from there and you will see all the required details.

singlestore connect

Next, Initialize DeepSeek through NVIDIA NIM
Get your DeepSeek-R1 API Key for free from NVIDIA NIM microservice. Get it from HERE.

client = ChatNVIDIA(
    model="deepseek-ai/deepseek-r1",
    api_key="Add your DeepSeek-R1 API key you received from NVIDIA NIM microservice",  # Replace with your NVIDIA API key
    temperature=0.7,
    top_p=0.8,
    max_tokens=4096
)
Enter fullscreen mode Exit fullscreen mode

Create RAG chain

qa_chain = RetrievalQA.from_chain_type(
    llm=client,
    chain_type="stuff",
    retriever=docsearch.as_retriever(search_kwargs={"k": 3}),
    return_source_documents=True
)
Enter fullscreen mode Exit fullscreen mode

Query the RAG system

query = "What India's GDP growth is projected to be?"
result = qa_chain.invoke({"query": query})
Enter fullscreen mode Exit fullscreen mode

Display results

print("Answer:", result["result"])
print("\nSources:")
for doc in result["source_documents"]:
    print(f"- Page {doc.metadata['page']}: {doc.page_content[:100]}...")
Enter fullscreen mode Exit fullscreen mode

You should see a fine response from the model:)

deepseek model response

You can go check your database to see how the data has been chunked and stored in the vector embeddings format.

data in embeddings

Here is the complete code repo you can try:)

RAG Application With DeepSeek-R1, LangChain and SingleStore

We will set the DeepSeek API key from NVIDIA, as we will be using NVIDIA NIM Microservice. NVIDIA NIM (Inference Microservices) is a set of microservices that help deploy AI models across clouds, data centers, and workstations. We will be using LangChain as our LLM framework to bind everything. We will be using SingleStore as our vector database.

Prerequisites

  • Free SingleStore account

  • Free NVIDIA NIM account

    Refer to my article on devto to know more about how you can run DeepSeek-R1 locally. I have also included this repo in the article and explained how you can create a simple RAG application.




Thank you for reading my article. Hope you tried the entire tutorial. You can also follow me through my Youtube channel. I create AI/ML/Data related videos on a weekly basis.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (24)

Collapse
 
aman_singh_296040fbbf47fd profile image
Aman Singh

What is the minimum Requirements of Hardware to run this?

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

As you can see when you go to Llama website, you can run the different parameters of DeepSeek-R1. You can find the details of requirements here: ollama.com/library/deepseek-r1

You can run 1.5b, 7b, 8b, 14b, 32b, 70b, 671b and obviously the hardware requirements increase as you choose bigger parameter. I used 7b one in the above tutorial.

Collapse
 
johnny_1ea09a3c277a1b46fe profile image
Johnny

Maybe be clearer about that in the article. It is deceiving to not specifically say what model you are running. "Running R1 locally" sounds like you are running their best OpenAI o1 equivalent locally, which is not the case.

Thread Thread
 
pavanbelagatti profile image
Pavan Belagatti

It is the same but with less parameter one. Done. Updated the article with 7b.

Collapse
 
chrisa profile image
Christian A

You literally need a tank for running 671b.
70b and smaller ones are possible at home. You can run it on CPU or on GPU, whicht is a lot faster. A cool one would be an NVIDIA 3090, you can rebuy it for around 700 euros atm.

Collapse
 
moeed_anjum_4ce66986d179a profile image
Moeed Anjum

Good one, it helped me a lot.

Say hello to DeepSeek R1—the AI-powered platform that’s changing the rules of data analytics!

🔍 What makes DeepSeek R1 a game-changer?
✅ Real-time data processing for instant insights
✅ Advanced machine learning & NLP capabilities
✅ Scalable, secure, and user-friendly
✅ Perfect for industries like healthcare, finance, e-commerce, and more
Whether you're a data scientist, business leader, or tech enthusiast, DeepSeek R1 is your ultimate tool to unlock the true potential of your data.

📖 Want to learn more? Dive into the full blog to discover how DeepSeek R1 can transform your business:

👉 myappranking.com/deepseek-r1

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

Thanks for the summary.

Collapse
 
activemode profile image
Luis Brown

Well done. Simple and straight to the point. Thank you for contributing and helping those of us that really need guidance. I'm running an Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz 1.99 GHz, with 16.0 GB (15.8 GB usable), and I downloaded the deepseek-r1:32b.

Wish me luck.

Collapse
 
muhamedkanapiya profile image
Muhamed-Kanapiya

is there GUi for local version?

Collapse
 
youssefma6 profile image
youssefma6

yeah there is one ! you can pair Ollama with Open WebUI – a graphical user interface (GUI) tool
just go to docs.openwebui.com

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

No idea, need to check.

Collapse
 
jody_elliott_f6913e0a78e5 profile image
Jody Elliott

MSTY.app is a great one and my favorite. LMStudio is nice as well.

Collapse
 
rakesh_manchanda_6738aec1 profile image
rakesh manchanda

What happened at tinanimun Square

Collapse
 
betweenwinters_d2addf3fae profile image
Betweenwinters
Collapse
 
pj_d723905209ef profile image
Paul Johnson

To be fair... As the other AIs what think of Donal trump

Collapse
 
steel32 profile image
Dustin Hao

the local one can actually answer this question i just tested it

Collapse
 
rairyu profile image
Radian al Mahmmud

how to download it to a specific drive and not the c drive?

Collapse
 
pavanbelagatti profile image
Pavan Belagatti

You can move it around wherever you want.

Collapse
 
zaw_myoaungzawmyoaung profile image
Zaw Myo Aung Zaw Myo Aung

Hi

Collapse
 
ali_akbar_f71bd483f2d8401 profile image
Ali Akbar

سلام

Collapse
 
eugnio_correia_e873058b8 profile image
Eugénio Correia

My name is Eugénio Correia

Collapse
 
mrfamous profile image
Luis F

Hola eugenio correia

Collapse
 
mcwood_f5848 profile image
mcwood

I asked who is the current US president and the answers is Joe Biden.
Maybe that is why it is free.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay