Skip to content

vllm.v1.worker.gpu.sample.batch_shard

Classes:

  • BatchShardMetadata –

    Collective layout for one sampling step.

  • BatchSharder –

    Shards the sampler inputs across TP ranks along the batch dimension.

Functions:

  • all_to_all_vocab_shards –

    Exchange vocab-shard logits so each rank gets full-vocab logits for its

  • batch_sharded_sampling_enabled –

    Whether the target's sampling and verification are batch-sharded.

  • get_tp_pynccl_comm –

    The TP group's PyNCCL communicator, or None if it is unavailable.

  • shard_owner –

    TP rank that samples the request at a batch position.

  • shard_owners –

    [num_reqs] The shard_owner of each batch position.

  • shard_row –

    Row of the request at a batch position in its shard_owner's sharded

  • shard_rows –

    [num_reqs] The shard_row of each batch position.

BatchShardMetadata dataclass

Collective layout for one sampling step.

Requests (and their logits) are owner-sorted: all requests owned by rank 0 first, then rank 1, etc. Within an owner, batch order is preserved (stable sort). Every field is a pure function of the replicated idx_mapping and cu_num_logits, so all ranks build identical plans without communication — which relies on request slots (idx_mapping) being assigned identically on every rank (see finish_requests in the model runner).

BatchSharder

Shards the sampler inputs across TP ranks along the batch dimension.

Methods:

shard_sampler_inputs(input_batch, grammar_output)

Owner-sort the batch and build this rank's local sampler inputs.

Returns the local sub-batch, the owner-sorted logits_indices (gather the sampling hidden states with these so compute_logits_local emits logits in all-to-all send order), the local grammar output (None if this rank owns none of the structured-output requests), and the shard metadata (used for all-gathering the sampler outputs).

all_to_all_vocab_shards(logits_shard, send_splits, num_local_rows)

Exchange vocab-shard logits so each rank gets full-vocab logits for its own rows. send_splits[r] rows of logits_shard go to rank r.

Returns:

  • Tensor –

    [num_local_rows, tp_size * shard_width] logits of this rank's rows.

batch_sharded_sampling_enabled(vllm_config, target_model)

Whether the target's sampling and verification are batch-sharded.

get_tp_pynccl_comm()

The TP group's PyNCCL communicator, or None if it is unavailable.

shard_owner(req_idx, NUM_SHARDS)

TP rank that samples the request at a batch position.

Mirrored on the host by shard_owners.

shard_owners(num_reqs, num_shards)

[num_reqs] The shard_owner of each batch position.

shard_row(req_idx, NUM_SHARDS)

Row of the request at a batch position in its shard_owner's sharded draft logits cache.

Mirrored on the host by shard_rows.

shard_rows(num_reqs, num_shards)

[num_reqs] The shard_row of each batch position.