Another MLP implementation along with multiplier support

Open
#937 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
python

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.

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

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)
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)
  1. stack gate and up projections then put it into activation functions
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)
  1. dual gemm with activations (and multiplier)
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

Dominant language
Python
Stars
6.7k
Forks
673
Avg merge
4d 20h
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linkedin/Liger-Kernel

All issues in linkedin/Liger-Kernel

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.