vllm.v1.sample.tpu.sampler ¶
Sampler layer implementing TPU supported operations.
Sampler ¶
Bases: Module
Source code in vllm/v1/sample/tpu/sampler.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
__init__ ¶
apply_min_p ¶
Filters logits using adaptive probability thresholding.
Source code in vllm/v1/sample/tpu/sampler.py
apply_temperature ¶
compute_logprobs ¶
forward ¶
forward(
logits: Tensor,
sampling_metadata: TPUSupportedSamplingMetadata,
) -> SamplerOutput
Source code in vllm/v1/sample/tpu/sampler.py
gather_logprobs ¶
gather_logprobs(
logprobs: Tensor, num_logprobs: int, token_ids: Tensor
) -> LogprobsTensors
Gather logprobs for topk and sampled/prompt token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logprobs | Tensor | (num tokens) x (vocab) tensor | required |
num_logprobs | int | minimum number of logprobs to retain per token | required |
token_ids | Tensor | prompt tokens (if prompt logprobs) or sampled tokens (if sampled logprobs); 1D token ID tensor with (num tokens) elements | required |
Returns:
Type | Description |
---|---|
LogprobsTensors | Top-k int indices tensor, (num tokens) x (num_logprobs + 1) |
LogprobsTensors | Top-k float logprobs tensor, (num tokens) x (num_logprobs + 1) |
LogprobsTensors | Sampled token rank tensor, (num tokens) |
Source code in vllm/v1/sample/tpu/sampler.py
greedy_sample ¶
random_sample ¶
Source code in vllm/v1/sample/tpu/sampler.py
sample ¶
sample(
logits: Tensor,
sampling_metadata: TPUSupportedSamplingMetadata,
) -> Tensor
Source code in vllm/v1/sample/tpu/sampler.py
apply_top_k_top_p ¶
Apply top-k and top-p optimized for TPU.
This algorithm avoids using torch.scatter which is extremely slow on TPU. This is achieved by finding a "cut-off" element in the original logit, and after thresholding the logit using this cut-off, the remaining elements shall constitute the top-p set.
Note: in the case of tie (i.e. multipple cut-off elements present in the logit), all tie elements are included in the top-p set. In other words, this function does not break ties. Instead, these tie tokens have equal chance of being chosen during final sampling, so we can consider the tie being broken then.