Instructions to use ewre324/moondream2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ewre324/moondream2 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf ewre324/moondream2:F16 # Run inference directly in the terminal: llama cli -hf ewre324/moondream2:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf ewre324/moondream2:F16 # Run inference directly in the terminal: llama cli -hf ewre324/moondream2: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 ewre324/moondream2:F16 # Run inference directly in the terminal: ./llama-cli -hf ewre324/moondream2: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 ewre324/moondream2:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf ewre324/moondream2:F16
Use Docker
docker model run hf.co/ewre324/moondream2:F16
- LM Studio
- Jan
- vLLM
How to use ewre324/moondream2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ewre324/moondream2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ewre324/moondream2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ewre324/moondream2:F16
- Ollama
How to use ewre324/moondream2 with Ollama:
ollama run hf.co/ewre324/moondream2:F16
- Unsloth Desktop
- Docker Model Runner
How to use ewre324/moondream2 with Docker Model Runner:
docker model run hf.co/ewre324/moondream2:F16
- Lemonade
How to use ewre324/moondream2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ewre324/moondream2:F16
Run and chat with the model
lemonade run user.moondream2-F16
List all available models
lemonade list
- Atomic Chat
| import torch | |
| import math | |
| from .weights import RegionModel | |
| from .layers import linear, mlp | |
| def fourier_features(x: torch.Tensor, w: torch.Tensor) -> torch.Tensor: | |
| """ | |
| Applies Fourier feature mapping to input tensor x using frequency matrix w. This | |
| projects inputs through sinusoidal functions to create higher dimensional features | |
| that help mitigate spectral bias - the tendency of neural networks to learn | |
| low-frequency functions more easily than high-frequency ones. By explicitly | |
| mapping inputs to higher frequencies through sin/cos transformations, we enable | |
| better learning of fine details and higher frequency patterns. | |
| Args: | |
| x: Input tensor to transform | |
| w: Matrix of frequencies for the Fourier features transformation | |
| Returns: | |
| Concatenated cosine and sine transformed features as a tensor | |
| """ | |
| f = 2 * math.pi * x @ w | |
| return torch.cat([f.cos(), f.sin()], dim=-1) | |
| def encode_coordinate(coord: torch.Tensor, w: RegionModel) -> torch.Tensor: | |
| """ | |
| Takes as input a tensor containing a single float coordinate value (x or y) | |
| and encodes it into hidden states for input to the text model. | |
| Args: | |
| coord: Tensor with single float coordinate value | |
| Returns: | |
| Encoded hidden states tensor for input to text model | |
| """ | |
| return linear(fourier_features(coord, w.coord_features), w.coord_encoder) | |
| def decode_coordinate(hidden_state: torch.Tensor, w: RegionModel) -> torch.Tensor: | |
| """ | |
| Takes as input the last hidden state from the text model and outputs a single logit | |
| representing either an x or y coordinate prediction. | |
| Args: | |
| hidden_state: The final hidden state tensor from the text model. | |
| Returns: | |
| A single logit representing the predicted coordinate value (x or y) | |
| """ | |
| return mlp(hidden_state, w.coord_decoder) | |
| def encode_size(size: torch.Tensor, w: RegionModel) -> torch.Tensor: | |
| """ | |
| Takes a tensor containing normalized width and height values in range [0,1] | |
| and encodes them into hidden states for input to the text model. | |
| Args: | |
| size: Tensor with two floats for width and height in range [0,1] | |
| Returns: | |
| Encoded hidden states tensor for input to text model | |
| """ | |
| return linear(fourier_features(size, w.size_features), w.size_encoder) | |
| def decode_size(hidden_state: torch.Tensor, w: RegionModel) -> torch.Tensor: | |
| """ | |
| Takes as input the last hidden state from the text model and outputs two logits | |
| for width and height respectively. | |
| Args: | |
| hidden_state: The final hidden state tensor from the text model. | |
| Returns: | |
| A tensor containing two logits - one for predicted width and one for | |
| predicted height. | |
| """ | |
| return mlp(hidden_state, w.size_decoder).view(2, -1) | |