Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use input size limits for constant folding #1903

Merged
merged 4 commits into from
Oct 12, 2024
Merged

Conversation

gramalingam
Copy link
Collaborator

Add input size limits for constant folding. Helps avoid excessive time in optimizer in some edge cases. (The edge cases, where we have non-trivial ops applied to large tensors, are not relevant for the exporter itself. They may be of potential interest for optimization in other settings, but that can be done by user taking explicit steps.)

Still to be done: how do we specify these values from the benchmarking code? For now, the default values will be quite useful, but experimenting with these values from the benchmarking code will need a way to control these option values.

Copy link

codecov bot commented Oct 11, 2024

❌ 13 Tests Failed:

Tests completed Failed Passed Skipped
11957 13 11944 2299
View the top 3 failed tests by shortest run time
tests.ir.serde_roundtrip_test.SerdeTest test_serialization_deserialization_produces_same_model_0430_test_dequantizelinear_float4e2m1_model_onnx
Stack Traces | 0.001s run time
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:711: in deserialize_type_proto_for_type
    return _core.TensorType(_enums.DataType(elem_type), denotation=denotation)
....../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py:714: in __call__
    return cls.__new__(cls, value)
....../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py:1137: in __new__
    raise ve_exc
E   ValueError: 23 is not a valid DataType

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:657: in deserialize_value_info_proto
    value.type = deserialize_type_proto_for_type(proto.type)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_type_proto_for_type with: tensor_type {
E     elem_type: 23
E     shape {
E       dim {
E         dim_value: 5
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:568: in _deserialize_graph
    deserialize_value_info_proto(info, value)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_value_info_proto with: name: "x"
E   type {
E     tensor_type {
E       elem_type: 23
E       shape {
E         dim {
E           dim_value: 5
E         }
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
..../test_onnx_weekly/lib/python3.11.../site-packages/parameterized/parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
tests/ir/serde_roundtrip_test.py:38: in test_serialization_deserialization_produces_same_model
    ir_model = ir.serde.deserialize_model(model)
onnxscript/ir/serde.py:459: in deserialize_model
    graph = _deserialize_graph(proto.graph, [])
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling _deserialize_graph with: main_graph
tests.ir.serde_roundtrip_test.SerdeTest test_serialization_deserialization_produces_same_model_0571_test_cast_FLOAT4E2M1_to_FLOAT_model_onnx
Stack Traces | 0.001s run time
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:711: in deserialize_type_proto_for_type
    return _core.TensorType(_enums.DataType(elem_type), denotation=denotation)
.../hostedtoolcache/Python/3.11.10....../x64/lib/python3.11/enum.py:714: in __call__
    return cls.__new__(cls, value)
.../hostedtoolcache/Python/3.11.10....../x64/lib/python3.11/enum.py:1137: in __new__
    raise ve_exc
E   ValueError: 23 is not a valid DataType

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:657: in deserialize_value_info_proto
    value.type = deserialize_type_proto_for_type(proto.type)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_type_proto_for_type with: tensor_type {
E     elem_type: 23
E     shape {
E       dim {
E         dim_value: 3
E       }
E       dim {
E         dim_value: 5
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:568: in _deserialize_graph
    deserialize_value_info_proto(info, value)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_value_info_proto with: name: "input"
E   type {
E     tensor_type {
E       elem_type: 23
E       shape {
E         dim {
E           dim_value: 3
E         }
E         dim {
E           dim_value: 5
E         }
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
..../test_onnx_weekly/lib/python3.11.../site-packages/parameterized/parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
tests/ir/serde_roundtrip_test.py:38: in test_serialization_deserialization_produces_same_model
    ir_model = ir.serde.deserialize_model(model)
onnxscript/ir/serde.py:459: in deserialize_model
    graph = _deserialize_graph(proto.graph, [])
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling _deserialize_graph with: main_graph
tests.ir.serde_roundtrip_test.SerdeTest test_serialization_deserialization_produces_same_model_0807_test_cast_FLOAT4E2M1_to_FLOAT_model_onnx
Stack Traces | 0.001s run time
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:711: in deserialize_type_proto_for_type
    return _core.TensorType(_enums.DataType(elem_type), denotation=denotation)
....../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py:714: in __call__
    return cls.__new__(cls, value)
....../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py:1137: in __new__
    raise ve_exc
E   ValueError: 23 is not a valid DataType

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:657: in deserialize_value_info_proto
    value.type = deserialize_type_proto_for_type(proto.type)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_type_proto_for_type with: tensor_type {
E     elem_type: 23
E     shape {
E       dim {
E         dim_value: 3
E       }
E       dim {
E         dim_value: 5
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
onnxscript/ir/serde.py:97: in wrapper
    return func(*args, **kwargs)
onnxscript/ir/serde.py:568: in _deserialize_graph
    deserialize_value_info_proto(info, value)
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling deserialize_value_info_proto with: name: "input"
E   type {
E     tensor_type {
E       elem_type: 23
E       shape {
E         dim {
E           dim_value: 3
E         }
E         dim {
E           dim_value: 5
E         }
E       }
E     }
E   }

The above exception was the direct cause of the following exception:
..../test_onnx_weekly/lib/python3.11.../site-packages/parameterized/parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
tests/ir/serde_roundtrip_test.py:38: in test_serialization_deserialization_produces_same_model
    ir_model = ir.serde.deserialize_model(model)
onnxscript/ir/serde.py:459: in deserialize_model
    graph = _deserialize_graph(proto.graph, [])
onnxscript/ir/serde.py:99: in wrapper
    raise SerdeError(
E   onnxscript.ir.serde.SerdeError: Error calling _deserialize_graph with: main_graph

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

onnxscript/optimizer/_constant_folding.py Outdated Show resolved Hide resolved
onnxscript/optimizer/__init__.py Show resolved Hide resolved
onnxscript/optimizer/_constant_folding.py Outdated Show resolved Hide resolved
@gramalingam gramalingam enabled auto-merge (squash) October 11, 2024 20:17
@gramalingam gramalingam merged commit 8fef233 into main Oct 12, 2024
24 of 39 checks passed
@gramalingam gramalingam deleted the rama/const-prop-limits branch October 12, 2024 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants