Skip to content

liger-kernels: sync changes for transformers - #906

Closed
vasqu wants to merge 13 commits into
huggingface:mainfrom
vasqu:fix-liger-for-transformers-latest
Closed

vasqu wants to merge 13 commits into
huggingface:mainfrom
vasqu:fix-liger-for-transformers-latest

Conversation

@vasqu

@vasqu vasqu commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

As per title, I need a few changes for transformers to work properly

  • Signature fixes
  • Init fixes
  • Torch compile fixes

Also dependent on huggingface/kernels#607 as this enables functions with torch compile (but it won't break without the other PR either way, it would only unlock the feature)

NOTE: This assumes full transformers usage and only adjusts the modules that we need, nothing else

@vasqu
vasqu requested review from danieldk and drbh as code owners June 1, 2026 20:47
@danieldk danieldk changed the title [Liger Kernels] Sync changes for transformers liger-kernels: sync changes for transformers Jun 2, 2026
@danieldk

danieldk commented Jun 2, 2026

Copy link
Copy Markdown
Member

Note that until we fully switch to the bot, the PR title must have the format

<kernel name>: description

Also see the CI result:

No colon found in PR title, skipping build

@danieldk

danieldk commented Jun 3, 2026

Copy link
Copy Markdown
Member

/build-bot build liger-kernels

@vasqu

vasqu commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Sorry guys I was delayed by the gemma release, I will try to get to this today:

  • Reverting to old state and adding transformers specific interfaces --> best of both worlds
  • Try to take a look into wrapping into fake ops, although might be better as an upstream fix. Will see what I can do

# NOTE: We have this intentional graph break as we encounter issues such as IMAs and Cublas errors.
# We know that this is an optimized kernel already so there is less ways to
# fuse it either way; we rely on torch compile to go through the base model to optimize.
@torch.compiler.disable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this for now. If we were to change this with fake ops etc, it would be something that would need to be done upstream tbh because it touches the core layers

unsqueeze_dim: int = 1,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Apply standard rotary positional embedding to ``q`` and ``k``."""
return LigerRopeFunction.apply(q, k, cos, sin, position_ids, unsqueeze_dim)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly we could also use this instead of rotary or FA one's - these will be at least properly maintained cc @sayakpaul

gate_proj: nn.Linear
up_proj: nn.Linear
down_proj: nn.Linear
num_shards: int

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to use these as opt in then we don't have this attribute in transformers but let me double check if things work as expected. This could be the training version

Comment on lines -498 to -504
"LigerGroupNorm",
"LigerDyT",
"LigerCrossEntropyLoss",
"LigerFusedLinearCrossEntropyLoss",
"LigerJSD",
"LigerKLDIVLoss",
"LigerTVDLoss",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted a bunch because their exact usage is not too obv imo especially since a lot of these modules should rather be functions (losses). We can always get another version or progressively update/add(?)

@vasqu

vasqu commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #948 to have a non-fork branch to be used (seems like some gh actions are dependent on write access so they fail here)

@vasqu vasqu closed this Jun 11, 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.

3 participants