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
61 changes: 61 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# General instructions that apply to all kernels

## Imports

All imports in a kernel (files inside `torch-ext/<kernel_name>`) of other
modules within the same kernel must be relative. For example:

```python
# Incorrect:
from activation.activations import silu_and_mul

# Correct:
from .activations import silu_and_mul
```

## `_ops` module

The `_ops` module (`_ops.py`) is generated by the build system in
`torch-ext/<kernel_name>`. This module contains the following:

- An `ops` variable that is assigned the Torch ops for the kernel
(`ops = torch.ops.<kernel_ops_name>`).
- A function `def add_op_namespace_prefix(op_name: str) -> str`,
which returns `f"<kernel_ops_name>::{op_name}"`.

## Registering Torch operators

All Torch operators that are registered must have a prefix that is unique
to the kernel and is generated by the build system. Under no circumstances,
the prefix should be fixed. The aforementioned `add_op_namespace_prefix`
is used to prepend this prefix. For instance, consider this registration
with `custom_op`:

```python
# Incorrect:
@torch.library.custom_op("scattermoe::scatter2scatter", mutates_args={"output"})

# Correct:
@torch.library.custom_op(add_op_namespace_prefix("scatter2scatter"), mutates_args={"output"})
```

Similarly, an op must always be prefixed using the kernel-unique prefix:

```python
# Incorrect:
@torch.library.custom_op("_flash_attn_forward", mutates_args=(), device_types="cuda")

# Correct:
@torch.library.custom_op(add_op_namespace_prefix("_flash_attn_forward"), mutates_args=(), device_types="cuda")
```

The same applies for other registrations of ops, such as fake ops:

```python
# Incorrect:
@register_fake("moe::single_marlin_gemm_moe")

# Correct:
@register_fake(add_op_namespace_prefix("single_marlin_gemm_moe"))
```

# Kernel-specific instructions

## flash-attn3
Expand Down
6 changes: 3 additions & 3 deletions activation/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions aiter-flash-attn/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions aiter-kernels/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions aiter-rope/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bitsandbytes-mps/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions causal-conv1d/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cv-utils/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions deep-gemm/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions deformable-detr/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions finegrained-fp8/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flash-attn-ops/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions flash-attn-ops/torch-ext/flash_attn_ops/_ops_compat.py

This file was deleted.

Loading