Skip to content

ComfyUI.cpp inside the engine: 1bit comfy - #65

Merged
bong-water-water-bong merged 1 commit into
mainfrom
comfyui
Sep 25, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
comfyui

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Brings ComfyUI.cpp into the engine.

  • Pinned: submodule third_party/comfyui.cpp at 4a08238 (1bit-MONSTER/comfyui.cpp master, with the SD1.5 fixes and the ComfyUI pin).
  • Build: -DONEBIT_COMFYUI=ON runs scripts/build-comfyui.sh, which builds build/comfyui/comfyui_cpp against LibTorch from Python's torch. It's off by default, and CI doesn't check out submodules, so CI is unaffected.
  • Run: 1bit comfy <workflow.json> runs a ComfyUI API-format workflow. It looks for the binary in $ONEBIT_COMFYUI first, then this build's, then PATH.
  • License: ComfyUI.cpp is GPL-3.0 and the engine is Apache-2.0. The engine runs ComfyUI.cpp as a separate program and never links it, the same way it treats the Linux kernel. NOTICE says so.

Measured on strixhalo (separate build of this branch, v1-5-pruned-emaonly): 1bit comfy runs txt2img "a cat" (seed 0, 20 steps, 512×512) in 48 s on the CPU, at 50.6 dB PSNR against Python ComfyUI (pinned 1568e6c). Image-to-image: 51.2 dB.

Docs: docs/comfyui.md (also in the site sidebar under Components), README feature list, NOTICE.

🤖 Generated with Claude Code

third_party/comfyui.cpp (1bit-MONSTER/comfyui.cpp, GPL-3.0) is built as its own program by
scripts/build-comfyui.sh (-DONEBIT_COMFYUI=ON); 1bit comfy execs it and never links it,
so the engine stays Apache-2.0. SD1.5 txt2img through 1bit comfy on Strix Halo: 48 s,
50.6 dB PSNR against ComfyUI. docs/comfyui.md, NOTICE, README, site nav.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@context7

context7 Bot commented Sep 25, 2026

Copy link
Copy Markdown

Docs7 for 1bit-monster/engine

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 0f8f705

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Security Risk in `run_comfy`

The run_comfy function in app/main.cpp uses execvp to execute the ComfyUI binary. If the ONEBIT_COMFYUI environment variable is set to a path pointing to a malicious binary, or if the binary is replaced between the check for existence and the execution, it could lead to arbitrary code execution. This is a security concern as it allows for potential privilege escalation or code injection if the environment is not properly controlled.

int run_comfy(int argc, char** argv) {
    if (argc < 1 || !std::strcmp(argv[0], "-h") || !std::strcmp(argv[0], "--help")) {
        std::printf("usage: 1bit comfy <workflow.json>\n"
                    "  runs a ComfyUI API-format workflow (SD1.5 txt2img/img2img, see docs/comfyui.md)\n");
        return argc < 1 ? 2 : 0;
    }
    std::string bin;
    if (const char* e = std::getenv("ONEBIT_COMFYUI"); e && *e) bin = e;
#ifdef ONEBIT_COMFYUI_BIN
    if (bin.empty() && std::filesystem::exists(ONEBIT_COMFYUI_BIN)) bin = ONEBIT_COMFYUI_BIN;
#endif
    if (bin.empty()) bin = "comfyui_cpp";
    std::vector<char*> args{bin.data()};
    for (int i = 0; i < argc; ++i) args.push_back(argv[i]);
    args.push_back(nullptr);
    ::execvp(args[0], args.data());
    std::fprintf(stderr, "1bit comfy: cannot run %s: %s (build with -DONEBIT_COMFYUI=ON or set ONEBIT_COMFYUI)\n",
                 bin.c_str(), std::strerror(errno));
    return 127;
}
Submodule Initialization Requirement

The build-comfyui.sh script requires the third_party/comfyui.cpp submodule to be initialized. If this submodule is not initialized, the script will fail with an error message. This could be a problem for users who are not familiar with Git submodules or who do not have the submodule initialized, leading to build failures.

[ -f "$src/CMakeLists.txt" ] || { echo "third_party/comfyui.cpp is empty: git submodule update --init third_party/comfyui.cpp"; exit 1; }

@bong-water-water-bong
bong-water-water-bong merged commit 8334e8b into main Sep 25, 2026
5 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the comfyui branch September 25, 2026 09:36
bong-water-water-bong added a commit that referenced this pull request Sep 25, 2026
…66)

* 1bit comfy: run the checked file (fexecve), absolute ONEBIT_COMFYUI; fetch the submodule when missing

PR-Agent review on #65: the binary is opened once, checked through the descriptor (regular,
executable, not writable by others) and run with fexecve, so no swap between check and exec;
ONEBIT_COMFYUI must be absolute and relative PATH entries are skipped. CMake and
build-comfyui.sh fetch third_party/comfyui.cpp themselves when it is not initialised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 1bit comfy: say why the descriptor needs no close after fexecve

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: bong-water-water-bong <bong-water-water-bong@1bit.gg>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
bong-water-water-bong added a commit that referenced this pull request Oct 2, 2026
…5 -> 90.9), MXFP4 weights (#282)

llama.cpp fork since d60cc4f:
- #64: a kernel for the MUL_MAT ggml hints as GGML_HINT_SRC0_IS_HADAMARD. Bonsai's 1024-point rotation
  of the 17408-wide FFN input ran on the CPU in every layer at prompt sizes. Ternary-Bonsai-2-27B,
  balanced mode: pp512 13.5 -> 90.9 tok/s, tg128 15.8 -> 19.0. test-hrx-hadamard: six shapes vs CPU
  and an exact product, x4, bitwise-identical repeats; 8 sanitizer-clean check.cases.
- #65: MXFP4 in the shared dequantizer, the E8M0 scale built exactly as GGML_E8M0_TO_FP32_HALF.
  test-hrx-mxfp4 bit-exact vs ggml on HRX0 (subnormal scales e = 0/1 flush to zero);
  test-backend-ops -b HRX0 1051/1051. MUL_MAT_ID admits only multiples of 256 (its kernels declare
  it): gpt-oss-20b's 2880-wide experts fall back to the CPU instead of failing the JIT.

Docs: docs/hrx.md Ternary Bonsai section and "Our patches". Registry regenerated (no mapping changes).

Co-authored-by: bong-water-water-bong <bong-water-water-bong@1bit.gg>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant