Skip to content

[Refactor] Decouple torch/triton backend from base deps - #937

Merged
zhiyuan1i merged 19 commits into
fla-org:mainfrom
kashif:decouple-gpu-backend-deps
Jun 11, 2026
Merged

zhiyuan1i merged 19 commits into
fla-org:mainfrom
kashif:decouple-gpu-backend-deps

Conversation

@kashif

@kashif kashif commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

On rocm/xpu/npu boxes pip install -e . happily pulls CUDA wheels because torch>=2.7.0 + triton>=3.3 get re-resolved against PyPI's default index. This makes the backend explicit.

pyproject.toml now keeps torch and the matching triton flavor in backend extras ([cuda] / [rocm] / [xpu] / [npu] / [cpu]) instead of base deps. The base wheel METADATA carries only transformers and einops, so pip install flash-linear-attention[rocm] --extra-index-url https://download.pytorch.org/whl/rocm7.2 resolves to torch (rocm) + pytorch-triton-rocm with no CUDA carryover, and the same shape works on prebuilt wheels (which addresses the earlier bot reviews about wheel metadata being baked at build time).

scripts/build_packages.py now reads deps and extras from pyproject.toml via tomllib. The split-package layout keeps backend extras with fla-core (since the kernels need torch + triton) and ergonomics extras (tilelang / conv1d / benchmark / test) with flash-linear-attention.

Install docs: short snippet in README, full backend table + NPU (Ascend) flow + source installs + --no-deps path in a new INSTALL.md.

CI: nvidia and intel paths unchanged in behavior. An amd-mi300-ci workflow is included as documentation behind a job-level if: false guard, ready to flip once fla has a runner.

Behavior change (worth flagging): bare pip install flash-linear-attention no longer pulls torch or triton. Users must pick a backend extra (e.g. [cuda]). This is the trade-off for not silently overlaying CUDA wheels on ROCm / XPU / NPU machines. Existing CI install lines that go through --index-url for torch first and then pip install . still work because the base no longer churns those packages.

Tested on a Strix Halo box (ROCm 7.2 + torch nightly): auto-detect picks the right flavor, egg-info comes out clean, no nvidia-* collection.

kashif added 2 commits June 4, 2026 18:03
setup.py picks the torch+triton flavor from FLA_TARGET_DEVICE or
the installed torch, so pip install -e . on a rocm/xpu box no
longer drags in CUDA wheels. extras [cuda]/[rocm]/[xpu]/[cpu] let
you pick explicitly.

also adds an amd-mi300 workflow (rocm/pytorch docker image, no
fresh venv) and pins FLA_TARGET_DEVICE in setup-ci-env.
no fla-owned amd runner yet — cron would queue forever.

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

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.

Code Review

This pull request introduces dynamic dependency resolution for different hardware backends (CUDA, ROCm, XPU, and CPU) during installation. It updates the CI configuration, documentation, pyproject.toml, and setup.py to support target device auto-detection and explicit backend selection via the FLA_TARGET_DEVICE environment variable or package extras. Feedback highlights a critical packaging limitation where dynamic dependencies do not behave as expected for pre-built wheels, as well as a robustness improvement to catch all exceptions when importing torch in setup.py to prevent installation crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pyproject.toml Outdated
Comment thread setup.py Outdated

@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: 82e9a725f2

ℹ️ 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 setup.py Outdated
Comment thread setup.py Outdated
@kashif kashif changed the title Decouple torch/triton backend from base deps [Refactor] Decouple torch/triton backend from base deps Jun 4, 2026
dynamic install_requires got baked into wheel METADATA at build
time, so pip install fla[rocm] still pulled the cuda triton. drop
torch/triton from base deps entirely — backend lives only in the
extras now, which wheels handle correctly.

also drops FLA_TARGET_DEVICE since it can't see the user's torch
through pep517 build isolation anyway.
@kashif

kashif commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 9151b7b061

