vllm.utils.jsontree ¶
Helper functions to work with nested JSON structures.
JSONTree module-attribute
¶
JSONTree: TypeAlias = (
dict[str, "JSONTree[_T]"]
| list["JSONTree[_T]"]
| tuple["JSONTree[_T]", ...]
| _T
)
A nested JSON structure where the leaves need not be JSON-serializable.
_JSONTree module-attribute
¶
_JSONTree: TypeAlias = (
dict[str, "JSONTree[_T]"]
| list["JSONTree[_T]"]
| tuple["JSONTree[_T]", ...]
| dict[str, _T]
| list[_T]
| tuple[_T, ...]
| _T
)
Same as JSONTree
but with additional Union
members to satisfy overloads.
json_count_leaves ¶
json_iter_leaves ¶
Iterate through each leaf in a nested JSON structure.
Source code in vllm/utils/jsontree.py
json_map_leaves ¶
json_map_leaves(
func: Callable[[Tensor], Tensor],
value: BatchedTensorInputs,
) -> BatchedTensorInputs
json_map_leaves(
func: Callable[[_T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_map_leaves" optional hover>_T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_map_leaves" optional hover>_T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_map_leaves" optional hover>_T], _T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_map_leaves" optional hover>_T], value: _T | dict[str, _T]
) -> _U | dict[str, _U]
json_map_leaves(
func: Callable[[_T], _U],
value: BatchedTensorInputs | _JSONTree[_T],
) -> BatchedTensorInputs | _JSONTree[_U]
Apply a function to each leaf in a nested JSON structure.
Source code in vllm/utils/jsontree.py
json_reduce_leaves ¶
json_reduce_leaves(
func: Callable[[_T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_reduce_leaves" optional hover>_T, _T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_reduce_leaves" optional hover>_T], _T" backlink-type="used-by" backlink-anchor="vllm.utils.jsontree.json_reduce_leaves" optional hover>_T], value: JSONTree[_T]
) -> _T
json_reduce_leaves(
func: Callable[..., _T | _U],
value: _JSONTree[_T],
initial: _U = cast(_U, ...),
) -> _T | _U
Apply a function of two arguments cumulatively to each leaf in a nested JSON structure, from left to right, so as to reduce the sequence to a single value.