Large Language Models - Coding - Beginner - Artificial Intelligence

Running DeepSeek R1 on Your Local Machine Offline: A Step-by-Step Guide

Over the past few months even weeks, DeepSeek has emerged as an unexpected guest in the AI market. It literally redefined the AI industry and cost trillions of dollars loss in stock markets. Even though I am also interested in, I won’t focus on that side of DeepSeek today. The reason it caused such a fundamental change is that it uses significantly fewer resources than its competitors in the market. The level of optimization is so high that you can run a fully pre-trained model even on a laptop. Today, I will take you through how to run DeepSeek R1 on your local machine even without connecting to internet at all.

There are at least two ways of running DeepSeek locally. First, using Ollama and second one is running it natively. Both methods are straightforward, and I’ll keep the instructions simple and easy to follow. By natively I mean that there is no intermediary service running in between you just configure and run on your own. Of course it gives you more freedom, configurability and fine-tuning capabilities. Nevertheless, freedom always comes by a cost which is complexity in this case.

Before starting, make sure you have a decent laptop in terms of resources and a good graphic card will make things way easier. Furthermore, if you are working on a corporate device like a company laptop, please make sure that DeepSeek complies with your company policies. As we know, DeepSeek is a Chinese made AI platform and there are concerns about how they collect and store data. I didn’t see any danger since it works fully offline nevertheless many companies in the West are currently blocking usage of DeepSeek, unless otherwise stated. In short, ask before acting, not to face any disciplinary issues in the future.

Option 1: Running DeepSeek R1 with Ollama

I started with this since it is the simplest and the most straightforward way to go.

1. Install Ollama

  • First, yon need to install Ollama. You can download and install Ollama from the official website: https://ollama.ai.
  • Choose the required binaries for your operation system and follow the instructions.

2. Pull the R1 model.

  • Open your terminal or command prompt.
  • Browse models on Ollama’s web site (top left). Find the model fitting you the best, people generally tend to use the highest model number but you can look at the details for the best fit.
  • As of today, we have 70b but 14b is also good option to run locally. Let’s use 14b for today.
  • Run the following command to pull the DeepSeek R1 model:
ollama pull deepseek-r1:14b

3. Run the model

  • Once the model is downloaded, start it with:
ollama run deepseek-r1:14b

Option 2: Running DeepSeek R1 Natively

1. Set Up a Python Environment

  • Ensure you have Python 3.8 or later installed. See https://www.python.org/downloads/
  • Create a virtual environment:
python -m venv deepseek-env
  • Activate the environment:
# Linux/Mac
source deepseek-env/bin/activate

# Windows
deepseek-env\Scripts\activate

2. Install Required Libraries

pip install torch transformers

3. Download and Run DeepSeek R1

Use the following code to load and run the model. As of today, we have 70b but 14b is also good option to run locally. Let’s use 14b for today.

from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the model and tokenizer
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-r1:r14")
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-r1:r14")

# Generate a response
input_text = "Hello, DeepSeek R1!"
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Now, you are ready to interact with DeepSeek R1 directly in your terminal! It will not only give the answer only, it will also tell you how it “thinks” first. Of course don’t expect the performance on the webchat bot, it is slower. If your laptop is older, it is even slower. However, having a fully functioning AI running on your machine offline is the actual beginning of an era.

Both methods are effective for running DeepSeek R1 locally. Whether you choose Ollama or a native setup, you’ll be able to leverage the power of DeepSeek R1 on your machine.

Suleyman Cabir Ataman, PhD

Sharing on social media:

Leave a Reply

Your email address will not be published. Required fields are marked *