ℹ️ 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 pyproject.toml Outdated
Comment thread pyproject.toml
kashif added 2 commits June 5, 2026 18:59
triton is imported at fla module load so [cpu] without it crashes.
setuptools>=64 for PEP 621 [project] support.
@kashif

kashif commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@yzhangcs this is ready for a review if you can kindly have a look

@zhiyuan1i

Copy link
Copy Markdown
Collaborator

hey, thanks for tackling this — backend dependency coupling has been a pain for rocm/xpu users for a while.

a couple of thoughts before merging:

first, i'd lean against adding the amd-mi300.yml workflow (and the amd branch in setup-ci-env) right now. fla doesn't actually have access to an amd-mi300 runner group, so that file would just sit there dead. maybe keep it in a local branch and add it back once the project actually has amd ci capacity?

also the installation section in README got pretty chunky. what do you think about moving the full backend table + per-platform commands into a separate INSTALL.md and leaving README with just the common one-liners (pip install -e .[cuda] etc.)? keeps the landing page from becoming a wall of text.

on the correctness side — scripts/build_packages.py still parses setup.py via AST to grab install_requires / extras_require for the split-package build. since this pr strips those out of setup.py entirely, the release script will generate wheels with empty deps. that'll break fla-core (no torch/triton) and the extension (no transformers). we'd need to point build_packages.py at pyproject.toml instead, or keep the deps mirrored in setup.py somehow.

lastly, the behavior change is worth flagging: with torch/triton moved out of base deps, a plain pip install flash-linear-attention no longer pulls torch at all. that's a breaking change for existing pypi users who expect pip install flash-linear-attention to just work. totally fine if that's the intended trade-off, but probably worth calling out explicitly in the pr description so folks aren't surprised.

happy to help iterate on any of the above if useful!

@kashif

kashif commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

thanks let me fix it up!

kashif added 5 commits June 10, 2026 14:20
keeps the install pattern documented; flip the guard when a
runner is wired in.
setup.py no longer holds deps. backend extras ride with fla-core,
the rest with flash-linear-attention.
@kashif

kashif commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

hey @zhiyuan1i thanks for the careful review, all four points addressed:

  • amd ci is back behind a job-level if: false guard rather than deleted (a3d184b) so the install pattern stays as documentation. flip the guard once fla has a runner.
  • scripts/build_packages.py now reads pyproject.toml via tomllib (77b3df9). backend extras (cuda/rocm/xpu/npu/cpu) ride with fla-core, the rest (tilelang/conv1d/benchmark/test) with flash-linear-attention. verified both wheels get the right Requires-Dist/extras.
  • readme install section is now a short snippet plus a link to a new INSTALL.md (b1abcc0) with the full backend table, ascend npu flow, source installs, and the --no-deps path. the behavior change is called out at the top of the install block too.
  • while at it i also added an [npu] extra (054f31b) since [Docs] Add Ascend NPU installation section to README #938 was landing the manual npu flow. after this pr the pip uninstall triton; pip install triton-ascend dance is unnecessary, pip install flash-linear-attention[npu] pulls torch-npu + triton-ascend directly. happy to coordinate with that pr if helpful.

pr description updated with the behavior change note.

Comment thread pyproject.toml Outdated
Comment thread INSTALL.md Outdated
@zheliuyu

Copy link
Copy Markdown
Collaborator

@kashif Thanks for factoring in NPU installation in this PR. Just tweaking the torch, torch_npu, and triton-ascend versions as mentioned above should cover NPU usage. We'll close #938 later. Thanks again for your work!

@kashif

kashif commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

fixed @zhiyuan1i

@kashif

kashif commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

note as an aside running the amd CI manually has already surfaced issues in triton which has now been fixed in main: triton-lang/triton#10381 so I hope this will be useful moving forward

@zhiyuan1i

Copy link
Copy Markdown
Collaborator

@codex review

@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: 696b82e905

