Instructions to use LiquidAI/d1-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/d1-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LiquidAI/d1-2B", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("LiquidAI/d1-2B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LiquidAI/d1-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LiquidAI/d1-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiquidAI/d1-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/LiquidAI/d1-2B
- SGLang
How to use LiquidAI/d1-2B 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 "LiquidAI/d1-2B" \ --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": "LiquidAI/d1-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "LiquidAI/d1-2B" \ --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": "LiquidAI/d1-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use LiquidAI/d1-2B with Docker Model Runner:
docker model run hf.co/LiquidAI/d1-2B
Check that torch has flash attention before taking the flash path (fixes CUDA on Windows)
On Windows, the official CUDA builds of torch ship without flash attention. _fused only checks the GPU generation, so any Ampere or newer card takes the flash path and the first system_one call fails:
RuntimeError: USE_FLASH_ATTENTION was not enabled for build.
attention.py, line 80, in causal_attention
out = torch.ops.aten._flash_attention_forward(...)
Setup: Windows 11, RTX laptop GPU (Ampere or newer), torch 2.6.0+cu124, transformers 5.22.2, bf16.
This PR adds torch.backends.cuda.is_flash_attention_available() to _fused. When flash is missing, every call site already falls back to its SDPA path (causal_attention, _windowed and Sees.attend), so nothing else changes. On builds that have flash, _fused returns the same value as before.
def _fused(q: torch.Tensor) -> bool:
"""Whether the flash kernels take these queries: a GPU in half precision, ROCm or CUDA from Ampere on."""
if not q.is_cuda or q.dtype not in (torch.float16, torch.bfloat16):
return False
if not torch.backends.cuda.is_flash_attention_available():
return False
return bool(torch.version.hip) or torch.cuda.get_device_capability(q.device)[0] >= 8
Tested with this change on the machine above: system_one runs, and our 20-sentence French intent set (one choice question, 9 options) gives the same answers as with _fused forced off, at a median of 91 ms per call. With is_flash_attention_available forced to True, the patched _fused takes the flash path again, so builds that have flash keep their current behaviour.
The same check is in d1-Omni-2B/attention.py (identical file) and d1-3B/hybrid.py (_fused, line 123). I can open the same PR there if that helps.
Context: we're testing d1-2B as the intent router of a local voice assistant (Mnemosyne OS), on French speech. Thanks for the open d1 release!