# kijai/comfyui-depth-fm architecture

> Architecture diagram of the GitHub repository kijai/comfyui-depth-fm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kijai/comfyui-depth-fm
- Repository: https://github.com/kijai/comfyui-depth-fm

## Overview

1. **What this repo is**
   - This is a **ComfyUI custom node package** that wraps the **DepthFM monocular depth estimation model**.
   - It is designed for **local inference inside ComfyUI**, not as a standalone service.

2. **Top-level structure**
   - `nodes.py` is the ComfyUI integration entrypoint.
   - `depthfm/` contains the actual model code and inference logic.
   - `depthfm/unet/` contains the U-Net building blocks adapted from the original DepthFM / Stable Diffusion-style architecture.
   - `assets/` is documentation-only content for the README.

3. **ComfyUI boundary**
   - The architectural boundary is the **node interface**: ComfyUI passes image tensors and model selections into `nodes.py`, which then delegates into the `depthfm` package.
   - The repo is meant to slot into `ComfyUI/custom_nodes`, and model files are expected in ComfyUI’s checkpoint storage.

4. **Model loading and checkpointing**
   - The README indicates the model is loaded from a **DepthFM checkpoint** or a **pruned safetensors checkpoint**.
   - The node uses a checkpoint from `ComfyUI/models/checkpoints`, so model weights are external to the codebase and are a first-class part of the deployment architecture.

5. **Inference path**
   - The main data flow is: **input image → preprocessing → DepthFM model inference → depth map output**.
   - Depth estimation is performed in a small number of steps; the README emphasizes **1–2 function evaluations** as typical usage.
   - The node likely exposes settings such as step count and ensemble size, which directly affect inference behavior.

6. **Core model package**
   - `depthfm/dfm.py` is the likely top-level model wrapper for loading, configuring, and running DepthFM inference.
   - This is where the repository probably bridges checkpoint weights, U-Net construction, and the output depth representation.

7. **U-Net subsystem**
   - `depthfm/unet/openaimodel.py`, `attention.py`, and `util.py` indicate a modular U-Net implementation with attention blocks and helper utilities.
   - This suggests the model architecture is **diffusion-model-like**, reusing Stable Diffusion-era U-Net patterns rather than a simple CNN depth head.

8. **Dependency profile**
   - `requirements.txt` implies the project depends on the usual **PyTorch-based** stack plus ComfyUI-compatible image/tensor tooling.
   - The runtime is Python, and execution is GPU-oriented, matching the README’s CUDA-focused setup notes.

9. **Original research lineage**
   - The repo is a packaging/integration layer around the original **DepthFM** model from the CompVis/Ommer Lab paper.
   - The codebase is not the research training repo; it is an **application wrapper** for inference in ComfyUI.

10. **External artifacts**
   - The README links to the official model release on Hugging Face and to the original checkpoint source.
   - These external weights are required for actual depth estimation, so the deployment architecture spans code in this repo plus separately downloaded model files.

11. **Operational constraints**
   - The README says any **SD 1.5 / 2.1 VAE** should work, which implies the node may rely on a compatible VAE/image latent pipeline from the ComfyUI ecosystem.
   - That makes this package dependent on surrounding ComfyUI model assets, not just its own checkpoint.