ℹ️ 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 scripts/build_packages.py Outdated
Comment thread INSTALL.md Outdated
flash-linear-attention[cuda] now forwards to fla-core[cuda] so the
released wheel actually pulls torch+triton. install docs split non-cuda
into 'install backend torch from pytorch index, then install fla' so
pip doesn't fall back to PyPI for torch.
@kashif

kashif commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: e639f65474

ℹ️ 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 pyproject.toml
kashif added 3 commits June 11, 2026 10:51
pytorch index uses different triton names on stable
(pytorch-triton-rocm) vs nightly (triton-rocm), so pinning either
brittles one path. drop the pin and follow the amd-recommended
pattern of installing torch from --index-url, which transitively
pulls the right triton.
@kashif

kashif commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

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

Optional layers/models imports now skip missing extension or runtime deps without hiding fla internal import errors. Export the public API only when both extension modules are available, and extend split-package/smoke tests to cover fla-core-only imports from the repo root plus backend-extra metadata.
@zhiyuan1i

Copy link
Copy Markdown
Collaborator

@codex review

@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: cef22c0711

ℹ️ 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 pyproject.toml
Comment thread scripts/smoke_test_split_packages.py
@zhiyuan1i
zhiyuan1i merged commit 97bcb88 into fla-org:main Jun 11, 2026
15 of 16 checks passed
Erix025 pushed a commit to Erix025/flash-linear-attention that referenced this pull request Jun 30, 2026
* decouple torch/triton backend from base deps

setup.py picks the torch+triton flavor from FLA_TARGET_DEVICE or
the installed torch, so pip install -e . on a rocm/xpu box no
longer drags in CUDA wheels. extras [cuda]/[rocm]/[xpu]/[cpu] let
you pick explicitly.

also adds an amd-mi300 workflow (rocm/pytorch docker image, no
fresh venv) and pins FLA_TARGET_DEVICE in setup-ci-env.

* amd-mi300: drop cron, keep workflow_dispatch only

no fla-owned amd runner yet — cron would queue forever.

* address bot review: extras-only, no dynamic deps

dynamic install_requires got baked into wheel METADATA at build
time, so pip install fla[rocm] still pulled the cuda triton. drop
torch/triton from base deps entirely — backend lives only in the
extras now, which wheels handle correctly.

also drops FLA_TARGET_DEVICE since it can't see the user's torch
through pep517 build isolation anyway.

* cpu extra needs triton, bump setuptools floor

triton is imported at fla module load so [cpu] without it crashes.
setuptools>=64 for PEP 621 [project] support.

* no em-dashes

* fix cpu triton flavor in table

* drop amd ci until runner exists

* amd ci: restore behind if:false guard

keeps the install pattern documented; flip the guard when a
runner is wired in.

* add npu extra

* build_packages: read pyproject.toml

setup.py no longer holds deps. backend extras ride with fla-core,
the rest with flash-linear-attention.

* slim install section, move details to INSTALL.md

* amd ci: drop if:always so a failed verify stops the run

* npu: pin to torch 2.6.0 + triton-ascend 3.2.0

* keep backend extras on extension wheel, two-step non-cuda install

flash-linear-attention[cuda] now forwards to fla-core[cuda] so the
released wheel actually pulls torch+triton. install docs split non-cuda
into 'install backend torch from pytorch index, then install fla' so
pip doesn't fall back to PyPI for torch.

* contributing: install with a backend extra

* rocm/xpu: let torch pull its own triton flavor

pytorch index uses different triton names on stable
(pytorch-triton-rocm) vs nightly (triton-rocm), so pinning either
brittles one path. drop the pin and follow the amd-recommended
pattern of installing torch from --index-url, which transitively
pulls the right triton.

* install: match intro to extras shape

* [Fix] Keep fla-core importable without extension deps

Optional layers/models imports now skip missing extension or runtime deps without hiding fla internal import errors. Export the public API only when both extension modules are available, and extend split-package/smoke tests to cover fla-core-only imports from the repo root plus backend-extra metadata.

---------

Co-authored-by: zhiyuan1i <uniartisan2017@gmail.com>
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.

3 participants