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
Eval Results
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
fuse_projections: view a group already in one storage instead of copying it
#3
by joe32140 - opened
lfm3.py
CHANGED
|
@@ -135,12 +135,26 @@ def fuse_projections(model) -> None:
|
|
| 135 |
names = SHARED_INPUT.get(type(m).__name__, ())
|
| 136 |
linears = [getattr(m, n, None) for n in names]
|
| 137 |
if names and all(type(lin) is torch.nn.Linear and lin.bias is None for lin in linears):
|
| 138 |
-
m.fused = Fused(
|
| 139 |
for i, name in enumerate(names):
|
| 140 |
setattr(m, name, Part(m.fused, i))
|
| 141 |
m.register_state_dict_post_hook(_unfused)
|
| 142 |
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
def _unfused(module, state_dict, prefix, local_metadata) -> None:
|
| 145 |
fused = module.fused
|
| 146 |
weight = state_dict.pop(prefix + "fused.weight")
|
|
|
|
| 135 |
names = SHARED_INPUT.get(type(m).__name__, ())
|
| 136 |
linears = [getattr(m, n, None) for n in names]
|
| 137 |
if names and all(type(lin) is torch.nn.Linear and lin.bias is None for lin in linears):
|
| 138 |
+
m.fused = Fused(_stacked([lin.weight for lin in linears]), names, [lin.out_features for lin in linears])
|
| 139 |
for i, name in enumerate(names):
|
| 140 |
setattr(m, name, Part(m.fused, i))
|
| 141 |
m.register_state_dict_post_hook(_unfused)
|
| 142 |
|
| 143 |
|
| 144 |
+
def _stacked(weights: list[torch.Tensor]) -> torch.Tensor:
|
| 145 |
+
"""`weights` stacked by rows: a view when they already sit back to back in one storage, in this order, else a
|
| 146 |
+
copy. A freshly loaded model's linears each own their storage, so this copies and the old weights are freed.
|
| 147 |
+
Linears that are slices of one merged tensor something else keeps would otherwise be held twice (d1-2B: 1.5 GiB)."""
|
| 148 |
+
first = weights[0].detach()
|
| 149 |
+
storage, offset = first.untyped_storage().data_ptr(), first.storage_offset()
|
| 150 |
+
for w in weights:
|
| 151 |
+
if (w.untyped_storage().data_ptr() != storage or w.storage_offset() != offset or not w.is_contiguous()
|
| 152 |
+
or w.dtype != first.dtype or w.shape[1:] != first.shape[1:]):
|
| 153 |
+
return torch.cat(weights)
|
| 154 |
+
offset += w.numel()
|
| 155 |
+
return first.as_strided((sum(w.shape[0] for w in weights), *first.shape[1:]), first.stride())
|
| 156 |
+
|
| 157 |
+
|
| 158 |
def _unfused(module, state_dict, prefix, local_metadata) -> None:
|
| 159 |
fused = module.fused
|
| 160 |
weight = state_dict.pop(prefix + "fused.weight")
|