[go: nahoru, domu]

Skip to content
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

Remove RESTORE_ONNX_MODEL_INITIALIZERS and make it run default #3119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
# this flag in such circumstances.
EXPORT_TO_ONNX_DIRECT = False

# Flag to enable restoring pruned initializers in ONNX graph
# By default, the flag is disabled because it is rare case we should restore initializers in most cases
RESTORE_ONNX_MODEL_INITIALIZERS = False

# runs the second pass of markers for non-leaf torch module and updates names of onnx ops belonging to
# non-leaf pytorch module
update_all_onnx_nodes_name = True
Expand Down Expand Up @@ -1125,8 +1121,7 @@ def load_simply_onnx_model(cls, filepath) -> onnx.ModelProto:
:return: Onnx model with optional simply pass
"""
onnx_model = onnx.load(filepath)
if RESTORE_ONNX_MODEL_INITIALIZERS:
onnx_model = restore_onnx_graph_initializers(onnx_model, inplace=True)
onnx_model = restore_onnx_graph_initializers(onnx_model, inplace=True)

if simplify_onnx_model:
onnx_model_simplified, check = onnxsim.simplify(onnx_model)
Expand Down
3 changes: 1 addition & 2 deletions TrainingExtensions/torch/src/python/aimet_torch/quantsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,7 @@ def export_onnx_model_and_encodings(path: str, filename_prefix: str, original_mo
else:
kwargs = onnx_export_args
torch.onnx.export(original_model, dummy_input, onnx_path, **kwargs)
if onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS:
save_initializer_restored_onnx_graph(onnx_path, onnx_path)
save_initializer_restored_onnx_graph(onnx_path, onnx_path)
else:
# Create onnx model and obtain node to i/o tensor name map
OnnxSaver.create_onnx_model_with_pytorch_layer_names(onnx_path, original_model, dummy_input, is_conditional,
Expand Down
2 changes: 0 additions & 2 deletions TrainingExtensions/torch/test/python/test_onnx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,6 @@ def test_set_node_name_for_multiple_p_relu_model(self, num_parameters):
with tempfile.TemporaryDirectory() as tmp_dir:
onnx_path = f"{tmp_dir}/multiple_p_relu_model.onnx"

onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = True
onnx_utils.OnnxSaver.set_node_names(onnx_path, model, dummy_input)
onnx_model = onnx.load(onnx_path)

Expand All @@ -913,7 +912,6 @@ def test_set_node_name_for_multiple_p_relu_model(self, num_parameters):
assert name in valid_param_set

self.check_onnx_node_name_uniqueness(onnx_model)
onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = False

def test_save_initializer_restored_onnx_graph(self):
model = MultiplePReluModel()
Expand Down
2 changes: 0 additions & 2 deletions TrainingExtensions/torch/test/python/test_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,6 @@ def test_export_to_onnx_for_multiple_p_relu_model(self, num_parameters, config_f
sim.compute_encodings(lambda m, _: m(dummy_input), None)
filename_prefix = "multiple_p_relu_model"

onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = True
sim.export(tmp_dir, filename_prefix, dummy_input)
with open(f"{tmp_dir}/{filename_prefix}.encodings") as encodings_file:
encodings = json.load(encodings_file)
Expand All @@ -2547,7 +2546,6 @@ def test_export_to_onnx_for_multiple_p_relu_model(self, num_parameters, config_f
assert len(param_encodings[param_name]) == num_parameters
else: # Per-tensor
assert len(param_encodings[param_name]) == 1
onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = False

def test_save_encodings_to_json(self):
model = ModelWithTwoInputsOneToAdd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,6 @@ def test_export_to_onnx_for_multiple_p_relu_model(self, num_parameters, config_f
sim.compute_encodings(lambda m, _: m(dummy_input), None)
filename_prefix = "multiple_p_relu_model"

onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = True
sim.export(tmp_dir, filename_prefix, dummy_input)
with open(f"{tmp_dir}/{filename_prefix}.encodings") as encodings_file:
encodings = json.load(encodings_file)
Expand All @@ -2348,7 +2347,6 @@ def test_export_to_onnx_for_multiple_p_relu_model(self, num_parameters, config_f
assert len(param_encodings[param_name]) == num_parameters
else: # Per-tensor
assert len(param_encodings[param_name]) == 1
onnx_utils.RESTORE_ONNX_MODEL_INITIALIZERS = False

def test_save_encodings_to_json(self):
model = ModelWithTwoInputsOneToAdd()
Expand Down
Loading