DeepSeek R1 and V3: A Leap in AI Efficiency

Introduction

China’s AI industry has been making remarkable progress, and DeepSeek R1 and V3 are prime examples of this advancement. While U.S. AI giants like OpenAI, Google, and Meta spend billions of dollars on training large language models (LLMs), DeepSeek has demonstrated that AI efficiency is just as important as raw computing power. With DeepSeek R1 trained for under $6 million, it challenges the notion that cutting-edge AI requires massive supercomputing resources.

In this post, we’ll dive into what makes DeepSeek R1 and V3 special, their implications for the global AI race, and provide a hands-on tutorial to run DeepSeek models locally on your machine using Ollama and Streamlit.


What is DeepSeek R1 and V3?

DeepSeek R1: Efficiency Over Raw Power

DeepSeek R1 is a large language model trained using just 2,000 GPUs over 55 days—a fraction of the resources used by OpenAI’s GPT-4. Despite this, R1 performs well in reasoning, math, and code generation. This suggests that China is focusing on algorithmic efficiency rather than relying solely on high-performance chips.

DeepSeek V3: Pushing Boundaries Further

DeepSeek V3 builds upon R1, improving performance in areas such as language understanding, multilingual capabilities, and model adaptability. While details on its architecture are still emerging, it’s clear that DeepSeek aims to compete directly with leading Western models like GPT-4.

Key Advantages of DeepSeek Models:

  • Cost-Effective Training: Achieves strong performance without the need for high-end AI chips.
  • Open Source: Available for researchers and developers worldwide.
  • Strong Coding Capabilities: Competes with models like Code Llama and OpenAI’s Codex.

Tutorial: Running DeepSeek Locally on Your Machine

You can try out DeepSeek R1 and V3 on your own system using Ollama. Below is a step-by-step guide to install and run DeepSeek models using Python and Streamlit.

Step 1: Install Ollama on WSL (Windows Subsystem for Linux)

DeepSeek models are supported on Ollama, a powerful framework for running AI models locally. To install Ollama on WSL (Windows Subsystem for Linux):

  1. Follow Ollama’s official installation guide for Linux: Ollama Installation Guide
  2. Once installed, verify the installation by running:ollama --version

Step 2: Install DeepSeek for Ollama

To download and install the DeepSeek model for Ollama, use the following command in WSL terminal:

ollama run deepseek-r1

This will fetch the latest version of the DeepSeek model to run locally.

Step 3: Set Up a Virtual Environment

Before running the provided Python script, create a specific folder for your script, and then in this folder create a virtual environment:

python3 -m venv env
source env/bin/activate  # On Mac/Linux

Step 4: Install Required Dependencies

Navigate to the project root directory (the folder you create above and make sure the environment is still active like the step above) and install the required Python packages:

pip install -r requirements.txt

Note: The package versions may change over time. If you face compatibility issues, upgrade all dependencies:

pip install -r requirements.txt --upgrade

Step 5: Run the DeepSeek Chatbot Script

Now, you can run the chatbot interface powered by Streamlit and DeepSeek:

streamlit run app.py

This will launch a web-based chat UI where you can interact with the DeepSeek model locally.


Code for Running DeepSeek with Ollama

Below is the Python script (app.py) to create a chatbot interface using Streamlit and Ollama:

# app.py
import streamlit as st
import requests
import json

# Configure Ollama
OLLAMA_HOST = "http://localhost:11434"

# Helper functions
def get_models():
    response = requests.get(f"{OLLAMA_HOST}/api/tags")
    return [model["name"] for model in response.json().get("models", [])]

def generate_response(model, prompt):
    response = requests.post(
        f"{OLLAMA_HOST}/api/generate",
        json={
            "model": model,
            "prompt": prompt,
            "stream": True
        },
        stream=True
    )
    for chunk in response.iter_lines():
        if chunk:
            yield json.loads(chunk.decode("utf-8")).get("response", "")

# UI Setup
st.title("Ollama Chat UI 🦙")

# Sidebar for model selection
with st.sidebar:
    st.header("Configuration")
    selected_model = st.selectbox(
        "Choose Model",
        options=get_models(),
        index=0
    )

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Chat input
if prompt := st.chat_input("What's up?"):
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})
    
    # Display user message
    with st.chat_message("user"):
        st.markdown(prompt)

    # Generate response
    with st.chat_message("assistant"):
        response = st.write_stream(
            generate_response(selected_model, prompt)
        )
    
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})

Requirements.txt

Make sure you create a file in project root directory as requirements.txt (as exactly how it spells here without any capital letter). Then copy the content below to requirements.txt.

altair==5.5.0
attrs==25.1.0
blinker==1.9.0
cachetools==5.5.1
certifi==2024.12.14
charset-normalizer==3.4.1
click==8.1.8
gitdb==4.0.12
GitPython==3.1.44
idna==3.10
Jinja2==3.1.5
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdurl==0.1.2
narwhals==1.24.1
numpy==2.2.2
packaging==24.2
pandas==2.2.3
pillow==11.1.0
protobuf==5.29.3
pyarrow==19.0.0
pydeck==0.9.1
Pygments==2.19.1
python-dateutil==2.9.0.post0
pytz==2024.2
referencing==0.36.2
requests==2.32.3
rich==13.9.4
rpds-py==0.22.3
six==1.17.0
smmap==5.0.2
streamlit==1.41.1
tenacity==9.0.0
toml==0.10.2
tornado==6.4.2
typing_extensions==4.12.2
tzdata==2025.1
urllib3==2.3.0
watchdog==6.0.0

Conclusion

DeepSeek R1 and V3 demonstrate that China’s AI research is advancing rapidly despite hardware restrictions. Their efficiency-focused approach could challenge the U.S. AI leadership in the coming years. Meanwhile, DeepSeek’s open-source release gives the world access to high-performing AI models at a fraction of the cost.

By following the tutorial above, you can explore DeepSeek locally and see its capabilities firsthand. Whether you’re a developer, researcher, or just an AI enthusiast, this is an exciting time to dive into the world of open-source LLMs.

🚀 Try it out and let us know your thoughts!



Leave a comment