Image-Text-to-Text
Transformers
Safetensors
lfm3_vl
feature-extraction
liquid
lfm3
edge
decision
classification
extraction
calibration
system-one
multimodal
decision-model
custom_code
conversational
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
Download slots.py from LiquidAI/d1-2B: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/LiquidAI/d1-2B/resolve/main/slots.py
- Command line
-
hf download hf://LiquidAI/d1-2B/slots.py
-
curl -L -o slots.py https://huggingface.co/LiquidAI/d1-2B/resolve/main/slots.py
2.46 kB
| """Answer positions of a right-padded batch, read through whatever wraps the model.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| import torch | |
| from .attention import state_attention, text_backbone | |
| class SlotLogits: | |
| """A batch's answer slots: the code slots' logits, in slot order, and the read slots' over their rows' state | |
| positions, in the pointer plan's order (pointer.py `query_plan`).""" | |
| codes: torch.Tensor | |
| positions: torch.Tensor | None = None | |
| def split(slots: torch.Tensor, states: torch.Tensor | None, plan: dict | None, project) -> SlotLogits: | |
| """The hidden states at the slots [S, D]: the code slots through `project` (the LM head, or its option rows), | |
| the read slots against their rows' state positions `states` [R, T, D].""" | |
| if plan is None: | |
| return SlotLogits(project(slots)) | |
| from .pointer import read_logits | |
| return SlotLogits(project(slots[plan["code_slots"].to(slots.device)]), read_logits(slots, states, plan)) | |
| def output_head(model): | |
| """The LM head, through whatever wrappers are in the way.""" | |
| head = getattr(model, "module", model).get_output_embeddings() | |
| if head is None: | |
| raise RuntimeError("no output embedding on this model") | |
| return head | |
| def slot_logits( | |
| model, | |
| ids: torch.Tensor, | |
| mask: torch.Tensor, | |
| last: torch.Tensor, | |
| state_len: torch.Tensor | None = None, | |
| question: torch.Tensor | None = None, | |
| row: torch.Tensor | None = None, | |
| pointer: dict | None = None, | |
| **vision, | |
| ): | |
| """Logits at one position per row (or at each `row`, `last` pair: a question may have several slots in a row), | |
| the backbone read directly and only the slots projected, never `B x T x vocab`. `vision`: the processor's picture | |
| inputs, for a vision-language model.""" | |
| with state_attention(model, state_len, question): # None: the model's own causal mask | |
| out = text_backbone(model)(input_ids=ids, attention_mask=mask, use_cache=False, **vision) | |
| hidden = getattr(out, "last_hidden_state", None) | |
| if hidden is None: | |
| hidden = out[0] | |
| row = torch.arange(hidden.size(0)) if row is None else row | |
| slots = hidden[row.to(hidden.device), last.to(hidden.device)] # a model over GPUs ends elsewhere | |
| states = hidden[pointer["rows"].to(hidden.device), : pointer["width"]] if pointer is not None else None | |
| return split(slots, states, pointer, output_head(model)) | |