fix(tensorrt): hash UNet engine cache key so ONNX export path stays under Windows MAX_PATH#29
Open
forkni wants to merge 1 commit into
Open
Conversation
…ws MAX_PATH EngineManager.get_engine_path encoded every UNet build flag verbatim into the on-disk directory name. With a realistic engine_dir (fp8 + static batch + pin_cache_frames + optlvl + resolution), the folder grew to 246 chars, and the derived unet.engine.onnx / unet.engine.opt.onnx paths hit 263/267 chars -- over Windows' 260-char MAX_PATH. Because the *directory* fit but the *file* didn't, mkdir succeeded while torch.onnx.export's open(onnx_path, "wb") raised FileNotFoundError, which wrapper.py's OOM-only fallback doesn't catch, so the build failed with "Acceleration has failed: [Errno 2] No such file or directory: ...unet.engine.onnx". Fix: for EngineType.UNET only, hash the fully-assembled flag prefix (sha1, first 12 hex chars) using the existing _lora_signature hashing idiom, keeping model name + fp8 + resolution human-readable in the folder name. Cache-key precision is unchanged (identical configs still hash identically, differing configs still diverge) -- only the on-disk encoding is compacted, from ~267 chars down to ~132. VAE/ControlNet directory naming is untouched, so existing VAE engines are not invalidated; UNet engines rebuild once under their new hashed folder name. Also adds a belt-and-suspenders warning if a derived path would still approach MAX_PATH (e.g. an unusually deep user engine_dir), and casts the "filename" config lookup to str to keep the type checker precise about self._configs' heterogeneous per-key value types. Adds a regression test (test_engine_path_length.py) that reproduces the exact crash-log config and asserts the derived .onnx / .opt.onnx paths stay under MAX_PATH, plus determinism and no-collision checks. Co-Authored-By: Claude Opus 4.8 <[email protected]>
3 tasks
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.
Problem
Loading StreamDiffusionTD with
sd-turbo+fp8: true+acceleration: tensorrtcrashes during TensorRT engine build:Root cause
EngineManager.get_engine_pathencodes every UNet build flag verbatim into the on-disk directory name. With a realisticengine_dirand a config using fp8 + static batch +pin_cache_frames+ optlvl + resolution, the generated directory was 246 chars; the derivedunet.engine.onnxpath was 263 andunet.engine.opt.onnxwas 267 — both over Windows' 260-charMAX_PATH.Because the directory fit but the file didn't,
mkdirsilently succeeded whiletorch.onnx.export→open(onnx_path, "wb")raised a bareFileNotFoundError.wrapper.py's OOM-only fallback doesn't catch this, so it re-raises asAcceleration has failed.Fix
For
EngineType.UNETonly, hash the fully-assembled flag prefix (sha1, first 12 hex chars) — reusing the existing_lora_signaturehashing idiom — keeping model name, fp8, and resolution human-readable in the folder name.VAE/ControlNetdirectory naming is untouched — existing VAE/ControlNet engines are not invalidated. UNet engines rebuild once under their new hashed folder name.MAX_PATH(e.g. an unusually deep userengine_dir), so a future added flag can't silently regress this again.Testing
Adds
tests/unit/test_engine_path_length.py, which reproduces the exact crash-log config and asserts:.onnx/.opt.onnxpaths stay underMAX_PATH(red before the fix, green after)static_batch_size) still produce distinct directories (no collisions)3 passed.
🤖 Generated with Claude Code