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

[Export] Keep user-provided dynamic axes #1442

Merged
merged 3 commits into from
Mar 16, 2023
Merged
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
25 changes: 13 additions & 12 deletions src/sparseml/pytorch/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,20 @@ def export_onnx(
if "output_names" not in export_kwargs:
export_kwargs["output_names"] = _get_output_names(out)

# Set all batch sizes to be dynamic
if dynamic_axes is not None:
warnings.warn(
"`dynamic_axes` is deprecated and does not affect anything. "
"The 0th axis is always treated as dynamic.",
category=DeprecationWarning,
)

dynamic_axes = {
tensor_name: {0: "batch"}
for tensor_name in (
export_kwargs["input_names"] + export_kwargs["output_names"]
)
}
for tensor_name in export_kwargs["input_names"] + export_kwargs["output_names"]:
if tensor_name not in dynamic_axes:
dynamic_axes[tensor_name] = {0: "batch"}
else:
dynamic_axes[tensor_name][0] = "batch"
else:
dynamic_axes = {
tensor_name: {0: "batch"}
for tensor_name in (
export_kwargs["input_names"] + export_kwargs["output_names"]
)
}

# disable active quantization observers because they cannot be exported
disabled_observers = []
Expand Down