linkedin / linkedin/Liger-Kernel
Another MLP implementation along with multiplier support
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 603
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 47
Description
### 🚀 The feature, motivation and pitch
Currently, LigerMLP modules only fuse swiglu/geglu computations together and leave matmuls untouched. These elementwise operations (including multiplier support #936 ) could be easily fused into matmul's epilogues. We can investigate the performance of this approach and see if we should adopt it.
TL;DR
Instead of
```python
gate_states = self.gate_proj(x)
up_states = self.up_proj(x)
intermidiate_states = LigerSiLUMulFunction.apply(gate_states , up_states)
return self.down_proj(intermidiate_states)
```
There are some other approaches worth exploring:
1. fuse activations (and multiplier) into gate_proj(x)
```python
up_states = self.up_proj(x)
intermidiate_states = LigerFusedLinearActMultiplierFunction.apply(x, self.gate_proj.weight, gate_multiplier, up_states)
return self.down_proj(intermidiate_states)
```
2. stack gate and up projections then put it into activation functions
```python
gate_up_states = self.gate_up_proj(x)
intermidiate_states = LigerSplitStatesActMultiplierFunction.apply(
gate_up_states,
config.hidden_act,
gate_multiplier,
up_states
)
return self.down_proj(intermidiate_states)
```
3. dual gemm with activations (and multiplier)
```python
intermidiate_states = LigerDualGemmActMulFuncion.apply(
x,
self.gate_proj.weight,
self.up_proj.weight,
config.hidden_act,
gate_multiplier,
)
return self.down_proj(intermidiate_states)
```
### Alternatives
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start by locating the LigerMLP modules and the existing fused SwiGLU/GeGLU implementation, then review multiplier support in issue #936. Compare the three proposed approaches with performance measurements; the work is done when an approach is selected, implemented, and its performance is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100