-
Notifications
You must be signed in to change notification settings - Fork 170
[5532019][AutoCast] Update GraphSanitizer to convert Double to Float32 #364
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,9 @@ def convert( | |
# Remove redundant casts | ||
self._cleanup() | ||
|
||
if self.keep_io_types: | ||
self._restore_original_io_types() | ||
|
||
self._sanity_check() | ||
|
||
return self.model | ||
|
@@ -210,6 +213,22 @@ def _ensure_types_are_defined(self): | |
if vi.type.tensor_type.elem_type == onnx.TensorProto.UNDEFINED: | ||
vi.type.tensor_type.elem_type = self.low_precision_type.onnx_type | ||
|
||
def _restore_original_io_types(self): | ||
"""Restore original I/O types.""" | ||
|
||
def restore_tensor_type(tensor): | ||
if tensor.name in self.original_network_io: | ||
original_type = self.original_network_io[tensor.name] | ||
if tensor.type.tensor_type.elem_type != original_type: | ||
tensor.type.tensor_type.elem_type = original_type | ||
|
||
# Update value_info_map if tensor exists there | ||
if tensor.name in self.value_info_map: | ||
self.value_info_map[tensor.name].type.tensor_type.elem_type = original_type | ||
|
||
# Restore input and output types | ||
for tensor in self.model.graph.input + self.model.graph.output: | ||
restore_tensor_type(tensor) | ||
|
||
def _propagate_types_shapes_custom_ops(self, model): | ||
"""Propagate types and shapes after insertion of 'Cast' nodes or other graph modifications.""" | ||
logger.info("Propagating tensor shapes and types in model with custom ops.") | ||
|
Uh oh!
There was an error while loading. Please reload this page.