Skip to content

Studio: stop installing flash-linear-attention and tilelang, unsloth_zoo vendors the GDN kernels - #10487

Merged
danielhanchen merged 11 commits into
mainfrom
studio-drop-fla-install
Sep 8, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
studio-drop-fla-install

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Studio's training worker installs flash-linear-attention 0.5.0, fla-core, tilelang 0.1.8 and apache-tvm-ffi 0.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 as fla at import unsloth. The vendor patch shadows any pip fla that is not strictly newer than 0.5.1, replaces transformers' is_flash_linear_attention_available and hard sets FLA_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_hooks now wires only the causal-conv1d gate. A one line log after the trainer import reports whether fla.ops.gated_delta_rule is 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, add test_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.py does if is_flash_linear_attention_available(): from fla.ops.gated_delta_rule import chunk_gated_delta_rule, fused_recurrent_gated_delta_rule and gates is_fast_path_available on those plus causal-conv1d. Two mechanisms make that true with only the vendored copy present:

  1. unsloth_zoo/temporary_patches/fla_vendor.py _patch_is_available clears the lru_cache and replaces transformers.utils.import_utils.is_flash_linear_attention_available with a probe that answers True for the qwen3_5, qwen3_5_moe and qwen3_next modeling modules, then rebinds the name in every already imported transformers.* namespace. The modeling modules import after import unsloth, so they bind the replaced probe.
  2. On transformers 5.5.0 the native probe would also return True: _is_package_available falls back to importlib.import_module when metadata is missing and reads the vendored fla.__version__ of 0.5.1, which passes the >= 0.2.2 check.

Verified in a venv with flash-linear-attention, fla-core, tilelang and apache-tvm-ffi uninstalled (torch 2.12.1+cu130, transformers 5.5.0, B200), after loading each of unsloth/Qwen3.5-2B, unsloth/Qwen3.8-27B and unsloth/Qwen3.6-35B-A3B:

check result
is_flash_linear_attention_available() True
layer.chunk_gated_delta_rule unsloth_zoo/_vendored/fla/ops/gated_delta_rule/chunk.py
layer.recurrent_gated_delta_rule vendored fused_recurrent_gated_delta_rule
torch fallback in use no
modeling_qwen3_5.is_fast_path_available True
causal_conv1d_fn causal_conv1d_cuda

Training 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.

model vendored only, median step ms pip FLA + TileLang, median step ms max loss diff vendored vs TileLang same condition repeat noise peak GB
Qwen3.5-2B 528.7 576.1 3.7e-3 4.3e-3 3.35
Qwen3.8-27B 1458.7 1411.7 1.5e-2 2.0e-2 19.06
Qwen3.6-35B-A3B 1375.0 1329.9 1.5e-2 1.1e-2 28.63

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_rule fwd+bwd, bf16, B200, backend selection confirmed through the FLA registry log:

model T Triton ms TileLang ms
Qwen3.5-2B 2048 1.516 1.582
Qwen3.5-2B 8192 1.801 1.773
Qwen3.8-27B 2048 1.610 1.635
Qwen3.8-27B 8192 4.690 4.631
Qwen3.6-35B-A3B 2048 1.619 1.702
Qwen3.6-35B-A3B 8192 3.267 3.186

TileLang only overrides chunk_bwd_dqkwg and 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 with tilelang.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 passed
  • every studio backend test file that imports the worker (36 files): 3679 passed, 1 skipped
  • tests/kaggle: 1032 passed
  • studio/backend/tests/test_mlx_repair.py: 36 passed
  • ruff check clean

Review follow-ups

  • The ROCm guard that sets FLA_TILELANG=0 before transformers imports is kept (as setdefault, so a user override survives), so a user-installed pip fla can never dispatch to TileLang on HIP.
  • UNSLOTH_DISABLE_VENDORED_FLA=1 is 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.
  • The no-install tests cover both the uv and the plain pip branches, the source check rejects any pip spec naming the four packages, and the FLA_TILELANG preservation tests are restored.

…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.
@danielhanchen
danielhanchen requested a review from Lyxot as a code owner September 8, 2026 07:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T12:16:19.446182Z 1eb611c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 1a7c5694c4

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

@Lyxot
Lyxot removed their request for review September 8, 2026 07:53
…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits September 8, 2026 09:35
…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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits September 8, 2026 10:24
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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 140d9713a3

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: a2e49982d5

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

…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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 1eb611ce89

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

@danielhanchen
danielhanchen merged commit bd1228f into main Sep 8, 2026
2 of 37 checks passed
@danielhanchen
danielhanchen deleted the studio-drop-fla-install branch September 8, 2026 12:29
@danielhanchen danielhanchen mentioned this pull request Sep 21, 2026
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