Skip to content
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

[Core]Add Ascend Quantize #7

Merged
merged 22 commits into from
Feb 11, 2025
Merged

[Core]Add Ascend Quantize #7

merged 22 commits into from
Feb 11, 2025

Conversation

Angazenn
Copy link

@Angazenn Angazenn commented Feb 5, 2025

This pr adds ascend quantization interface to vllm-ascend, including AscendQuantConfig class which inherits from vllm QuantizationConfig class, AscendLinearMethod class which inherits from vllm LinearMethodBase class, AscendQuantizer class that dispatches corresponding quanzation methods.

@Angazenn Angazenn changed the base branch from main to develop February 7, 2025 01:55
@Angazenn Angazenn changed the title Add Ascend Quantize [Core]Add Ascend Quantize Feb 7, 2025
angazenn added 7 commits February 7, 2025 10:08
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>

def forward_oot(
self,
x: torch.Tensor,
residual: Optional[torch.Tensor] = None,
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
if hasattr(self, "module"):
return self.module.forward_anti_outlier(x, residual)
Copy link
Collaborator

@wangxiyuan wangxiyuan Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does self.module only used here? If yes, how about something like:

try:
    from mindie_turbo import RMSNormWithAntiOutlier
except:
    RMSNormWithAntiOutlier = None


def forward_oot():
    if RMSNormWithAntiOutlier is not None:
        return RMSNormWithAntiOutlier(self.hidden_size).forward_anti_outlier(x, residual)
  ....

Not sure enable_rmsnorm_with_antioutlier is need, it seems only added a new self.module there.

Copy link
Author

@Angazenn Angazenn Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Details of RMSNormWithAntiOutlier are moved out of vllm_ascend. There's no need to change the implemantation of rmsnorm in vllm_ascend now.

angazenn added 5 commits February 7, 2025 17:18
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>

return MindIETurboQuantizer.get_quantizer(quant_config)
except Exception:
raise NotImplementedError("There is no available ascend quantizer.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use import_lib to check if mindie_turbo is available or not. The try cache here is too large.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be fixed.

]


@pytest.mark.skipif(not is_mindie_turbo_supported(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a TODO here. Once more method is available in vllm-ascend. the skip can be removed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is designed for quantization methods based on mindie-turbo. For other possible quantization methods in the future, we can add new test cases.


import vllm_ascend # noqa: F401
from vllm_ascend.quantization.quant_config import AscendLinearMethod

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why import inner the test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because mindie_turbo should be import before vllm in early versions of mindie_turbo. Perhaps this conflict has been resolved now and these packages imported can be moved outside.


# When not using anti-outlier algorithms, "anti_method" refers to an empty string.
if len(quant_config["anti_method"]) > 0:
enable_rmsnorm_with_antioutlier()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my perspective, this looks kind of strange, this interface seems very detail and specific, Is it possible for you to hide more detail under the hood? I believe this part can be wrote in more general way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Details of RMSNormWithAntiOutlier are moved out of vllm_ascend. Related codes will be hidden into mindie_turbo.

angazenn added 3 commits February 8, 2025 10:43
…quantizer

Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
angazenn added 4 commits February 8, 2025 11:41
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
from tests.quantization.utils import is_mindie_turbo_supported, example_quantization

MODELS = [
"/home/zyj/data/Qwen2.5-0.5B-Instruct/",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this path?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an mistake. changed to Qwen/Qwen2.5-0.5B-Instruct now

"""
Do some pre-registeration or update action for ascend platform.
"""
from vllm_ascend.quantization.quant_config import AscendQuantConfig # noqa: F401
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vllm-project/vllm#12432 is not merged. Maybe you can move this import to register function in __init__.py, but I'm not sure if it will lead the circle import error or not. You can have a try first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that there are circular import if moving this import. But the codes still work and whole inference process can generate correct texts, so I move this codes to register function

angazenn added 2 commits February 10, 2025 13:26
Signed-off-by: angazenn <zengyanjia@huawei.com>
Signed-off-by: angazenn <zengyanjia@huawei.com>
@wangxiyuan wangxiyuan merged commit 7637759 into vllm-project:develop Feb 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants