Skip to content

Community project: Depth-Anything-V2 running via a from-scratch PyTorch-API shim (torch-mlx) #1449

Description

@bahaehmimdi

Hi — sharing a community project in case it's of interest, and to ask whether you'd consider a pointer to it somewhere (this repo, a discussion, or wherever you think fits best).

depth-anything-mlx: runs the real, unmodified transformers.AutoModelForDepthEstimation (Depth-Anything-V2) on Apple Silicon via torch-mlx — a from-scratch torch-API-compatible layer backed by mlx.core — instead of a hand-written native mlx.nn reimplementation.

I want to be upfront that this takes a different approach from every example in this repo: mlx-examples' convention (e.g. clip/, segment_anything/) is a native mlx.nn model definition, with torch used only for one-time offline weight conversion. depth-anything-mlx instead runs the real PyTorch model through a compatibility shim at inference time, every call — so it isn't a fit for an inline PR into the example gallery itself, which is why I'm opening this as an issue instead rather than a pull request.

Despite the different approach, the results seemed worth sharing:

  • Fully verified against real PyTorch at every stage (weights, preprocessing, model forward) — see the repo's BENCHMARK_RESULTS.md for the full accounting, including negative results.
  • After a series of fixes (fused attention/layer-norm kernels, fp16, native preprocessing, an exact conv-fold), it now beats real PyTorch's own MPS backend by a consistent ~1.4-1.5x across image sizes from 480x640 up to 108MP.

Happy to answer any questions, and no worries at all if this isn't a fit for anything here — just wanted to put it in front of the people most likely to find it interesting.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HooZphcpzukceMrdArswsP

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions