From cb08175be78f79b4101029f1db62a82fbc9cb8a1 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 19 Jul 2026 13:53:19 -0400 Subject: [PATCH] fix: guard fold_constants against 0-node graphs for CLIP's optimize() override too CLIP's optimize() (models.py) overrides BaseModel.optimize() entirely and calls opt.fold_constants() directly, bypassing the 0-node guard added to BaseModel.optimize() in the prior fix (#16). Move an equivalent guard into Optimizer.fold_constants() itself so every optimize() variant -- current and future -- is covered by a single check at the one call site that actually crashes on an empty/corrupt source ONNX. Co-Authored-By: Claude Sonnet 5 --- .../acceleration/tensorrt/models/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/streamdiffusion/acceleration/tensorrt/models/models.py b/src/streamdiffusion/acceleration/tensorrt/models/models.py index 4d3a13f7..a47a68be 100644 --- a/src/streamdiffusion/acceleration/tensorrt/models/models.py +++ b/src/streamdiffusion/acceleration/tensorrt/models/models.py @@ -60,6 +60,15 @@ def fold_constants(self, return_onnx=False): # quantize), so is_fp8 is always False here for the UNet/ControlNet path. Gate on size # too (same >2GB threshold Optimizer.infer_shapes uses below) so the doomed ORT attempt # is skipped for any large graph. Small fp16/CLIP/VAE graphs keep the faster ORT path. + if len(self.graph.nodes) == 0: + # Catches a corrupt/truncated source ONNX (e.g. left behind by an interrupted + # export) here too -- CLIP's optimize() override (below) calls fold_constants() + # directly without going through BaseModel.optimize()'s equivalent guard, so that + # check alone doesn't cover every caller. + raise RuntimeError( + "Optimizer.fold_constants: input ONNX graph has 0 nodes -- the source ONNX is " + "empty or corrupt. Delete the cached .onnx file for this engine and rebuild." + ) onnx_graph = gs.export_onnx(self.graph) is_fp8 = any(n.op in ("QuantizeLinear", "DequantizeLinear") for n in self.graph.nodes) is_large = onnx_graph.ByteSize() > 2147483648