Skip to content

[AI] Fix disk cache load with dynamic encoder output shapes#20601

Merged
TurboGit merged 1 commit intodarktable-org:masterfrom
andriiryzhkov:cache_fix
Mar 20, 2026
Merged

[AI] Fix disk cache load with dynamic encoder output shapes#20601
TurboGit merged 1 commit intodarktable-org:masterfrom
andriiryzhkov:cache_fix

Conversation

@andriiryzhkov
Copy link
Contributor

Problem

The disk cache for object mask encoder embeddings always fails on the first load after restarting darktable. The second load of the same image (within the same session) works fine.

Root cause

When the model loads with ORT_DISABLE_ALL (fallback for ORT versions where optimization crashes), encoder output shapes are reported as dynamic (-1). The cache file stores the resolved shapes from a previous inference (e.g. [1, 32, 256, 256]), but on load the validation compares them against the model's unresolved shapes ([-1, 32, -1, -1]) and rejects the mismatch.

After re-encoding, ctx->enc_shapes gets updated with resolved values, so subsequent cache loads in the same session succeed.

Fix

  • Skip dimension validation when either the model or cache file reports a dynamic dim (<= 0)
  • Copy resolved shapes from the cache file into ctx->enc_shapes after a successful load, so the decoder gets valid shapes instead of -1

@TurboGit TurboGit added this to the 5.6 milestone Mar 20, 2026
@TurboGit TurboGit added the scope: codebase making darktable source code easier to manage label Mar 20, 2026
Copy link
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TurboGit TurboGit merged commit 97169d8 into darktable-org:master Mar 20, 2026
5 checks passed
@andriiryzhkov andriiryzhkov deleted the cache_fix branch March 20, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: codebase making darktable source code easier to manage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants