Skip to content

Commit aa0590b

Browse files
authored
Avoid override new_value info with None from old_value (#227)
Users could have a well-defined new_value and use it to replace an old value which has less information. Signed-off-by: Ti-Tai Wang <titaiwang@microsoft.com>
1 parent c7b8908 commit aa0590b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/onnx_ir/_convenience/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,15 @@ def replace_nodes_and_values(
397397
"""
398398
for old_value, new_value in zip(old_values, new_values):
399399
# Propagate relevant info from old value to new value
400-
# TODO(Rama): Perhaps this should be a separate utility function. Also, consider
401-
# merging old and new type/shape info.
402-
new_value.type = old_value.type
403-
new_value.shape = old_value.shape
404-
new_value.const_value = old_value.const_value
405-
new_value.name = old_value.name
400+
# TODO(Rama): Perhaps this should be a separate utility function.
401+
new_value.type = old_value.type if old_value.type is not None else new_value.type
402+
new_value.shape = old_value.shape if old_value.shape is not None else new_value.shape
403+
new_value.const_value = (
404+
old_value.const_value
405+
if old_value.const_value is not None
406+
else new_value.const_value
407+
)
408+
new_value.name = old_value.name if old_value.name is not None else new_value.name
406409

407410
# Reconnect the users of the deleted values to use the new values
408411
replace_all_uses_with(old_values, new_values)

0 commit comments

Comments
 (0)