Skip to content

Implement timestep zero reference images to krea 2 for ostris ref loras.#14843

Open
comfyanonymous wants to merge 1 commit into
masterfrom
krea2_ref_latent
Open

Implement timestep zero reference images to krea 2 for ostris ref loras.#14843
comfyanonymous wants to merge 1 commit into
masterfrom
krea2_ref_latent

Conversation

@comfyanonymous

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1e86d1b2-2f29-43ac-9af4-574e437f4784

📥 Commits

Reviewing files that changed from the base of the PR and between 6cc8144 and e4cb830.

📒 Files selected for processing (2)
  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: test (windows-2022)
  • GitHub Check: test (windows-latest)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Keep imports at module scope; avoid inline imports unless they are already part of an established optional-backend probe or are needed to avoid an import cycle.
Do not add unnecessary try/except blocks; use them only for optional dependency, platform, or backend capability detection when the program has a useful fallback, and prefer specific exception types when changing new code.
Remove workarounds for PyTorch versions that ComfyUI no longer officially supports; if a workaround does not have a comment naming the exact supported PyTorch version(s), remove it.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently producing lower quality output.
Match the existing local style in the file you edit; this codebase tolerates long lines, simple helper functions, module-level state, and direct tensor operations when they make the code easier to follow.
Keep comments sparse and useful; strip useless comments that restate the code or describe obvious behavior, while allowing short TODOs that name the concrete missing follow-up.
Treat dtype, device placement, VRAM usage, and offloading behavior as core correctness concerns; check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low VRAM implications when touching shared execution or loading code.
Prefer native ComfyUI formats and existing quantization/offload helpers over adding parallel code paths; use comfy.quant_ops, comfy.model_management, comfy.memory_management, comfy.pinned_memory, comfy_aimdo, and comfy-kitchen helpers where they already solve the problem.
Use optimized comfy-kitchen ops where they improve performance without changing expected dtype, device, memory, or interface behavior.
All models should use the optimized attention function selected by ComfyUI; higher-level code must not inspect function identity, names, modules, or implementation details to decide behavior.
Apply the same opacity rule to similar patterns beyond...

Files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
**

⚙️ CodeRabbit configuration file

**: ## Engineering Style

  • Keep changes small and direct. Most fixes should touch the narrowest code path
    that explains the bug, performance issue, dtype issue, model-format issue, or
    user-facing behavior.
  • Change the least amount of files possible. A change that touches many files is
    more likely to be a bad change than a good one unless the broader scope is
    directly required.
  • Prefer practical fixes over broad architecture work. Add abstractions only
    when they remove real repeated logic or match an existing ComfyUI pattern.
  • Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they
    are absolutely necessary.
  • Delete obsolete code aggressively when newer infrastructure makes it useless.
    Remove dead fallbacks, migration paths, unused options, debug prints, and
    compatibility branches that are no longer needed. Do not leave dead branches,
    unreachable code, or functions that are never called. If code is not
    necessary for the current behavior, remove it.
  • Revert or disable problematic behavior quickly when it breaks users. It is
    better to remove a broken feature path than keep a complicated partial fix.
  • Preserve existing APIs, node names, model-loading behavior, file layout, and
    workflow compatibility unless the change is explicitly about replacing them.
  • Code must look hand-written for this repository. Changes that read like
    generic AI-generated code will be rejected automatically: unnecessary helper
    layers, vague names, boilerplate comments, defensive branches without a real
    failure mode, broad rewrites, or code that ignores the local style.

Architecture Boundaries

  • Keep each layer focused on the concepts it owns. Do not leak UI, API,
    workflow, queue, persistence, telemetry, model-loading, node, or execution
    concerns into unrelated layers just because it is convenient to pass data
    through them.
  • Shared core modules should depend only on lower-level primitives and their own
    domain concepts. Highe...

Files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py

⚙️ CodeRabbit configuration file

**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing a with: block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.

Files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
comfy/**

⚙️ CodeRabbit configuration file

comfy/**: Core ML/diffusion engine. Focus on:

  • Backward compatibility (breaking changes affect all custom nodes)
  • Memory management and GPU resource handling
  • Performance implications in hot paths
  • Thread safety for concurrent execution

Files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
🧠 Learnings (2)
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.

Applied to files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
📚 Learning: 2026-05-13T12:31:45.069Z
Learnt from: rattus128
Repo: Comfy-Org/ComfyUI PR: 13802
File: comfy/pinned_memory.py:19-30
Timestamp: 2026-05-13T12:31:45.069Z
Learning: When reviewing code that uses comfy/pinned_memory.py’s `HostBuffer.extend(size=..., reallocate=...)`: by default (`reallocate` is not True / False), `extend(size=...)` is a *relative increment* that grows the buffer by `size` bytes—so slicing like `[offset:offset+size]` after `hostbuf.extend(size=size)` is correct and the argument should not be rewritten to `offset + size`. Only in the single-segment reallocation mode (`reallocate=True`, e.g., as used by `resize_pin_buffer()` in `comfy/model_management.py`) should `size` be treated as an *absolute target* and the call/arguments should be checked accordingly.

Applied to files:

  • comfy/ldm/krea2/model.py
  • comfy/model_base.py
🔇 Additional comments (6)
comfy/ldm/krea2/model.py (5)

162-199: LGTM!


261-267: LGTM!


268-278: LGTM!


280-310: LGTM!


313-351: LGTM!

comfy/model_base.py (1)

2285-2305: LGTM!


📝 Walkthrough

Walkthrough

This PR adds reference-latent conditioning support to the Krea2 single-stream DiT model. SingleStreamDiT gains a process_img helper and threads ref_latents through forward/_forward, concatenating reference image tokens with primary image tokens and tracking a timestep_zero_index boundary. SingleStreamBlock.forward now splits modulation parameters between base and reference tokens for attention and MLP branches when this index is provided. In comfy/model_base.py, Krea2 was updated to process reference_latents from kwargs, publish them as ref_latents conditioning via CONDList, and compute their expected shapes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No meaningful description was provided, so the PR intent cannot be assessed from the text. Add a short description of the behavior change and affected components.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding timestep-zero reference image support for Krea 2.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants