Skip to content

Liger support for Llama4 - #740

Merged
shimizust merged 70 commits into
linkedin:mainfrom
Manan17:llama4
Jun 29, 2025
Merged

shimizust merged 70 commits into
linkedin:mainfrom
Manan17:llama4

Conversation

@Manan17

@Manan17 Manan17 commented Jun 2, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Adding liger support to llama4 (text and multimodal). Liger rope is not supported yet for llama4 as it has a different implementation.
The tolerance are set higher than usual to pass the tests.

Testing Done

  • Hardware Type: NVIDIA H100 80GB HBM3
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

@Manan17

Manan17 commented Jun 27, 2025

Copy link
Copy Markdown
Contributor Author

Hey @Tcc0403, @shimizust , @vaibhavjindal can you please take a look at this? I

@Manan17 Manan17 changed the title Working on llama4 Liger support for Llama4 Jun 27, 2025

@shimizust shimizust left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm, thanks for adding!

@shimizust
shimizust merged commit 8e231a3 into linkedin:main Jun 29, 2025
vaibhavjindal added a commit to kashif/Liger-Kernel that referenced this pull request Sep 27, 2026
## Summary

`llama4.lce_forward` is the only one of the 42 forwards under
`transformers/model/` that has no `skip_logits` parameter. It still
decides on its own:

```python
if self.training and (labels is not None or shift_labels is not None):
```

linkedin#704 added `skip_logits` precisely so a caller could override that, and
swept every model that existed on 2025-05-23. llama4 arrived a month
later in linkedin#740 and never picked it up; everything added since has it.

Because the signature does not name it, a `skip_logits` argument lands
in `**kwargs` and is silently ignored, so `skip_logits=False` during
training still takes the fused path and returns `logits=None`. That is
the one thing the flag exists to prevent, and the convergence harness
relies on it, setting `eval_batch["skip_logits"] = False` before reading
`eval_output.logits`.

The change mirrors `mllama`, which has the identical
`LigerForCausalLMLoss` shape. `skip_logits=None` evaluates to the
previous condition, so nothing moves for callers that do not pass it.

## Testing Done

New `test/transformers/test_llama4.py`. Both cases stay on the non-fused
branch, so they run without a GPU:

- `skip_logits=False` in training mode returns logits and a loss. On
`main` this fails: the flag is ignored, the fused path runs, and on a
CPU box Triton raises `RuntimeError: 0 active drivers`. On a GPU box it
fails on `logits is None` instead.
- `skip_logits=True` with no labels raises `ValueError`, as it does on
every other model. On `main` this is `DID NOT RAISE`.

- `pytest test/transformers/test_monkey_patch.py
test/transformers/test_llama4.py`: 65 passed / 1 skipped (63 + the 2
new; the skip is `muse_glimmer` missing from the installed
transformers).
- `ruff check .` and `ruff format --check .` with the v0.14.11 pinned in
`.pre-commit-config.yaml`: clean.

Hardware Type: CPU. Ran on transformers 5.9.0 / torch 2.11.0.

---------

Co-authored-by: Vaibhav Jindal <vaibhav.jndl@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

4 participants