Skip to content

vllm.v1.worker.gpu_worker

A GPU worker class.

Classes:

Functions:

AsyncIntermediateTensors

Bases: IntermediateTensors

IntermediateTensors with lazy comm synchronization

Worker

Bases: WorkerBase

Methods:

_discardable_parameters(model)

Storage of the parameters the weight update rewrites.

_get_cudagraph_capture_context()

Let the configured profiler observe CUDA graph capture.

_init_workspace_and_model_runner()

Set up the workspace manager, build the model runner, report usage.

_make_elastic_ep_executor()

Construct elastic EP lazily so platform workers can opt out.

_make_model_runner()

Construct the platform's model runner; subclasses override this.

_scoped_allocator_max_split(max_split_size_mb)

Limit CUDA/ROCm allocator splitting, restoring settings on exit.

determine_available_memory()

Profiles the peak memory usage of the model to determine how much memory can be used for KV cache without OOMs.

The engine will first conduct a profiling of the existing memory usage. Then, it calculates the free memory that can be used for KV cache in bytes.

Tip

You may limit the usage of GPU memory by adjusting the gpu_memory_utilization parameter.

extend_kv_cache(num_blocks)

Commit the final size of an extensible KV cache.

finish_weight_update()

Finish the current weight update session.

get_encoder_timing_stats()

Get encoder timing stats from model runner.

get_kv_connector_handshake_metadata()

Get KV connector metadata from this worker if available.

Returned dict is keyed by (pp_rank, tp_rank).

init_weight_transfer_engine(init_info)

Initialize weight transfer mechanism. For NCCL backend, this creates a process group with the trainer.

Parameters:

  • init_info

    (dict) –

    Dictionary containing backend-specific initialization info

initialize_from_config(kv_cache_config)

Allocate GPU KV cache with the specified kv_cache_config.

set_kv_cache_reclaimable(reclaimable)

Whether the KV cache holds nothing to keep, so that a weight update may borrow its memory; see EngineCore._set_kv_cache_reclaimable.

shutdown_weight_transfer_engine()

Release a trainer connection without shutting down inference.

start_draft_weight_update()

Like start_weight_update, but retargets the engine at the speculative draft model for this session.

start_weight_update()

Start a new weight update session.

Delegates engine-specific preparation (e.g. layerwise reload setup) to the configured weight transfer engine. The worker only tracks that a session is active.

update_config(overrides)

Apply config overrides to the worker, its model runner and the shared VllmConfig.

update_max_model_len(max_model_len)

Update max_model_len after auto-fit to GPU memory. This is called when max_model_len=-1 is used and the engine automatically determines the maximum context length that fits in GPU memory. Workers need to update their cached max_model_len to match the engine's decision.

update_weights(update_info)

Receive one weight update chunk from the trainer.

start_weight_update must be called before update_weights and finish_weight_update must be called after all chunks have been sent. Every chunk loads into whichever model the session's start_weight_update / start_draft_weight_update call selected.

Parameters:

  • update_info

    (dict | list[dict]) –

    Backend-specific update info, or a list indexed by global worker rank across data parallel replicas.

_bound_model_loader(model_runner)

The loader that loaded the runner's model, if it recorded itself.

_min_across_ranks(value)

Minimum of value over the world group: every rank of this engine and of those that run in lockstep with it (MoE data parallel, external launcher).

init_worker_distributed_environment(vllm_config, rank, distributed_init_method=None, local_rank=-1, backend='nccl')

Initialize the distributed environment.

maybe_rocm_profiling_fallback(profile_result)

Memory in bytes to size the KV cache from when profiling measured a release on ROCm, or None to keep what profiling measured.

The measurement is the drop in free device memory across startup, so it comes out negative when anything else on the device released memory meanwhile. Torch reserved is process local, so it stands in as a lower bound instead of refusing to start. Kept to ROCm, where the AMD CI groups hit this, following #45490.