Skip to content

Studio training cond cache: evict only entries the cache wrote - #18564

Merged
danielhanchen merged 1 commit into
mainfrom
fix-recheck-cond-cache-owner
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-recheck-cond-cache-owner

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

#18519 added a size cap to the persistent training conditioning cache, with least recently used eviction. Eviction decided ownership from the file name alone: any *.safetensors starting with lat_v, txt_v, h3clip_v or h3img_v was counted and could be unlinked. The cache directory can be set by the user (cond_cache_dir), so a user's own file in that directory such as txt_vintage.safetensors or txt_v1_my_embeddings.safetensors was deleted once a write crossed the cap.

Change

  • Every entry written by PersistentConditioningCache.put now carries an owner marker (unsloth_cond_cache: 1) in its safetensors metadata.
  • _entries() only considers a file that passes all of these checks:
    • it is a regular file, not a symlink;
    • its name matches a cache key (lat|txt|h3clip|h3img, then _v and a version digit);
    • its safetensors header has the marker. Entries written before this change are also accepted when their header holds exactly the metadata the cache wrote then (version, family, none_slots, count over t<i> tensors), so existing caches stay bounded.
  • Only the header is read, at most 1 MiB. Files that are unreadable or unexpected are never counted or removed.
  • Files already confirmed are remembered per instance by name, inode and size, so a rescan does not read their headers again.

Reads, keys and stored tensors are unchanged.

Tests

  • test_eviction_never_touches_a_user_file_named_like_a_cache_key writes valid user safetensors files named with every cache prefix, plus one with a partial lookalike header. It then fills the cache past a 1 byte cap. It fails on main (the user files are unlinked) and passes here.

  • test_entries_written_before_the_owner_marker_are_still_evicted checks that an entry with the pre-marker metadata is still evicted oldest first. It passes on both.

  • tests/test_diffusion_train_cond_cache_default.py, test_diffusion_cond_cache.py, test_diffusion_cond_cache_rekey.py, test_diffusion_h3_trainer.py, test_diffusion_train_extras.py, test_diffusion_bucketing.py, test_diffusion_cond_blocks.py, test_diffusion_dit_trainer_ltx25.py and test_diffusion_prompt_cache.py:

    • main: 348 passed, 15 failed;
    • this branch: 350 passed, 15 failed.

    The same 15 test IDs fail on both. They are environment failures (missing jwt and similar optional modules on the CPU test host).

Not proven

  • The cost of the header read on a very large cache directory (tens of thousands of entries) was not timed. It runs once per instance and again only when eviction triggers.

Eviction picked any *.safetensors whose name started with lat_v, txt_v, h3clip_v or h3img_v, so in an explicitly
chosen directory a user file such as txt_vintage.safetensors was unlinked once the cap was crossed. Entries now carry
an owner marker in their safetensors metadata and eviction requires a cache key name plus that marker (or the exact
metadata older entries were written with); anything else is never counted or removed.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T05:36:42.986118Z d07c9ee Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d07c9ee841

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f760c90 into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the fix-recheck-cond-cache-owner branch November 20, 2026 06:28
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