Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 58 additions & 88 deletions REPO_LAYOUT.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,71 @@
# Repository Layout

Legend: `[exp]` experimental / unwired Β· `[non-KDA]` other operator.

```
cuLA/
β”œβ”€β”€ cula/ # Python package (pip install -e .)
β”‚ β”œβ”€β”€ kda/ # KDA (Kimi Delta Attention) operators
β”‚ β”‚ β”œβ”€β”€ chunk.py # End-to-end chunk KDA (fwd + bwd entry point)
β”‚ β”‚ β”œβ”€β”€ chunk_fwd.py # Chunk forward dispatch
β”‚ β”‚ β”œβ”€β”€ chunk_intra.py # Intra-chunk forward logic
β”‚ β”‚ β”œβ”€β”€ blackwell_fused_fwd.py # Fused KDA forward (SM100)
β”‚ β”‚ └── hopper_fused_fwd.py # Fused KDA forward (SM90)
β”‚ β”œβ”€β”€ lightning/ # Lightning Attention operators
β”‚ β”‚ └── la_decode.py # Single-token decode kernel (CuTe DSL)
β”‚ β”œβ”€β”€ ops/ # CuTe DSL kernel implementations
β”‚ β”‚ β”œβ”€β”€ chunk_delta_h_sm100.py # Chunk delta-H kernel (SM100)
β”‚ β”‚ β”œβ”€β”€ fwd_o_sm100.py # Forward output kernel (SM100)
β”‚ β”‚ β”œβ”€β”€ lightning_attn_sm100.py # Lightning Attention prefill kernel (SM100)
β”‚ β”‚ β”œβ”€β”€ linear_attn_sm100.py # Generic linear attention kernel (SM100)
β”‚ β”‚ β”œβ”€β”€ kda_fully_fused_sm100_wip.py # WIP fully fused KDA kernel (SM100)
β”‚ └── utils.py # Shared utilities
β”‚
β”œβ”€β”€ csrc/ # CUDA C++ / CUTLASS kernels
β”‚ β”œβ”€β”€ api/ # PyBind11 bindings
β”‚ β”‚ β”œβ”€β”€ pybind.cu # Python ↔ CUDA binding entry
β”‚ β”‚ β”œβ”€β”€ kda_sm90.cu # SM90 API wrappers
β”‚ β”‚ └── kda_sm100.cu # SM100 API wrappers
β”‚ β”œβ”€β”€ kda/
β”‚ β”‚ β”œβ”€β”€ sm90/ # Hopper KDA kernels (CUTLASS 3.x)
β”‚ β”‚ β”‚ β”œβ”€β”€ kda_fwd_sm90.cu
β”‚ β”‚ β”‚ β”œβ”€β”€ kda_fwd_sm90_safe_gate.cu
β”‚ β”‚ β”‚ β”œβ”€β”€ prefill_kernel.hpp
β”‚ β”‚ β”‚ β”œβ”€β”€ collective/ # CUTLASS collective mainloop
β”‚ β”‚ β”‚ β”œβ”€β”€ device/ # Device-level kernel wrappers
β”‚ β”‚ β”‚ β”œβ”€β”€ kernel/ # Kernel-level logic
β”‚ β”‚ β”‚ └── utils/ # SM90-specific helpers
β”‚ β”‚ └── sm100/ # Blackwell KDA kernels (CUTLASS 3.x)
β”‚ β”‚ β”œβ”€β”€ kda_fwd_sm100.cu
β”‚ β”‚ β”œβ”€β”€ kda_fwd_common.cuh
β”‚ β”‚ β”œβ”€β”€ kda_fwd_intra_kernel_sm100.hpp
β”‚ β”‚ β”œβ”€β”€ kda_fwd_intra_mainloop_sm100.hpp # Chunk intra mainloop
β”‚ β”‚ β”œβ”€β”€ kda_fwd_recomp_w_u_kernel_sm100.hpp
β”‚ β”‚ β”œβ”€β”€ kda_fwd_recomp_w_u_mainloop_sm100.hpp # Recompute W&U mainloop
β”‚ β”‚ β”œβ”€β”€ kda_config.hpp
β”‚ β”‚ β”œβ”€β”€ fwd_helpers.hpp
β”‚ β”‚ β”œβ”€β”€ sm100_umma_ext.hpp
β”‚ β”‚ └── tile_scheduler.hpp
β”‚ └── kerutils/
β”‚ └── include/ # Shared C++ header utilities
β”‚
β”œβ”€β”€ benchmarks/ # Performance benchmarks
β”‚ β”œβ”€β”€ bench_kda.py # KDA fixed + varlen benchmark
β”‚ β”œβ”€β”€ bench_lightning_attn.py # Lightning Attention prefill + varlen
β”‚ β”œβ”€β”€ bench_la_decode_vs_fla.py # Decode: la_decode vs fla fused_recurrent
β”‚ β”œβ”€β”€ bench_kda_fused_fwd.py # KDA fused forward benchmark
β”‚ β”œβ”€β”€ bench_kda_chunk_intra.py # KDA chunk intra benchmark
β”‚ β”œβ”€β”€ bench_chunk_delta_h.py # Chunk delta-H benchmark
β”‚ β”œβ”€β”€ bench_fwd_o.py # Forward output benchmark
β”‚ β”œβ”€β”€ bench_linear_attn.py # Linear attention benchmark
β”‚ β”œβ”€β”€ generate_benchmark_md.py # Auto-generate BENCHMARK_GB200.md (Blackwell)
β”‚ β”œβ”€β”€ generate_benchmark_hopper_md.py # Auto-generate BENCHMARK_H200.md (Hopper)
β”‚ └── utils.py # Benchmark utilities
β”‚
β”œβ”€β”€ tests/ # Unit / integration tests
β”‚ β”œβ”€β”€ test_kda_compare_fla.py # Modular KDA forward vs FLA Triton
β”‚ β”œβ”€β”€ test_kda.py # Modular KDA forward vs naive reference
β”‚ β”œβ”€β”€ test_kda_fused_fwd.py # Fused KDA forward tests
β”‚ β”œβ”€β”€ test_chunk_delta_h.py # Chunk delta-H tests
β”‚ β”œβ”€β”€ test_fwd_o.py # Forward output tests
β”‚ β”œβ”€β”€ test_compare_with_fla.py # General FLA comparison
β”‚ β”œβ”€β”€ test_lightning_attn.py # Lightning Attention tests
β”‚ └── test_la_decode.py # Decode kernel tests
β”‚
β”œβ”€β”€ docs/ # Design documents
β”‚ β”œβ”€β”€ chunk_delta_h_pipeline.md
β”‚ β”œβ”€β”€ fwd_o_pipeline.md
β”‚ └── lightning_attn_pipeline.md
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ utils.py # arch asserts, get_pre_scan, cu_seqlens helpers, ...
β”‚ β”œβ”€β”€ cudac.py # re-export shim over the compiled C++ extension(s)
β”‚ β”‚
β”‚ β”œβ”€β”€ kda/ # KDA PUBLIC API + autograd + dispatch (NO kernels)
β”‚ β”‚ β”œβ”€β”€ __init__.py # lazy PUBLIC API: chunk_kda, kda_prefill_hopper,
β”‚ β”‚ β”‚ # kda_decode, fused_sigmoid_gating_delta_rule_update
β”‚ β”‚ β”œβ”€β”€ chunk.py # chunk_kda + autograd β€” SM100 modular path (train + Blackwell prefill)
β”‚ β”‚ β”œβ”€β”€ chunk_fwd.py # chunk_kda_fwd β€” fwd orchestration (lazy-imports kernels)
β”‚ β”‚ β”œβ”€β”€ chunk_intra.py # fwd intra (C++ ext) + bwd intra (Triton)
β”‚ β”‚ β”œβ”€β”€ chunk_bwd.py # chunk_kda_bwd β€” Triton + FLA + CuTeDSL + C++ mix
β”‚ β”‚ └── hopper_fused_fwd.py # cula_kda_prefill (=kda_prefill_hopper) β€” SM90 prefill via the C++ kernel (cula.cudac)
β”‚ β”‚
β”‚ β”œβ”€β”€ lightning/ # [non-KDA] Lightning Attention operator (LinearAttentionChunkwiseDecay, lightning_attn_fwd, linear_attention_decode)
β”‚ β”‚ └── __init__.py
β”‚ β”‚
β”‚ └── ops/ # backend kernels (CuTe DSL / TVM-FFI) + shared helpers
β”‚ β”œβ”€β”€ __init__.py # exports kda_decode, fused_sigmoid_..., linear_attention_decode
β”‚ β”œβ”€β”€ inv.py / ptx.py # shared low-level helpers
β”‚ β”œβ”€β”€ sm100/ # SM100 shared helper only
β”‚ β”‚ └── ptx.py # shared PTX helpers (used by KDA + lightning kernels)
β”‚ β”‚
β”‚ β”œβ”€β”€ kda/ # β˜… KDA Python backends β€” by arch (sm100 today)
β”‚ β”‚ β”œβ”€β”€ policy.py # SM100 CP dispatch policy: use_intracard_cp:"auto"|bool
β”‚ β”‚ β”œβ”€β”€ sm100/ # SM100 (Blackwell) modular-chunk kernels
β”‚ β”‚ β”‚ β”œβ”€β”€ delta_h.py # recurrence (chunk_gated_delta_rule_fwd_h)
β”‚ β”‚ β”‚ β”œβ”€β”€ fwd_o.py # output (chunk_gla_fwd_o)
β”‚ β”‚ β”‚ β”œβ”€β”€ bwd_wy_dqkg.py# backward wy/dqkg fused (used by chunk_bwd)
β”‚ β”‚ β”‚ └── cp/ # SM100 intracard-CP: chunk_delta_h, pre_scan, merge
β”‚ β”‚ β”œβ”€β”€ decode/ # single-token decode
β”‚ β”‚ β”‚ β”œβ”€β”€ cute.py # kda_decode / fused_sigmoid_gating_delta_rule_update (CuTe DSL)
β”‚ β”‚ β”‚ └── reference_fla.py
β”‚ β”‚ └── experimental/sm100_fused/ # [exp] unwired fully-fused
β”‚ β”‚ β”œβ”€β”€ kda_fully_fused_wip.py # KDAChunkwise (~6k lines)
β”‚ β”‚ └── wrapper.py # flash_kda_prefill (dead path; raises on SM100 dispatch)
β”‚ β”‚
β”‚ β”œβ”€β”€ lightning/ # [non-KDA] Lightning/linear attention kernels
β”‚ β”‚ β”œβ”€β”€ prefill_sm100.py # Lightning Attn prefill (LinearAttentionChunkwiseDecay, lightning_attn_fwd[_varlen])
β”‚ β”‚ └── decode.py # linear_attention_decode
β”‚ └── experimental/
β”‚ └── linear_attn_prototype.py # [non-KDA] unwired normalized-linear-attn prototype
β”‚
β”œβ”€β”€ third_party/
β”‚ └── flash-linear-attention/ # FLA submodule (baseline)
β”œβ”€β”€ csrc/ # CUDA C++ / CUTLASS
β”‚ β”œβ”€β”€ api/{kda_sm90.cu, kda_sm100.cu} # PyBind11 (cula.cudac): SM90 prefill + SM100 chunk intra/recompute_w_u
β”‚ β”œβ”€β”€ kda/sm90/ # SM90 (Hopper) KDA C++ kernels (CUTLASS 3.x, TMA/wgmma)
β”‚ β”œβ”€β”€ kda/sm100/ # Blackwell KDA C++ kernels (CUTLASS 3.x + UMMA)
β”‚ └── kerutils/include/ # shared C++ headers (generic device helpers sm80/sm90/sm100, host)
β”‚
β”œβ”€β”€ BENCHMARK_GB200.md # Auto-generated Blackwell benchmark results
β”œβ”€β”€ BENCHMARK_H200.md # Auto-generated Hopper benchmark results
β”œβ”€β”€ README.md # Project overview
β”œβ”€β”€ setup.py # Build configuration
β”œβ”€β”€ pyproject.toml # Project metadata
└── LICENSE
β”œβ”€β”€ benchmarks/ tests/ docs/
β”œβ”€β”€ scripts/build_wheel.sh
β”œβ”€β”€ third_party/flash-linear-attention/ # FLA submodule (baseline + reused gate/CP ops)
β”œβ”€β”€ README.md USAGE.md REPO_LAYOUT.md RECOMMENDED_CODING_STYLE.md
└── setup.py pyproject.toml LICENSE
```

