Skip to content

fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call#12

Merged
forkni merged 1 commit into
SDTD_040_beta_releasefrom
integ/fio-cache-gate-to-040
Jul 19, 2026
Merged

fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call#12
forkni merged 1 commit into
SDTD_040_beta_releasefrom
integ/fio-cache-gate-to-040

Conversation

@forkni

@forkni forkni commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes a crash on every frame for non-TensorRT SD1.5/2.1 backends (acceleration: none/xformers/sfast): UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'.
  • Root cause: unet_step()'s SD1.5/2.1 branch unconditionally passed fio_cache/fi_strength/fi_threshold to self.unet(...), but those TensorRT-only feature-injection kwargs are not understood by the patched eager PyTorch UNet (_patches/diffusers_kvo_patch.py only adds kvo_cache). The SDXL branch already gated these correctly on _check_unet_tensorrt(); the SD1.5/2.1 branch did not.
  • Fix (Option B): always pass kvo_cache (supported on both backends via the import-time patch), but gate fio_cache/fi_strength/fi_threshold behind self._check_unet_tensorrt(), matching the SDXL branch's convention.
  • Reproduced against a real crash report (sd-turbo/SD2.1, acceleration: none).

Test plan

  • New regression test tests/unit/test_unet_call_backend_gate.py — constructs StreamDiffusion via __new__ (no model download) and a real patched tiny UNet2DConditionModel; watched red pre-fix (TypeError: unexpected keyword argument 'fio_cache'), green post-fix.
  • Verifies the TensorRT-engine path still receives all four cache kwargs (no regression to feature-injection).
  • Full unit suite green: 216/216 (./venv/Scripts/python.exe -m pytest tests/unit -q).
  • ruff check clean on both changed files.

🤖 Generated with Claude Code

…Net call

The SD1.5/2.1 branch of unet_step() unconditionally passed kvo_cache/fio_cache/
fi_strength/fi_threshold to self.unet(...). The import-time diffusers patch
(_patches/diffusers_kvo_patch.py) adds kvo_cache support to the eager PyTorch
UNet, but feature injection is TensorRT-engine-only — the patched forward()
has no fio_cache/fi_strength/fi_threshold parameters. Every non-TRT SD1.5/2.1
run (e.g. acceleration: none) crashed on the first call:

  UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'

Mirrors the SDXL branch's existing _check_unet_tensorrt() gate: kvo_cache is
always passed (both backends support it), the FI trio only when TRT is active.

Adds tests/unit/test_unet_call_backend_gate.py, which reproduces the crash via
a real (patched) tiny UNet2DConditionModel at the actual unet_step() call site
and locks in that the TensorRT path keeps receiving all four cache kwargs.
@forkni
forkni merged commit 996927e into SDTD_040_beta_release Jul 19, 2026
1 check passed
@forkni
forkni deleted the integ/fio-cache-gate-to-040 branch July 19, 2026 13:12
forkni added a commit that referenced this pull request Jul 19, 2026
…Net call (#12) (#13)

The SD1.5/2.1 branch of unet_step() unconditionally passed kvo_cache/fio_cache/
fi_strength/fi_threshold to self.unet(...). The import-time diffusers patch
(_patches/diffusers_kvo_patch.py) adds kvo_cache support to the eager PyTorch
UNet, but feature injection is TensorRT-engine-only — the patched forward()
has no fio_cache/fi_strength/fi_threshold parameters. Every non-TRT SD1.5/2.1
run (e.g. acceleration: none) crashed on the first call:

  UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'

Mirrors the SDXL branch's existing _check_unet_tensorrt() gate: kvo_cache is
always passed (both backends support it), the FI trio only when TRT is active.

Adds tests/unit/test_unet_call_backend_gate.py, which reproduces the crash via
a real (patched) tiny UNet2DConditionModel at the actual unet_step() call site
and locks in that the TensorRT path keeps receiving all four cache kwargs.
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.

1 participant