Repository navigation
[ZenCPU] Add zencpu Platform Runtime Logging and Docs #42726
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
Changes from 5 commits
934be93
7fa2107
6ac6b41
f35e221
7555ddc
d24d0dc
8074d81
bc8c57d
6bda06d
0ca058a
04f3971
cffd91a
eea4fb6
aaf22b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,14 @@ | |
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Tests for CPU unquantized GEMM dispatch behavior.""" | ||
|
|
||
| import sys | ||
| import types | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.model_executor.layers import utils | ||
| from vllm.platforms import current_platform | ||
| from vllm.platforms import current_platform, zen_cpu | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
|
|
@@ -66,3 +69,64 @@ def test_dispatch_cpu_unquantized_gemm_zen_remove_weight(monkeypatch): | |
| utils.dispatch_cpu_unquantized_gemm(layer, remove_weight=True) | ||
|
|
||
| assert layer.weight.numel() == 0 | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("_mock_zentorch_linear_unary") | ||
| def test_dispatch_cpu_unquantized_gemm_logs_zentorch_dispatch(monkeypatch): | ||
|
Comment on lines
+71
to
+72
Member
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. Should this be skipped if platform is not zen_cpu?
Contributor
Author
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. No, this is intentional. The test is a unit test for the dispatcher logic. It uses the Skipping on non-Zen hardware would mean the new logging code is never validated in CI. The pattern matches the two existing tests above it (
Contributor
Author
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. although, would love to get your thoughts on adding UT for logging |
||
| monkeypatch.setattr(current_platform, "is_zen_cpu", lambda: True) | ||
| expected_prepacked = bool(utils.envs.VLLM_ZENTORCH_WEIGHT_PREPACK) and hasattr( | ||
| torch.ops.zentorch, "zentorch_weight_prepack_for_linear" | ||
| ) | ||
|
|
||
| log_calls = [] | ||
| monkeypatch.setattr(utils.logger, "info_once", lambda *args: log_calls.append(args)) | ||
|
|
||
| layer = torch.nn.Linear(16, 8, bias=True) | ||
| utils.dispatch_cpu_unquantized_gemm(layer, remove_weight=False) | ||
|
|
||
| assert log_calls == [ | ||
| ( | ||
| "CPU unquantized GEMM dispatch: using zentorch_linear_unary (prepacked=%s)", | ||
| expected_prepacked, | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| def test_zen_cpu_platform_logs_activation(monkeypatch): | ||
|
Member
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. same
Contributor
Author
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. same answer as the previous one |
||
| fake_zentorch = types.SimpleNamespace( | ||
| __version__="5.2.1", | ||
| __config__="zentorch build config", | ||
| ) | ||
| monkeypatch.setitem(sys.modules, "zentorch", fake_zentorch) | ||
| monkeypatch.setattr(zen_cpu.envs, "VLLM_ZENTORCH_WEIGHT_PREPACK", 1) | ||
| monkeypatch.setattr(zen_cpu.torch.cpu, "_is_avx512_supported", lambda: True) | ||
| monkeypatch.setattr(zen_cpu.torch.cpu, "_is_avx512_bf16_supported", lambda: False) | ||
|
|
||
| log_calls = [] | ||
| monkeypatch.setattr( | ||
| zen_cpu.logger, "info_once", lambda *args: log_calls.append(args) | ||
| ) | ||
|
|
||
| def fake_check_and_update_config(cls, vllm_config): | ||
| pass | ||
|
|
||
| monkeypatch.setattr( | ||
| zen_cpu.CpuPlatform, | ||
| "check_and_update_config", | ||
| classmethod(fake_check_and_update_config), | ||
| ) | ||
|
|
||
| zen_cpu.ZenCpuPlatform.check_and_update_config(object()) | ||
|
|
||
| assert log_calls == [ | ||
| ( | ||
| "ZenCpuPlatform activated | zentorch=%s | " | ||
| "VLLM_ZENTORCH_WEIGHT_PREPACK=%d | " | ||
| "AVX-512=%s | AVX-512_BF16=%s", | ||
| "5.2.1", | ||
| 1, | ||
| True, | ||
| False, | ||
| ), | ||
| ("zentorch build config: %s", "zentorch build config"), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,6 +258,10 @@ def dispatch_cpu_unquantized_gemm( | |
| ) | ||
| if remove_weight: | ||
| layer.weight = torch.nn.Parameter(torch.empty(0), requires_grad=False) | ||
| logger.info_once( | ||
| "CPU unquantized GEMM dispatch: using zentorch_linear_unary (prepacked=%s)", | ||
| is_prepacked, | ||
| ) | ||
|
Member
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. Could you change this to |
||
| return | ||
|
|
||
| if envs.VLLM_CPU_SGL_KERNEL and check_cpu_sgl_kernel(N, K, dtype): | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,21 @@ | ||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||||||||
|
|
||||||||
| from typing import TYPE_CHECKING | ||||||||
|
|
||||||||
| import torch | ||||||||
|
|
||||||||
| from vllm import envs | ||||||||
| from vllm.logger import init_logger | ||||||||
| from vllm.platforms.cpu import CpuPlatform | ||||||||
|
|
||||||||
| logger = init_logger(__name__) | ||||||||
|
|
||||||||
| if TYPE_CHECKING: | ||||||||
| from vllm.config import VllmConfig | ||||||||
| else: | ||||||||
| VllmConfig = None | ||||||||
|
|
||||||||
|
|
||||||||
| class ZenCpuPlatform(CpuPlatform): | ||||||||
| """CPU platform with AMD Zen (ZenDNN/zentorch) optimizations. | ||||||||
|
|
@@ -30,3 +38,27 @@ def is_zen_cpu(self) -> bool: | |||||||
| @property | ||||||||
| def supported_dtypes(self) -> list[torch.dtype]: | ||||||||
| return [torch.bfloat16, torch.float32] | ||||||||
|
|
||||||||
| @classmethod | ||||||||
| def check_and_update_config(cls, vllm_config: VllmConfig) -> None: | ||||||||
| super().check_and_update_config(vllm_config) | ||||||||
|
|
||||||||
| import zentorch | ||||||||
|
|
||||||||
| zentorch_version = getattr(zentorch, "__version__", "unknown") | ||||||||
| avx512 = torch.cpu._is_avx512_supported() | ||||||||
| avx512_bf16 = torch.cpu._is_avx512_bf16_supported() | ||||||||
|
|
||||||||
| logger.info_once( | ||||||||
| "ZenCpuPlatform activated | zentorch=%s | " | ||||||||
| "VLLM_ZENTORCH_WEIGHT_PREPACK=%d | " | ||||||||
| "AVX-512=%s | AVX-512_BF16=%s", | ||||||||
| zentorch_version, | ||||||||
| int(envs.VLLM_ZENTORCH_WEIGHT_PREPACK), | ||||||||
| avx512, | ||||||||
| avx512_bf16, | ||||||||
| ) | ||||||||
|
|
||||||||
| zentorch_config = getattr(zentorch, "__config__", None) | ||||||||
| if zentorch_config: | ||||||||
| logger.info_once("zentorch build config: %s", zentorch_config) | ||||||||
|
Member
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. check_and_update_config is not the right place to print info banners. We already have logging that the zen platform is being used here - perhaps upgrade that logging level to info instead? vllm/vllm/platforms/__init__.py Lines 190 to 192 in 02606b0
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.