Repository navigation
Studio: stop installing flash-linear-attention and tilelang, unsloth_zoo vendors the GDN kernels - #10487
Conversation
…zoo vendors the GDN kernels unsloth_zoo now ships the gated-delta FLA kernels in unsloth_zoo/_vendored/fla and injects them as a real top-level fla during `import unsloth`, where it also rebinds transformers' is_flash_linear_attention_available probe and sets FLA_TILELANG=0. That makes the worker's pip installs inert: the vendored tree shadows any pip flash-linear-attention at 0.5.1 or older, so the wheels Studio pulled were paid for and never imported, and the TileLang backend was switched off before FLA could dispatch to it. This removes those install paths, their skip env vars, the tvm-ffi repair, the transformers model-type discovery that gated them, and the FLA hook on the availability gate; causal-conv1d, mamba-ssm and the long-context flash-attn install keep their existing gating and wheel-first logic unchanged. The worker now logs FLA availability from the vendored import once the trainer has imported unsloth, rather than from pip metadata. Verified on this box that after `import unsloth` fla resolves to unsloth_zoo/_vendored/fla, FLA_TILELANG is 0 and is_flash_linear_attention_available() is True even with pip flash-linear-attention 0.5.0 and tilelang 0.1.8 installed. Ran the rewritten studio/backend/tests/test_training_worker_flash_attn.py (45 passed), every studio backend test that imports worker.py (3679 passed, 1 skipped), tests/kaggle (1032 passed), ruff check over the repo and the canonical scripts/run_ruff_format.py over each edited file.
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. Delightful! 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". |
…ests Dropping the installers also dropped the HIP guard, so a user who already has a pip flash-linear-attention plus tilelang would let FLA's dispatcher pick the TileLang backend on ROCm, where tilelang has no HIP GEMM. _install_fast_path_hooks sets FLA_TILELANG=0 again when torch.version.hip is truthy, via setdefault so an explicit user value still wins, and it imports torch lazily so nothing new is pulled in before transformers. The no-install tests were weaker than they looked: the shutil.which double returned None for everything, so the uv branch of every installer was never built, and the source check only rejected the exact pinned spec "flash-linear-attention==". They are now parametrized over uv present and absent, and the source check parses worker.py with ast and rejects any string constant starting with one of the four package names, allowlisting the two prose log lines by exact text. Also adds direct coverage for _flash_linear_attention_importable in both directions and corrects three comments that named the deleted _torch_has_hip helper or claimed fla is not importable before from_pretrained, which the vendored injection at import unsloth makes false.
|
@codex security review |
…n the FLA_TILELANG guard Move the FLA_TILELANG guard out of _install_fast_path_hooks into a small _guard_fla_tilelang helper and give it back the second HIP signal the removed _torch_has_hip helper had, since AMD SDK and Radeon ROCm wheels can leave torch.version.hip unset while still tagging torch.__version__ with rocm. It also restores the offline half of the old tvm-ffi protection: when a leftover pip tilelang is importable and apache-tvm-ffi is 0.1.10 or 0.1.11, which fault with "CUDA: misaligned address" on sm_100, set FLA_TILELANG=0 instead of installing or downgrading anything. Both checks use setdefault, so an explicit user FLA_TILELANG still wins, and the source guard test gains the two bare package names its probes pass while still failing on any pip spec.
UNSLOTH_STUDIO_SKIP_FAST_PATH_HOOKS=1 returned before the ROCm and broken tvm-ffi guard ran, so a retained pip fla could still dispatch to TileLang on that path. The guard now runs first; the opt-out only skips the hooks.
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
…l check, accurate guard log A test that calls monkeypatch.delenv on an already absent FLA_TILELANG records no undo, so the guard's os.environ.setdefault created the variable and leaked it into later tests and xdist workers; a module level autouse fixture now snapshots and restores FLA_TILELANG and UNSLOTH_STUDIO_SKIP_FAST_PATH_HOOKS exactly, present or absent. The torch stub used by the guard tests now pins torch.__version__ as well as torch.version.hip, so the CUDA case is not turned into a ROCm case by the host's own rocm tagged wheel. The source allowlist stopped forbidding a bare "tilelang" once those names were added to it wholesale, so the check is now context aware: a constant naming the vendored stack passes only as one of the two prose log lines or as the sole argument of importlib.util.find_spec / importlib.metadata.version, and any occurrence in a list or tuple literal, or in an append / extend / concatenation argument, fails. Finally the guard only logs the disabling line when it actually set the value, says so plainly when an environment override is kept, and reports a skipped detection at debug level instead of swallowing it.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
Summary
Studio's training worker installs
flash-linear-attention0.5.0,fla-core,tilelang0.1.8 andapache-tvm-ffi0.1.9 before training a Qwen3.5 / Qwen3.6 / Qwen3-Next model (added in #5434). None of that is used any more: unsloth_zoo vendors the FLA gated delta net kernels (unsloth_zoo/_vendored/fla, 0.5.1) and injects them asflaatimport unsloth. The vendor patch shadows any pip fla that is not strictly newer than 0.5.1, replaces transformers'is_flash_linear_attention_availableand hard setsFLA_TILELANG=0, so the pinned 0.5.0 install and the TileLang backend were never on the training path. This PR removes the installers and their tests and keeps causal-conv1d, mamba-ssm and the long context flash-attn install exactly as they are.Changes
studio/backend/core/training/worker.py: drop_ensure_flash_linear_attention*,_ensure_tilelang_backend*,_discover_fla_model_types,_model_wants_tilelang, the tvm-ffi version probes and their constants and skip env vars._install_fast_path_hooksnow wires only the causal-conv1d gate. A one line log after the trainer import reports whetherfla.ops.gated_delta_ruleis importable (it comes from the vendored copy).studio/backend/tests/test_training_worker_flash_attn.py: remove the tests for the deleted helpers, adapt the hook tests to the causal-conv1d only gate, addtest_no_install_path_pips_flash_linear_attention_or_tilelang, which records every pip argv the worker builds across the causal-conv1d, mamba-ssm, flash-attn and hook paths and asserts none of them names the four packages.docker/Dockerfile: the nvcc + cudart-dev comment credited the TileLang JIT; it now credits flashinfer, which is the remaining consumer. Package list unchanged.tests/kaggle/t4_smoke/kernel_provenance.py,studio/backend/utils/mlx_repair.py: docstrings updated to describe the vendored source.Does transformers need a patch?
No.
transformers/models/qwen3_5/modeling_qwen3_5.pydoesif is_flash_linear_attention_available(): from fla.ops.gated_delta_rule import chunk_gated_delta_rule, fused_recurrent_gated_delta_ruleand gatesis_fast_path_availableon those plus causal-conv1d. Two mechanisms make that true with only the vendored copy present:unsloth_zoo/temporary_patches/fla_vendor.py_patch_is_availableclears thelru_cacheand replacestransformers.utils.import_utils.is_flash_linear_attention_availablewith a probe that answers True for theqwen3_5,qwen3_5_moeandqwen3_nextmodeling modules, then rebinds the name in every already importedtransformers.*namespace. The modeling modules import afterimport unsloth, so they bind the replaced probe._is_package_availablefalls back toimportlib.import_modulewhen metadata is missing and reads the vendoredfla.__version__of 0.5.1, which passes the>= 0.2.2check.Verified in a venv with
flash-linear-attention,fla-core,tilelangandapache-tvm-ffiuninstalled (torch 2.12.1+cu130, transformers 5.5.0, B200), after loading each ofunsloth/Qwen3.5-2B,unsloth/Qwen3.8-27Bandunsloth/Qwen3.6-35B-A3B:is_flash_linear_attention_available()layer.chunk_gated_delta_ruleunsloth_zoo/_vendored/fla/ops/gated_delta_rule/chunk.pylayer.recurrent_gated_delta_rulefused_recurrent_gated_delta_rulemodeling_qwen3_5.is_fast_path_availablecausal_conv1d_fncausal_conv1d_cudaTraining parity
30 step LoRA runs (r=16, 4-bit, bs 2 x ga 2, seq 2048, seed 3407) in three conditions: vendored only, pip FLA present but shadowed (current Studio state), and pip FLA + TileLang forced on (
UNSLOTH_DISABLE_VENDORED_FLA=1 FLA_TILELANG=1). Each condition was also repeated unchanged to get the run to run noise floor.Loss differences between conditions sit at or below the same condition repeat noise, step times are within the repeat spread, and peak memory is byte identical.
TileLang
TileLang was re-measured at the shapes transformers actually calls (q/k are expanded to the value head count before the kernel runs, H = HV of 16, 48 and 32).
chunk_gated_delta_rulefwd+bwd, bf16, B200, backend selection confirmed through the FLA registry log:TileLang only overrides
chunk_bwd_dqkwgand is 2 to 5 percent slower at 2048 tokens and 1 to 2.5 percent faster at 8192, on a kernel that is about 1.6 ms of a 1100 ms step. The 26 percent speedup reported in #5434 did not reproduce end to end (three repeats of Qwen3.8-27B: Triton 1108 / 1169 / 1138 ms, TileLang 1231 / 1249 / 1152 ms). Vendoring it is not an option: the TileLang kernels are 45 KB of Python decorated withtilelang.jit, so they still need the 180 MB tilelang runtime, apache-tvm-ffi, nvcc at run time, a per shape JIT compile of about 12 s and a cache under the home directory, and tilelang 0.1.8 has no Windows wheel.Tests
studio/backend/tests/test_training_worker_flash_attn.py: 45 passedtests/kaggle: 1032 passedstudio/backend/tests/test_mlx_repair.py: 36 passedruff checkcleanReview follow-ups
FLA_TILELANG=0before transformers imports is kept (assetdefault, so a user override survives), so a user-installed pip fla can never dispatch to TileLang on HIP.UNSLOTH_DISABLE_VENDORED_FLA=1is an explicit opt-out of Unsloth's kernels. Before this PR Studio's pinned pip fla 0.5.0 happened to serve as a fallback for that flag; now the flag alone leaves the pure torch path, and the loader prints the pip advice. Studio does not reinstate an install for that case.