Skip to content

Commit fd8facc

Browse files
committed
Update torch api to include value names when raising error on uninitialized values
Signed-off-by: Justin Chu <[email protected]>
1 parent 81f8444 commit fd8facc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

onnxscript/_framework_apis/torch_2_5.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ def save_model_with_external_data(model: ir.Model, model_path: str | os.PathLike
6767
"""Save the model with external data. The model is unchanged after saving."""
6868

6969
# TODO(#1835): Decide if we want to externalize large attributes as well
70-
for value in model.graph.initializers.values():
71-
if value.const_value is None:
72-
raise ValueError(
73-
"The model contains uninitialized initializer values. "
74-
"Please make sure all initializer values are initialized."
75-
)
70+
uninitialized_values = [
71+
value.name for value in model.graph.initializers.values() if value.const_value is None
72+
]
73+
if uninitialized_values:
74+
raise ValueError(
75+
f"The model contains uninitialized initializer values ({uninitialized_values}). "
76+
"Please make sure all initializer values are initialized."
77+
)
7678
destination_path = pathlib.Path(model_path)
7779
data_path = f"{destination_path.name}.data"
7880

0 commit comments

Comments
 (0)