Skip to content

import_fixes + drift detectors: cover transformers 5.x drift (unblocks PR #5376)#5423

Merged
danielhanchen merged 1 commit into
mainfrom
fix/torchcodec-disable-on-transformers-5x
May 14, 2026
Merged

import_fixes + drift detectors: cover transformers 5.x drift (unblocks PR #5376)#5423
danielhanchen merged 1 commit into
mainfrom
fix/torchcodec-disable-on-transformers-5x

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

PR #5414's drift detectors and the corresponding import_fixes helpers were written against transformers 4.x. The Repo tests (CPU) step (studio-backend-ci.yml) installs transformers>=4.51,<5.5 and currently resolves to 5.4.0, which surfaces three real predicate gaps. PR #5376's red Repo tests (CPU) cell is the canonical reproducer.

Two of those gaps land here; the third (triton predicate strictness) was already fixed in PR #5421 and just needs PR #5376 to merge main to pick it up.

What this PR changes

1. test_pretrained_model_enable_input_require_grads_uses_old_pattern

The detector fires DRIFT DETECTED whenever the source contains for module in self.modules(). But the unsloth replacement that patch_enable_input_require_grads installs also uses that pattern (deliberately, just wrapped in try / except NotImplementedError). So the predicate cannot distinguish broken upstream from the working patch. The fix accepts either:

  • pre-HF#41993 shape (no self.modules() loop in the source), or
  • post-patch shape (loop + NotImplementedError handler in the source).

2. test_transformers_torchcodec_available_flag_is_present + disable_torchcodec_if_broken

Detector currently asserts the pre-5.x module-level _torchcodec_available flag. transformers 5 replaced it with an lru_cache'd is_torchcodec_available() callable. Two changes:

  • Detector accepts either symbol (the 4.x flag or the 5.x function).
  • disable_torchcodec_if_broken learns to actually disable on 5.x: clear the function's lru_cache and rebind it to lambda: False. Pre-5.x path (flag flip) is preserved verbatim.

Local verification

  • transformers 4.57.6 + trl 0.25.1 + peft 0.19.1 + triton 3.5.1 + vllm 0.15.1+cu130 (the Core HF=4.57.6 cell shape): 18 passed.
  • transformers 5.8.1 + peft 0.19.1 + torch 2.9 CPU (the Repo tests (CPU) shape, drop trl / vllm / datasets / xformers): 12 passed, 6 skipped on missing optional libs, 0 failed.

How this unblocks PR #5376

PR #5376's Repo tests (CPU) is failing on three drift detectors:

Detector Root cause Fix
triton strict class-only predicate; PR #5376 not rebased onto post-#5421 main merge main into PR #5376
enable_input_require_grads predicate cannot distinguish broken upstream from working patch THIS PR
torchcodec predicate assumes pre-5.x symbol; patch is a no-op on 5.x THIS PR

Once this PR merges, PR #5376 just needs to merge main and CI goes green.

Test plan

PR #5414's drift detectors and the corresponding import_fixes helpers
were written against transformers 4.x. The Repo tests (CPU) step (which
installs transformers>=4.51,<5.5 and currently resolves to 5.4.0)
surfaces three real predicate gaps:

  * test_pretrained_model_enable_input_require_grads_uses_old_pattern
    fires DRIFT DETECTED whenever the source contains
    "for module in self.modules()". But the unsloth replacement that
    patch_enable_input_require_grads installs ALSO uses that pattern --
    deliberately, just wrapped in try / except NotImplementedError. So
    the predicate cannot distinguish broken upstream from the working
    patch. Accept either pre-HF#41993 shape (no self.modules() loop) or
    the post-patch shape (loop + NotImplementedError handler).

  * test_transformers_torchcodec_available_flag_is_present asserts the
    pre-5.x module-level _torchcodec_available flag. transformers 5
    replaced it with an lru_cache'd is_torchcodec_available() callable.
    Accept either symbol. Also update disable_torchcodec_if_broken to
    actually disable on 5.x: clear the cache and rebind the function to
    return False.

Local verification:

  * transformers 4.57.6 + trl 0.25.1 + peft 0.19.1 + triton 3.5.1 +
    vllm 0.15.1+cu130 (the Core HF=4.57.6 cell shape): 18 passed.
  * transformers 5.8.1 + peft 0.19.1 + torch 2.9 CPU (the Repo tests
    (CPU) shape, drop trl / vllm / datasets / xformers): 12 passed,
    6 skipped on missing optional libs, 0 failed.

PR #5376's Repo tests (CPU) failure was a triple:
  - triton + enable_input_require_grads: fixed by merging current main
    (PR #5421's relaxed triton predicate + conftest 'import unsloth').
  - torchcodec: fixed by THIS PR.
@danielhanchen danielhanchen merged commit 770714a into main May 14, 2026
27 of 31 checks passed
@danielhanchen danielhanchen deleted the fix/torchcodec-disable-on-transformers-5x branch May 14, 2026 12:14
danielhanchen added a commit that referenced this pull request May 14, 2026
Brings in PR #5421 (drift detector parity: relaxed triton predicate +
conftest 'import unsloth') and PR #5423 (transformers 5.x coverage:
enable_input_require_grads + torchcodec) which together close the three
DRIFT DETECTED failures on this branch's Repo tests (CPU) cell.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d9a42b226

ℹ️ 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".

Comment thread unsloth/import_fixes.py
is_avail.cache_clear()
except AttributeError:
pass
tf_import_utils.is_torchcodec_available = lambda: False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update the cached backend mapping when stubbing torchcodec

On transformers 5.x, this only rebinds transformers.utils.import_utils.is_torchcodec_available, but BACKENDS_MAPPING is built at import time with the original function object for the "torchcodec" backend. In environments where torchcodec is installed but its native libraries/FFmpeg are broken, any path that checks requires_backends(..., "torchcodec") still calls the old cached function and reports torchcodec as available, so the later audio decode import can still crash instead of falling back. Please also update the BACKENDS_MAPPING["torchcodec"] entry (and any re-exported checker, if present) to point at the false stub.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d9a42b226

ℹ️ 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".

Comment thread unsloth/import_fixes.py
is_avail.cache_clear()
except AttributeError:
pass
tf_import_utils.is_torchcodec_available = lambda: False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update the cached backend mapping when stubbing torchcodec

On transformers 5.x, this only rebinds transformers.utils.import_utils.is_torchcodec_available, but BACKENDS_MAPPING is built at import time with the original function object for the "torchcodec" backend. In environments where torchcodec is installed but its native libraries/FFmpeg are broken, any path that checks requires_backends(..., "torchcodec") still calls the old cached function and reports torchcodec as available, so the later audio decode import can still crash instead of falling back. Please also update the BACKENDS_MAPPING["torchcodec"] entry (and any re-exported checker, if present) to point at the false stub.

Useful? React with 👍 / 👎.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

CodeMan62 pushed a commit to CodeMan62/unsloth-zoo that referenced this pull request May 14, 2026
…3) (unslothai#642)

The two transformers-targeting drift detectors in tests/test_upstream_
import_fixes_drift.py had predicates written against transformers 4.x
only; on the Core matrix's HF=latest cell (transformers>=5,<6) they
fire DRIFT DETECTED even when the upstream / fix combination is healthy.

  * test_pretrained_model_enable_input_require_grads_uses_old_pattern
    fired whenever the source contains "for module in self.modules()".
    But the unsloth replacement that patch_enable_input_require_grads
    installs deliberately ALSO uses that pattern, just wrapped in
    try / except NotImplementedError. The predicate could not
    distinguish broken upstream from the working patch. Accept either
    pre-HF#41993 shape (no self.modules() loop) or the post-patch shape
    (loop + NotImplementedError handler).

  * test_transformers_torchcodec_available_flag_is_present asserted the
    pre-5.x module-level _torchcodec_available flag. transformers 5
    replaced it with an lru_cache'd is_torchcodec_available() callable.
    Accept either symbol -- the patch in unsloth/import_fixes.py now
    targets both (PR #5423 on unslothai/unsloth).

Local verification:

  * transformers 4.57.6 + trl 0.25.1 + peft 0.19.1 + triton 3.5.1 +
    vllm 0.15.1+cu130 (the Core HF=4.57.6 cell shape): 18 passed.
  * transformers 5.8.1 + peft 0.19.1 + torch 2.9 CPU (no trl / vllm /
    datasets / xformers installed): 12 passed, 6 skipped on missing
    optional libs, 0 failed.

The corresponding import_fixes.py changes already shipped on
unslothai/unsloth#5423. Zoo only carries the detectors so this PR is
test-only.
rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request May 17, 2026
Resolve conflict in studio/backend/core/inference/llama_cpp.py: take main's
load_model body wrapped in the serial_load_lock (unslothai#5401 / unslothai#5161) and the
unslothai#5347 mmproj guard, layered with this PR's two intended edits:

- New @staticmethod _build_windows_path_dirs(binary_dir, prefix, cuda_path)
  next to _windows_pip_nvidia_dll_dirs, returning the win32 PATH ordering
  binary_dir, pip-nvidia wheels, CUDA_PATH/bin, CUDA_PATH/bin/x64.
- start_llama_server's win32 branch now calls the helper instead of
  re-implementing the same ordering inline.

The PR's own install_llama_prebuilt.py nit (f"llama-" -> "llama-") and the
new test file under studio/backend/tests/ auto-merged cleanly.

Picks up PR unslothai#5423's transformers 5.x drift-detector predicate fixes via the
merge, which is what was failing on the three Core CI jobs.
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