# kijai/comfyui-lbmwrapper architecture

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

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

## Overview

This repository is a **ComfyUI custom-node wrapper** around **Latent Bridge Matching (LBM)**, with the current packaged use case being **relighting**. The repo is not a training codebase; it is an **inference integration layer** that lets ComfyUI load LBM weights and run them inside a node graph.

1. **Top-level integration boundary**
   - `nodes.py` is the likely ComfyUI registration surface: it exposes node classes and makes the package discoverable by ComfyUI.
   - `readme.md` points to the model checkpoint location expected by ComfyUI: `ComfyUI/models/diffusion_models`.
   - `example_workflows/lbm_relight_example_01.json` shows the intended graph-level usage and is the best reference for dataflow through the nodes.

2. **Package layout**
   - The main implementation lives under `lbm/`.
   - `utils.py` at the repo root and `lbm/models/utils.py` are shared helper layers, likely used across model loading, tensor handling, and ComfyUI-specific glue.
   - `__init__.py` at the root indicates the repo is packaged as a Python module for import by ComfyUI.

3. **Configuration subsystem**
   - `lbm/config.py` is the central package-level configuration entrypoint.
   - Each model family also has its own config object:
     - `lbm/models/base/model_config.py`
     - `lbm/models/lbm/lbm_config.py`
     - `lbm/models/vae/autoencoderKL_config.py`
     - `lbm/models/unets/...` and embedder configs
   - This suggests a consistent pattern where model architecture, checkpoint metadata, and runtime options are separated from execution logic.

4. **Base model abstractions**
   - `lbm/models/base/base_model.py` and `lbm/models/base/model_config.py` define the common lifecycle for models.
   - These base classes likely encapsulate responsibilities such as loading weights, moving modules to device, and sharing common interface methods across the different model components.

5. **LBM core model**
   - `lbm/models/lbm/lbm_model.py` is the heart of the repository: it likely composes the full Latent Bridge Matching inference pipeline.
   - `lbm/models/lbm/lbm_config.py` holds the LBM-specific parameters and wiring.
   - This is the subsystem that ties together the latent bridge logic, backbone network, and conditioning inputs.

6. **Conditioning / embedder subsystem**
   - `lbm/models/embedders/base/base_conditioner.py` and `base_conditioner_config.py` define the abstract interface for conditioning modules.
   - `lbm/models/embedders/conditioners_wrapper.py` is a coordination layer that probably normalizes multiple conditioners into one interface for the main model.
   - `lbm/models/embedders/latents_concat/...` is a concrete embedder that turns inputs into latent features and concatenates them, which is important for architectures that inject conditioning directly into latent-space processing.

7. **Generative backbone**
   - `lbm/models/unets/unet.py` contains the U-Net backbone used by the model.
   - This is the main denoising / transformation network in the latent pipeline, and it is the part most likely to dominate compute at inference time.

8. **VAE subsystem**
   - `lbm/models/vae/autoencoderKL.py` and `autoencoderKL_config.py` implement the latent autoencoder boundary.
   - The VAE is the bridge between image space and latent space: inputs are encoded into latents before the LBM/U-Net path, and outputs are decoded back to images afterward.

9. **End-to-end data flow**
   - The practical flow in ComfyUI is:
     - user loads a workflow node graph,
     - nodes load the LBM checkpoint from ComfyUI’s diffusion model directory,
     - input images / conditioning signals are encoded or embedded,
     - conditioning is merged in latent space,
     - the LBM/U-Net core transforms the latent representation,
     - the VAE decodes the result into the final image output.
   - The example workflow file is the clearest artifact showing how these pieces connect.

10. **Model composition boundaries**
    - The repo separates **core orchestration** (`lbm_model.py`) from **specialized components**:
      - embedders for conditioning,
      - U-Net for latent transformation,
      - VAE for encoding/decoding.
    - This makes it easier to swap or extend one subsystem without rewriting the others.

11. **External runtime assumptions**
    - The main runtime is **ComfyUI**.
    - Model weights are expected to be supplied externally, with the README specifically referencing a Hugging Face checkpoint for relighting.
    - `requirements.txt` defines the Python-side dependency boundary for running these nodes in that environment.

12. **What the architecture diagram should emphasize**
    - A single ComfyUI integration entrypoint feeding into a layered model stack.
    - The main internal split is: node/wrapper layer → config/base abstractions → LBM orchestration → conditioning embedders + U-Net + VAE.
    - The important external boundaries are ComfyUI on one side and model checkpoints/weights on the other.

