How kijai/comfyui-lbmwrapper works
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_model.py LBM core · nodes.py Node reg · conditioners_wrapper.py Conditioners · lbm_relight_example_01.json Example graph
Components 18
ComfyUI layer
Package entrypoints and example workflow used by ComfyUI.
- Package init · Python package marker for importing the wrapper.
__init__.py - Node reg · Registers custom nodes for ComfyUI discovery and execution.
nodes.py - README · Documents setup, checkpoint placement, and intended ComfyUI usage.
readme.md - Example graph · Reference ComfyUI workflow showing end-to-end relighting dataflow.
example_workflows/lbm_relight_example_01.json - Root utils · Repository-wide utilities used by the wrapper layer.
utils.py
LBM stack
Core model orchestration and reusable subcomponents.
- LBM config · Top-level configuration entrypoint for the LBM package.
lbm/config.py - Base model · Shared lifecycle and loading abstractions for model components.
lbm/models/base/base_model.py - Base config · Common configuration schema for model components.
lbm/models/base/model_config.py - LBM core · Composes the Latent Bridge Matching inference pipeline.
lbm/models/lbm/lbm_model.py - LBM params · LBM-specific wiring and runtime parameters.
lbm/models/lbm/lbm_config.py - Conditioners · Normalizes and combines conditioning inputs for the main model.
lbm/models/embedders/conditioners_wrapper.py - Conditioner base · Abstract interface for conditioning modules.
lbm/models/embedders/base/base_conditioner.py - Latent concat · Concrete embedder that injects conditioning by concatenating latent features.
lbm/models/embedders/latents_concat/latents_concat_embedder_model.py - U-Net · Latent transformation network used during inference.
lbm/models/unets/unet.py - VAE · Encodes images into latents and decodes final results back to image space.
lbm/models/vae/autoencoderKL.py - Model utils · Common tensor and model utilities shared across the stack.
lbm/models/utils.py
External boundary
Runtime and weight sources consumed by the wrapper.
- ComfyUI · Host application that loads and runs the custom nodes.
- Model weights · External diffusion model checkpoints expected in ComfyUI's model directory.
Connections 17
- 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.