Instructions to use moondream/moondream-2b-2025-04-14-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use moondream/moondream-2b-2025-04-14-4bit with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="moondream/moondream-2b-2025-04-14-4bit", filename="moondream2-mmproj-f16.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use moondream/moondream-2b-2025-04-14-4bit with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf moondream/moondream-2b-2025-04-14-4bit:F16 # Run inference directly in the terminal: llama-cli -hf moondream/moondream-2b-2025-04-14-4bit:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf moondream/moondream-2b-2025-04-14-4bit:F16 # Run inference directly in the terminal: llama-cli -hf moondream/moondream-2b-2025-04-14-4bit:F16
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf moondream/moondream-2b-2025-04-14-4bit:F16 # Run inference directly in the terminal: ./llama-cli -hf moondream/moondream-2b-2025-04-14-4bit:F16
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf moondream/moondream-2b-2025-04-14-4bit:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf moondream/moondream-2b-2025-04-14-4bit:F16
Use Docker
docker model run hf.co/moondream/moondream-2b-2025-04-14-4bit:F16
- LM Studio
- Jan
- vLLM
How to use moondream/moondream-2b-2025-04-14-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moondream/moondream-2b-2025-04-14-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moondream/moondream-2b-2025-04-14-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/moondream/moondream-2b-2025-04-14-4bit:F16
- Ollama
How to use moondream/moondream-2b-2025-04-14-4bit with Ollama:
ollama run hf.co/moondream/moondream-2b-2025-04-14-4bit:F16
- Unsloth Studio
How to use moondream/moondream-2b-2025-04-14-4bit with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for moondream/moondream-2b-2025-04-14-4bit to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for moondream/moondream-2b-2025-04-14-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for moondream/moondream-2b-2025-04-14-4bit to start chatting
- Atomic Chat new
- Docker Model Runner
How to use moondream/moondream-2b-2025-04-14-4bit with Docker Model Runner:
docker model run hf.co/moondream/moondream-2b-2025-04-14-4bit:F16
- Lemonade
How to use moondream/moondream-2b-2025-04-14-4bit with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull moondream/moondream-2b-2025-04-14-4bit:F16
Run and chat with the model
lemonade run user.moondream-2b-2025-04-14-4bit-F16
List all available models
lemonade list
snowclipsed commited on
Commit ·
8f87bef
1
Parent(s): fa2446a
safely remove text_model loading in weights.py
Browse files- weights.py +0 -34
weights.py
CHANGED
|
@@ -162,24 +162,6 @@ def load_weights_from_safetensors(weights_file: str, model: nn.Module) -> None:
|
|
| 162 |
with safetensors_open(weights_file) as get_tensor:
|
| 163 |
all_keys = get_tensor.keys()
|
| 164 |
|
| 165 |
-
# is_quantized = any(
|
| 166 |
-
# ".qweight" in key or "_quantized" in key or "quant." in key
|
| 167 |
-
# for key in all_keys
|
| 168 |
-
# )
|
| 169 |
-
|
| 170 |
-
if "text_model.transformer.h.0.ln.weight" in all_keys:
|
| 171 |
-
layernorm_dtype = get_tensor("text_model.transformer.h.0.ln.weight").dtype
|
| 172 |
-
else:
|
| 173 |
-
layernorm_dtype = torch.float16
|
| 174 |
-
|
| 175 |
-
# linear_dtype = torch.int8 if is_quantized else torch.float16
|
| 176 |
-
|
| 177 |
-
model.text = build_text_model(
|
| 178 |
-
TextConfig
|
| 179 |
-
)
|
| 180 |
-
if model.setup_caches_flag:
|
| 181 |
-
model._setup_caches()
|
| 182 |
-
|
| 183 |
if (
|
| 184 |
"vision.blocks.0.attn.proj.bias" in all_keys
|
| 185 |
or "model.vision.blocks.0.attn.proj.bias" in all_keys
|
|
@@ -201,22 +183,6 @@ def load_weights_from_pt(weights_file: str, model: nn.Module) -> None:
|
|
| 201 |
"""Load weights from a PyTorch file into a MoondreamModel instance."""
|
| 202 |
tensors = torch.load(weights_file, map_location="cpu", weights_only=True)
|
| 203 |
all_keys = tensors.keys()
|
| 204 |
-
# is_quantized = any(
|
| 205 |
-
# ".qweight" in key or "_quantized" in key or "quant." in key for key in all_keys
|
| 206 |
-
# )
|
| 207 |
-
|
| 208 |
-
if "text.blocks.0.ln.weight" in all_keys:
|
| 209 |
-
layernorm_dtype = tensors["text.blocks.0.ln.weight"].dtype
|
| 210 |
-
else:
|
| 211 |
-
layernorm_dtype = torch.float16
|
| 212 |
-
|
| 213 |
-
# linear_dtype = torch.int8 if is_quantized else torch.float16
|
| 214 |
-
model.text = build_text_model(
|
| 215 |
-
TextConfig
|
| 216 |
-
)
|
| 217 |
-
if model.setup_caches_flag:
|
| 218 |
-
model._setup_caches()
|
| 219 |
-
|
| 220 |
if (
|
| 221 |
"vision.blocks.0.attn.proj.bias" in all_keys
|
| 222 |
or "model.vision.blocks.0.attn.proj.bias" in all_keys
|
|
|
|
| 162 |
with safetensors_open(weights_file) as get_tensor:
|
| 163 |
all_keys = get_tensor.keys()
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
if (
|
| 166 |
"vision.blocks.0.attn.proj.bias" in all_keys
|
| 167 |
or "model.vision.blocks.0.attn.proj.bias" in all_keys
|
|
|
|
| 183 |
"""Load weights from a PyTorch file into a MoondreamModel instance."""
|
| 184 |
tensors = torch.load(weights_file, map_location="cpu", weights_only=True)
|
| 185 |
all_keys = tensors.keys()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
if (
|
| 187 |
"vision.blocks.0.attn.proj.bias" in all_keys
|
| 188 |
or "model.vision.blocks.0.attn.proj.bias" in all_keys
|