12. **What to draw in an architecture diagram**
   - Show **ComfyUI graph/runtime** on the left, **nodes.py** as the custom node boundary, **depthfm/dfm.py** as the model orchestration layer, and **depthfm/unet/** as the core neural network subsystem.
   - Show **external checkpoint storage** as a separate input to the model layer, and a single output path producing a **depth map** back into the ComfyUI workflow.

Main entry points: [`nodes.py`](https://github.com/kijai/comfyui-depth-fm/blob/main/nodes.py) (nodes.py), [`depthfm/dfm.py`](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/dfm.py) (dfm.py), [`depthfm/unet/openaimodel.py`](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/openaimodel.py) (U-Net), [`README.md`](https://github.com/kijai/comfyui-depth-fm/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["ComfyUI boundary"]
  node_comfyui_runtime(("ComfyUI<br/>workflow runtime"))
  node_node_entry["nodes.py<br/>custom node<br/>[nodes.py]"]
  node_package_init["__init__.py<br/>package hook<br/>[__init__.py]"]
  node_input_image(("Image input<br/>tensor input"))
  node_depth_output(("Depth map<br/>tensor output"))
end

subgraph group_model["DepthFM model"]
  node_dfm_wrapper["dfm.py<br/>model wrapper<br/>[dfm.py]"]
  node_depthfm_pkg["depthfm<br/>model package<br/>[__init__.py]"]
  node_unet_core["U-Net<br/>network core<br/>[openaimodel.py]"]
  node_attention_blocks["Attention<br/>network blocks<br/>[attention.py]"]
  node_unet_utils["Utils<br/>helpers<br/>[util.py]"]
  node_unet_pkg["unet<br/>submodule<br/>[__init__.py]"]
end

subgraph group_external["External assets"]
  node_checkpoint_store[("Checkpoints<br/>external weights")]
  node_vae_assets[("ComfyUI VAE<br/>external asset")]
  node_dependencies["PyTorch stack<br/>runtime deps<br/>[requirements.txt]"]
  node_readme_docs["README<br/>docs<br/>[README.md]"]
  node_assets_docs["Assets"]
end

node_comfyui_runtime -->|"loads node"| node_node_entry
node_package_init -->|"registers"| node_node_entry
node_node_entry -->|"accepts"| node_input_image
node_node_entry -->|"invokes"| node_dfm_wrapper
node_dfm_wrapper -->|"loads weights from"| node_checkpoint_store
node_dfm_wrapper -->|"uses VAE"| node_vae_assets
node_dfm_wrapper -->|"orchestrates"| node_depthfm_pkg
node_depthfm_pkg -->|"contains"| node_unet_pkg
node_unet_pkg -->|"implements"| node_unet_core
node_unet_core -->|"uses"| node_attention_blocks
node_unet_core -->|"uses"| node_unet_utils
node_dfm_wrapper -->|"produces"| node_depth_output
node_node_entry -->|"exposes"| node_depth_output
node_dependencies -.->|"enables"| node_node_entry
node_readme_docs -.->|"documents"| node_checkpoint_store
node_readme_docs -.->|"documents"| node_vae_assets
node_assets_docs -.->|"supports"| node_readme_docs

click node_node_entry "https://github.com/kijai/comfyui-depth-fm/blob/main/nodes.py"
click node_package_init "https://github.com/kijai/comfyui-depth-fm/blob/main/__init__.py"
click node_dfm_wrapper "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/dfm.py"
click node_depthfm_pkg "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/__init__.py"
click node_unet_core "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/openaimodel.py"
click node_attention_blocks "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/attention.py"
click node_unet_utils "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/util.py"
click node_unet_pkg "https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/__init__.py"
click node_dependencies "https://github.com/kijai/comfyui-depth-fm/blob/main/requirements.txt"
click node_readme_docs "https://github.com/kijai/comfyui-depth-fm/blob/main/README.md"
click node_assets_docs "https://github.com/kijai/comfyui-depth-fm/tree/main/assets"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_comfyui_runtime,node_node_entry,node_package_init,node_input_image,node_depth_output toneBlue
class node_dfm_wrapper,node_depthfm_pkg,node_unet_core,node_attention_blocks,node_unet_utils,node_unet_pkg toneAmber
class node_checkpoint_store,node_vae_assets,node_dependencies,node_readme_docs,node_assets_docs toneMint
```

## Components

### ComfyUI boundary

Custom node entrypoint and workflow-facing runtime boundary.

- **ComfyUI**: workflow runtime · Hosts the custom node and passes tensors through the graph.
- [nodes.py](https://github.com/kijai/comfyui-depth-fm/blob/main/nodes.py): custom node · ComfyUI integration entrypoint and node interface. · `nodes.py`
- [__init__.py](https://github.com/kijai/comfyui-depth-fm/blob/main/__init__.py): package hook · Registers the package as a ComfyUI custom node module. · `__init__.py`
- **Image input**: tensor input · Incoming image tensor from the ComfyUI workflow.
- **Depth map**: tensor output · Predicted monocular depth returned to the workflow.

### DepthFM model

Core inference package and U-Net implementation.

- [dfm.py](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/dfm.py): model wrapper · Orchestrates loading, configuration, and inference. · `depthfm/dfm.py`
- [depthfm](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/__init__.py): model package · Top-level package for the DepthFM inference code. · `depthfm/__init__.py`
- [U-Net](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/openaimodel.py): network core · Main diffusion-style backbone used for depth prediction. · `depthfm/unet/openaimodel.py`
- [Attention](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/attention.py): network blocks · Attention layers used inside the U-Net architecture. · `depthfm/unet/attention.py`
- [Utils](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/util.py): helpers · Shared U-Net utilities and building blocks. · `depthfm/unet/util.py`
- [unet](https://github.com/kijai/comfyui-depth-fm/blob/main/depthfm/unet/__init__.py): submodule · U-Net subsystem namespace for the DepthFM backbone. · `depthfm/unet/__init__.py`

### External assets

Weights and surrounding ComfyUI model assets required at runtime.

- **Checkpoints**: external weights · DepthFM or pruned safetensors weights stored outside the repo.
- **ComfyUI VAE**: external asset · Compatible SD 1.5 / 2.1 VAE or related ComfyUI model asset.
- [PyTorch stack](https://github.com/kijai/comfyui-depth-fm/blob/main/requirements.txt): runtime deps · Python dependencies required for tensor execution and model loading. · `requirements.txt`
- [README](https://github.com/kijai/comfyui-depth-fm/blob/main/README.md): docs · Usage notes and model-loading guidance. · `README.md`
- [Assets](https://github.com/kijai/comfyui-depth-fm/tree/main/assets): docs assets · Documentation figures and README support files. · `assets`

## Connections

- ComfyUI → nodes.py: loads node · ComfyUI discovers the custom node entrypoint.
- __init__.py → nodes.py: registers · Package import path exposes the node to ComfyUI.
- nodes.py → Image input: accepts · The node receives image tensors from the workflow.
- nodes.py → dfm.py: invokes · Node code delegates inference orchestration to the model wrapper.
- dfm.py → Checkpoints: loads weights from · Inference uses external DepthFM checkpoint files.
- dfm.py → ComfyUI VAE: uses VAE · Image/latent compatibility depends on surrounding ComfyUI VAE assets.
- dfm.py → depthfm: orchestrates · Wrapper coordinates the DepthFM package internals.
- depthfm → unet: contains · The package houses the U-Net subsystem.
- unet → U-Net: implements · The core network definition lives in the OpenAI-style U-Net module.
- U-Net → Attention: uses · Attention is integrated into the backbone.
- U-Net → Utils: uses · Utility helpers support blocks and construction.
- dfm.py → Depth map: produces · The model returns a predicted depth tensor.
- nodes.py → Depth map: exposes · ComfyUI-facing output is the depth map.
- PyTorch stack → nodes.py: enables · Python and PyTorch dependencies support the node runtime.
- README → Checkpoints: documents · README explains how to obtain and place weights.
- README → ComfyUI VAE: documents · README notes compatible VAE requirements.
- Assets → README: supports · Figures and supporting files back the documentation.
