Skip to content

Commit 08b4d53

Browse files
authored
liger-kernels: sync with liger-kernels upstream (#857)
* sync with liger-kernels upstream * update flakes * expose LigerForCausalLMLoss
1 parent 30f2b22 commit 08b4d53

19 files changed

Lines changed: 1646 additions & 566 deletions

AGENTS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,44 @@ steps:
3535

3636
If the user did not specify the version tag, stop and ask which tag to sync
3737
from.
38+
39+
## liger-kernels
40+
41+
When the user asks to sync a Liger-Kernel release, carry out the following
42+
steps:
43+
44+
- Fetch the upstream Git repository from https://github.com/linkedin/Liger-Kernel.git
45+
- Check out the tag that the user specified (e.g. `v0.8.0`).
46+
- Liger-Kernel ops are in the directory `src/liger_kernel/ops` of the upstream
47+
repo. There is no `cute` / `quack` dependency — only the Triton ops are
48+
mirrored.
49+
- For each file already present in `liger-kernels/torch-ext/liger_kernels/`,
50+
except `__init__.py` and `layers.py` (which are local additions, not
51+
upstream), copy the matching file from `src/liger_kernel/ops/` upstream,
52+
overwriting the local copy. Do not introduce new files that were not
53+
previously synced — the local tree intentionally tracks a subset of upstream
54+
ops.
55+
- Some helpers used by the ops live in the upstream top-level module
56+
`src/liger_kernel/utils.py` (e.g. `is_npu_available`) rather than in
57+
`src/liger_kernel/ops/utils.py`. If a synced op imports such a helper, fold
58+
the helper into `liger-kernels/torch-ext/liger_kernels/utils.py` instead of
59+
adding a separate file.
60+
- Now make all imports of Liger-Kernel in
61+
`liger-kernels/torch-ext/liger_kernels` relative imports. In particular:
62+
- `from liger_kernel.ops.<name> import ...``from .<name> import ...`
63+
- `from liger_kernel.ops.utils import ...``from .utils import ...`
64+
- `from liger_kernel.utils import ...``from .utils import ...` (after
65+
folding the helper into the local `utils.py`).
66+
- Do not modify `liger-kernels/torch-ext/liger_kernels/__init__.py` or
67+
`layers.py` — these are local `torch.nn.Module` wrappers that are not
68+
derived from upstream.
69+
- Check whether any Torch custom ops are defined in the synced files (look
70+
for `torch.library.custom_op`, `torch.library.define`, etc.). If any are
71+
found, update them to use `add_op_namespace_prefix` for the op name,
72+
importing it from `._ops` (see
73+
`flash-attn3/torch-ext/flash_attn3/flash_attn_interface.py` for an
74+
example). Upstream Liger-Kernel does not currently define any such ops, so
75+
this step is usually a no-op.
76+
77+
If the user did not specify the version tag, stop and ask which tag to sync
78+
from.

liger-kernels/flake.lock

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

liger-kernels/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description = "Flake for Unsloth Kernels";
33

44
inputs = {
5-
kernel-builder.url = "github:huggingface/kernels/torch-2.12";
5+
kernel-builder.url = "github:huggingface/kernels";
66
};
77

88
outputs =
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from . import layers
2+
from .layers import CrossEntropyOutput, LigerForCausalLMLoss
23

3-
__all__ = ["layers"]
4+
__all__ = ["layers", "LigerForCausalLMLoss", "CrossEntropyOutput"]

0 commit comments

Comments
 (0)