Skip to content

Commit 9d9cda0

Browse files
yushangdifacebook-github-bot
authored andcommitted
More robust DCE pass (#4565)
Summary: X-link: pytorch/pytorch#132764 Pull Request resolved: #4565 - make default DCE pass check schema, - mark Proxy dump as NotImplemented for better error msg - Remove Proxy from tensors when dumping models, as Proxy cannot be dumped. More details in https://docs.google.com/document/d/1G5vmTXjzxoyVGRI2kpA1gQukK_Glyg2NrE0Oh6Nlg9A/edit?usp=sharing. Reviewed By: angelayi Differential Revision: D60319175 fbshipit-source-id: d9815ca07e1caaa49bb6a82836765030a67a4270
1 parent 20cb298 commit 9d9cda0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

exir/serde/serialize.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,19 @@ def serialize(
342342
)
343343
else:
344344
example_inputs = b""
345+
346+
# TODO (shangdi): change to use `torch._export.utils.remove_proxy_from_state_dict`
347+
# after pytorch repo is updated.
348+
# Proxy cannot be dumped, so we remove them.
349+
new_state_dict = {}
350+
for k, v in exported_program.state_dict.items():
351+
if "proxy" in v.__dict__:
352+
new_state_dict[k] = v.clone().detach()
353+
else:
354+
new_state_dict[k] = v
345355
return export_serialize._SerializedProgram(
346356
serialized_ep,
347-
export_serialize.serialize_torch_artifact(exported_program.state_dict),
357+
export_serialize.serialize_torch_artifact(new_state_dict),
348358
export_serialize.serialize_torch_artifact(constants),
349359
example_inputs,
350360
)

0 commit comments

Comments
 (0)