Repository navigation
Description
Summary
The .venv_t5_* sidecar targets are validated by directory and METADATA version only, so a truncated or deleted file inside an otherwise-intact sidecar is neither detected nor repaired. The worker then dies on import when a Transformers 5.x model is exported or run.
Where
_venv_dir_is_valid (studio/backend/utils/transformers_version.py:1923) checks exactly three things per package: the target dir is non-empty, the package directory exists, and .dist-info/METADATA carries the expected Version:. Nothing looks at file integrity.
That predicate is the sole gate on the existing self-heal:
def _ensure_venv_dir(venv_dir: str, packages: tuple[str, ...], label: str) -> bool:
if _venv_dir_is_valid(venv_dir, packages):
return True
logger.warning("%s not found or incomplete at %s -- installing at runtime", label, venv_dir)
shutil.rmtree(venv_dir, ignore_errors = True)
...So the repair path already exists (transformers_version.py:2030-2044); it just never triggers for this class of damage. A whole package directory being deleted is caught by the existence check. Only sub-file damage slips through.
The installer side has the same blind spot: _target_has_pkg_version (studio/setup.sh:1116-1130) greps METADATA for a version string, so _NEED_T5_INSTALL stays false (setup.sh:1138-1145).
Consequence
activate_transformers_for_subprocess (studio/backend/utils/transformers_version.py:457-460) calls _ensure_venv_t5_550_exists() and then prepends the directory to sys.path. A damaged sidecar passes validation, gets prepended, and the export worker (studio/backend/core/export/worker.py:172) fails on import with an error that points at transformers rather than at a damaged install.
Reachability
Narrow, but real. It needs sub-file damage inside a sidecar with the transformers METADATA intact, plus a fully up-to-date base install, because [ "$_SKIP_PYTHON_DEPS" = false ] && _NEED_T5_INSTALL=true (setup.sh:1145) forces a wholesale sidecar reinstall whenever the base deps pass runs. The usual causes of this shape of damage are a disk-full or an interrupted pip.
Blast radius is one worker spawn for 5.x-tier models, not a Studio that will not boot.
Suggested direction
Make _venv_dir_is_valid compare each distribution's RECORD against the filesystem, in the same shape used by the update-time check in #7691: flag only entries that are missing or shorter than recorded, ignore .dist-info and .pyc, and treat a file larger than recorded as a packaging collision rather than damage. That makes the existing wipe-and-reinstall fire, which repairs automatically and covers users who never run unsloth studio update.
Two things worth deciding rather than assuming:
- Cost. Measured on a live install, scanning all three sidecars is 7918 files in 0.11 seconds with zero false positives.
_venv_dir_is_validruns per sidecar per worker spawn, so roughly 0.04s each. Small next to spawning a Python worker and importing transformers, but it is not free and could be limited to the pinned packages. - False-positive tolerance. A false positive costs a sidecar reinstall (bandwidth and time), not data loss. That is the safer direction, but it is a judgement call about how aggressive the predicate should be.
Raised from Codex review feedback on #7691, which suggested extending that PR's CLI-side scan to cover the sidecars. Declined there because the CLI can only report, while this location repairs.
Activity
fix(studio): detect truncated sidecar files via RECORD in _venv_dir_i…
Repair .venv_t5_* sidecars whose files are damaged (unslothai#7725)
fix(studio): detect truncated sidecar files via RECORD in _venv_dir_i…