Repository navigation
Replies: 1 comment 1 reply
|
@horsten the linked documents are returning a 404, perhaps they were moved? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I've often found it tricky to navigate the both brilliantly efficient but also very undocumented internals of ComfyUI when writing custom nodes, patching models, or generally hacking around. There are a lot of implicit "API contracts" and core concepts that are non-obvious because they're not documented anywhere, so it often involves trying to find a "close enough example" of what you want to do if you're not a core developer and trying to understand the system.
I've tried to document the key concepts that one needs to understand when adding features, models, or experiments. It started mostly for my own benefit, but I hope others might find it useful - perhaps especially those who create "wrapper nodes" for external models and similar, often resulting in something very fragile that doesn't coexist happily with anything else Comfy.
Below's the README, and the repository can be found here: https://github.com/horsten/comfyui-internals-doc
Feedback and pull requests are welcome.
ComfyUI Internals: The Missing Manual
Overview
ComfyUI has become the de-facto operating system for open-source generative AI. However, its core architecture—the execution engine, memory management, and sampling loop—has remained largely undocumented, residing only in the source code and the minds of its original creators and the core development team. The code and design of these core parts is brilliant, complex, and highly optimized, which is why ComfyUI works so well, but for the same reasons it's very easy to break it when you want to add something or change some behavior in your specific use case.
This repository aims to solve the "Black Box" problem.
It provides deep architectural analysis, explicit API contracts, and reference documentation for developers who want to write robust custom nodes, implement new model architectures, or simply understand how the engine works under the hood.
🛑 Why This Matters: The "Ghost" Bugs
Without understanding these internals, developers often encounter "Ghost Bugs"—issues that appear randomly or only on specific hardware. This documentation explains the root causes of:
self.pipeline = DiffusersPipeline(...)).ModelManagementsystem cannot see or offload, causing immediate OOMs when other nodes try to run. It also prevents your "wrapper" from taking advantage of the very features that makes ComfyUI so fast, and efficient, often negating the impact of your custom model "optimizations".ModelPatcherand return them. Let the engine handle the loading. People who write wrapper nodes often add inferior versions of features that are already in the core engine, but finding what you're looking for, and understanding how to use it, can be incredibly complex if you have to deduce it all by finding a similar "example" somewhere in the code..to('cuda')) instead of usingModelPatcher, which bypasses the memory manager's accounting..clone()), causing side effects to leak into other branches of the workflow.comfy.sdguesses the wrong architecture (e.g., loading an SDXL-Turbo model as SD1.5) because of ambiguous state dict keys.📚 The Architecture (Textbook)
If you are new to ComfyUI development (and even if you're not, because unless you're a member of the core development team, you probably, like me, had to guess about a great number of things), read these in order to build a mental model of the system.
ModelPatcher,model_management, and why you must always.clone()before modifying.INPUT_TYPES,RETURN_TYPES, and the V1 vs V3 initialization protocols work.comfy.samplers. How Guiders, Schedulers, and Conditionings interact to generate an image.comfy.sd. How the system "guesses" which model architecture a SafeTensors file contains.⚡ Quick Reference (Cheatsheet)
For active development, keep these open.
intermediate_device.MODEL,LATENT, orMASKobject?Core Concepts at a Glance
Contributing
This documentation was generated through a collaboration between human insight (and practical experience of "getting things wrong" and learning where the friction points were), and AI analysis of the source code (Jan 2026). As the ComfyUI codebase evolves, these documents may need updates. Pull Requests to keep this "Source of Truth" accurate are welcome.
I'll try my best to keep it up-to-date with major changes in the core of ComfyUI, especially if I'm notified in the form of a pull requests, and of course if the ComfyUI team would like to "adopt" this documentation and make it part of the main project, I'd welcome that as well.
All reactions