LocalAI ships ByteDance depth estimation in C++ that beats PyTorch on CPU

depth-anything.cpp ports ByteDance Depth Anything 3 to ggml with no Python at inference. On CPU it runs 1.31x faster than PyTorch at q8_0, uses half the RAM, and loads 6.7x faster. LocalAI v4.5 exposes it via POST /v1/depth.

SaifullahSaifullah
4 min read
LocalAI ships ByteDance depth estimation in C++ that beats PyTorch on CPU

Depth maps power robotics, AR placement, and scene understanding. Most reference implementations still drag a Python runtime and a multi-gigabyte PyTorch install to production.

depth-anything.cpp is LocalAI maintainer Emanuele Ciocca's C++17 port of ByteDance Depth Anything 3. One GGUF file. No Python at inference. And on CPU it is faster than PyTorch on the same model.

What you get from Depth Anything 3

Depth Anything 3 estimates metric depth in meters from a single RGB photo, plus:

OutputUse case
Per-pixel depth mapObstacle detection, scene layout
Confidence + sky maskFilter unreliable regions
Camera intrinsics / extrinsicsAR alignment, photogrammetry glue
Point cloud / GLB export3D viewers, simulation

The C++ port targets dependency-free deployment: ship a binary and a quantized GGUF, not a conda environment.

depth-anything.cpp pipeline showing photo input, GGUF model, metric depth map and point cloud output without Python

Benchmark numbers that matter on CPU

LocalAI published apples-to-apples numbers on a Ryzen 9 9950X3D (16 threads, 504x336 input):

EngineQuantModel sizeLoad (ms)Infer (ms)Peak RAM (MB)vs PyTorch
PyTorchf32516 MB749416.913281.00x
C++/ggmlf32393 MB112346.46141.20x
C++/ggmlq8_0142 MB40319.43631.31x
C++/ggmlq4_k99 MB25395.23201.05x

The q4_k build is a 99 MB file with near-lossless depth quality (correlation 1.0 vs reference in parity tests). That is the profile you want on a factory NUC or a VPS without a GPU.

CPU benchmark chart comparing PyTorch versus C++ ggml depth-anything on speed, memory, and load time

Ciocca's engineering write-up is honest: the big GEMMs are close to a wash because everyone calls similar BLAS kernels. The wins come from host-side work Python never optimized (cached positional embeddings, faster load path) and from not booting an interpreter to run inference.

On GPU, the story is flatter: with ggml CUDA and flash attention, depth-anything.cpp roughly ties tuned PyTorch and mainly wins cold start.

LocalAI v4.5 integration

LocalAI v4.5.0 wires depth-anything.cpp as a native Go gRPC backend via purego (no Python at inference).

Three access patterns:

InterfaceReturns
POST /v1/depthFull depth surface (map, stats, camera matrices)
Depth gRPC RPCSame typed payload for service meshes
GenerateImageMin-max normalized grayscale depth PNG

Eight GGUF variants live at mudler/depth-anything.cpp-gguf (base/small/large/giant plus mono-large, multiple quants). Builds cover cpu, CUDA 12/13, Intel SYCL, Vulkan, and L4T arm64.

The release also adds Depth Anything V2 gallery models and a CED audio event detector (527 AudioSet classes). Depth and sound tagging in one LocalAI install is a useful combo for edge agents that need both scene geometry and anomaly audio.

When I would deploy this

Good fits:

  • Warehouse or retail robots that need metric depth on CPU-only edge boxes
  • AR try-on pipelines that already run LocalAI for LLM/VLM tasks
  • Privacy-sensitive sites that cannot ship frames to a cloud depth API
  • CI parity checks against PyTorch reference outputs (bit-exact correlation)

Weak fits:

  • Training or fine-tuning depth models (still a Python workflow)
  • Sub-millisecond depth on every frame of a 4K 60fps stream without GPU help
  • Teams with zero appetite for operating native binaries (use a hosted API instead)

Build and embed options

The upstream repo supports CLI (da3-cli), static/shared libraries, and optional CUDA/Metal/Vulkan backends. Key CMake flags include DA_GGML_LLAMAFILE for tinyBLAS CPU kernels and DA_BUILD_TESTS for the 37-test parity suite.

If you are already on the LocalAI gallery pattern, this is another GGUF + engine drop-in, same mental model as whisper.cpp and llama.cpp ports.

Depth on CPU without Python is the kind of boring infrastructure win that unlocks real edge products. If you are wiring perception into voice agents, robotics, or on-prem automation, book a free call and we can map where metric depth fits your stack.

Share this post

Related posts