-
Notifications
You must be signed in to change notification settings - Fork 13.3k
model : disable SWA for Phi models #13676
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 I didn't saw your review request.
Hmm I think these configs still need to be kept. The original issue talked about phi-4 and not phi-3, and these branches of code was to make sure old phi-3 model works correctly.
Probably phi-4 conflicts with this but I'll have a look. In anw, I think
n_swa
should still be set (it can't be forced to 0), so that the model can mask out tokens correctly for long sequence.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.
The problem is that
n_swa
value never does anything whenn_swa_pattern == 1
, which has always been like this. So unless I am missing something, these configs didn't do anything.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.
Hmm ok it seems like
n_swa_pattern = 1
meaning all layers use SWA. I had a look at modeling_phi3.py and seems likeuse_sliding_windows
is set to the same value globally.In anw, I think we can just remove SWA altogether for phi-3/phi-4 if you feel like we spent too much efforts fixing this.
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.
With our current logic
n_swa_pattern = 1
actually means that none of the layers use SWA:llama.cpp/src/llama-hparams.cpp
Lines 73 to 79 in 3398305
Some models have a parameter
dense_attention_every_n_layers
:https://huggingface.co/microsoft/Phi-3-small-128k-instruct/blob/main/config.json#L18
This probably corresponds to our
n_swa_pattern
, but the conversion scripts and model loading logic completely ignores this atm.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.
Ok I haven't noticed about that
dense_attention_every_n_layers
. I think for now let's just disable the whole thing (as you are currently doing) and come back to this later. I don't think many users are still using these models, especially using it for long context. So probably it's not worth our time trying to fix this.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.
Yes, I think the only correct way to handle all Phi models is to update the convert scripts to provide information about the dense/swa layer pattern, which we can then use to create the respective cache. We also have to rework
n_swa_pattern
in some way to support "all-SWA layers" - mayben_swa_pattern == 0
could correspond to this:n_swa_pattern == 0
: all layers are SWAn_swa_pattern == 1
: all layers are non-SWAn_swa_pattern == n
: every nth layer is non-SWAMerging this for now as I agree it's more effort to resolve and this was incorrect even before the recent SWA changes.