Extensions/Depth Anything V2 & Distill-Any-Depth — Native-Res, TensorRT Accelerated
ComfyUI Extension

Depth Anything V2 & Distill-Any-Depth — Native-Res, TensorRT Accelerated

Depth Anything V2 / Distill-Any-Depth depth estimation at native resolution, accelerated with ONNX Runtime and TensorRT — one chainable node set

By PineCookie·Created 3 months ago·Updated 4 days ago· 1
PineCookie/ComfyUI-DepthAnythingAccel
Nodes9
On cloudLocal install
CategoryDepth Anything Accel/Convert, Depth Anything Accel/PyTorch
Stars1
Updated4 days ago
Readme

ComfyUI DepthAnythingAccel

Native-resolution Depth Anything V2 / Distill-Any-Depth depth estimation nodes for ComfyUI — one pipeline that runs the same model on PyTorch, ONNX Runtime, or TensorRT.

中文文档见 README_zh.md。

Why this pack

  • Full-resolution depth. Depth nodes usually run the model at about 500 px by default and upscale the result. This pack runs it at your image's own resolution, so the depth map keeps the detail of large images.
  • Faster. Native FP16 + GPU pre/postprocessing makes the PyTorch backend fast out of the box, and TensorRT cuts inference latency nearly in half again (~1.8–1.9× faster, e.g. Large at 784×1176 in 46 ms). Convert models with nodes inside your workflow — no command line, no restart.
  • DA2 and Distill-Any-Depth in one node set. Model size and family are detected from the checkpoint.
  • Shares VRAM with your other models. ComfyUI loads and frees the PyTorch model like its own models.
  • Auto-download. Pick a supported model in the Load node and it is downloaded on first use.

Measured on an RTX 5070 Ti (FP16, 784×1176, inference-only GPU mean over 20 warm runs on PyTorch 2.15 + CUDA 13.2 / ORT 1.32 / TensorRT 11.5):

| Encoder | PyTorch | ONNX Runtime (fused) | TensorRT | | --- | ---: | ---: | ---: | | Small (vits) | 13.2 ms | 14.5 ms | 6.8 ms | | Base (vitb) | 29.8 ms | 30.4 ms | 15.6 ms | | Large (vitl) | 83.9 ms | 86.3 ms | 46.0 ms |

TensorRT is about 1.8–1.9× faster than PyTorch and fused ONNX Runtime. End-to-end latency (including GPU pre/postprocessing and CPU↔GPU transfers) adds ~2–3 ms per image (e.g. Large: 86.9 ms PyTorch, 88.4 ms ONNX, 48.3 ms TensorRT). All backends closely match the FP32 reference output (correlation ≈ 1.0, normalized error ≈ 1e-3).

Installation

ComfyUI Manager (recommended): search for DepthAnythingAccel and install.

Manual:

git clone https://github.com/PineCookie/ComfyUI-DepthAnythingAccel "$env:ComfyUI\custom_nodes\ComfyUI-DepthAnythingAccel"
& "$env:ComfyUI\.venv\Scripts\python.exe" -m pip install -r "$env:ComfyUI\custom_nodes\ComfyUI-DepthAnythingAccel\requirements.txt"

This is all the PyTorch nodes need. ONNX Runtime and TensorRT are optional; see Faster.

Quick start

Open ComfyUI's workflow templates and pick Depth estimation - PyTorch under this node pack, or build it yourself:

[Load Image] -> [Estimate Depth (PyTorch)] -> [Save Image]
                         ^
        [Load Depth Model (PyTorch)]

Nodes are in the Depth Anything Accel category. Pick a model and, optionally, a precision. The example uses DA2 Small, which is small and licensed for commercial use; see Models for the others.

Faster: ONNX Runtime / TensorRT

Conversion nodes chain directly in the graph: each takes the previous model and returns one ready to use. The converted files are saved to ComfyUI/models/depthanything/, so later sessions can load them with the Load Depth Model (ONNX) / (TensorRT) nodes and skip converting.

