Flux Block Share KV
Make Every Image in a Flux Batch Attend to the Whole Batch
- model
- MODEL
This is the weird sibling in the Flux blocks patcher pack, and nobody's really talking about it - which tracks, because it's pure research-toy territory. While its sibling FluxBlockPatcherSampler scales weights to find which blocks matter, FluxBlockShareKV rewires how Flux's attention works in the middle of a batch. If you generate batches (say, four images of the same scene at once), this node makes every image in the batch attend to the keys and values of the entire batch, not just its own.
The pitch is consistency and experiment: a 4-up batch stops being four independent rolls and becomes four images sharing one visual context. Whether that's a feature or a bug depends entirely on what you're trying to do. It's honest-to-goodness "try it and see" material from cubiq (Matteo, of Latent Vision / ComfyUI_IPAdapter_plus fame), and the README's own words apply: very advanced, very experimental.
How it works
FluxBlockShareKV sits between your model loader and the sampler. Drop it in the model path - UNETLoader → FluxBlockShareKV → KSampler - and it hands the same MODEL object back, so everything downstream gets the patched model.
Under the hood it monkey-patches the forward() of whichever Flux transformer blocks your regex selects. The custom forwards take the image-token keys and values, concatenate the whole batch's worth into one sequence, and repeat that into every sample. Result: each image's attention sees its own tokens and every other image's tokens. The text path is left alone (Flux's 512 text tokens keep their own KV), so only the image side shares.
A few consequences worth knowing:
- It only does anything with batch size > 1. Batch of one and it's a no-op wearing a trenchcoat.
- Patching all 19 double + 38 single blocks by default is a big hammer. The
blocksbox takes regex lines likedouble_blocks\.([0-9]+), so you can limit it to, say, justdouble_blocks\.0\.to confine the experiment. - The model is modified in place. There's no "unpatch" - the returned model is the patched model, so anything downstream of it (including a second sampler in the same graph) sees the shared-KV behavior.
Inputs and outputs
Sparse on both, which is refreshing. Required: model and blocks (a multiline regex box, defaulting to all double and single blocks). Output: a single MODEL that you feed to a normal sampler. The pack's example workflow shows it feeding both a BasicGuider and a BasicScheduler, then a standard SamplerCustomAdvanced - so yes, you still use a regular sampler after it.
Installing
ComfyUI Manager (search "Flux blocks patcher sampler") or:
cd ComfyUI/custom_nodes
git clone https://github.com/cubiq/Block_Patcher_ComfyUI
Restart and it's live. No requirements.txt, no model downloads - it hardcodes against ComfyUI's own comfy.ldm.flux layers, which is exactly the thing to keep in mind.
The honest warning
This node is Flux-only by construction, hardcodes the 512-token text assumption, and reaches into comfy.ldm.flux internals. The author's own TODO - speed up, support other models, make it user-friendly - is still a TODO. Every ComfyUI update is a chance for this to quietly break, and because the failure is a wrong-forward monkey-patch rather than a clean error, "quietly" is doing a lot of work there. Use it as a curiosity, verify the output, and don't build a production pipeline on it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| blocks | STRING | double_blocks\.([0-9]+) single_blocks\.([0-9]+) | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |