vllm.entrypoints.scale_out.token_in_token_out.logprobs_render
¶
Object-free rendering of /inference/v1/generate sample logprobs.
:func:render_tokens_logprobs reads the engine rows of a
:class:~vllm.logprobs.FlatLogprobs and produces exactly the JSON that
ServingTokens._create_tokens_logprobs + model_dump + Starlette's
JSONResponse.render produce for the same rows, without a Python object
per entry. :func:render_top_k_logprobs renders the packed form of the rows
(packed_top_k_logprobs). :func:render_json_with_fragments splices such
pre-rendered values into the JSON of the remaining (small) response.
Functions:
-
format_float_reprs–[repr(float(v)).encode() for v in values]for a non-empty 1-D -
render_json_with_fragments–Render
contentlikeJSONResponse, with the value of -
render_tokens_logprobs–Render the
GenerateLogProbsJSON of one choice, as parts whose -
render_top_k_logprobs–Render the
packed_top_k_logprobsGenerateLogProbsJSON of one
_LeadTable
¶
token id -> prefix + str(id) + suffix as a numpy object array, so a
block of ids maps to its JSON pieces with one fancy index.
Covers ids below max_ids, kept for the process lifetime (a few MB per
table at a 150k vocabulary); blocks with other ids are formatted per call.
Methods:
-
lookup–The pieces of a non-empty array of ids, in its shape.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
lookup(ids)
¶
The pieces of a non-empty array of ids, in its shape.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
_dumps(content)
¶
Same serialization as starlette.responses.JSONResponse.render.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
_msgspec_floats_match_repr()
¶
Probe the msgspec fast path against repr once at import: float32
boundaries of the fast range, powers of ten, extremes and a fixed
pseudo-random sample.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
_rank_pieces(ranks)
¶
,"rank":<rank> with a rank of 0 sent as null, like rank or None.
format_float_reprs(values)
¶
[repr(float(v)).encode() for v in values] for a non-empty 1-D
float64 array of finite values that float32 represents exactly.
repr is what json.dumps emits. msgspec's shortest round-trip
encoder is used instead where it gives the same digits: for
1e-4 <= |v| < 1e16 and zeros; other magnitudes, where the exponent
notation differs (1e-05 vs 0.00001), use repr. The fast path
is disabled if an import-time probe finds msgspec formatting that differs
from repr.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
render_json_with_fragments(content, key, fragments)
¶
Render content like JSONResponse, with the value of
content["choices"][i][key] replaced by the pre-rendered JSON
fragments[i] (parts to concatenate), as parts whose concatenation is
the body. content is modified in place.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
render_tokens_logprobs(sampled_token_ids, container)
¶
Render the GenerateLogProbs JSON of one choice, as parts whose
concatenation is the JSON.
Per position, the per-entry path builds a dict from the row (keys keep
their first occurrence's order, values come from the last occurrence;
slot 0 has the engine rank, slot j rank j), looks the sampled
entry up by the sampled id, and lists every dict item as top_logprobs
(one fewer when the sampled id repeats in the top-k); logprobs are clamped
(NaN and values below -9999 are -9999.0) and a rank of 0 is null.
Returns None when the rows do not map to that shape directly (sampled id not in slot 0, repeated top-k ids, a value JSON cannot represent): the caller then uses the per-entry path.
Source code in vllm/entrypoints/scale_out/token_in_token_out/logprobs_render.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
render_top_k_logprobs(container, num_tokens, num_output_top_logprobs)
¶
Render the packed_top_k_logprobs GenerateLogProbs JSON of one
choice, as parts whose concatenation is the JSON that model_dump +
JSONResponse give for content=None and top_k.
top_k holds slots 1..k of the rows as raw little-endian bytes,
base64-encoded in one pass. Raises GenerationError if the rows cannot be
packed (irregular widths or ranks, ids beyond int32, or a row count that
differs from the tokens).