-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Monkeypatch for Phi3 #76
Monkeypatch for Phi3 #76
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @shivam15s
@@ -153,6 +153,8 @@ loss.backward() | |||
| Mixtral | `liger_kernel.transformers.apply_liger_kernel_to_mixtral` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss | | |||
| Gemma2 | `liger_kernel.transformers.apply_liger_kernel_to_gemma` | RoPE, RMSNorm, GeGLU, CrossEntropyLoss | | |||
| Qwen2 | `liger_kernel.transformers.apply_liger_kernel_to_qwen2` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy | | |||
| Phi3 | `liger_kernel.transformers.apply_liger_kernel_to_phi3` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the whitespace modifications here, this is the only change in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for helping on the housekeeping! <3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want to implement for FusedLinearCrossEntropy in the next PR and also create a issue to track? Essentially add a method patch
def lce_forward( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah happy to do that as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -38,3 +38,27 @@ def __init__(self, config): | |||
def forward(self, x): | |||
|
|||
return self.w2(LigerSiLUMulFunction.apply(self.w1(x), self.w3(x))) | |||
|
|||
|
|||
class LigerPhi3SwiGLUMLP(nn.Module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Llama has its own MLP implementation here, but its named very generally. I went for a model-specific name here, but open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. this is necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this hyper speed PR woo hoo
yeah let's bump to 4.41. sdpa seems not a hard requirement since most users use flash attn |
we can merge after transformers bump and fix conflict |
All relevant tests passing, mini_gemma test convergence is failing on my 4090 now though, perhaps related to the recent PR (#85):
|
I think I'll need a review from @yundai424 as well to bypass the "changes requested" flag |
@yundai424 can you take a look? ty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm and we can fix gemma in #92
Summary
Add a new monkeypatch function to support patching Huggingface's Phi3 implementation with Liger Kernels.
Phi3 has its own MLP implementation (
Phi3MLP
) so aLigerPhi3SwiGLUMLP
implementation that leveragesLigerSiLUMulFunction
is provided as well.Testing Done
make test
to ensure correctnessmake checkstyle
to ensure code stylemake test-convergence
to ensure convergenceConvergence test added (and passing on my 4090) for a minimodel based on Phi3 patched with liger kernels.
All tests passing.
Questions for Discussion
Apparently Phi3 was only added in transformers v4.41, but the lowest supported version of transformers in Liger-Kernel is 4.40.1. Additionally, only more recently has
sdpa
been supported in HF Phi3. Thoughts? Should I leave the transformers dependency version as-is?