vllm.platforms
¶
Modules:
-
cpu– -
cuda–Code inside this file can safely assume cuda platform, e.g. importing
-
interface– -
rocm– -
rocm_device_memory–Free device memory corrected by amdgpu's exact VRAM count.
-
xpu– -
zen_cpu–
Classes:
-
Platform– -
PlatformEnum–Enumeration of supported hardware platforms.
Functions:
-
_is_amd_zen_cpu–Detect AMD CPU with AVX-512 via /proc/cpuinfo.
Platform
¶
Methods:
-
apply_config_platform_defaults–Apply the platform-specific default values to the config.
-
can_update_inplace–Checks if the platform allows inplace memory updates.
-
check_and_update_config–Check and update the configuration for the current platform.
-
check_and_update_eplb_config–Choose and validate the platform's EPLB policy and communicator.
-
check_if_supports_dtype–Check if the dtype is supported by the current platform.
-
check_max_model_len–Check max_model_len for the current platform.
-
check_runner_kv_caches_multi_layer–Check whether the platform's ModelRunner can handle multiple attention
-
device_control_id_to_physical_device_id–Map one device-control env entry to an integer physical device ID.
-
device_id_to_physical_device_id–Map a vLLM-local logical device ID to a physical device ID.
-
enable_multi_stream_overlap–Whether the current platform should enable multi-stream overlap
-
fp8_dtype–Returns the preferred FP8 type on the current platform.
-
free_device_memory–Free bytes on device (None: the current one) to size memory from.
-
get_all_gpu_pci_bus_ids–Return a mapping of device index to PCI bus ID string.
-
get_attn_backend_cls–Get the attention backend class of a device.
-
get_compile_backend–Get the custom compile backend for current platform.
-
get_cpu_architecture–Determine the CPU architecture of the current system.
-
get_cudagraph_capture_defaults–Return capture defaults without mutating user configuration.
-
get_current_memory_usage–Return the memory usage in bytes.
-
get_decode_cudagraph_capture_grid–Return uniform decode request counts, independent of query length.
-
get_default_ir_op_priority–Get the default IR op priority for the current platform.
-
get_device_capability–Stateless version of torch.cuda.get_device_capability.
-
get_device_communicator_cls–Get device specific communicator class for distributed communication.
-
get_device_name–Get the name of a device.
-
get_device_total_memory–Get the total memory of a device in bytes.
-
get_device_uuid–Get the uuid of a device, e.g. the PCI bus ID.
-
get_global_graph_pool–Return the global graph pool for this platform.
-
get_hisparse_backend_cls–Return the device implementation for the common HiSparse runtime.
-
get_infinity_values–Return the platform specific values for (-inf, inf).
-
get_kv_cache_config_builder_cls–Resolve the fully-qualified class path of the platform's KV cache
-
get_mla_prefill_backend_cls–Get the MLA prefill backend class of a device.
-
get_moe_backends–Out-of-tree MoE backends by
--moe-backendname, in the priority -
get_nixl_memory_type–Returns the nixl memory type for the current platform.
-
get_nixl_supported_devices–Returns a mapping from device_type to a tuple of supported
-
get_pass_manager_cls–Get the pass manager class for this platform.
-
get_prefill_cudagraph_capture_grid–Return prefill token sizes within
max_tokens; zero returns[]. -
get_punica_wrapper–Return the punica wrapper for current platform.
-
get_static_graph_wrapper_cls–Get static graph wrapper class for static graph.
-
get_varlen_decode_cudagraph_capture_grid–Return adaptive verification token sizes within
max_tokens. -
get_vit_attn_backend–Get the vision attention backend class of a device.
-
has_device_capability–Test whether this platform is compatible with a device capability.
-
import_ir_kernels–The default implementation imports
vllm.kernels, which registers -
import_kernels–Import any platform-specific C kernels.
-
inference_mode–A device-specific wrapper of
torch.inference_mode. -
is_arch_support_pdl–Does the current platform support PDL (Programmatic Dependent Launch)?
-
is_confidential_compute–Whether the device runs in a confidential-computing mode that makes
-
is_cuda_alike–Stateless version of torch.cuda.is_available.
-
is_current_stream_capturing–Return whether the current accelerator stream is capturing a graph.
-
is_device_capability–Test whether this platform has exactly the specified device capability.
-
is_device_capability_family–Returns True if the device capability is any
.x. -
is_fp8_fnuz–Returns whether the preferred FP8 type is FNUZ on the current platform.
-
is_integrated_gpu–Returns whether the GPU is an integrated (UMA) device that shares
-
is_pin_memory_available–Checks whether pin memory is available on the current platform.
-
log_warnings–Log platform-specific diagnostics after logging is configured.
-
logical_device_id_to_visible_device_id–Map a vLLM-local logical device ID to the current process's
-
make_synced_weight_loader–Wrap the original weight loader to make it synced.
-
manual_seed_all–Set RNG seed across all devices for the current platform.
-
num_compute_units–Get the number of compute units for the current platform.
-
opaque_attention_op–Returns True if we register attention as one giant opaque custom op
-
pre_register_and_update–Do some pre-registration or update action for the current platform.
-
prepare_ubatch_streams–Set up per-stream library state before dual batch overlap runs its
-
register_triton_kernel_overrides–Override core Triton kernels with platform implementations.
-
reset_global_graph_pool–Make the next
get_global_graph_poolcall create a new pool. -
set_additional_forward_context–Set some additional forward context for the current platform if needs.
-
set_device–Set the device for the current platform.
-
stateless_init_device_torch_dist_pg–Init platform-specific torch distributed process group.
-
support_deep_gemm–Returns if DeepGEMM is supported by the current platform.
-
support_hybrid_kv_cache–Returns if the hybrid kv cache is supported by the current platform.
-
support_static_graph_mode–Returns if the graph mode is supported by the current platform.
-
supports_eplb–Whether this platform can run expert parallel load balancing.
-
supports_fp8–Returns whether the current platform supports FP8 types.
-
supports_mx–Returns whether the current platform supports MX types.
-
update_block_size_for_backend–Ensure block_size is compatible with the attention backend.
-
use_all_gather–Whether to use allgather in LogitsProcessor to gather the logits.
-
use_custom_allreduce–Returns if custom allreduce is supported on the current platform.
-
use_custom_op_collectives–Whether this platform should use torch.ops.vllm.* custom ops for collectives.
-
use_sync_weight_loader–Returns if the current platform needs to sync weight loader.
-
uses_host_device_handling–Whether vLLM should leave DeviceConfig.device unset.
-
uses_standalone_cpu_model_runner–Returns if Model Runner V2 runs as the standalone (no-Triton) CPU
-
validate_environ–Validate environment variables for the current platform.
-
validate_request–Raises if this request is unsupported on this platform.
-
verify_model_arch–Verify whether the current platform supports the specified model
-
verify_quantization–Verify whether the quantization is supported by the current platform.
-
visible_device_id_to_physical_device_id–Map a visible accelerator ordinal (e.g.
torch.device.index)
Attributes:
-
pass_key(str) –Inductor config key for the PassManager custom pass.
-
supported_dtypes(list[dtype]) –Returns the supported dtypes for the current platform.
pass_key
property
¶
Inductor config key for the PassManager custom pass.
supported_dtypes
property
¶
Returns the supported dtypes for the current platform.
_align_heterogeneous_kv_block_size(vllm_config, backend_cls)
classmethod
¶
Align block size when several KV dtypes share one block pool.
A quantized primary (e.g. nvfp4) shares the block pool with one or more
higher-precision "padded specs" (skip layers today; the first/last-N
sibling in the future). A padded spec's per-token page is larger than
the primary's and not an integer multiple of it, so the trivial
unify_kv_cache_spec_page_size cannot reconcile them. We do it here
instead, before the specs are built:
- Bump the primary
block_size(kernel-aligned) until the primary page is large enough to cover the largest padded-spec page. - Record that shared page in each padded spec's
*_page_size_paddedhint, so it pads up to the shared page.
unify then sees equal pages and stays trivial.
To add a padded-spec type: append its per-token page to padded_pages
and set its *_page_size_padded hint below.
_align_hybrid_block_size(vllm_config, backend_cls)
classmethod
¶
For hybrid attention/mamba models, ensure that the attention page size is >= the mamba page size, and pad the mamba page size to match.
_check_aligned_block_size(vllm_config, backend_classes, pre_block_size)
classmethod
¶
Fail now, not at worker setup, if alignment left a rejected size.
Alignment rounds by the first backend's kernel block only, so it can land on a size a sibling backend rejects.
_find_non_ssm_backends(vllm_config)
classmethod
¶
Distinct non-SSM attention backends, in layer order.
_preferred_block_size_for_backends(backend_classes, default_block_size, vllm_config)
classmethod
¶
Block size every backend accepts.
One backend keeps its preferred size. When every backend accepts the default, several backends keep that preference only when they all ask for the same size and all accept it. Differing preferences keep the default. If any backend rejects the default, the LCM search is unchanged.
supports_block_size may be overridden to accept exact sizes only
(CPU_MLA takes 16 and no multiple of it), so candidates are the LCMs of
one supported size per backend, each checked against every backend.
Raises:
-
ValueError–If the backends share no supported block size.
apply_config_platform_defaults(vllm_config)
classmethod
¶
Apply the platform-specific default values to the config.
This function is called during the initialization of global VllmConfig, after parsing cli arguments. It can modify the defaults of the config according to the platform. For example, it can enable custom_ops based on the enabled features.
The config is passed by reference, so it can be modified in place.
can_update_inplace()
classmethod
¶
Checks if the platform allows inplace memory updates.
check_and_update_config(vllm_config)
classmethod
¶
Check and update the configuration for the current platform.
It can raise an exception if the configuration is not compatible with the current platform, or it can update the configuration to make it compatible with the current platform.
The config is passed by reference, so it can be modified in place.
check_and_update_eplb_config(parallel_config)
classmethod
¶
Choose and validate the platform's EPLB policy and communicator.
Out-of-tree overrides validate their own policy and communicator names.
check_if_supports_dtype(dtype)
classmethod
¶
Check if the dtype is supported by the current platform.
check_max_model_len(max_model_len)
classmethod
¶
Check max_model_len for the current platform.
check_runner_kv_caches_multi_layer()
classmethod
¶
Check whether the platform's ModelRunner can handle multiple attention layers that share the same layer index (e.g. cross attention and self attention in the same decoder block of an encoder-decoder model such as BART).
Platforms that have verified that their runner_kv_caches is not
impacted by this case should override this to a no-op. Otherwise the
default implementation raises NotImplementedError.
device_control_id_to_physical_device_id(device_id)
classmethod
¶
Map one device-control env entry to an integer physical device ID.
device_id_to_physical_device_id(device_id)
classmethod
¶
Map a vLLM-local logical device ID to a physical device ID.
The input is a logical local ID (e.g. a local rank), NOT a visible device ordinal; for the latter use visible_device_id_to_physical_device_id(). The two coincide only when no logical-to-physical mapping is in effect.
enable_multi_stream_overlap(aux_stream_list, attn_metadata)
classmethod
¶
Whether the current platform should enable multi-stream overlap for the given aux streams and attention metadata.
fp8_dtype()
classmethod
¶
Returns the preferred FP8 type on the current platform.
See the documentation for is_fp8_fnuz for details.
free_device_memory(device=None)
classmethod
¶
Free bytes on device (None: the current one) to size memory from. Platforms whose reported free memory is too low override this.
get_all_gpu_pci_bus_ids()
classmethod
¶
Return a mapping of device index to PCI bus ID string.
Used by VLLM_GPU_NIC_PCIE_MAPPING for RDMA NIC selection.
Subclasses should override with platform-specific discovery
(e.g. pynvml for CUDA).
get_attn_backend_cls(selected_backend, attn_selector_config, num_heads=None)
classmethod
¶
Get the attention backend class of a device.
get_compile_backend()
classmethod
¶
Get the custom compile backend for current platform.
get_cpu_architecture()
classmethod
¶
Determine the CPU architecture of the current system. Returns CpuArchEnum indicating the architecture type.
get_cudagraph_capture_defaults(vllm_config)
¶
Return capture defaults without mutating user configuration.
The common resolver applies these only to unset settings; explicit legacy settings retain their shared-grid semantics.
get_current_memory_usage(device=None)
classmethod
¶
Return the memory usage in bytes.
get_decode_cudagraph_capture_grid(max_requests)
classmethod
¶
Return uniform decode request counts, independent of query length.
get_default_ir_op_priority(vllm_config)
classmethod
¶
Get the default IR op priority for the current platform.
get_device_capability(device_id=0)
classmethod
¶
Stateless version of torch.cuda.get_device_capability.
Parameters:
get_device_communicator_cls()
classmethod
¶
Get device specific communicator class for distributed communication.
get_device_name(device_id=0)
classmethod
¶
Get the name of a device.
get_device_total_memory(device_id=0)
classmethod
¶
Get the total memory of a device in bytes.
get_device_uuid(device_id=0)
classmethod
¶
Get the uuid of a device, e.g. the PCI bus ID.
get_global_graph_pool()
¶
Return the global graph pool for this platform.
get_hisparse_backend_cls()
classmethod
¶
Return the device implementation for the common HiSparse runtime.
get_infinity_values(dtype)
classmethod
¶
Return the platform specific values for (-inf, inf).
get_kv_cache_config_builder_cls(vllm_config)
classmethod
¶
Resolve the fully-qualified class path of the platform's KV cache config builder.
Note
Experimental, like the KVCacheConfigBuilder interface it selects.
The builder supplies grouping (get_kv_cache_groups) and tensor
placement (get_kv_cache_config_from_groups). Vendors may override
this to return a platform-specific builder. The default builder honors a
model implementing
SupportsKVCacheGrouping;
a builder that overrides get_kv_cache_groups owns grouping and
bypasses that model hook unless it calls super().
Returns:
-
str–Fully-qualified class path of a
KVCacheConfigBuildersubclass.
get_mla_prefill_backend_cls(mla_selector_config)
classmethod
¶
Get the MLA prefill backend class of a device.
Platforms that have a single, fixed MLA prefill backend can override this to return it directly. The default implementation selects the best backend from a device-capability-based priority list.
Returns:
-
type[MLAPrefillBackend]–The selected backend class.
Raises:
-
ValueError–If no MLA prefill backend is valid for the configuration.
get_moe_backends()
classmethod
¶
Out-of-tree MoE backends by --moe-backend name, in the priority
order used by auto. Names are lowercase with underscores and must not
reuse an in-tree backend's.
get_nixl_memory_type()
classmethod
¶
Returns the nixl memory type for the current platform.
get_nixl_supported_devices()
classmethod
¶
Returns a mapping from device_type to a tuple of supported kv_buffer_device for nixl.
get_pass_manager_cls()
classmethod
¶
Get the pass manager class for this platform. It will be registered as a custom pass under the current_platform.pass_key.
get_prefill_cudagraph_capture_grid(max_tokens, dense_head=False)
classmethod
¶
Return prefill token sizes within max_tokens; zero returns [].
get_punica_wrapper()
classmethod
¶
Return the punica wrapper for current platform.
get_static_graph_wrapper_cls()
classmethod
¶
Get static graph wrapper class for static graph.
get_varlen_decode_cudagraph_capture_grid(max_tokens, dense_head=False)
classmethod
¶
Return adaptive verification token sizes within max_tokens.
get_vit_attn_backend(head_size, dtype, backend=None)
classmethod
¶
Get the vision attention backend class of a device.
NOTE: ViT Attention should be checked and override in the platform-specific
implementation. we should not override this in any other places, like
the model_executor/models/
We check if the backend is None or not
- If not, check if the backend is supported by the platform.
- If None, continue to the default selection logic.
has_device_capability(capability, device_id=0)
classmethod
¶
Test whether this platform is compatible with a device capability.
The capability argument can either be:
- A tuple
(major, minor). - An integer
<major><minor>. (SeeDeviceCapability.to_int)
import_ir_kernels()
classmethod
¶
The default implementation imports vllm.kernels, which registers
the built-in IR op implementations. Out-of-tree (OOT) platforms should
override this method to import their own kernel modules.
import_kernels()
classmethod
¶
Import any platform-specific C kernels.
inference_mode()
classmethod
¶
A device-specific wrapper of torch.inference_mode.
This wrapper is recommended because some hardware backends such as TPU
do not support torch.inference_mode. In such a case, they will fall
back to torch.no_grad by overriding this method.
is_arch_support_pdl()
classmethod
¶
Does the current platform support PDL (Programmatic Dependent Launch)?
is_confidential_compute()
classmethod
¶
Whether the device runs in a confidential-computing mode that makes host<->device copies host-synchronous and host mappings incoherent.
is_cuda_alike()
¶
Stateless version of torch.cuda.is_available.
is_current_stream_capturing()
classmethod
¶
Return whether the current accelerator stream is capturing a graph.
is_device_capability(capability, device_id=0)
classmethod
¶
Test whether this platform has exactly the specified device capability.
The capability argument can either be:
- A tuple
(major, minor). - An integer
<major><minor>. (SeeDeviceCapability.to_int)
is_device_capability_family(capability, device_id=0)
classmethod
¶
Returns True if the device capability is any
is_fp8_fnuz()
classmethod
¶
Returns whether the preferred FP8 type is FNUZ on the current platform.
There are two representations of FP8, OCP FP8 and FNUZ FP8. The OCP specification can be found at https://tinyurl.com/b7jvwpft. The FNUZ specification can be found at https://tinyurl.com/5n6hwwu5.
AMD's MI300 and MI325 have native hardware support for FNUZ. All other hardware has converged on the OCP FP8 standard.
is_integrated_gpu(device_id=0)
classmethod
¶
Returns whether the GPU is an integrated (UMA) device that shares system memory with the CPU. device_id None means the current device.
On UMA systems (e.g. NVIDIA DGX Spark, Jetson Orin), cudaMemGetInfo may underreport free memory because it does not account for reclaimable OS memory (page cache, buffers).
is_pin_memory_available()
classmethod
¶
Checks whether pin memory is available on the current platform.
log_warnings()
classmethod
¶
Log platform-specific diagnostics after logging is configured.
logical_device_id_to_visible_device_id(device_id)
classmethod
¶
Map a vLLM-local logical device ID to the current process's visible accelerator ordinal.
vLLM internals use logical local IDs. Physical IDs are used only
at platform/topology boundaries. This helper performs the final
translation needed by APIs such as torch.device("cuda:N").
make_synced_weight_loader(original_weight_loader)
classmethod
¶
Wrap the original weight loader to make it synced.
manual_seed_all(seed)
classmethod
¶
Set RNG seed across all devices for the current platform.
num_compute_units(device_id=0)
classmethod
¶
Get the number of compute units for the current platform. (NVIDIA SM / AMD CU / Intel EU)
opaque_attention_op()
classmethod
¶
Returns True if we register attention as one giant opaque custom op on the current platform
pre_register_and_update(parser=None)
classmethod
¶
Do some pre-registration or update action for the current platform.
This function is called before global VllmConfig is initialized or cli arguments are parsed. It's used for out-of-tree platforms to register or update the configuration.
For example, the out-of-tree quantization config can be imported and registered here dynamically.
prepare_ubatch_streams(device, streams, num_threads)
classmethod
¶
Set up per-stream library state before dual batch overlap runs its
microbatches on streams from num_threads new threads.
register_triton_kernel_overrides()
classmethod
¶
Override core Triton kernels with platform implementations.
Platforms whose Triton kernels need replacement implementations
override this method and call
vllm.triton_utils.dispatcher.register_kernels
with their overrides. Platforms that only need other launch values
(e.g. block sizes) call
vllm.triton_utils.dispatcher.override_kernel_heuristics.
It runs during model runner init, before any kernel launch. The
default implementation does nothing.
reset_global_graph_pool()
classmethod
¶
Make the next get_global_graph_pool call create a new pool.
Call this once all graphs in the pool are destroyed. Their outputs can keep the old pool allocated, and capturing into it would fail.
set_additional_forward_context(*args, **kwargs)
classmethod
¶
Set some additional forward context for the current platform if needs.
set_device(device)
classmethod
¶
Set the device for the current platform.
stateless_init_device_torch_dist_pg(backend, prefix_store, group_rank, group_size, timeout)
classmethod
¶
Init platform-specific torch distributed process group.
support_deep_gemm()
classmethod
¶
Returns if DeepGEMM is supported by the current platform.
support_hybrid_kv_cache()
classmethod
¶
Returns if the hybrid kv cache is supported by the current platform.
support_static_graph_mode()
classmethod
¶
Returns if the graph mode is supported by the current platform.
supports_eplb()
classmethod
¶
Whether this platform can run expert parallel load balancing.
supports_fp8()
classmethod
¶
Returns whether the current platform supports FP8 types.
supports_mx()
classmethod
¶
Returns whether the current platform supports MX types.
update_block_size_for_backend(vllm_config)
classmethod
¶
Ensure block_size is compatible with the attention backend. For hybrid models, also aligns block_size with mamba page sizes.
use_all_gather()
classmethod
¶
Whether to use allgather in LogitsProcessor to gather the logits.
use_custom_allreduce()
classmethod
¶
Returns if custom allreduce is supported on the current platform.
use_custom_op_collectives()
classmethod
¶
Whether this platform should use torch.ops.vllm.* custom ops for collectives.
Returns False by default - platforms must explicitly opt-in.
use_sync_weight_loader()
classmethod
¶
Returns if the current platform needs to sync weight loader.
uses_host_device_handling()
¶
Whether vLLM should leave DeviceConfig.device unset.
uses_standalone_cpu_model_runner()
classmethod
¶
Returns if Model Runner V2 runs as the standalone (no-Triton) CPU runner instead of the Triton-based one.
validate_environ(hard_fail)
classmethod
¶
Validate environment variables for the current platform.
validate_request(processed_inputs, params)
classmethod
¶
Raises if this request is unsupported on this platform.
verify_model_arch(model_arch)
classmethod
¶
Verify whether the current platform supports the specified model architecture.
- This will raise an Error or Warning based on the model support on the current platform.
- By default all models are considered supported.
verify_quantization(quant)
classmethod
¶
Verify whether the quantization is supported by the current platform.
visible_device_id_to_physical_device_id(device_id)
classmethod
¶
Map a visible accelerator ordinal (e.g. torch.device.index)
to a physical device ID.
This is the inverse of the env-var translation performed by logical_device_id_to_visible_device_id() and is independent of any logical-to-physical mapping set via set_assigned_physical_gpu_ids().
_is_amd_zen_cpu()
¶
Detect AMD CPU with AVX-512 via /proc/cpuinfo.
vllm_version_matches_substr(substr)
¶
Check to see if the vLLM version matches a substring.