Text Generation
MLX
Safetensors
deepseek_v4
deepseek
deepseek-v4
quantized
2bit
mixed-precision
optiq
Mixture of Experts
ssd-streaming
apple-silicon
conversational
2-bit
Instructions to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit 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("mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit") 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
- LM Studio
- Pi
How to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "mlx-community/DeepSeek-V4-Flash-0731-OptiQ-2bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Flappy Bird</title> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| background: #1a1a2e; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| min-height: 100vh; | |
| font-family: 'Courier New', monospace; | |
| } | |
| canvas { | |
| display: block; | |
| border: 4px solid #2c3e50; | |
| border-radius: 8px; | |
| background: #4ec0ca; | |
| box-shadow: 0 8px 16px rgba(0,0,0,0.3); | |
| cursor: pointer; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <canvas id="gameCanvas" width="400" height="600"></canvas> | |
| <script> | |
| // ========== CONSTANTS AND VARIABLES ========== | |
| const canvas = document.getElementById('gameCanvas'); | |
| const ctx = canvas.getContext('2d'); | |
| const WIDTH = canvas.width; | |
| const HEIGHT = canvas.height; | |
| const BIRD_X = 100; | |
| const BIRD_RADIUS = 12; | |
| const BIRD_COLOR = '#ffcc00'; | |
| const BIRD_ACCELERATION = 0.45; | |
| const BIRD_JUMP_VELOCITY = -8; | |
| const GRAVITY = 0.5; | |
| const PIPE_WIDTH = 60; | |
| const PIPE_GAP = 140; | |
| const PIPE_SPACING = 220; | |
| const PIPE_SPEED = 2.4; | |
| const GROUND_HEIGHT = 80; | |
| const GROUND_COLOR = '#8b5a2b'; | |
| const PIPE_COLOR = '#4a9e4a'; | |
| const PIPE_BORDER_COLOR = '#2d7a2d'; | |
| const SCORE_COLOR = '#ffffff'; | |
| const GAME_OVER_COLOR = '#ff0000'; | |
| const RESTART_COLOR = '#ffffff'; | |
| const GAME_OVER_FONT = 'bold 28px sans-serif'; | |
| const SCORE_FONT = 'bold 20px sans-serif'; | |
| const RESTART_FONT = 'bold 16px sans-serif'; | |
| // ========== STATE ========== | |
| let bird = { x: 80, y: 250, vy: 0, width: 34, height: 24 }; | |
| let pipes = []; | |
| let groundY = 560; // top of ground line | |
| let pipeGap = 140; | |
| let pipeSpacing = 200; | |
| let score = 0; | |
| let gameOver = false; | |
| let gameOverScreen = false; | |
| let frames = 0; | |
| let restartRequested = false; | |
| let lastTime = 0; | |
| let pipeSpawnCounter = 0; | |
| let pipeSpawnInterval = 90; // frames between pipes | |
| let birdFlap = false; | |
| let birdFlapTime = 0; | |
| // Ground line | |
| const GROUND_Y = 560; | |
| const BIRD_HEIGHT = 20; | |
| const BIRD_WIDTH = 20; | |
| // ========== GAME STATE ========== | |
| let gameState = 'play'; // 'play' | 'gameover' | |
| let pipeFrameCounter = 0; | |
| let birdY = 250; | |
| let birdVelocity = 0; | |
| let pipeList = []; | |
| let frameCount = 0; | |
| let gameOverScreenShown = false; | |
| // ========== CONSTANTS (reuse) ========== | |
| const CANVAS_WIDTH = 400; | |
| const CANVAS_HEIGHT = 600; | |
| const JUMP_VELOCITY = -8; | |
| // ========== INITIALIZE ========== | |
| canvas.width = 400; | |
| canvas.height = 600; | |
| // ========== GAME STATE ========== | |
| let frame = 0; | |
| let pipeInterval = 90; // frames between pipes | |
| // ========== RESTART ========== | |
| function restart() { | |
| bird = { x: BIRD_X, y: 300, vy: 0, width: BIRD_WIDTH, height: BIRD_HEIGHT }; | |
| pipes = []; | |
| score = 0; | |
| gameOver = false; | |
| gameOverScreen = false; | |
| frame = 0; | |
| pipeSpawnCounter = 0; | |
| // reset any other state | |
| cancelAnimationFrame(lastFrameId); | |
| requestAnimationFrame(gameLoop); | |
| } | |
| // --- shims: the model declared these constants in UPPER_CASE and then | |
| // --- referenced the camelCase forms, and called a helper it never defined. | |
| const gravity = GRAVITY; | |
| const pipeSpeed = PIPE_SPEED; | |
| const pipeWidth = PIPE_WIDTH; | |
| let gameOverScreenActive = false; | |
| let pipeCounter = 0; | |
| function randomRange(lo, hi) { return Math.random() * (hi - lo) + lo; } | |
| // ========== GAME LOOP ========== | |
| let lastFrameId; | |
| function gameLoop(timestamp) { | |
| if (!lastTime) lastTime = timestamp; | |
| let delta = timestamp - lastTime; | |
| lastTime = timestamp; | |
| if (delta > 200) delta = 200; // avoid huge jumps | |
| // Update | |
| update(delta / 1000); | |
| // Draw | |
| draw(); | |
| // Request next frame | |
| requestAnimationFrame(gameLoop); | |
| } | |
| // ========== UPDATE ========== | |
| function update(dt) { | |
| frame++; | |
| // Bird physics | |
| bird.vy += 0.45 * dt * 60; | |
| bird.y += bird.vy * dt * 60; | |
| if (bird.y > groundY) { | |
| bird.y = groundY; | |
| if (!gameOver) { | |
| gameOver = true; | |
| gameOverScreenActive = true; | |
| } | |
| } | |
| // Pipes | |
| for (let i = 0; i < pipes.length; i++) { | |
| const p = pipes[i]; | |
| p.x -= p.speed * dt * 60; | |
| if (p.x + p.width < 0) { | |
| pipes.splice(i, 1); | |
| i--; | |
| score++; | |
| } | |
| } | |
| // Spawn | |
| if (frame % 100 === 0) { | |
| const top = randomRange(50, 300); | |
| const gap = 140; | |
| const width = 60; | |
| pipes.push({ | |
| x: canvas.width, | |
| top: top, | |
| bottom: top + gap, | |
| width: width, | |
| speed: 2.4, | |
| passed: false | |
| }); | |
| } | |
| // Collision | |
| if (!gameOver) { | |
| for (let i = 0; i < pipes.length; i++) { | |
| const p = pipes[i]; | |
| if (bird.x + 20 > p.x && bird.x + 20 < p.x + p.width && | |
| (bird.y < p.top || bird.y + 20 > p.bottom)) { | |
| gameOver = true; | |
| break; | |
| } | |
| } | |
| if (bird.y + 20 > groundY) { | |
| gameOver = true; | |
| } | |
| } | |
| // Score | |
| if (!gameOver) { | |
| for (const p of pipes) { | |
| if (p.passed === false && bird.x > p.x + p.width) { | |
| score++; | |
| p.passed = true; | |
| } | |
| } | |
| } | |
| } | |
| // ========== DRAW ========== | |
| function draw() { | |
| // Clear | |
| ctx.clearRect(0, 0, WIDTH, HEIGHT); | |
| // Sky | |
| ctx.fillStyle = '#87CEEB'; | |
| ctx.fillRect(0, 0, WIDTH, 200); | |
| // Ground | |
| ctx.fillStyle = '#c9a96e'; | |
| ctx.fillRect(0, HEIGHT - 80, WIDTH, 80); | |
| // Ground lines | |
| ctx.strokeStyle = '#7a5c3c'; | |
| ctx.lineWidth = 2; | |
| for (let i = 0; i < 20; i++) { | |
| ctx.beginPath(); | |
| ctx.moveTo(i * 40, HEIGHT - 40); | |
| ctx.lineTo(i * 40 + 20, HEIGHT - 80); | |
| ctx.stroke(); | |
| } | |
| // Pipes | |
| for (let i = 0; i < pipes.length; i++) { | |
| const p = pipes[i]; | |
| const gap = 150; | |
| const topHeight = p.top; | |
| const bottomY = p.bottom; | |
| // top pipe | |
| ctx.fillStyle = '#4a9e4a'; | |
| ctx.fillRect(p.x, 0, p.width, topHeight); | |
| ctx.fillStyle = '#2d7a2d'; | |
| ctx.fillRect(p.x - 5, topHeight - 20, p.width + 10, 20); | |
| // bottom pipe | |
| ctx.fillStyle = '#4a9e4a'; | |
| ctx.fillRect(p.x, bottomY, p.width, HEIGHT - bottomY); | |
| ctx.fillStyle = '#2d7a2d'; | |
| ctx.fillRect(p.x - 5, bottomY, p.width + 10, 20); | |
| // pipe highlight | |
| ctx.fillStyle = '#6ccb6c'; | |
| ctx.fillRect(p.x + 5, 0, 10, topHeight - 20); | |
| ctx.fillRect(p.x + 5, bottomY, 10, HEIGHT - bottomY); | |
| } | |
| // Ground | |
| ctx.fillStyle = '#c9a96e'; | |
| ctx.fillRect(0, HEIGHT - 80, WIDTH, 80); | |
| // Grass lines | |
| ctx.strokeStyle = '#8b6f3e'; | |
| ctx.lineWidth = 2; | |
| for (let i = 0; i < WIDTH; i += 15) { | |
| ctx.beginPath(); | |
| ctx.moveTo(i, HEIGHT - 80); | |
| ctx.lineTo(i + 10, HEIGHT - 70); | |
| ctx.stroke(); | |
| } | |
| // Bird | |
| ctx.fillStyle = '#ffcc00'; | |
| ctx.strokeStyle = '#b8860b'; | |
| ctx.lineWidth = 2; | |
| ctx.beginPath(); | |
| ctx.arc(BIRD_X, bird.y, 12, 0, Math.PI * 2); | |
| ctx.fill(); | |
| ctx.stroke(); | |
| // Eye | |
| ctx.fillStyle = '#000'; | |
| ctx.beginPath(); | |
| ctx.arc(BIRD_X + 5, bird.y - 5, 3, 0, Math.PI * 2); | |
| ctx.fill(); | |
| // Beak | |
| ctx.fillStyle = '#ff6600'; | |
| ctx.beginPath(); | |
| ctx.moveTo(BIRD_X + 10, bird.y - 4); | |
| ctx.lineTo(BIRD_X + 18, bird.y); | |
| ctx.lineTo(BIRD_X + 10, bird.y + 4); | |
| ctx.fill(); | |
| // Score | |
| ctx.font = '20px Arial'; | |
| ctx.fillStyle = 'white'; | |
| ctx.fillText(score, 20, 40); | |
| // Game over | |
| if (gameOver) { | |
| ctx.fillStyle = 'rgba(0,0,0,0.7)'; | |
| ctx.fillRect(0, 0, WIDTH, HEIGHT); | |
| ctx.font = '30px Arial'; | |
| ctx.fillStyle = 'white'; | |
| ctx.fillText('Game Over', 80, 250); | |
| ctx.font = '16px Arial'; | |
| ctx.fillText('Press Space or Click to restart', 70, 300); | |
| } | |
| } | |
| // ========== RESTART ========== | |
| function restart() { | |
| bird.y = 150; | |
| bird.vy = 0; | |
| pipes = []; | |
| score = 0; | |
| gameOver = false; | |
| frame = 0; | |
| // Reset any other state | |
| } | |
| // ========== KEY/CLICK ========== | |
| document.addEventListener('keydown', function(e) { | |
| if (e.code === 'Space') { | |
| e.preventDefault(); | |
| if (gameOver) { | |
| restart(); | |
| } else { | |
| bird.vy = -4.2; | |
| } | |
| } | |
| }); | |
| canvas.addEventListener('click', function(e) { | |
| if (gameOver) { | |
| restart(); | |
| } else { | |
| bird.vy = -4.2; | |
| } | |
| }); | |
| // start the game | |
| restart(); | |
| requestAnimationFrame(gameLoop);</script> | |
| </body> | |
| </html> |