Text Generation
MLX
Safetensors
GGUF
English
llama
llm
purple-squirrel
video-processing
blockchain
fine-tuned
aidp
decentralized-inference
openai-compatible
deepseek-r1
deepseek
reasoning
chain-of-thought
8b
apple-silicon
local-inference
conversational
Eval Results (legacy)
4-bit precision
bitsandbytes
Instructions to use purplesquirrelnetworks/purple-squirrel-r1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use purplesquirrelnetworks/purple-squirrel-r1 with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("purplesquirrelnetworks/purple-squirrel-r1") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use purplesquirrelnetworks/purple-squirrel-r1 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf purplesquirrelnetworks/purple-squirrel-r1:F16 # Run inference directly in the terminal: llama cli -hf purplesquirrelnetworks/purple-squirrel-r1:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf purplesquirrelnetworks/purple-squirrel-r1:F16 # Run inference directly in the terminal: llama cli -hf purplesquirrelnetworks/purple-squirrel-r1:F16
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf purplesquirrelnetworks/purple-squirrel-r1:F16 # Run inference directly in the terminal: ./llama-cli -hf purplesquirrelnetworks/purple-squirrel-r1:F16
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf purplesquirrelnetworks/purple-squirrel-r1:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf purplesquirrelnetworks/purple-squirrel-r1:F16
Use Docker
docker model run hf.co/purplesquirrelnetworks/purple-squirrel-r1:F16
- LM Studio
- Jan
- vLLM
How to use purplesquirrelnetworks/purple-squirrel-r1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "purplesquirrelnetworks/purple-squirrel-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": "purplesquirrelnetworks/purple-squirrel-r1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/purplesquirrelnetworks/purple-squirrel-r1:F16
- Ollama
How to use purplesquirrelnetworks/purple-squirrel-r1 with Ollama:
ollama run hf.co/purplesquirrelnetworks/purple-squirrel-r1:F16
- Unsloth Studio
How to use purplesquirrelnetworks/purple-squirrel-r1 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for purplesquirrelnetworks/purple-squirrel-r1 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for purplesquirrelnetworks/purple-squirrel-r1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for purplesquirrelnetworks/purple-squirrel-r1 to start chatting
- MLX LM
How to use purplesquirrelnetworks/purple-squirrel-r1 with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "purplesquirrelnetworks/purple-squirrel-r1"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "purplesquirrelnetworks/purple-squirrel-r1" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "purplesquirrelnetworks/purple-squirrel-r1", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use purplesquirrelnetworks/purple-squirrel-r1 with Docker Model Runner:
docker model run hf.co/purplesquirrelnetworks/purple-squirrel-r1:F16
- Lemonade
How to use purplesquirrelnetworks/purple-squirrel-r1 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull purplesquirrelnetworks/purple-squirrel-r1:F16
Run and chat with the model
lemonade run user.purple-squirrel-r1-F16
List all available models
lemonade list
- Atomic Chat
Upload purple_squirrel_r1_demo.ipynb with huggingface_hub
Browse files- purple_squirrel_r1_demo.ipynb +181 -0
purple_squirrel_r1_demo.ipynb
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# Purple Squirrel R1 - Demo Notebook\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"This notebook demonstrates how to use the Purple Squirrel R1 model, a fine-tuned version of DeepSeek-R1-Distill-Llama-8B specialized for Purple Squirrel platform questions.\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"[](https://colab.research.google.com/github/purplesquirrelnetworks/purple-squirrel-r1/blob/main/purple_squirrel_r1_demo.ipynb)"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "markdown",
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"source": [
|
| 18 |
+
"## Option 1: Use the REST API (Recommended)\n",
|
| 19 |
+
"\n",
|
| 20 |
+
"The fastest way to use the model - no GPU required!"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": null,
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [],
|
| 28 |
+
"source": [
|
| 29 |
+
"import requests\n",
|
| 30 |
+
"\n",
|
| 31 |
+
"API_URL = \"https://purplesquirrelnetworks--purple-squirrel-r1-api-purplesqu-1e3c01.modal.run\"\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"def ask_purple_squirrel(prompt, max_tokens=256, temperature=0.3):\n",
|
| 34 |
+
" response = requests.post(\n",
|
| 35 |
+
" API_URL,\n",
|
| 36 |
+
" json={\"prompt\": prompt, \"max_tokens\": max_tokens, \"temperature\": temperature}\n",
|
| 37 |
+
" )\n",
|
| 38 |
+
" return response.json()[\"response\"]\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"# Test it out\n",
|
| 41 |
+
"print(ask_purple_squirrel(\"What is Purple Squirrel?\"))"
|
| 42 |
+
]
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"cell_type": "code",
|
| 46 |
+
"execution_count": null,
|
| 47 |
+
"metadata": {},
|
| 48 |
+
"outputs": [],
|
| 49 |
+
"source": [
|
| 50 |
+
"# More examples\n",
|
| 51 |
+
"questions = [\n",
|
| 52 |
+
" \"Can I mint NFTs with Purple Squirrel?\",\n",
|
| 53 |
+
" \"What AI capabilities does Purple Squirrel have?\",\n",
|
| 54 |
+
" \"How does Purple Squirrel handle video transcription?\",\n",
|
| 55 |
+
"]\n",
|
| 56 |
+
"\n",
|
| 57 |
+
"for q in questions:\n",
|
| 58 |
+
" print(f\"Q: {q}\")\n",
|
| 59 |
+
" print(f\"A: {ask_purple_squirrel(q)}\")\n",
|
| 60 |
+
" print(\"-\" * 50)"
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"cell_type": "markdown",
|
| 65 |
+
"metadata": {},
|
| 66 |
+
"source": [
|
| 67 |
+
"## Option 2: Load Model Locally (Requires GPU)\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"For local inference with full control. Requires ~16GB VRAM or use 4-bit quantization."
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"cell_type": "code",
|
| 74 |
+
"execution_count": null,
|
| 75 |
+
"metadata": {},
|
| 76 |
+
"outputs": [],
|
| 77 |
+
"source": [
|
| 78 |
+
"# Install dependencies\n",
|
| 79 |
+
"!pip install -q torch transformers accelerate bitsandbytes"
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"cell_type": "code",
|
| 84 |
+
"execution_count": null,
|
| 85 |
+
"metadata": {},
|
| 86 |
+
"outputs": [],
|
| 87 |
+
"source": [
|
| 88 |
+
"import torch\n",
|
| 89 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
|
| 90 |
+
"\n",
|
| 91 |
+
"MODEL_ID = \"purplesquirrelnetworks/purple-squirrel-r1\"\n",
|
| 92 |
+
"\n",
|
| 93 |
+
"# 4-bit quantization for lower memory usage\n",
|
| 94 |
+
"quantization_config = BitsAndBytesConfig(\n",
|
| 95 |
+
" load_in_4bit=True,\n",
|
| 96 |
+
" bnb_4bit_compute_dtype=torch.bfloat16,\n",
|
| 97 |
+
" bnb_4bit_use_double_quant=True,\n",
|
| 98 |
+
" bnb_4bit_quant_type=\"nf4\",\n",
|
| 99 |
+
")\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"print(\"Loading tokenizer...\")\n",
|
| 102 |
+
"tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)\n",
|
| 103 |
+
"\n",
|
| 104 |
+
"print(\"Loading model with 4-bit quantization...\")\n",
|
| 105 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 106 |
+
" MODEL_ID,\n",
|
| 107 |
+
" quantization_config=quantization_config,\n",
|
| 108 |
+
" device_map=\"auto\",\n",
|
| 109 |
+
")\n",
|
| 110 |
+
"print(\"Model loaded!\")"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"cell_type": "code",
|
| 115 |
+
"execution_count": null,
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [],
|
| 118 |
+
"source": [
|
| 119 |
+
"def generate_response(prompt, max_tokens=256, temperature=0.3):\n",
|
| 120 |
+
" messages = [{\"role\": \"user\", \"content\": prompt}]\n",
|
| 121 |
+
" formatted = tokenizer.apply_chat_template(\n",
|
| 122 |
+
" messages, tokenize=False, add_generation_prompt=True\n",
|
| 123 |
+
" )\n",
|
| 124 |
+
" inputs = tokenizer(formatted, return_tensors=\"pt\").to(model.device)\n",
|
| 125 |
+
" \n",
|
| 126 |
+
" outputs = model.generate(\n",
|
| 127 |
+
" **inputs,\n",
|
| 128 |
+
" max_new_tokens=max_tokens,\n",
|
| 129 |
+
" temperature=temperature,\n",
|
| 130 |
+
" do_sample=True,\n",
|
| 131 |
+
" pad_token_id=tokenizer.eos_token_id,\n",
|
| 132 |
+
" repetition_penalty=1.1,\n",
|
| 133 |
+
" )\n",
|
| 134 |
+
" \n",
|
| 135 |
+
" response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n",
|
| 136 |
+
" # Extract assistant response\n",
|
| 137 |
+
" if \"<|Assistant|>\" in response:\n",
|
| 138 |
+
" response = response.split(\"<|Assistant|>\")[-1]\n",
|
| 139 |
+
" if \"</think>\" in response:\n",
|
| 140 |
+
" response = response.split(\"</think>\")[-1].strip()\n",
|
| 141 |
+
" return response\n",
|
| 142 |
+
"\n",
|
| 143 |
+
"# Test\n",
|
| 144 |
+
"print(generate_response(\"What is Purple Squirrel?\"))"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"cell_type": "markdown",
|
| 149 |
+
"metadata": {},
|
| 150 |
+
"source": [
|
| 151 |
+
"## Model Info\n",
|
| 152 |
+
"\n",
|
| 153 |
+
"| Attribute | Value |\n",
|
| 154 |
+
"|-----------|-------|\n",
|
| 155 |
+
"| Base Model | DeepSeek-R1-Distill-Llama-8B |\n",
|
| 156 |
+
"| Parameters | 8B |\n",
|
| 157 |
+
"| Training Method | LoRA |\n",
|
| 158 |
+
"| Training Examples | 74 |\n",
|
| 159 |
+
"| Token Accuracy | 91% |\n",
|
| 160 |
+
"\n",
|
| 161 |
+
"## Links\n",
|
| 162 |
+
"\n",
|
| 163 |
+
"- [Model on HuggingFace](https://huggingface.co/purplesquirrelnetworks/purple-squirrel-r1)\n",
|
| 164 |
+
"- [Purple Squirrel Networks](https://purplesquirrel.io)"
|
| 165 |
+
]
|
| 166 |
+
}
|
| 167 |
+
],
|
| 168 |
+
"metadata": {
|
| 169 |
+
"kernelspec": {
|
| 170 |
+
"display_name": "Python 3",
|
| 171 |
+
"language": "python",
|
| 172 |
+
"name": "python3"
|
| 173 |
+
},
|
| 174 |
+
"language_info": {
|
| 175 |
+
"name": "python",
|
| 176 |
+
"version": "3.11.0"
|
| 177 |
+
}
|
| 178 |
+
},
|
| 179 |
+
"nbformat": 4,
|
| 180 |
+
"nbformat_minor": 4
|
| 181 |
+
}
|