## Key Directories

| Directory | Language | Description |
|-----------|----------|-------------|
| `cula/ops/` | Python (CuTe DSL) | Warp-specialized GPU kernels written in CuTe DSL β€” compiled to CUDA at import time |
| `cula/kda/` | Python | KDA operator dispatch β€” selects SM90 or SM100 path, handles chunking and autograd |
| `cula/lightning/` | Python (CuTe DSL) | Lightning Attention decode kernel |
| `csrc/kda/sm90/` | CUDA C++ | Hopper KDA kernels using CUTLASS 3.x collective API |
| `csrc/kda/sm100/` | CUDA C++ | Blackwell KDA kernels using CUTLASS 3.x + UMMA extensions |
| `csrc/api/` | CUDA C++ | PyBind11 entry points exposing C++ kernels to Python |
| `benchmarks/` | Python | Performance benchmarks vs FLA Triton baselines |
| `tests/` | Python | Correctness tests (pytest) |
| `docs/` | Markdown | Internal pipeline design notes |
| `cula/kda/` | Python | KDA **public API only** β€” autograd + dispatch, no kernels. Two prefill entries: modular chunk `chunk_kda` (SM100) and `kda_prefill_hopper` (SM90, driving the C++ kernel). |
| `cula/ops/kda/` | Python (CuTe DSL) | **KDA Python backends**, by arch: `sm100/` (+cp), `decode/`, `experimental/`, plus `policy.py` (CP dispatch). |
| `cula/ops/lightning/` Β· `cula/ops/experimental/` | Python (CuTe DSL) | `[non-KDA]` Lightning/linear attention kernels. |
| `cula/ops/{inv,ptx}.py`, `cula/ops/sm100/ptx.py` | Python | Shared low-level helpers (kept in place; not KDA-specific). |
| `csrc/kda/{sm90,sm100}/` Β· `csrc/api/` | CUDA C++ | Hopper SM90 prefill + Blackwell SM100 (chunk intra + recompute_w_u), exposed as `cula.cudac`. |
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ import os
os.environ["CULA_INTRACARD_CP"] = "1"

