Repository navigation
Studio: reuse image header dimensions in the dataset labeling listing while the file is unchanged - #16366
Conversation
… while the file is unchanged
…st_ctime is the creation time
|
On the Windows xplat staging leg for this PR (danielhanchen#3687), the new This looks like a real gap in the cache key on Windows, not a test problem. The key is Two ways to close it: on Windows, fall back to rereading the header whenever the key cannot prove the file is unchanged, or skip the cache entirely on |
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
What changes
GET /api/train/diffusion/dataset/{name}/imagesserves the image dataset showcase on dataset selection, the labeling grid toggle, and every refresh after an upload. On every call it opened each image with Pillow to read the header dimensions. The listing now keeps those dimensions per path in a bounded LRU (8192 entries, like the gallery recipe-chunk cache). The key is the stat the listing already takes forsize_bytes:(st_dev, st_ino, st_size, st_mtime_ns, st_ctime_ns). The header is read again as soon as any of these changes: a rewrite moves ctime even when mtime is restored, and a replace moves the inode.size_bytesand every other field are unchanged.upload_diffusion_datasetis not touched. The commit cherry-picks cleanly onto Studio: list the dataset folder once per upload for the caption-stem check #16353 and onto Studio: run diffusion dataset upload file work on a worker thread #16361, and all three merge together.Results (CPU, TestClient end to end, median of 15 requests, 3 runs each, warm page cache)
The first listing in a process still reads every header and takes as long as on base (20 images: 10-12 ms on both; 200: 19-24 ms on both; 3000: 240-294 ms on both). Fixture: 512x512 PNG and JPEG files, half of them with
.txtsidecars, and onemetadata.jsonlrow per image.Tests
New
studio/backend/tests/test_diffusion_dataset_image_size_cache.py:os.replaceis read again;Base vs head differential over 300 seeded datasets. The fixtures cover:
.txt,.captionand.TXTsidecars, including empty, whitespace-only and invalid UTF-8;dir.png;Each seed ran 6 mutation steps (rewrite, rewrite with the old mtime, replace with the old mtime, delete, add, caption PUT, metadata rewrite) and compared the images listing and
/diffusion/infoafter every step. All 4978 responses were byte identical, with 16527 cache hits. As a control, a cache keyed on path only, ignoring the stat key, gives 948 differing responses.test_diffusion_dataset_api.py,test_diffusion_dataset_clips.py,test_dataset_upload_limits.py,test_diffusion_train*.pyandtest_diffusion_training*.py: 369 passed and 4 skipped. The same 3 tests fail on both base and head:test_diffusion_train_perf.py::test_gather_sigmas_matches_search_based_gathertest_diffusion_train_speed.py::test_checkpoint_modes_match_uncheckpointed_grads[plain]test_diffusion_train_speed.py::test_checkpoint_modes_match_uncheckpointed_grads[partial]The suites that read
routes/training.pyas source give the same result on both (725 passed).tests/studio -k "dataset or caption or diffusion_train or labeling": 5 passed, 1 skipped.Not covered
st_ctimeis the creation time, so a same-size rewrite that also restores the old mtime would not be noticed there. The gallery listing cache makes the same tradeoff. The test for that case is skipped on Windows; a normal in-place save, which moves the mtime, is reread on every OS (test_in_place_rewrite_is_reread)./diffusion/infodataset summaries and the metadata reread on caption save are unchanged. At realistic dataset sizes both are below the bar.