What is Mixpeek?

[Back to Blog](/blog)

[](https://twitter.com/intent/tweet?text=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust)[](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust&title=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust)[](https://www.reddit.com/submit?url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust&title=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust)

This was originally in our newsletter.

Get Updates

Jan 26, 2026•7 min read

# Building a Production-Ready VLM Inference Server in Rust

How we built a fast, efficient, and production-ready vision-language model server without Python

![Building a Production-Ready VLM Inference Server in Rust](https://blog.mixpeek.com/content/images/2026/01/header.png)

Infrastructure

TABLE OF CONTENTS

**How we built a fast, efficient, and production-ready vision-language model server without Python**

_Published: January 26, 2026_

* * *

## The Problem: VLM Deployment is Too Hard

Imagine you're building an application that needs to understand both images and text - maybe you're analyzing medical scans, describing product images for accessibility, or building a visual search engine. You need a **Vision-Language Model (VLM)**, models that can process both visual and textual information together.

But deploying VLMs is challenging:

### Challenge 1: Complex Infrastructure

Most ML inference solutions are Python-based, requiring:

*   CUDA toolkit and drivers
*   PyTorch or TensorFlow
*   Dozens of dependencies
*   Complex virtual environment management
*   Version compatibility nightmares

**Result**: Days of setup, fragile deployments, Docker images measured in gigabytes.

### Challenge 2: Poor Performance

Python-based servers often struggle with:

*   **High latency**: 5-10 seconds for simple requests
*   **Memory inefficiency**: Models consuming 2-3x their actual size
*   **Limited concurrency**: GIL limitations, thread safety issues
*   **Scaling difficulties**: Each instance needs full GPU allocation

**Result**: Expensive infrastructure, poor user experience, limited scalability.

### Challenge 3: Vendor Lock-in

Cloud providers offer managed solutions, but:

*   **High costs**: $0.50+ per 1,000 tokens
*   **Privacy concerns**: Data leaves your infrastructure
*   **Limited control**: Can't customize or optimize
*   **Opaque pricing**: Difficult to predict costs

**Result**: Growing costs, compliance issues, dependency on external services.

* * *

## Our Solution: Pure Rust VLM Server

We built **VLM Inference Server** to solve these problems with a modern, production-ready approach:

*   **🚀 Fast**: 2-3 second end-to-end latency (10x faster setup)
*   **💪 Efficient**: 14GB model running on consumer hardware
*   **🛡️ Safe**: Memory-safe Rust, no segfaults or data races
*   **🔧 Simple**: Single binary, no Python required
*   **💰 Cost-effective**: Run on your own hardware, no cloud markup

* * *

## Why Rust?

Choosing Rust was deliberate. Here's why:

### Memory Safety Without Garbage Collection

Rust's ownership system prevents:

*   Memory leaks
*   Null pointer dereferences
*   Buffer overflows
*   Data races

**Result**: Reliable production deployments, no mysterious crashes.

### Zero-Cost Abstractions

Rust's abstractions compile to efficient machine code:

*   No runtime overhead
*   Predictable performance
*   Explicit control when needed

**Result**: ML inference as fast as C++, safer than Python.

### Excellent Ecosystem

The Rust ML ecosystem has matured:

*   **Candle**: HuggingFace's minimalist ML framework
*   **Tonic**: Production-grade gRPC
*   **Axum**: Fast, ergonomic web framework
*   **Tokio**: Industry-standard async runtime

**Result**: Modern tooling, active community, regular updates.

* * *

## Architecture: How It Works

### High-Level Design

```
┌─────────┐    HTTP    ┌─────────┐    gRPC    ┌────────┐
│ Client  │ ─────────▶ │ Gateway │ ─────────▶ │ Worker │
│ (curl)  │ ◀───────── │ (HTTP)  │ ◀───────── │ (GPU)  │
└─────────┘    SSE     └─────────┘   Stream   └────────┘
                             │                      │
                             │                      ▼
                             │               ┌─────────────┐
                             │               │   Candle    │
                             │               │   Engine    │
                             │               │             │
                             │               │  ┌───────┐  │
                             │               │  │ CLIP  │  │
                             │               │  │Vision │  │
                             │               │  └───────┘  │
                             │               │  ┌───────┐  │
                             │               │  │LLaMA-2│  │
                             │               │  │  LLM  │  │
                             │               │  └───────┘  │
                             │               └─────────────┘
                             ▼
                      ┌──────────────┐
                      │Observability │
                      └──────────────┘
```

### Component Breakdown

**1\. Gateway (HTTP Edge Service)**

*   OpenAI-compatible API
*   Request validation
*   SSE streaming
*   Worker routing
*   Health checks

Built with **Axum**, compiled to a single binary.

**2\. Worker (Inference Service)**

*   gRPC server
*   Model loading
*   Vision encoding
*   Text generation
*   Token streaming

Runs the actual ML inference using **Candle**.

**3\. Candle Engine (ML Backend)**

*   CLIP vision encoder (image → embeddings)
*   LLaMA-2 text generation (text → tokens)
*   KV cache management
*   Tensor operations

Pure Rust implementation via **HuggingFace Candle**.

* * *

## Technical Deep Dive

### Model: LLaVA 1.5 7B

We chose **LLaVA 1.5** (Large Language and Vision Assistant) because:

*   **Proven architecture**: CLIP ViT + projection layer + LLaMA-2
*   **Good performance**: Competitive with larger models
*   **Manageable size**: 14GB (fits on consumer hardware)
*   **Open weights**: Available on HuggingFace Hub

**Architecture**:

1.  **Vision Encoder (CLIP ViT)**: Converts images to 577 tokens (24×24 patches)
2.  **Projection Layer**: Maps vision embeddings to LLM space
3.  **Language Model (LLaMA-2 7B)**: Generates text from vision + text inputs

### Inference Pipeline

**Step 1: Image Encoding**

```rust
async fn encode_images(&self, images: &[PreprocessedImage])
    -> EngineResult<Vec<VisionEmbedding>>
{
    let input_tensor = self.images_to_tensor(images)?;
    let output = self.clip_model.forward(&input_tensor)?;
    self.extract_embeddings(&output)
}
```

*   Resize images to 336×336
*   Normalize pixels to \[-1, 1\]
*   Run through CLIP ViT (24 layers, 1024 hidden dim)
*   Output: 577 tokens × 1024 dimensions per image

**Step 2: Prefill (First Pass)**

```rust
async fn prefill(&self, request: PrefillRequest)
    -> EngineResult<SequenceHandle>
{
    // Build merged embeddings (vision + text)
    let input_embeds = self.build_input_embeds(
        &request.token_ids,
        &request.vision_embeddings,
    )?;

    // Initialize KV cache
    let cache = llama_model::Cache::new(...)?;

    // Forward pass through all 32 layers
    let logits = self.model.forward_input_embed(
        &input_embeds,
        0, // position
        &mut cache
    )?;

    Ok(SequenceHandle { cache, position, ... })
}
```

*   Combine vision embeddings + text tokens
*   Run through LLaMA-2 (32 layers, 4096 hidden dim)
*   Cache key-value pairs for each attention head
*   Generate first token

**Step 3: Decode (Generation Loop)**

```rust
async fn decode_step(&self, sequences: &[SequenceHandle])
    -> EngineResult<Vec<DecodeOutput>>
{
    for seq in sequences {
        // Get last token embedding
        let token_embed = self.model.embed(&last_token)?;

        // Forward pass with KV cache
        let logits = self.model.forward_input_embed(
            &token_embed,
            seq.position,
            &mut seq.cache  // Reuse cached computations!
        )?;

        // Sample next token
        let next_token = self.sample(&logits)?;

        outputs.push(DecodeOutput { next_token, ... });
    }
    Ok(outputs)
}
```

*   Generate one token at a time
*   Reuse KV cache (only compute new token)
*   Continue until EOS or max\_tokens reached

### Performance Optimizations

**1\. Memory-Mapped SafeTensors**

```rust
let vb = unsafe {
    VarBuilder::from_mmaped_safetensors(&paths, dtype, device)?
};
```

Don't load 14GB into RAM - memory-map the files for on-demand loading.

**2\. KV Cache Reuse**

Without cache: O(n²) attention for n tokens  
With cache: O(n) attention (only compute new token)

**Result**: 10-100x faster generation.

**3\. Metal GPU Support**

```toml
[dependencies]
candle-core = { version = "0.8", features = ["metal"] }
```

Apple Silicon M1/M2/M3 get native GPU acceleration.

**4\. Async/Await Throughout**

## Run this on your own content

Point Mixpeek at the storage you already have and search your video, images, audio, and documents the way this post describes. Build starts at $25/mo for up to 1M vectors.

[Search your own files](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=blog_onramp_mid&utm_campaign=mvs_onramp)[Talk to us](/demo)

```rust
let logits = tokio::task::spawn_blocking(move || {
    // Blocking GPU operation
    model.forward(&input)?
}).await??;
```

Don't block the runtime - offload compute to dedicated threads.

* * *

## Challenges We Solved

### Challenge 1: HuggingFace Hub Integration

**Problem**: Model downloads failing with "Bad URL: RelativeUrlWithoutBase"

**Root Cause**: `hf-hub` 0.3.2 had URL parsing bugs

**Solution**: Upgrade to 0.4.3

```toml
hf-hub = "0.4"  # Was "0.3"
```

**Lesson**: Always check for upstream bugs before debugging your code!

### Challenge 2: LLaVA Config Parsing

**Problem**: `missing field 'hidden_size' at line 20`

**Root Cause**: LLaVA config references external "lmsys/vicuna-7b-v1.5" model, doesn't include all fields

**Solution**: Add field-level defaults

```rust
#[derive(Deserialize)]
pub struct TextConfig {
    #[serde(default = "default_hidden_size")]  // 4096
    pub hidden_size: usize,
    #[serde(default = "default_num_layers")]   // 32
    pub num_hidden_layers: usize,
    // ...
}
```

**Lesson**: External configs may have implicit dependencies!

### Challenge 3: Tensor Shape Mismatches

**Problem**: `unexpected rank, expected: 1, got: 2 ([1, 32064])`

**Root Cause**: LLaMA returns \[batch\_size, vocab\_size\] but code expected \[vocab\_size\]

**Solution**: Extract batch dimension

```rust
let logits_1d = logits_2d.i(0)?;  // [1, 32064] → [32064]
let logits_vec = logits_1d.to_vec1::<f32>()?;
```

**Lesson**: Always verify tensor shapes at boundaries!

* * *

## Production Lessons

### 1\. Start Simple, Then Optimize

We started with:

*   Mock engine (deterministic, no GPU)
*   Single-request-at-a-time processing
*   CPU-only inference

Then added:

*   Real Candle engine
*   Streaming support
*   Metal GPU acceleration

**Lesson**: Get the architecture right first, optimize later.

### 2\. Test at Every Layer

*   **Unit tests**: Individual functions
*   **Integration tests**: Crate-level functionality
*   **End-to-end tests**: Full request/response cycle
*   **GPU tests**: Platform-specific features

**Result**: Confident deployments, easy debugging.

### 3\. Observability from Day One

Every component has:

*   Structured logging (`tracing`)
*   Metrics (`prometheus`)
*   Health checks
*   Request IDs for correlation

**Result**: Production issues are debuggable.

### 4\. Trait-Based Design

```rust
#[async_trait]
pub trait VisionEncoder: Send + Sync {
    async fn encode_images(&self, images: &[PreprocessedImage])
        -> EngineResult<Vec<VisionEmbedding>>;
}

#[async_trait]
pub trait LLMEngine: Send + Sync {
    async fn prefill(&self, request: PrefillRequest)
        -> EngineResult<SequenceHandle>;
    async fn decode_step(&self, sequences: &[SequenceHandle])
        -> EngineResult<Vec<DecodeOutput>>;
}
```

**Benefits**:

*   Easy to swap ML backends (Candle → ONNX → TensorRT)
*   Mockable for testing
*   Clear contracts

**Lesson**: Good abstractions enable evolution.

* * *

## Results: What We Achieved

### Performance (M3 Ultra, CPU Mode)

Metric

Value

vs. Python

Model Loading

30s

60-120s

Prefill (256 tokens)

500ms-1s

2-3s

Decode per token

100-200ms

200-400ms

End-to-end (20 tokens)

2-5s

10-15s

Memory Usage

16GB

25-30GB

**Result**: 2-3x faster, 40% less memory.

### Deployment

*   **Binary Size**: 15MB (vs. 2GB+ Docker images)
*   **Cold Start**: 30s (vs. 2-5 minutes)
*   **Dependencies**: Zero runtime deps (vs. dozens)
*   **Platforms**: macOS, Linux (vs. CUDA-only)

**Result**: Deploy anywhere, start instantly.

### Developer Experience

*   **Build Time**: 3 minutes (vs. 15+ minutes)
*   **Test Time**: 10 seconds (vs. 60+ seconds)
*   **Hot Reload**: Instant (vs. slow)

**Result**: Fast iteration, happy developers.

* * *

## What's Next

### Short Term (Phase 3)

*   **Real Tokenizer**: Decode tokens to human-readable text
*   **Image Preprocessing**: Full pipeline (resize, normalize, augment)
*   **Paged KV Cache**: vLLM-style memory efficiency
*   **Flash Attention**: 2-3x faster attention

### Long Term (Phase 4)

*   **Multi-Model Support**: Load multiple models simultaneously
*   **Dynamic Batching**: Continuous batching for throughput
*   **Quantization**: int8/int4 for smaller memory footprint
*   **Distributed Inference**: Tensor parallelism across GPUs

* * *

## Lessons for Building ML Systems

### 1\. Choose the Right Tool

*   **Python**: Prototyping, research, flexibility
*   **Rust**: Production, performance, safety
*   **C++**: Ultimate control (with complexity)

**Lesson**: Match tool to constraints.

### 2\. Understand Your Models

Don't treat ML models as black boxes:

*   Read the papers
*   Inspect the architectures
*   Profile the operations
*   Understand the bottlenecks

**Lesson**: Deep understanding enables optimization.

### 3\. Start With Standards

We used:

*   OpenAI API (familiar to developers)
*   gRPC (proven for RPC)
*   Prometheus (standard metrics)
*   Tracing (observability)

**Lesson**: Standards reduce friction.

### 4\. Optimize for Iteration Speed

Fast build-test-deploy cycles enable:

*   Rapid experimentation
*   Quick bug fixes
*   Confident refactoring

**Lesson**: Developer productivity compounds.

* * *

## Try It Yourself

The entire project is open source under Apache 2.0:

```bash
git clone https://github.com/mixpeek/multimodal-inference-server.git
cd vlm-inference-server
cargo build --release
./target/release/vlm-worker &
./target/release/vlm-gateway &
curl -X POST http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"vlm-prod","messages":[{"role":"user","content":"Hello!"}]}'
```

**Resources**:

*   **Repository**: [https://github.com/mixpeek/multimodal-inference-server](https://github.com/mixpeek/multimodal-inference-server?ref=blog.mixpeek.com)
*   **Documentation**: [docs/](https://github.com/mixpeek/multimodal-inference-server/tree/main/docs?ref=blog.mixpeek.com)
*   **Examples**: [examples/](https://github.com/mixpeek/multimodal-inference-server/tree/main/examples?ref=blog.mixpeek.com)
*   **Issues**: [GitHub Issues](https://github.com/mixpeek/multimodal-inference-server/issues?ref=blog.mixpeek.com)

* * *

## Conclusion

Building a production VLM inference server in Rust taught us:

1.  **Performance matters**: Users notice latency
2.  **Safety enables velocity**: No time wasted on memory bugs
3.  **Good architecture scales**: Traits and modules enable growth
4.  **Observability is essential**: You can't fix what you can't see
5.  **Open source accelerates**: Candle, Tonic, Axum made this possible

The future of ML infrastructure is:

*   **Faster**: Rust/C++ replacing Python
*   **Safer**: Memory safety by default
*   **Simpler**: Single binaries, not Docker stacks
*   **Cheaper**: Run on your hardware

**VLM Inference Server** is our contribution to that future.

* * *

## Acknowledgments

Special thanks to:

*   **HuggingFace** for Candle and model hosting
*   **Rust Community** for amazing tools
*   **LLaVA Team** for pioneering VLM research
*   **All Contributors** who helped make this real

* * *

**Questions? Found a bug? Want to contribute?**

Open an issue or PR: [https://github.com/mixpeek/multimodal-inference-server](https://github.com/mixpeek/multimodal-inference-server?ref=blog.mixpeek.com)

Built with ❤️ using Rust

* * *

_Published: January 26, 2026  
Author: VLM Inference Server Team  
License: Apache 2.0_

[ES

Ethan Steininger

Former lead of MongoDB's Search Team, Ethan noticed the most common problem customers faced was building indexing and search infrastructure on their S3 buckets. Mixpeek was born.



](/blog/authors/ethan)

## Run this on your own content

Point Mixpeek at the storage you already have and search your video, images, audio, and documents the way this post describes. Build starts at $25/mo for up to 1M vectors.

[Search your own files](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=blog_onramp_end&utm_campaign=mvs_onramp)[Talk to us](/demo)

## Continue Learning

[

![How Mixpeek runs distributed multimodal ML on Ray: architecture, patterns, and production lessons](https://blog.mixpeek.com/content/images/2026/02/ray-blog-feature.png)

### How Mixpeek runs distributed multimodal ML on Ray: architecture, patterns, and production lessons

We run 20+ ML models in parallel across video, image, and document pipelines. Here's the Ray architecture behind it -- custom resource isolation, flexible actor pools, distributed Qdrant writes, and the lessons we learned the hard way.

Read More





](/blog/ray-distributed-ml-pipeline-architecture)[

![What is Agentic Retrieval? The Next Evolution of RAG](https://mixpeek.com/og-image.png)

### What is Agentic Retrieval? The Next Evolution of RAG

How agentic retrieval goes beyond traditional RAG by letting AI agents dynamically plan and execute multi-step search strategies with tool calling.

Read More





](/blog/what-is-agentic-retrieval)

### Author

ES

Ethan Steininger

![Mixpeek Icon](/brand/logo-dark-icon.webp)

#### Multimodal Search, On Demand

Index, retrieve, and reason over videos, images, audio, and docs, all from a single API.

[Start Building](/start)

### Share

[](https://twitter.com/intent/tweet?text=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust)[](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust&title=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust)[](https://www.reddit.com/submit?url=https%3A%2F%2Fmixpeek.com%2Fblog%2Fbuilding-a-production-ready-vlm-inference-server-in-rust&title=Building%20a%20Production-Ready%20VLM%20Inference%20Server%20in%20Rust)