Skip to content

vllm.utils.jsontree

Helper functions to work with nested JSON structures.

Functions:

Attributes:

  • JSONTree (TypeAlias) –

    A nested JSON structure where the leaves need not be JSON-serializable.

JSONTree = dict[str, 'JSONTree[_T]'] | list['JSONTree[_T]'] | tuple['JSONTree[_T]', ...] | _T module-attribute

A nested JSON structure where the leaves need not be JSON-serializable.

_JSONTree = dict[str, 'JSONTree[_T]'] | list['JSONTree[_T]'] | tuple['JSONTree[_T]', ...] | dict[str, _T] | list[_T] | tuple[_T, ...] | _T module-attribute

Same as JSONTree but with additional Union members to satisfy overloads.

json_count_leaves(value)

Count the number of leaves in a nested JSON structure.

json_iter_leaves(value)

Iterate through each leaf in a nested JSON structure.

json_map_leaves(func, value)

json_map_leaves(
    func: Callable[[torch.Tensor], torch.Tensor],
    value: BatchedTensorInputs,
) -> BatchedTensorInputs
json_map_leaves(
    func: Callable[[_T], _U], value: _T | dict[str, _T]
) -> _U | dict[str, _U]
json_map_leaves(
    func: Callable[[_T], _U], value: _T | list[_T]
) -> _U | list[_U]
json_map_leaves(
    func: Callable[[_T], _U], value: _T | tuple[_T, ...]
) -> _U | tuple[_U, ...]
json_map_leaves(
    func: Callable[[_T], _U], value: JSONTree[_T]
) -> JSONTree[_U]

Apply a function to each leaf in a nested JSON structure.

json_reduce_leaves(func, value, initial=...)

json_reduce_leaves(
    func: Callable[[_T, _T], _T], value: _T | dict[str, _T]
) -> _T
json_reduce_leaves(
    func: Callable[[_T, _T], _T], value: _T | list[_T]
) -> _T
json_reduce_leaves(
    func: Callable[[_T, _T], _T], value: _T | tuple[_T, ...]
) -> _T
json_reduce_leaves(
    func: Callable[[_T, _T], _T], value: JSONTree[_T]
) -> _T
json_reduce_leaves(
    func: Callable[[_U, _T], _U],
    value: JSONTree[_T],
    initial: _U,
) -> _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.