-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Hello,
When cloning a model whose nodes contain a MetadataStore, the underlying metadata objects are shallow copied. Therefore, the original and cloned models share references to the same metadata entries (see code below).
import onnx_ir as ir
def check_meta():
ir_model = ir.from_onnx_text("""
< ir_version: 10, opset_import: ["" : 21] >
test_model (float[N, 32] X) => (float [N, ?] Y)
{
Y = Relu(X)
}
""")
# Add metadata to the node
ir_model.graph[0].meta["test_meta"] = "test_value"
# Clone the model
cloned_ir_model = ir_model.clone()
# Check that the metadata is cloned
assert cloned_ir_model.graph[0].meta is not ir_model.graph[0].meta
# Check that the metadata value is the same
print(
cloned_ir_model.graph[0].meta["test_meta"] is ir_model.graph[0].meta["test_meta"]
) # -> True
check_meta()The fix is that MetadataStore content should be deep copied. I can open a PR if necessary.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels