Image-Text-to-Text
Transformers
Safetensors
lfm2_vl
liquid
lfm2.5
edge
decision
classification
calibration
system-one
multimodal
decision-model
conversational
custom_code
Instructions to use LiquidAI/d1-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/d1-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LiquidAI/d1-3B", 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("LiquidAI/d1-3B", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("LiquidAI/d1-3B", trust_remote_code=True, device_map="auto") 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?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LiquidAI/d1-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LiquidAI/d1-3B" # 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-3B", "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-3B
- SGLang
How to use LiquidAI/d1-3B 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-3B" \ --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-3B", "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-3B" \ --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-3B", "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-3B with Docker Model Runner:
docker model run hf.co/LiquidAI/d1-3B
Download api.py from LiquidAI/d1-3B: direct link, hf CLI and curl.
- Browser
- Download file 3.48 kB
-
https://huggingface.co/LiquidAI/d1-3B/resolve/refs%2Fpr%2F6/api.py
- Command line
-
hf download hf://LiquidAI/d1-3B@refs/pr/6/api.py
-
curl -L -o api.py https://huggingface.co/LiquidAI/d1-3B/resolve/refs%2Fpr%2F6/api.py
3.48 kB
| """The System One API: named questions over a state in, typed answers out. | |
| model.system_one(state, {"refund": {"type": "noul", "instructions": "Is this a refund request?"}}) | |
| # {"answers": {"refund": {"type": "noul", "noul": p}}, "usage": {"input_tokens": n, "output_tokens": 0}} | |
| A state is a string, any JSON value, or None with pictures alone. A question is a dict in the Decision | |
| Index's schema (`type`, `instructions`, `criteria`) or one of `prompt`'s classes. | |
| """ | |
| from __future__ import annotations | |
| from collections.abc import Mapping, Sequence | |
| from typing import Any | |
| from .prompt import Choice, Noul, Question, as_question | |
| def answer(q: Question, probs: Sequence[float]) -> dict: | |
| """A noul's P(yes); a choice's pick and its probabilities; a score's expected level.""" | |
| if isinstance(q, Noul): | |
| return {"type": "noul", "noul": probs[0]} | |
| best = max(range(len(probs)), key=probs.__getitem__) | |
| if isinstance(q, Choice): | |
| names = list(q.criteria) | |
| return {"type": "choice", "choice": names[best], "confidence": probs[best], | |
| "probabilities": dict(zip(names, probs))} | |
| return {"type": "score", "score": sum(i * p for i, p in enumerate(probs)), "confidence": probs[best], | |
| "probabilities": {str(i): p for i, p in enumerate(probs)}, | |
| "legend": {str(i): text for i, text in enumerate(q.criteria)}} | |
| class SystemOneApi: | |
| """`system_one` and `system_one_batch`, and the plain probabilities under them, over a model's | |
| `run(requests)`: each `(state, questions, images)` request's probabilities (in its questions' order) | |
| and the tokens it read.""" | |
| def run(self, requests: Sequence[tuple[Any, list[Question], Sequence]]) -> list[tuple[list[list[float]], int]]: | |
| raise NotImplementedError | |
| def probabilities(self, state: Any, questions: Sequence, images: Sequence | None = None) -> list[list[float]]: | |
| """Each question's distribution over its options (`yes`, `no` for a noul), in one pass.""" | |
| return self.run([(state, [as_question(q) for q in questions], images or ())])[0][0] | |
| def probabilities_batch(self, requests: Sequence[tuple]) -> list[list[list[float]]]: | |
| """`probabilities` for many `(state, questions[, images])` requests, packed as `system_one_batch`.""" | |
| reqs = [(r[0], [as_question(q) for q in r[1]], (r[2] if len(r) > 2 else None) or ()) for r in requests] | |
| return [probs for probs, _ in self.run(reqs)] | |
| def system_one(self, state: Any, questions: Mapping[str, Any], images: Sequence | None = None) -> dict: | |
| """Named questions over one state, and its pictures if any, in one forward pass.""" | |
| return self.system_one_batch([(state, questions, images)])[0] | |
| def system_one_batch(self, requests: Sequence[tuple]) -> list[dict]: | |
| """Many `(state, questions)` or `(state, questions, images)` requests. Single-question requests | |
| are packed together with no padding; a request with several questions reads its state once.""" | |
| named = [(r[0], {n: as_question(q) for n, q in r[1].items()}, (r[2] if len(r) > 2 else None) or ()) | |
| for r in requests] | |
| done = self.run([(state, list(qs.values()), images) for state, qs, images in named]) | |
| return [{"answers": {n: answer(q, p) for (n, q), p in zip(qs.items(), probs)}, | |
| "usage": {"input_tokens": read, "output_tokens": 0}} | |
| for (_, qs, _), (probs, read) in zip(named, done)] | |