Image-Text-to-Text
Transformers
Safetensors
deepseek_v41
text-generation
nvfp4
fp4
deepseek
Mixture of Experts
multimodal
libertai
8-bit precision
fp8
Instructions to use LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4
- SGLang
How to use LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4 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 "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4 with Docker Model Runner:
docker model run hf.co/LibertAIDAI/DeepSeek-V4.1-Flash-NVFP4
| #!/usr/bin/env python3 | |
| """Prove the MXFP4->NVFP4 expert transcode is bit-exact, and measure the Engram FP4 loss. | |
| Reconstructs values from BOTH representations and compares: | |
| source : FP4_TABLE[nibble] * scale_e8m0 | |
| output : FP4_TABLE[nibble] * scale_e4m3 * global_f32 | |
| A single non-identical element fails the run. | |
| """ | |
| import json, os, sys | |
| import torch | |
| from safetensors import safe_open | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from dsv41_fp4_stream import (FP4_TABLE, SRC_BLOCK, NVFP4_BLOCK, EXPERT_RE, ENGRAM_RE, | |
| unpack_e2m1) | |
| src_dir, out_dir, shard = sys.argv[1], sys.argv[2], sys.argv[3] | |
| sf = safe_open(os.path.join(src_dir, shard), framework="pt") | |
| of = safe_open(os.path.join(out_dir, shard), framework="pt") | |
| src_keys, out_keys = set(sf.keys()), set(of.keys()) | |
| n_exp = n_bad = 0 | |
| max_abs = 0.0 | |
| checked_elems = 0 | |
| for name in sorted(src_keys): | |
| if not EXPERT_RE.match(name): | |
| continue | |
| base = name[:-len(".weight")] | |
| a = unpack_e2m1(sf.get_tensor(name)) | |
| sa = sf.get_tensor(base + ".scale").float() | |
| ref = a.view(a.shape[0], -1, SRC_BLOCK) * sa.unsqueeze(-1) | |
| ref = ref.reshape(a.shape) | |
| b = unpack_e2m1(of.get_tensor(base + ".weight")) | |
| sb = of.get_tensor(base + ".weight_scale").float() | |
| g = of.get_tensor(base + ".weight_scale_2").float() | |
| got = b.view(b.shape[0], -1, NVFP4_BLOCK) * (sb * g).unsqueeze(-1) | |
| got = got.reshape(b.shape) | |
| d = (ref - got).abs().max().item() | |
| max_abs = max(max_abs, d) | |
| if d != 0.0: | |
| n_bad += 1 | |
| if n_bad <= 3: | |
| print(f" MISMATCH {base} max|d|={d:.6g}") | |
| n_exp += 1 | |
| checked_elems += ref.numel() | |
| if n_exp >= 200: # 200 experts is plenty and keeps the check quick | |
| break | |
| print(f"[experts] {n_exp} weights checked ({checked_elems/1e6:.1f}M elements), " | |
| f"mismatches={n_bad}, max|delta|={max_abs:.6g}") | |
| n_eng = 0 | |
| for name in sorted(src_keys): | |
| if not ENGRAM_RE.match(name): | |
| continue | |
| base = name[:-len(".weight")] | |
| rows = 65536 | |
| w = sf.get_slice(name)[:rows] | |
| s = sf.get_slice(base + ".scale")[:rows].float() | |
| ref = w.float().view(rows, -1, SRC_BLOCK) * s.unsqueeze(-1) | |
| b = unpack_e2m1(of.get_slice(base + ".weight")[:rows]) | |
| sb = of.get_slice(base + ".scale")[:rows].float() | |
| got = b.view(rows, -1, SRC_BLOCK) * sb.unsqueeze(-1) | |
| a2, b2 = ref.flatten(1), got.flatten(1) | |
| num = (a2 * b2).sum(1); den = a2.norm(dim=1) * b2.norm(dim=1) | |
| ok = den > 0 | |
| cos = (num[ok] / den[ok]) | |
| rel = ((a2 - b2).norm(dim=1) / a2.norm(dim=1).clamp(min=1e-30))[ok] | |
| print(f"[engram] {base} rows={rows} cos mean={cos.mean():.6f} min={cos.min():.6f} " | |
| f"rel-err mean={rel.mean():.4f}") | |
| n_eng += 1 | |
| if n_eng == 0: | |
| print("[engram] none in this shard") | |
| print("RESULT:", "LOSSLESS" if n_bad == 0 and n_exp > 0 else ("FAIL" if n_bad else "no experts here")) | |