[Multimodal] Expose mm hash algothrim selection to cli args (#49686)
Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user