-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[300I][Bugfix] fix unquant model weight nd2nz error #6851
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
16 commits
Select commit
Hold shift + click to select a range
a792359
[300I][Bugfix] fix unquant model weight nd2nz error
Tflowers-0129 ec9fee0
add ut
Tflowers-0129 8ce786d
ut
Tflowers-0129 3be1e5d
[310p] add vocab parallel nz
Tflowers-0129 e42e58e
refactoring utils maybe_trans_nz
Tflowers-0129 7a07d65
add vocabembedding ut
Tflowers-0129 4f50b0f
ruffformat error fix
Tflowers-0129 dad79ea
cleancode
Tflowers-0129 65c021d
ut
Tflowers-0129 fd842d0
remove patch on 310p vocabembedding
Tflowers-0129 bb8382b
cleancode
Tflowers-0129 ffa3f3a
refactor
Tflowers-0129 d0c73dd
cleancode
Tflowers-0129 2f50b65
cleancode
Tflowers-0129 a369ad5
cleancode
Tflowers-0129 f3d13f0
trigger
Tflowers-0129 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
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # | ||
| # Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import torch | ||
| import torch.nn.functional as F | ||
| from vllm.model_executor.layers.quantization.base_config import QuantizationConfig | ||
| from vllm.model_executor.layers.vocab_parallel_embedding import ( | ||
| DEFAULT_VOCAB_PADDING_SIZE, | ||
| UnquantizedEmbeddingMethod, | ||
| ) | ||
|
|
||
| from vllm_ascend.ops.vocab_parallel_embedding import AscendParallelLMHead, AscendVocabParallelEmbedding | ||
| from vllm_ascend.utils import maybe_trans_nz | ||
|
|
||
|
|
||
| class AscendUnquantizedEmbeddingMethod310(UnquantizedEmbeddingMethod): | ||
| def process_weights_after_loading(self, layer: torch.nn.Module) -> None: | ||
| layer.weight_nz = maybe_trans_nz(layer.weight) | ||
|
|
||
| def apply( | ||
| self, | ||
| layer: torch.nn.Module, | ||
| x: torch.Tensor, | ||
| bias: torch.Tensor | None = None, | ||
| ) -> torch.Tensor: | ||
| return F.linear(x, layer.weight_nz, bias) | ||
|
|
||
|
|
||
| class AscendVocabParallelEmbedding310(AscendVocabParallelEmbedding): | ||
| def __init__( | ||
| self, | ||
| num_embeddings: int, | ||
| embedding_dim: int, | ||
| params_dtype: torch.dtype | None = None, | ||
| org_num_embeddings: int | None = None, | ||
| padding_size: int = DEFAULT_VOCAB_PADDING_SIZE, | ||
| quant_config: QuantizationConfig | None = None, | ||
| prefix: str = "", | ||
| ): | ||
| super().__init__( | ||
| num_embeddings, embedding_dim, params_dtype, org_num_embeddings, padding_size, quant_config, prefix | ||
| ) | ||
| if quant_config is None: | ||
| self.quant_method = AscendUnquantizedEmbeddingMethod310() | ||
|
|
||
|
|
||
| class AscendParallelLMHead310(AscendParallelLMHead): | ||
| """ | ||
| Register ParallelLMHead as a custom op for Atlas 310p. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| num_embeddings: int, | ||
| embedding_dim: int, | ||
| bias: bool = False, | ||
| params_dtype: torch.dtype | None = None, | ||
| org_num_embeddings: int | None = None, | ||
| padding_size: int = DEFAULT_VOCAB_PADDING_SIZE, | ||
| quant_config: QuantizationConfig | None = None, | ||
| prefix: str = "", | ||
| ): | ||
| super().__init__( | ||
| num_embeddings, embedding_dim, bias, params_dtype, org_num_embeddings, padding_size, quant_config, prefix | ||
| ) | ||
|
|
||
| if quant_config is None: | ||
| self.quant_method = AscendUnquantizedEmbeddingMethod310() |
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
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
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.