How to install and use DeepSeek R-1 locally
Modley Essex
writer, copywriting, content writing, WordPress, blogging, graphics, Data entry
What is DeepSeek R-1?
DeepSeek R-1 is an open-source AI language model developed by a Chinese AI firm, DeepSeek. It’s based on a large foundational model (DeepSeek-V3) and refined using supervised fine-tuning. It’s known for its reasoning capabilities and offers free access, which makes it a popular option for AI enthusiasts and developers.
Running it locally ensures better data privacy since you avoid sending your data to external servers.
Step 1: Prerequisites
Before installing DeepSeek R-1, make sure your system meets the following requirements:
Hardware Requirements
Software Requirements
Step 2: Download DeepSeek R-1
git clone <repository-url>
cd deepseek-r1
2. Download the Model Weights Visit the official website or repository to download the pre-trained model weights. These are usually provided as .bin or .pt files. Place the downloaded weights in the appropriate folder (e.g., models/).
Step 3: Install Dependencies
python -m venv deepseek_env
source deepseek_env/bin/activate # On Windows: deepseek_env\Scripts\activate
2. Install Required Libraries: Use pip to install dependencies listed in the requirements.txt file:
pip install -r requirements.txt
3. Ensure CUDA is Configured: Verify that PyTorch is using your GPU by running:
领英推荐
import torch
print(torch.cuda.is_available())
Step 4: Running DeepSeek R-1 Locally
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("path_to_weights")
# Load model
model = AutoModelForCausalLM.from_pretrained("path_to_weights")
# Verify the setup
text = "What is DeepSeek R-1?"
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs)
print(tokenizer.decode(outputs[0]))
2. Run the Model: Execute the script to interact with DeepSeek R-1. You can fine-tune the script for different tasks like question-answering, summarization, or creative text generation.
3. Optional: Use a Web Interface Set up a simple web-based interface (e.g., using Gradio or Streamlit) to interact with the model:
import gradio as gr
def reply(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs)
return tokenizer.decode(outputs[0])
interface = gr.Interface(fn=reply, inputs="text", outputs="text")
interface.launch()
Step 5: Fine-Tune (Optional)
If you want to fine-tune DeepSeek R-1 on your own dataset:
from transformers import Trainer, TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=8,
save_steps=10,
save_total_limit=2,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
)
trainer.train()
Step 6: Use Cases
Once DeepSeek R-1 is running on your local machine, you can use it for:
Troubleshooting
model = AutoModelForCausalLM.from_pretrained("path_to_weights", device_map="cpu")
3. Dependency Issues: Update your Python and library versions.
SEE ALSO: