Skip to content

Studio: Fix export subprocess crash by restoring transformers activation helper#4959

Closed
Imagineer99 wants to merge 1 commit intounslothai:studio/export-dialog-live-logsfrom
Imagineer99:studio/export-dialog-live-logs
Closed

Studio: Fix export subprocess crash by restoring transformers activation helper#4959
Imagineer99 wants to merge 1 commit intounslothai:studio/export-dialog-live-logsfrom
Imagineer99:studio/export-dialog-live-logs

Conversation

@Imagineer99
Copy link
Copy Markdown
Collaborator

@Imagineer99 Imagineer99 commented Apr 10, 2026

Issue:

Exporting unsloth/qwen2.5-vl-3b-instruct-unsloth-bnb-4bit checkpoint failed with Failed to activate transformers version: cannot import name 'activate_transformers_for_subprocess' ...

Fixes GGUF/export subprocess startup failure caused by a missing activate_transformers_for_subprocess symbol.
Restores a backward-compatible helper in backend/utils/transformers_version.py so core/export/worker.py can activate the correct transformers environment before ML imports.

Root Cause

core/export/worker.py imported activate_transformers_for_subprocess, but the function had been removed from utils/transformers_version.py in this branch, causing import-time export failure.

Test plan

  • Start Studio and load a checkpoint in Export.
  • Run GGUF export for a known checkpoint that previously failed.
  • Confirm export proceeds past subprocess initialization without import errors.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the activate_transformers_for_subprocess function to manage transformers versions for worker subprocesses by updating sys.path and PYTHONPATH. A critical concern was raised regarding the call to _resolve_base_model, which might trigger a premature import of the transformers library, effectively locking the process into the default version and rendering the subsequent environment switch ineffective.

prepends ``.venv_t5`` to ``sys.path`` and propagates that path via
``PYTHONPATH`` so child processes (e.g. GGUF converter) inherit it.
"""
resolved = _resolve_base_model(model_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calling _resolve_base_model here carries a risk of prematurely loading the transformers library before the environment is switched. Specifically, _resolve_base_model (at line 118) can lazily import utils.models, which is listed in _PURGE_PREFIXES as a module that holds references to transformers internals. If this import triggers a transformers load, the subprocess will be locked into the default version, and subsequent attempts to switch versions via sys.path will be ignored because the module is already in sys.modules.

Since this function is intended to be called before any ML imports, consider if _resolve_base_model can be made safe (e.g., by avoiding the heavy fallback that imports utils.models) or if the path switch should happen earlier.

@rolandtannous rolandtannous marked this pull request as draft April 10, 2026 17:47
@rolandtannous rolandtannous self-assigned this Apr 10, 2026
@rolandtannous
Copy link
Copy Markdown
Collaborator

This is no longer needed as rebasing from main branch into studio/export-dialog-live-logs resolved that issue in the branch. thank you for the effort !

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.

2 participants