Main entry points: [`lbm/models/lbm/lbm_model.py`](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/lbm/lbm_model.py) (LBM core), [`nodes.py`](https://github.com/kijai/comfyui-lbmwrapper/blob/main/nodes.py) (Node reg), [`lbm/models/embedders/conditioners_wrapper.py`](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/conditioners_wrapper.py) (Conditioners), [`example_workflows/lbm_relight_example_01.json`](https://github.com/kijai/comfyui-lbmwrapper/blob/main/example_workflows/lbm_relight_example_01.json) (Example graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["ComfyUI layer"]
  node_package_init["Package init<br/>module entry<br/>[__init__.py]"]
  node_nodes_py["Node reg<br/>comfyui registration<br/>[nodes.py]"]
  node_readme["README<br/>usage docs<br/>[readme.md]"]
  node_workflow["Example graph<br/>workflow example"]
  node_repo_utils["Root utils<br/>helper module<br/>[utils.py]"]
end

subgraph group_model["LBM stack"]
  node_lbm_config["LBM config<br/>package config<br/>[config.py]"]
  node_base_model["Base model<br/>model base<br/>[base_model.py]"]
  node_base_model_config["Base config<br/>model config<br/>[model_config.py]"]
  node_lbm_model["LBM core<br/>inference orchestrator<br/>[lbm_model.py]"]
  node_lbm_model_config["LBM params<br/>lbm config<br/>[lbm_config.py]"]
  node_conditioners["Conditioners<br/>conditioning wrapper"]
  node_base_conditioner["Conditioner base<br/>conditioning base"]
  node_latents_concat["Latent concat<br/>embedder"]
  node_unet["U-Net<br/>backbone<br/>[unet.py]"]
  node_vae["VAE<br/>autoencoder<br/>[autoencoderKL.py]"]
  node_models_utils["Model utils<br/>shared helpers<br/>[utils.py]"]
end

subgraph group_external["External boundary"]
  node_comfyui(("ComfyUI<br/>runtime"))
  node_weights[("Model weights<br/>checkpoint source")]
end

node_comfyui -->|"loads"| node_nodes_py
node_nodes_py -->|"imports"| node_package_init
node_nodes_py -->|"uses"| node_lbm_config
node_readme -->|"guides"| node_weights
node_workflow -->|"demonstrates"| node_nodes_py
node_workflow -.->|"exercises"| node_lbm_model
node_lbm_config -->|"extends"| node_base_model_config
node_lbm_model -->|"inherits"| node_base_model
node_lbm_model -->|"configured by"| node_lbm_model_config
node_lbm_model -->|"routes conditioning"| node_conditioners
node_conditioners -->|"implements"| node_base_conditioner
node_conditioners -->|"includes"| node_latents_concat
node_lbm_model -->|"runs through"| node_unet
node_lbm_model -->|"encodes/decodes"| node_vae
node_lbm_model -.->|"shares helpers"| node_models_utils
node_nodes_py -.->|"uses"| node_repo_utils
node_lbm_model -->|"loads"| node_weights

click node_package_init "https://github.com/kijai/comfyui-lbmwrapper/blob/main/__init__.py"
click node_nodes_py "https://github.com/kijai/comfyui-lbmwrapper/blob/main/nodes.py"
click node_readme "https://github.com/kijai/comfyui-lbmwrapper/blob/main/readme.md"
click node_workflow "https://github.com/kijai/comfyui-lbmwrapper/blob/main/example_workflows/lbm_relight_example_01.json"
click node_repo_utils "https://github.com/kijai/comfyui-lbmwrapper/blob/main/utils.py"
click node_lbm_config "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/config.py"
click node_base_model "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/base/base_model.py"
click node_base_model_config "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/base/model_config.py"
click node_lbm_model "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/lbm/lbm_model.py"
click node_lbm_model_config "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/lbm/lbm_config.py"
click node_conditioners "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/conditioners_wrapper.py"
click node_base_conditioner "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/base/base_conditioner.py"
click node_latents_concat "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/latents_concat/latents_concat_embedder_model.py"
click node_unet "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/unets/unet.py"
click node_vae "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/vae/autoencoderKL.py"
click node_models_utils "https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/utils.py"

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_package_init,node_nodes_py,node_readme,node_workflow,node_repo_utils toneBlue
class node_lbm_config,node_base_model,node_base_model_config,node_lbm_model,node_lbm_model_config,node_conditioners,node_base_conditioner,node_latents_concat,node_unet,node_vae,node_models_utils toneAmber
class node_comfyui,node_weights toneMint
```

## Components

### ComfyUI layer

Package entrypoints and example workflow used by ComfyUI.

- [Package init](https://github.com/kijai/comfyui-lbmwrapper/blob/main/__init__.py): module entry · Python package marker for importing the wrapper. · `__init__.py`
- [Node reg](https://github.com/kijai/comfyui-lbmwrapper/blob/main/nodes.py): comfyui registration · Registers custom nodes for ComfyUI discovery and execution. · `nodes.py`
- [README](https://github.com/kijai/comfyui-lbmwrapper/blob/main/readme.md): usage docs · Documents setup, checkpoint placement, and intended ComfyUI usage. · `readme.md`
- [Example graph](https://github.com/kijai/comfyui-lbmwrapper/blob/main/example_workflows/lbm_relight_example_01.json): workflow example · Reference ComfyUI workflow showing end-to-end relighting dataflow. · `example_workflows/lbm_relight_example_01.json`
- [Root utils](https://github.com/kijai/comfyui-lbmwrapper/blob/main/utils.py): helper module · Repository-wide utilities used by the wrapper layer. · `utils.py`

### LBM stack

Core model orchestration and reusable subcomponents.

- [LBM config](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/config.py): package config · Top-level configuration entrypoint for the LBM package. · `lbm/config.py`
- [Base model](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/base/base_model.py): model base · Shared lifecycle and loading abstractions for model components. · `lbm/models/base/base_model.py`
- [Base config](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/base/model_config.py): model config · Common configuration schema for model components. · `lbm/models/base/model_config.py`
- [LBM core](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/lbm/lbm_model.py): inference orchestrator · Composes the Latent Bridge Matching inference pipeline. · `lbm/models/lbm/lbm_model.py`
- [LBM params](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/lbm/lbm_config.py): lbm config · LBM-specific wiring and runtime parameters. · `lbm/models/lbm/lbm_config.py`
- [Conditioners](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/conditioners_wrapper.py): conditioning wrapper · Normalizes and combines conditioning inputs for the main model. · `lbm/models/embedders/conditioners_wrapper.py`
- [Conditioner base](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/base/base_conditioner.py): conditioning base · Abstract interface for conditioning modules. · `lbm/models/embedders/base/base_conditioner.py`
- [Latent concat](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/embedders/latents_concat/latents_concat_embedder_model.py): embedder · Concrete embedder that injects conditioning by concatenating latent features. · `lbm/models/embedders/latents_concat/latents_concat_embedder_model.py`
- [U-Net](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/unets/unet.py): backbone · Latent transformation network used during inference. · `lbm/models/unets/unet.py`
- [VAE](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/vae/autoencoderKL.py): autoencoder · Encodes images into latents and decodes final results back to image space. · `lbm/models/vae/autoencoderKL.py`
- [Model utils](https://github.com/kijai/comfyui-lbmwrapper/blob/main/lbm/models/utils.py): shared helpers · Common tensor and model utilities shared across the stack. · `lbm/models/utils.py`

### External boundary

Runtime and weight sources consumed by the wrapper.

- **ComfyUI**: runtime · Host application that loads and runs the custom nodes.
- **Model weights**: checkpoint source · External diffusion model checkpoints expected in ComfyUI's model directory.

## Connections

- ComfyUI → Node reg: loads · ComfyUI discovers and registers the custom nodes.
- Node reg → Package init: imports · Node registration relies on the package import surface.
- Node reg → LBM config: uses · Node layer forwards package configuration into the model stack.
- README → Model weights: guides · Documentation points users to the expected checkpoint location.
- Example graph → Node reg: demonstrates · Example graph shows how registered nodes are intended to be wired.
- Example graph → LBM core: exercises · Workflow represents the operational path through the LBM pipeline.
- LBM config → Base config: extends · Package config builds on shared model configuration patterns.
- LBM core → Base model: inherits · LBM orchestration uses the shared model lifecycle boundary.
- LBM core → LBM params: configured by · LBM-specific parameters define how the pipeline is assembled.
- LBM core → Conditioners: routes conditioning · Orchestrator passes conditioning inputs into the wrapper layer.
- Conditioners → Conditioner base: implements · Concrete conditioning modules follow the common conditioner interface.
- Conditioners → Latent concat: includes · Wrapper can coordinate latent concatenation conditioning.
- LBM core → U-Net: runs through · Core inference transforms latents with the U-Net backbone.
- LBM core → VAE: encodes/decodes · VAE forms the image-latent boundary around the core model.
- LBM core → Model utils: shares helpers · Model stack relies on shared tensor and loading utilities.
- Node reg → Root utils: uses · ComfyUI-facing glue may reuse repository helpers.
- LBM core → Model weights: loads · Inference components are initialized from external checkpoints.
