-
Notifications
You must be signed in to change notification settings - Fork 33.7k
GptOss experts implementation #43227
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 15 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2aff4a8
experts impl gpt oss
IlyasMoutawwakil 9958efb
no need to transpose dequantized experts
IlyasMoutawwakil b23e1ff
skip test_reverse_loading_mapping
IlyasMoutawwakil e28f155
fix custom gating
IlyasMoutawwakil e57d0a8
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil be08fe4
revert transposition and simply support transposed experts to avoid m…
IlyasMoutawwakil e1dba4d
style
IlyasMoutawwakil 0261a46
don't rely on weight shapes as they can be square matrices
IlyasMoutawwakil 5bd25c7
no need to relaod
IlyasMoutawwakil 846adca
fallback to eager
IlyasMoutawwakil b1a71a7
Update src/transformers/models/gpt_oss/modeling_gpt_oss.py
IlyasMoutawwakil 9dbed89
fix
IlyasMoutawwakil 2f3fd11
force 16 bytes alignmenet during weight loading
IlyasMoutawwakil dd377e1
simplify logic
IlyasMoutawwakil 52e0778
quantization conversions should be applied first
IlyasMoutawwakil 1c49112
avoid baddbmm as it is less performant / less optimizable by max-auto…
IlyasMoutawwakil 4b0323c
no need for logger
IlyasMoutawwakil aa34996
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil f094c31
add comment explaining limitation
IlyasMoutawwakil 221f9bd
standarize operations and only reshape when needed
IlyasMoutawwakil 944afb5
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil 1fc01dc
fixup conversion and test
vasqu d820713
Update src/transformers/conversion_mapping.py
IlyasMoutawwakil 71fdb18
force alignment docstring
IlyasMoutawwakil e852cbb
move default apply gate
IlyasMoutawwakil d698dcb
offsets
IlyasMoutawwakil 5c2ca3c
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil d6631bb
add docs and make kernel_config optional
IlyasMoutawwakil 4f7226d
use reshapes as they are equivalent to views when memory is contiguous
IlyasMoutawwakil 2117303
fix and better notes
IlyasMoutawwakil 944a0ec
reshapes instead of views
IlyasMoutawwakil 1a0ea12
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil 16e6536
keep model saving and reloading in grouped_mm test to catch misalignm…
IlyasMoutawwakil 75ab275
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil 711a652
Merge branch 'main' into gpt-oss-experts-impl
IlyasMoutawwakil 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -439,6 +439,39 @@ def reverse_op(self) -> ConversionOps: | |
| return Transpose(dim0=self.dim1, dim1=self.dim0) | ||
|
|
||
|
|
||
| class Force16BytesAlignment(ConversionOps): | ||
| """ | ||
| Ensures that the given tensor is 16-bytes aligned in memory. | ||
|
IlyasMoutawwakil marked this conversation as resolved.
Outdated
|
||
| """ | ||
|
Comment on lines
+444
to
+447
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very nice 🫡 |
||
|
|
||
| @torch.no_grad() | ||
| def convert( | ||
| self, | ||
| input_dict: dict[str, list[torch.Tensor]], | ||
| source_patterns: list[str], | ||
| target_patterns: list[str], | ||
| config, | ||
| **kwargs, | ||
| ) -> dict[str, list[torch.Tensor]]: | ||
| if len(input_dict) != len(target_patterns): | ||
| raise ValueError( | ||
| f"Force16BytesAlignment conversion can only happen on each key ({len(input_dict)}) " | ||
| f"and should match exact one target ({len(target_patterns)})." | ||
| ) | ||
|
|
||
| output: dict[str, list[torch.Tensor]] = {} | ||
| for key, target_pattern in zip(input_dict.keys(), target_patterns): | ||
| tensor = input_dict.get(key, []) | ||
| if len(tensor) != 1: | ||
| raise ValueError(f"Force16BytesAlignment conversion requires exactly one tensor, found {len(tensor)}.") | ||
| output[target_pattern] = tensor[0].clone() if tensor[0].data_ptr() % 16 == 0 else tensor[0].clone() | ||
| return output | ||
|
|
||
| @property | ||
| def reverse_op(self) -> ConversionOps: | ||
| return deepcopy(self) | ||
|
|
||
|
|
||
| @dataclass(slots=True) | ||
| class WeightTransform: | ||
| source_patterns: str | list[str] = field(init=True) | ||
|
|
||
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.
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.
it's seems that the order of operations matters when both quantization conversions and weight conversions are defined. e.g. with gpt_oss if I want to apply the Force16ByteAlignment conversion, it has to be placed after the dequantization otherwise the loader is confused (see output below). @vasqu @ArthurZucker
results in:
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.
also @Cyrilvallez
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! Since
get_weight_conversionsis only to DEQUANTIZE it makes sense that it's first. However, as discussed offline, for now it's not possible to match 1 param with 2 converter (i.e. 1 dequant converter, and 1 from the hardcoded mapping). So it means that any model with a mapping registered cannot be dequantized 😭 So in theory you're right it should come first, but as it does not work anyway currently it does not make a difference 😭 Let's still keep this change adding a comment on all that please!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 @Cyrilvallez added a comment mostly rewording your explanation !