mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[Bugfix][vLLM] Explicitly do not support instead of crashing for named tuples in infer schema (#165191)
Fixes https://github.com/vllm-project/vllm/issues/25270 by being explicit in erroring; previously we had a cryptic `__origin__ undefined` error, but now should give proper error message that we don't support NamedTuples in schema Test with ``` python test/test_custom_ops.py TestCustomOp.test_unsupported_param_types ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/165191 Approved by: https://github.com/zou3519
This commit is contained in:
committed by
PyTorch MergeBot
parent
6f713e25bb
commit
1fa11f42b1
@ -1069,6 +1069,16 @@ class TestCustomOp(CustomOpTestCaseBase):
|
||||
|
||||
del foo
|
||||
|
||||
# Define a named tuple for a Point with x and y coordinates
|
||||
Point = collections.namedtuple("Point", ["x", "y"])
|
||||
with self.assertRaisesRegex(ValueError, "unsupported type"):
|
||||
|
||||
@custom_ops.custom_op(f"{TestCustomOp.test_ns}::foo")
|
||||
def foo(x: Tensor, y: Point) -> Tensor:
|
||||
raise NotImplementedError
|
||||
|
||||
del foo
|
||||
|
||||
def test_supported_schemas(self):
|
||||
# All of these should already be tested by PyTorch codegen
|
||||
# (we share the same mechanism), but here's a sanity check.
|
||||
|
@ -132,7 +132,10 @@ def infer_schema(
|
||||
"as it is a ScriptObject. Please manually specify the schema "
|
||||
"using the `schema=` kwarg with the actual type of the ScriptObject."
|
||||
)
|
||||
elif annotation_type.__origin__ is tuple:
|
||||
elif (
|
||||
hasattr(annotation_type, "__origin__")
|
||||
and annotation_type.__origin__ is tuple
|
||||
):
|
||||
list_type = tuple_to_list(annotation_type)
|
||||
example_type_str = "\n\n"
|
||||
# Only suggest the list type if this type is supported.
|
||||
|
Reference in New Issue
Block a user