[Multimodal] Expose mm hash algothrim selection to cli args (#49686)

Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
Isotr0py
2026-07-31 05:25:19 +00:00
committed by GitHub
parent 0f17394564
commit 1180b604f8
17 changed files with 234 additions and 61 deletions
+24 -7
View File
@@ -229,40 +229,57 @@ Uses a list instead of a tensor if the dimensions of each element do not match.
"""
def nested_tensors_equal(a: NestedTensors, b: NestedTensors) -> bool:
def nested_tensors_equal(
a: NestedTensors,
b: NestedTensors,
check_dtype: bool = True,
) -> bool:
"""
Equality check between
[`NestedTensors`][vllm.multimodal.inputs.NestedTensors] objects.
If `check_dtype` is `True`, the tensors must have the same dtype.
"""
check_dtype_func = (
lambda a, b, check_dtype: a.dtype == b.dtype if check_dtype else True
)
if isinstance(a, torch.Tensor):
return isinstance(b, torch.Tensor) and torch.equal(a, b)
return (
isinstance(b, torch.Tensor)
and torch.equal(a, b)
and check_dtype_func(a, b, check_dtype)
)
elif isinstance(b, torch.Tensor):
return isinstance(a, torch.Tensor) and torch.equal(b, a)
return (
isinstance(a, torch.Tensor)
and torch.equal(b, a)
and check_dtype_func(b, a, check_dtype)
)
if isinstance(a, list):
return (
isinstance(b, list)
and len(a) == len(b)
and all(nested_tensors_equal(a_, b_) for a_, b_ in zip(a, b))
and all(nested_tensors_equal(a_, b_, check_dtype) for a_, b_ in zip(a, b))
)
if isinstance(b, list):
return (
isinstance(a, list)
and len(b) == len(a)
and all(nested_tensors_equal(b_, a_) for b_, a_ in zip(b, a))
and all(nested_tensors_equal(b_, a_, check_dtype) for b_, a_ in zip(b, a))
)
if isinstance(a, tuple):
return (
isinstance(b, tuple)
and len(a) == len(b)
and all(nested_tensors_equal(a_, b_) for a_, b_ in zip(a, b))
and all(nested_tensors_equal(a_, b_, check_dtype) for a_, b_ in zip(a, b))
)
if isinstance(b, tuple):
return (
isinstance(a, tuple)
and len(b) == len(a)
and all(nested_tensors_equal(b_, a_) for b_, a_ in zip(b, a))
and all(nested_tensors_equal(b_, a_, check_dtype) for b_, a_ in zip(b, a))
)
# Both a and b are scalars