fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call#12
Merged
Merged
Conversation
…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.
3 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
acceleration: none/xformers/sfast):UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'.unet_step()'s SD1.5/2.1 branch unconditionally passedfio_cache/fi_strength/fi_thresholdtoself.unet(...), but those TensorRT-only feature-injection kwargs are not understood by the patched eager PyTorch UNet (_patches/diffusers_kvo_patch.pyonly addskvo_cache). The SDXL branch already gated these correctly on_check_unet_tensorrt(); the SD1.5/2.1 branch did not.kvo_cache(supported on both backends via the import-time patch), but gatefio_cache/fi_strength/fi_thresholdbehindself._check_unet_tensorrt(), matching the SDXL branch's convention.sd-turbo/SD2.1,acceleration: none).Test plan
tests/unit/test_unet_call_backend_gate.py— constructsStreamDiffusionvia__new__(no model download) and a real patched tinyUNet2DConditionModel; watched red pre-fix (TypeError: unexpected keyword argument 'fio_cache'), green post-fix../venv/Scripts/python.exe -m pytest tests/unit -q).ruff checkclean on both changed files.🤖 Generated with Claude Code