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

torch export to onnx extern data size configurable #1481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion tools/torch_export_to_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def main():
parser.add_argument("out_onnx_filename", type=str, help="Filename of the final ONNX model.")
parser.add_argument("--verbosity", default=4, type=int, help="5 for all seqs (default: 4)")
parser.add_argument("--device", type=str, default="cpu", help="'cpu' (default) or 'gpu'.")
parser.add_argument(
"--dyn_dim_min_sizes", type=dict, default=None, help="Specify min sizes for dim tags with dynamic sizes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this? What exactly did you pass as argument? I wonder how it would correctly convert it into a dict, and specifically with the right Dim objects as keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it by setting the Dim object like this

time_data_dim = SpatialDim('time:data')
extern_data_dict = {'data': {
        'dim_tags': [
            batch_dim,
            time_data_dim,
            FeatureDim('feat', 1),
        ],
        'dtype': 'float32',
    }}
dyn_dim_max_sizes={time_data_dim:100}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, how did you start this script? How did you pass --dyn_dim_min_sizes when starting the script?

)
parser.add_argument(
"--dyn_dim_max_sizes", type=dict, default=None, help="Specify max sizes for dim tags with dynamic sizes"
)

args = parser.parse_args()

init(config_filename=args.config, checkpoint=args.checkpoint, log_verbosity=args.verbosity, device=args.device)
Expand Down Expand Up @@ -223,7 +230,9 @@ def main():
if not v.available_for_inference:
del extern_data.data[k]

tensor_dict_fill_random_numpy_(extern_data)
tensor_dict_fill_random_numpy_(
extern_data, dyn_dim_max_sizes=args.dyn_dim_max_sizes, dyn_dim_min_sizes=args.dyn_dim_min_sizes
)
tensor_dict_numpy_to_torch_(extern_data)
extern_data_raw = extern_data.as_raw_tensor_dict(include_scalar_dyn_sizes=False, exclude_duplicate_dims=True)
model_outputs_raw_keys = _get_model_outputs_raw_keys()
Expand Down
Loading