import torch
from cula.ops.chunk_delta_h import chunk_gated_delta_rule_fwd_h
from cula.ops.kda.sm100.delta_h import chunk_gated_delta_rule_fwd_h

B, T, H, K, V = 1, 65536, 8, 128, 128
device = 'cuda'
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_chunk_delta_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from benchmarks.utils import benchmark_cuda_mode_fn, relative_rms_error_max_mean_abs

# ─── CuTe DSL wrapper (TVM-FFI compile cache) ───
_delta_h_mod = importlib.import_module("cula.ops.chunk_delta_h_sm100")
_delta_h_mod = importlib.import_module("cula.ops.kda.sm100.delta_h")
chunk_gated_delta_rule_fwd_h = _delta_h_mod.chunk_gated_delta_rule_fwd_h

# ─── FLA baseline imports ───
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_fwd_o.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))

# ─── CuTe DSL wrapper (TVM-FFI compile cache) ───
_fwd_o_mod = importlib.import_module("cula.ops.fwd_o_sm100")
_fwd_o_mod = importlib.import_module("cula.ops.kda.sm100.fwd_o")
chunk_gla_fwd_o = _fwd_o_mod.chunk_gla_fwd_o
build_chunk_indices = _fwd_o_mod.build_chunk_indices

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_intracard_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
set_seed,
)
from cula.kda.chunk_fwd import chunk_kda_fwd
from cula.ops.cp.chunk_delta_h import (
from cula.ops.kda.sm100.cp.chunk_delta_h import (
compute_subseq_len,
prepare_subseq_cu_seqlens,
should_use_intracard_cp,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_kda_bwd_wy_dqkg_sm100.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
relative_rms_error_rel_max_mean_abs,
set_seed,
)
from cula.ops.chunk_wy_dqkg_sm100 import chunk_kda_bwd_wy_dqkg_fused as cula_chunk_kda_bwd_wy_dqkg_fused
from cula.ops.kda.sm100.bwd_wy_dqkg import chunk_kda_bwd_wy_dqkg_fused as cula_chunk_kda_bwd_wy_dqkg_fused

torch.backends.cuda.matmul.allow_tf32 = True

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_kda_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

from benchmarks.utils import benchmark_cuda_fn, relative_rms_error_rel_max
from cula.kda import fused_sigmoid_gating_delta_rule_update as cula_fused
from cula.ops.kda_decode_fla import fused_sigmoid_gating_delta_rule_update as fla_fused
from cula.ops.kda.decode.reference_fla import fused_sigmoid_gating_delta_rule_update as fla_fused


# ──────────────────────────────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_kda_fused_fwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Automatically selects the cuLA fully-fused implementation based on the current
GPU architecture:
- sm100 (Blackwell) β†’ cula.kda.blackwell_fused_fwd.flash_kda_prefill
- sm100 (Blackwell) β†’ cula.ops.kda.experimental.sm100_fused.wrapper.flash_kda_prefill
- sm90 (Hopper) β†’ cula.kda.hopper_fused_fwd.cula_kda_prefill

Compares:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_la_decode_vs_fla.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from fla.ops.common.fused_recurrent import fused_recurrent_fwd, fused_recurrent_fwd_kernel

from benchmarks.utils import benchmark_cuda_fn, relative_rms_error
from cula.ops.la_decode import _get_compiled_kernel, linear_attention_decode
from cula.ops.lightning.decode import _get_compiled_kernel, linear_attention_decode
from cula.utils import USE_FAST_MATH


Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_lightning_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from fla.ops.simple_gla.chunk import chunk_simple_gla_fwd

from benchmarks.utils import gen_random, gen_skewed, gen_uniform, relative_rms_error, time_cuda_fn
from cula.ops.lightning_attn_sm100 import lightning_attn_fwd, lightning_attn_fwd_varlen
from cula.ops.lightning.prefill_sm100 import lightning_attn_fwd, lightning_attn_fwd_varlen

# =============================================================================
# Constants
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bench_linear_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# from fla.ops.linear_attn.naive import naive_recurrent_linear_attn
from fla.utils import assert_close, device

from cula.ops.linear_attn_sm100 import LinearAttentionChunkwise
from cula.ops.experimental.linear_attn_prototype import LinearAttentionChunkwise

os.environ.setdefault("FLA_USE_FAST_OPS", os.getenv("CULA_USE_FAST_MATH", "1")) # Enable fast ops in FLA for fair comparison

Expand Down
6 changes: 0 additions & 6 deletions cula/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,3 @@
from cula._version import version as __version__
except ImportError:
__version__ = "0.1.0"

from cula.ops.lightning_attn_sm100 import LinearAttentionChunkwiseDecay

__all__ = [
"LinearAttentionChunkwiseDecay",
]
29 changes: 24 additions & 5 deletions cula/kda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from cula.kda.blackwell_fused_fwd import flash_kda_prefill as kda_prefill_blackwell
from cula.kda.chunk import chunk_kda
from cula.kda.hopper_fused_fwd import cula_kda_prefill as kda_prefill_hopper
from cula.ops.kda_decode import fused_sigmoid_gating_delta_rule_update, kda_decode
"""Public KDA API exports for chunk, prefill, and decode"""

__all__ = [
"chunk_kda",
"kda_prefill_blackwell",
"kda_decode",
"fused_sigmoid_gating_delta_rule_update",
"kda_prefill_hopper",
]

_LAZY = {
"chunk_kda": ("cula.kda.chunk", "chunk_kda"),
"kda_prefill_hopper": ("cula.kda.hopper_fused_fwd", "cula_kda_prefill"),
"kda_decode": ("cula.ops.kda.decode.cute", "kda_decode"),
"fused_sigmoid_gating_delta_rule_update": (
"cula.ops.kda.decode.cute",
"fused_sigmoid_gating_delta_rule_update",
),
}


def __getattr__(name):
target = _LAZY.get(name)
if target is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
import importlib

return getattr(importlib.import_module(target[0]), target[1])


def __dir__():
return sorted(__all__)
23 changes: 23 additions & 0 deletions cula/kda/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# Copyright (c) 2023-2025, Songlin Yang, Yu Zhang
# Related files are modified and supported by the Moonshot AI Team

"""SM100 modular chunk KDA public API and autograd wrapper"""

from typing import Literal

import torch
from fla.modules.l2norm import l2norm_bwd, l2norm_fwd
from fla.ops.cp import FLACPContext
Expand All @@ -23,6 +27,7 @@

from cula.kda.chunk_bwd import chunk_kda_bwd
from cula.kda.chunk_fwd import chunk_kda_fwd
from cula.ops.kda.policy import IntracardCPMode, resolve_intracard_cp_mode


class ChunkKDAFunction(torch.autograd.Function):
Expand Down Expand Up @@ -50,6 +55,7 @@ def forward(
disable_recompute: bool = False,
return_intermediate_states: bool = False,
cp_context: FLACPContext | None = None,
use_intracard_cp: IntracardCPMode | None = None,
):
chunk_size = 64

Expand Down Expand Up @@ -85,6 +91,7 @@ def forward(
disable_recompute=disable_recompute,
return_intermediate_states=return_intermediate_states,
cp_context=cp_context,
use_intracard_cp=use_intracard_cp,
)

if return_intermediate_states:
Expand Down Expand Up @@ -211,6 +218,7 @@ def backward(
None,
None,
None,
None,
)


Expand All @@ -233,6 +241,7 @@ def chunk_kda(
disable_recompute: bool = False,
return_intermediate_states: bool = False,
cp_context: FLACPContext = None,
use_intracard_cp: Literal["auto"] | bool | None = None,
**kwargs,
):
r"""
Expand Down Expand Up @@ -345,7 +354,15 @@ def chunk_kda(
)
"""

# just for backward compatibility, resolve the deprecated `use_cp` argument
# TODO: maybe we can remove this in the future
use_cp_alias = kwargs.pop("use_cp", None)
use_intracard_cp = resolve_intracard_cp_mode(use_intracard_cp, use_cp_alias)

if cp_context is not None:
if use_intracard_cp is True:
raise ValueError("use_intracard_cp=True cannot be combined with FLA cp_context.")
use_intracard_cp = False
assert initial_state is None, "Initial state is not supported for CP"
assert output_final_state is False, "Output final state is not supported for CP"
assert cp_context.cu_seqlens is not None, "cu_seqlens is required for CP"
Expand All @@ -354,6 +371,11 @@ def chunk_kda(
if cp_context.cu_seqlens_cpu is not None:
cu_seqlens_cpu = cp_context.cu_seqlens_cpu

if return_intermediate_states:
if use_intracard_cp is True:
raise ValueError("use_intracard_cp=True is not supported with return_intermediate_states=True.")
use_intracard_cp = False

if cu_seqlens is not None:
if q.shape[0] != 1:
raise ValueError(
Expand Down Expand Up @@ -414,4 +436,5 @@ def chunk_kda(
disable_recompute,
return_intermediate_states,
cp_context,
use_intracard_cp,
)
Loading