ONNX Runtime (portable / CPU & CUDA)

[Load Depth Model (PyTorch)] -> [Export to ONNX] -> [Fuse ONNX Attention] -> [Estimate Depth (ONNX)]

Fuse ONNX Attention is where the ONNX speedup comes from (optional; the unfused graph also runs, just slower). On modern PyTorch + CUDA, fused ONNX roughly matches PyTorch speed; it is mainly useful for portable/CPU deployment or setups without TensorRT.

TensorRT (~1.8–1.9× faster, NVIDIA only) — template Depth estimation - TensorRT

[Load Depth Model (PyTorch)] -> [Export to ONNX] -> [Build TensorRT Engine] -> [Estimate Depth (TensorRT)]

Build engines from the unfused ONNX model. An engine accepts any input up to its Max H / Max W and is tied to the TensorRT version and GPU that built it — rebuild after upgrading TensorRT or changing GPUs (engines built by these nodes report a version mismatch on load).

Installing the optional backends

Install what fits your machine into ComfyUI's Python:

| Machine | ONNX Runtime | TensorRT | | --- | --- | --- | | NVIDIA GPU | onnxruntime-gpu | tensorrt-cu12 or tensorrt-cu13, matching torch.version.cuda | | Mac, AMD, Intel, CPU only | onnxruntime (runs on CPU) | not supported |

  • Install only one of onnxruntime / onnxruntime-gpu; they overwrite each other. If another node pack installed onnxruntime, uninstall it before installing onnxruntime-gpu.
  • Export to ONNX and Fuse ONNX Attention need onnx (onnxslim is optional). Export is verified on CUDA and CPU.

Limits

  • Image size. To avoid running out of VRAM, the PyTorch and ONNX nodes refuse inputs above about 2.6 MP in FP32 and 4.7 MP in FP16/BF16; resize larger images first. TensorRT is limited by the engine's Max H / Max W instead.
  • Size rounding. Width and height are rounded down to a multiple of 14 for the model (its patch size); the output is resized back to your image.
  • Batches. All backends process batches one image at a time to keep VRAM bounded.
  • Precision. FP16/BF16 in the PyTorch loader only takes effect on CUDA/ROCm; elsewhere it runs in FP32.

Models

Weights are not bundled. Pick a model in the Load node's dropdown to download it automatically, or place files in ComfyUI/models/depthanything/ yourself (subfolders work).

| Model | Source | License | | --- | --- | --- | | DA2 Small | Kijai/DepthAnythingV2-safetensors (default) or depth-anything/Depth-Anything-V2-Small (.pth) | Apache-2.0 | | DA2 Base / Large | Kijai/DepthAnythingV2-safetensors (default) or depth-anything/Depth-Anything-V2-Base / -Large (.pth) | CC-BY-NC-4.0, non-commercial | | Distill-Any-Depth Small / Base / Large | xingyang1/Distill-Any-Depth | Apache-2.0 (model card) |

⚠️ Kijai's conversions are labeled CC-BY-4.0, but they are converted from the official weights, so treat Base / Large as non-commercial either way. ONNX models and engines you export carry the same license as their checkpoint. See THIRD_PARTY.md.

DA2 Giant has not been released publicly; a vitg checkpoint you supply yourself is detected and loaded.

Nodes

| Node | Does | | --- | --- | | Load Depth Model (PyTorch) / Estimate Depth (PyTorch) | Reference backend | | Load Depth Model (ONNX) / Estimate Depth (ONNX) | ONNX Runtime backend | | Load Depth Model (TensorRT) / Estimate Depth (TensorRT) | TensorRT backend | | Export to ONNX | PyTorch model → ONNX model | | Fuse ONNX Attention | ONNX model → fused ONNX model | | Build TensorRT Engine | Unfused ONNX model → TensorRT engine |

License

Source code is licensed under the Apache License 2.0; see LICENSE. Model weights are licensed separately by their owners; see THIRD_PARTY.md.

For developers

CLI tools, tests, and development notes are in DEVELOPMENT.md.