vllm.utils.jsontree ¶
Helper functions to work with nested JSON structures.
JSONTree module-attribute
¶
JSONTree = Union[
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 = Union[
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], _U],
value: Union[_T, dict[str, _T]],
) -> Union[_U, dict[str, _U]]
json_map_leaves(
func: Callable[[_T], _U],
value: Union[BatchedTensorInputs, _JSONTree[_T]],
) -> Union[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[..., Union[_T, _U]],
value: _JSONTree[_T],
initial: _U = cast(_U, ...),
) -> Union[_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.