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 8 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 |
|---|---|---|
|
|
@@ -142,19 +142,25 @@ VLLM_USE_PRECOMPILED=1 VLLM_PRECOMPILED_WHEEL_VARIANT=cpu VLLM_TARGET_DEVICE=cpu | |
| === "IBM Z (S390X)" | ||
| --8<-- "docs/getting_started/installation/cpu.s390x.inc.md:build-image-from-source" | ||
|
|
||
| ## AMD Zen optimizations {#amd-zen-optimizations} | ||
|
|
||
| --8<-- "docs/getting_started/installation/cpu.x86.inc.md:amd-zen-optimizations" | ||
|
|
||
| ## Related runtime environment variables | ||
|
|
||
| - `VLLM_CPU_KVCACHE_SPACE`: specify the KV Cache size (e.g, `VLLM_CPU_KVCACHE_SPACE=40` means 40 GiB space for KV cache), larger setting will allow vLLM to run more requests in parallel. This parameter should be set based on the hardware configuration and memory management pattern of users. Default value is `0`. | ||
| - `VLLM_CPU_OMP_THREADS_BIND`: specify the CPU cores dedicated to the OpenMP threads, can be set as CPU id lists, `auto` (by default), or `nobind` (to disable binding to individual CPU cores and to inherit user-defined OpenMP variables). For example, `VLLM_CPU_OMP_THREADS_BIND=0-31` means there will be 32 OpenMP threads bound on 0-31 CPU cores. `VLLM_CPU_OMP_THREADS_BIND=0-31|32-63` means there will be 2 tensor parallel processes, 32 OpenMP threads of rank0 are bound on 0-31 CPU cores, and the OpenMP threads of rank1 are bound on 32-63 CPU cores. By setting to `auto`, the OpenMP threads of each rank are bound to the CPU cores in each NUMA node respectively. If set to `nobind`, the number of OpenMP threads is determined by the standard `OMP_NUM_THREADS` environment variable. | ||
| - `VLLM_CPU_NUM_OF_RESERVED_CPU`: specify the number of CPU cores which are not dedicated to the OpenMP threads for each rank. The variable only takes effect when VLLM_CPU_OMP_THREADS_BIND is set to `auto`. Default value is `None`. If the value is not set and use `auto` thread binding, no CPU will be reserved for `world_size == 1`, 1 CPU per rank will be reserved for `world_size > 1`. | ||
| - `CPU_VISIBLE_MEMORY_NODES`: specify visible NUMA memory nodes for vLLM CPU workers, similar to ```CUDA_VISIBLE_DEVICES```. The variable only takes effect when VLLM_CPU_OMP_THREADS_BIND is set to `auto`. The variable provides more control for the auto thread-binding feature, such as masking nodes and changing nodes binding sequence. | ||
| - `VLLM_CPU_SGL_KERNEL` (x86 only, Experimental): whether to use small-batch optimized kernels for linear layer and MoE layer, especially for low-latency requirements like online serving. The kernels require AMX instruction set, BFloat16 weight type and weight shapes divisible by 32. Default is `0` (False). | ||
| - `VLLM_ZENTORCH_WEIGHT_PREPACK` (AMD Zen only): when `ZenCpuPlatform` is active, eagerly prepack linear weights into ZenDNN's blocked layout at model load time, eliminating per-inference layout conversion overhead. Default is `1` (enabled). See [AMD Zen optimizations](#amd-zen-optimizations). | ||
|
|
||
| ## FAQ | ||
|
|
||
| ### Which `dtype` should be used? | ||
|
|
||
| - Currently, vLLM CPU uses model default settings as `dtype`. However, due to unstable float16 support in torch CPU, it is recommended to explicitly set `dtype=bfloat16` if there are any performance or accuracy problem. | ||
| - On AMD Zen CPUs (`ZenCpuPlatform`), `float16` is **not** supported. Only `bfloat16` and `float32` are accepted; models declared with `float16` are auto-downcast to `bfloat16` at model load time. See [AMD Zen optimizations](#amd-zen-optimizations). | ||
|
|
||
| ### How to launch a vLLM service on CPU? | ||
|
|
||
|
|
@@ -227,6 +233,27 @@ By providing MODEL_FILTER and DTYPE_FILTER, only commands for related model ID a | |
| ON_CPU=1 SERVING_JSON=serving-tests-cpu-text.json DRY_RUN=1 MODEL_FILTER=meta-llama/Llama-3.1-8B-Instruct DTYPE_FILTER=bfloat16 bash .buildkite/performance-benchmarks/scripts/run-performance-benchmarks.sh | ||
| ``` | ||
|
|
||
| ### How do I enable AMD Zen optimizations? {#how-do-i-enable-amd-zen-optimizations} | ||
|
|
||
| On an AMD Zen 4 / Zen 5 CPU, install the CPU wheel with the `zen` extra so vLLM pulls the tested `zentorch` version for that release: | ||
|
|
||
| ```bash | ||
| export VLLM_VERSION=0.20.2 | ||
| pip install "vllm[zen] @ https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}%2Bcpu-cp38-abi3-manylinux_2_35_x86_64.whl" \ | ||
| --extra-index-url https://download.pytorch.org/whl/cpu | ||
| ``` | ||
|
|
||
| vLLM auto-detects the platform and routes linear layers through ZenDNN-optimized kernels - no flag needed. To verify it is engaged, run with INFO-level logs and look for the platform-selection line: | ||
|
|
||
| ```bash | ||
| VLLM_LOGGING_LEVEL=INFO vllm serve facebook/opt-125m --dtype bfloat16 \ | ||
| 2>&1 | grep "AMD Zen CPU detected with zentorch installed" | ||
|
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. Let's update the model to something more modern. (Qwen3 0.6b? In that case you won't have to set
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. changed the model |
||
| ``` | ||
|
|
||
| For per-backend dispatch details (which kernel each linear layer was bound to), re-run with `VLLM_LOGGING_LEVEL=DEBUG` and grep for `CPU unquantized GEMM dispatch`. | ||
|
|
||
| See [AMD Zen optimizations](#amd-zen-optimizations) for detection rules, supported dtypes, and the `VLLM_ZENTORCH_WEIGHT_PREPACK` knob. | ||
|
|
||
| ### How to decide `VLLM_CPU_OMP_THREADS_BIND`? | ||
|
|
||
| - Default `auto` thread-binding is recommended for most cases. Ideally, each OpenMP thread will be bound to a dedicated physical core respectively, threads of each rank will be bound to the same NUMA node respectively, and 1 CPU per rank will be reserved for other vLLM components when `world_size > 1`. If you have any performance problems or unexpected binding behaviours, please try to bind threads as following. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,3 +66,26 @@ 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, "debug_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, | ||
| ) | ||
| ] | ||
Uh oh!
There was an error while loading. Please reload this page.