Extensions/Relay-Attn
ComfyUI Extension

Relay-Attn

Model-agnostic ComfyUI accelerators: DiTFastAttn residual-window attention and PostCFGCache 2nd-order trajectory cache, with dev-only research nodes. Zero model names in core/hot path. MIT.

By ZenHG·Created a day ago·Updated about 23 hours ago· 0
ZenHG/ComfyUI-Relay-Attn
Nodes—
On cloudLocal install
Stars0
Updatedabout 23 hours ago
Readme

Relay-Attn

English · 中文

<p align="center"><img src="assets/banner.png" width="100%" alt="Relay-Attn"></p>

Relay-Attn is a ComfyUI acceleration pack with two orthogonal axes: trajectory caching skips whole denoising steps, while attention backends reduce the cost of each remaining step. The core is model-agnostic; MOSS and H3-Image are validation workloads only.

| Item | Value | |---|---| | Version | 1.0.0 (V1.0) | | Repository | https://github.com/ZenHG/ComfyUI-Relay-Attn | | Registry id | relay-attn | | Registry | https://registry.comfy.org/nodes/relay-attn | | License | MIT; see LICENSE and THIRD-PARTY-NOTICES.md | | Host | ComfyUI ≥ 0.45.0 | | Base requirements | Host-provided torch / comfy / einops; Kitchen/Sage/FA4/Sparge/Sol require optional native packages |

Quick start

  1. Clone into ComfyUI/custom_nodes/ and restart ComfyUI:
    git clone https://github.com/ZenHG/ComfyUI-Relay-Attn.git
    
  2. Drag a UI workflow from examples/ into ComfyUI, or use its .api.json pair.
  3. Pick the workflow for your model. MOSS and H3-Image use different samplers, so absolute runtimes must not be compared across models.

| Example | Purpose | |---|---| | moss_postcfg_strict_lossless | MOSS quality-first default | | moss_postcfg_fast_turbo | MOSS perceptual speed mode | | moss_ditfastattn_window_sparse | Sparse-attention preview | | h3_image_postcfg | H3-Image LCM 6-step + Kitchen speed preview; strict quality gate not passed |

Model prerequisites: MOSS examples need MOSSImage R4, Qwen3.5 text encoder, and Flux2 VAE. H3-Image examples need the MiniMax H3 Image model, CLIP, VAE, and Kitchen.

Recommended routes

  • MOSS image generation: use PostCFGCachePatch(strict_lossless) by default. Use fast_turbo when perceptual drift is acceptable.
  • H3-Image quality-first: keep SDPA as the reference. No tested H3-Image 4K combination currently passes the strict quality gate with attributable speedup.
  • H3-Image speed-first: Kitchen is viable only with same-seed A/B validation.
  • Probes: use preview for debugging, balanced for a trade-off, strict for final validation, and an offline calibrated plan to remove runtime probes.

Public nodes

| Node | Role | |---|---| | PostCFGCachePatch | Second-order trajectory cache after PREDICT_NOISE merging | | DiTFastAttnPatch | Dense/approximate attention backends plus residual-window scheduling | | PostCFGCacheStats | Computed/skipped step counters | | RelayAttnStats | Exact/approximate/probe/fallback counters | | ResolutionGatedAttentionPatch | Token-count-based dense/full-attention routing | | ContextWindowPatch | Model-agnostic 1D/2D overlapping windows | | ContextWindowStats | Context-window coverage and fusion statistics |

The two patches are orthogonal: caching skips whole steps; backends reduce the cost of the remaining steps.

Backends

  • Dense/full-attention: sdpa / kitchen / sage / flash4. Dense does not mean mathematically lossless; Kitchen and Sage are quantized.
  • Approximate: window_sparse / sparge / sol / tome. Use only for previews or after perceptual validation.
  • Unsupported backends fall back explicitly to SDPA and increment counters. No error does not prove the backend ran.

Quality gate

Final image acceptance requires all three thresholds at the same time:

SSIM ≥ 0.99
PSNR ≥ 36 dB
LPIPS ≤ 0.02

Runtime probes are intermediate error gates; they do not replace final same-seed image A/B validation.

V1.0 boundaries

  • MOSS 1024²: strict_lossless reaches 1.23× and passes all three gates across three seeds; fast_turbo reaches 1.51× and beats native LazyCache.
  • H3-Image 4K: Kitchen 1.11×, FA4 0.83×. Kitchen+PostCFG reaches 1.55× and Sol/Sparge+PostCFG reach 1.46–1.50× / 1.39–1.44×, but all fail the strict quality gate.
  • Qwen 2.1 4K (user recipe): Kitchen is 1.50× vs SDPA. PostCFG strict/custom add 1.05× with 0 skipped steps at 4-step, Relay DiTFastAttn is 0.98× because GQA blocks sparse attention, and ResolutionGate is 1.04×. Our nodes add little beyond Kitchen on this workload.
  • ProgressiveLift, M2A/Reblock/Anchor/StaticKV, and related research nodes are DEV_ONLY + EXPERIMENTAL.
  • H3-Image seed sweeps should reuse one conditioning branch to avoid repeated VL encoding; use --cache-none only for benchmarks.

Speedups

| Workload | Configuration | Speedup | Strict gate | |---|---|---:|---| | MOSS 1024² / 30-step | PostCFG strict_lossless | 1.23× | PASS | | MOSS 1024² / 30-step | PostCFG fast_turbo | 1.51× | FAIL | | H3-Image 4K / 6-step | Kitchen | 1.11× | FAIL | | H3-Image 4K / 6-step | Sol + PostCFG | 1.46–1.50× | FAIL | | H3-Image 4K / 6-step | Sparge + PostCFG | 1.39–1.44× | FAIL | | H3-Image 4K / 6-step | Kitchen + PostCFG | 1.55× | FAIL |

Detailed parameters, calibration notes, and negative results are kept in local development documents and are not shipped with the node package.