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

Pass folder path to store initializers as files #929

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 10 additions & 2 deletions onnxscript/function_libs/torch_lib/graph_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import logging
import os
import typing
import warnings
from typing import Any, Dict, Final, List, Mapping, Optional, Sequence, Tuple, Union
Expand Down Expand Up @@ -671,7 +672,12 @@ def to_function_proto(self, opset_version: int, function_name: str) -> onnx.Func

@runtime_typing.checked
def to_model_proto(
self, opset_version: int, include_initializers: bool = True
self, opset_version: int,
include_initializers: bool = True,
# If "my_folder/my_sub_folder/" is provided,
# the initializers will be stored to "my_folder/my_sub_folder/".
# There will be one file per initializer.
external_initializer_path: Optional[str] = None,
) -> onnx.ModelProto:
function_proto_dict: Mapping[
Tuple[str, str], onnx.FunctionProto
Expand All @@ -698,7 +704,9 @@ def to_model_proto(
keep_initializers_as_inputs=False,
custom_opsets={},
add_node_names=True,
onnx_file_path="",
# This PyTorch API strips the last component in onnx_file_path,
# we append "tmp.onnx" so that "external_initializer_path/tmp.onnx".
onnx_file_path=os.path.join(external_initializer_path, "tmp.onnx"),
node_attr_to_name={},
)

Expand Down
Loading