From fd8facc9a3cee3e703f78d38cbb1c57c9799486f Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 2 Oct 2025 22:27:01 -0700 Subject: [PATCH] Update torch api to include value names when raising error on uninitialized values Signed-off-by: Justin Chu --- onnxscript/_framework_apis/torch_2_5.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/onnxscript/_framework_apis/torch_2_5.py b/onnxscript/_framework_apis/torch_2_5.py index 2f8601c7c6..162faf4b75 100644 --- a/onnxscript/_framework_apis/torch_2_5.py +++ b/onnxscript/_framework_apis/torch_2_5.py @@ -67,12 +67,14 @@ def save_model_with_external_data(model: ir.Model, model_path: str | os.PathLike """Save the model with external data. The model is unchanged after saving.""" # TODO(#1835): Decide if we want to externalize large attributes as well - for value in model.graph.initializers.values(): - if value.const_value is None: - raise ValueError( - "The model contains uninitialized initializer values. " - "Please make sure all initializer values are initialized." - ) + uninitialized_values = [ + value.name for value in model.graph.initializers.values() if value.const_value is None + ] + if uninitialized_values: + raise ValueError( + f"The model contains uninitialized initializer values ({uninitialized_values}). " + "Please make sure all initializer values are initialized." + ) destination_path = pathlib.Path(model_path) data_path = f"{destination_path.name}.data"