ComfyUI Node

Bokeh KSampler

The KSampler That Speaks Bokeh (And Knows It's a FLUX)

By jrabek·Created 9 months ago·Updated 9 months ago· 1
Bokeh KSampler
  • model
  • positive
  • negative
  • latent_image
  • bokeh_control
  • latent
seed0
steps30
cfg3.0
sampler_nameeuler
schedulersimple
true_cfg1.0

This is the payoff node. Bokeh KSampler is a drop-in replacement for the standard KSampler with one extra job: it reads the BOKEH_CONTROL coming out of Bokeh Level and feeds your bokeh level straight into the model's attention while it denoises. Every other node in this pack is setup; this one is the show.

You'll notice immediately that it looks like a normal KSampler - same model, positive, negative, latent, seed, steps, cfg, sampler, scheduler. That's the point. The one thing you must not do is swap in the vanilla KSampler: it has no idea what a BOKEH_CONTROL is, and the whole blur-control mechanism evaporates.

How it works

When it runs, the node checks that your model actually has the adapter attached (if you forgot Apply Bokeh Adapter, it refuses with a clear error). Then it takes the bokeh level - normalized to 0–1 - and converts it to an embedding via the adapter's embedding layer. It patches the transformer's forward pass to slip that embedding into joint_attention_kwargs, and the custom attention processors injected by Apply Bokeh Adapter use it to add defocus-specific key and value projections. In grounded mode, it also swaps batch rows during the first num_grounding_steps to keep the scene anchored at the pivot level before transitioning. Then it hands everything to ComfyUI's normal sampling routine, so all your usual samplers and schedulers still work.

The inputs that matter

  • bokeh_control - required, from Bokeh Level. This is the input that makes it a bokeh sampler.
  • cfg - defaults to 3.0, which is sensible: FLUX guidance lives around 3.5, and the community's comfort zone for people shots is lower, roughly 1.8–2.0. You'll want the higher end when you want that background to actually melt.
  • sampler_name / scheduler - same lists as the stock KSampler (the node pulls ComfyUI's own sampler constants). The defaults, euler + simple, are the right place to start on FLUX.
  • true_cfg - the one oddball, optional. The tooltip calls it "True CFG scale for negative prompt," i.e. a way to give your negative prompt real pressure. Default 1.0 means off. Fair warning: the shipped code stores it on the transformer but doesn't visibly consume it in the attention processors, so don't expect dramatic changes - treat it as the author's future hook and leave it at 1.0 unless you're experimenting.

Output is a latent, exactly like a normal KSampler - feed it to a VAE Decode and you're done.

Installing the pack

ComfyUI Manager, search BokehDiffusionComfyUI, or:

cd ComfyUI/custom_nodes
git clone https://github.com/jrabek/BokehDiffusionComfyUI

Restart, then ensure the real dependencies are installed (diffusers>=0.32.2, transformers>=4.53.0, huggingface_hub, opencv-python). The first generation downloads the adapter weights from HuggingFace, so expect a pause.

Common issues

  • "Model does not have bokeh adapter applied" - you skipped Apply Bokeh Adapter (or your model was reloaded). Reconnect the chain.
  • First run is slow / seems stuck - that's the HF download of atfortes/BokehDiffusion plus the adapter moving to your GPU. Normal once.
  • No visible bokeh effect - check Bokeh Level: if num_grounding_steps is 0 the sampler just does plain blur control at your level, and a low bokeh_level genuinely means near-sharp. Also confirm bokeh_scale on the loader isn't pulled down toward 0.

This is research-grade software with next to no community footprint, so the console's verbose ===== debug logs are your real support forum. But once the chain is connected, it's just a KSampler with a superpower - and FLUX is exactly the model you want it on, since realistic depth of field is where vanilla models consistently lie.

Categorybokeh_diffusion/sampling

Inputs (11)

NameTypeDefaultDescription
modelMODEL
positiveCONDITIONING
negativeCONDITIONING
latent_imageLATENT
seedINT00–18446744073709550000
stepsINT301–10000
cfgFLOAT3.00–100
sampler_nameCOMBOeuler44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38
schedulerCOMBOsimple9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3
bokeh_controlBOKEH_CONTROL
true_cfgoptFLOAT1.00–10True CFG scale for negative prompt

Outputs (1)

NameTypeDescription
latentLATENT