linkedin / linkedin/Liger-Kernel
mllama patch modifies nn.LayerNorm globally
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 603
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 47
Description
### 🐛 Describe the bug
Instead of only patching the transformers mllama module (`transformers.models.mllama.modeling_mllama`), `apply_liger_kernel_to_mllama` modifies `torch.nn.LayerNorm` globally.
The issue is [here](https://github.com/linkedin/Liger-Kernel/commit/6ab3b9febc29f5045e6d2e27ba6bacaa4f041d91#diff-376c16dd1328612cf488158c6ce9805b044773659c8459cdcb2c6ec35dac346bR163).
The fix would be to:
(1) Not patch LayerNorm in Liger by assigning to `modeling_mllama.nn.LayerNorm`
(2) Change `transformers.models.mllama.modeling_mllama` to not use `from torch import nn` and to instead just import layernorm like `from torch.nn import LayerNorm`
(3) instead patch layernorm in Liger by assigning to `modeling_mllama.LayerNorm`
### Reproduce
```bash
pip install transformers==4.45 liger-kernel-nightly
```
```python
from liger_kernel.transformers import apply_liger_kernel_to_mllama
from torch import nn
apply_liger_kernel_to_mllama()
print(nn.LayerNorm)
```
### Versions
Environment Report:
-------------------
Operating System: Linux-6.1.85+-x86_64-with-glibc2.35
Python version: 3.10.12
PyTorch version: 2.4.1+cu121
CUDA version: Not available
Triton version: 3.1.0
Transformers version: 4.45.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with apply_liger_kernel_to_mllama and the referenced patch in transformers.models.mllama.modeling_mllama. Reproduce the issue with the listed package versions, then verify that applying the mllama patch leaves torch.nn.LayerNorm unchanged while the mllama module uses the Liger layer normalization implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100