fix: isolate embedding staging dir to prevent cross-model contamination#18
fix: isolate embedding staging dir to prevent cross-model contamination#18vojtech-cifka wants to merge 2 commits into
Conversation
Embedding jobs wrote to a shared, persistent output_dir
(embeddings/{split}/tiles) reused across models. Concurrent virchow2 and
provgigapath runs raced in that dir, so log_artifacts uploaded both models'
files into each run's mlflow artifact. Because both models embed the same tile
grid (identical slide_id,x,y keys), this surfaced as mixed embedding
dimensions (2560 + 1536) within a single artifact: a reshape crash for
provgigapath, and inflated many-to-many joins for virchow2.
Write each split into a per-run tempfile.TemporaryDirectory under output_dir
instead. Runs no longer share a path, so concurrent jobs cannot contaminate
each other, and the staging dir is auto-removed after upload (nothing reads it
afterward; training consumes the mlflow run artifacts via runs:/ URIs).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 57 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChangesEmbedding output staging
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
preprocessing/embeddings.py (1)
224-241: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCore staging logic is sound.
The isolated
TemporaryDirectoryapproach correctly prevents cross-run contamination, the artifact layout (split_dircontainingslides.parquetandtiles/) matches the downstream contract (runs:/{embedding_run_id}/{split}/tiles), and auto-cleanup on context exit is safe since MLflowlog_artifactscopies files.One minor nit:
Path(config.output_dir).mkdir(parents=True, exist_ok=True)at line 228 is inside the per-split loop and runs redundantly on every iteration. Consider moving it before the loop.♻️ Move mkdir before the loop
Path(config.output_dir).mkdir(parents=True, exist_ok=True) + for name in config.get("splits", ["train", "test"]): # ... existing loop body ... # Isolated per-run staging dir: avoids cross-model contamination and # stale-file carryover from concurrent or previous runs sharing # output_dir. Auto-removed after upload; nothing reads it afterward # (training reads the mlflow run artifacts via runs:/ URIs). - Path(config.output_dir).mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(dir=config.output_dir) as tmp_root:🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@preprocessing/embeddings.py` around lines 224 - 241, Move the Path(config.output_dir).mkdir(parents=True, exist_ok=True) initialization out of the per-split loop and execute it once before iteration begins. Keep the TemporaryDirectory staging and per-split artifact generation unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@preprocessing/embeddings.py`:
- Around line 224-241: Move the Path(config.output_dir).mkdir(parents=True,
exist_ok=True) initialization out of the per-split loop and execute it once
before iteration begins. Keep the TemporaryDirectory staging and per-split
artifact generation unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9a9714ff-c2c7-4f70-8ecf-edc479960d54
📒 Files selected for processing (1)
preprocessing/embeddings.py
There was a problem hiding this comment.
Code Review
This pull request refactors the preprocessing pipeline in preprocessing/embeddings.py to use a temporary directory (tempfile.TemporaryDirectory) for staging output files instead of writing directly to a shared output directory. This ensures isolated concurrent runs and prevents stale-file carryover. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Why: embedding extraction staging dir was shared across models, risking cross-model contamination of cached embeddings.
What: isolate staging dir per model run.
Summary by CodeRabbit