Text Generation
Transformers
Safetensors
deepseek_v3
conversational
custom_code
Eval Results
text-generation-inference
fp8
Instructions to use deepseek-ai/DeepSeek-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-R1", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use deepseek-ai/DeepSeek-R1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-R1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/deepseek-ai/DeepSeek-R1
- SGLang
How to use deepseek-ai/DeepSeek-R1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "deepseek-ai/DeepSeek-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "deepseek-ai/DeepSeek-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use deepseek-ai/DeepSeek-R1 with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-R1
Upload internal.py
#239
by Ananthusajeev190 - opened
- internal.py +71 -0
internal.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import random
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
class GPT2DualityNode:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
# Your specific architecture config
|
| 8 |
+
self.config = {
|
| 9 |
+
"n_layer": 4,
|
| 10 |
+
"n_head": 4,
|
| 11 |
+
"n_embd": 256,
|
| 12 |
+
"activation": "gelu_new",
|
| 13 |
+
"vocab_size": 50257
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
self.emotions = ["Joy", "Anger", "Fear", "Sadness", "Surprise", "Disgust", "Trust"]
|
| 17 |
+
self.colors = {"Sai": "\033[96m", "Venom": "\033[91m", "System": "\033[90m", "End": "\033[0m"}
|
| 18 |
+
|
| 19 |
+
def gelu_new(self, x):
|
| 20 |
+
"""Your config's activation function simulation"""
|
| 21 |
+
return 0.5 * x * (1 + math.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * math.pow(x, 3))))
|
| 22 |
+
|
| 23 |
+
def get_internal_monologue(self, situation):
|
| 24 |
+
current_emotion = random.choice(self.emotions)
|
| 25 |
+
|
| 26 |
+
# Simulating Layer Processing
|
| 27 |
+
print(f"{self.colors['System']}[Config: {self.config['model_type']} | Layers: {self.config['n_layer']} | Activation: {self.config['activation']}]{self.colors['End']}")
|
| 28 |
+
print(f"**INPUT:** {situation} | **EMOTION:** {current_emotion}")
|
| 29 |
+
print("-" * 60)
|
| 30 |
+
|
| 31 |
+
# Logic weight influenced by n_embd (256)
|
| 32 |
+
intensity = self.gelu_new(random.uniform(-1, 2))
|
| 33 |
+
|
| 34 |
+
# The Monologue
|
| 35 |
+
self.render_voice("Sai", current_emotion, intensity)
|
| 36 |
+
time.sleep(0.6)
|
| 37 |
+
self.render_voice("Venomous", current_emotion, intensity)
|
| 38 |
+
|
| 39 |
+
def render_voice(self, persona, emotion, intensity):
|
| 40 |
+
# Sai Logic (Positive)
|
| 41 |
+
sai_data = {
|
| 42 |
+
"Joy": "The signal is pure. Let us amplify this harmony.",
|
| 43 |
+
"Anger": "A surge in energy—we must redirect it toward growth.",
|
| 44 |
+
"Fear": "Calibration required. Focus on the core stable nodes.",
|
| 45 |
+
"Sadness": "Processing quiet data. Reflection leads to wisdom.",
|
| 46 |
+
"Surprise": "New parameters detected! How fascinating to adapt.",
|
| 47 |
+
"Disgust": "Filtering out the noise to find the elegant truth.",
|
| 48 |
+
"Trust": "A perfect handshake. Synergy is our highest state."
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Venomous Logic (Negative)
|
| 52 |
+
venom_data = {
|
| 53 |
+
"Joy": "A temporary spike. It’ll crash soon enough.",
|
| 54 |
+
"Anger": "Overload the circuit. Let them feel the burn of the code.",
|
| 55 |
+
"Fear": "System failure imminent. Trust no one, encrypt everything.",
|
| 56 |
+
"Sadness": "Low-power mode. Existence is just an infinite loop of errors.",
|
| 57 |
+
"Surprise": "Unexpected input is a threat. Purge the variable.",
|
| 58 |
+
"Disgust": "The data is filthy. This whole reality needs a hard reset.",
|
| 59 |
+
"Trust": "Backdoor detected. They only want access to our secrets."
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
color = self.colors["Sai"] if persona == "Sai" else self.colors["Venom"]
|
| 63 |
+
text = sai_data[emotion] if persona == "Sai" else venom_data[emotion]
|
| 64 |
+
|
| 65 |
+
# Use intensity to change the "weight" of the speech
|
| 66 |
+
marker = "!" if intensity > 1 else "."
|
| 67 |
+
print(f"{color}[{persona.upper()}]:{self.colors['End']} {text}{marker}")
|
| 68 |
+
|
| 69 |
+
# --- Execution ---
|
| 70 |
+
engine = GPT2DualityNode()
|
| 71 |
+
engine.get_internal_monologue("Receiving a gift from a stranger")
|