Skip to content

Commit 6cf22bf

Browse files
awoll-bdaiexploy-bot
authored andcommitted
Make opset and ir version parameterizable (#25)
# Pull Request ### What change is being made Allow to parameterize onnx opset and ir version. ### Why this change is being made More flexibility for onnx runtime usage. ### Tested Good to go if CI passes. GitOrigin-RevId: 4d406775f9b082ae568fb33ea7a0632435005ffc
1 parent 6806f1f commit 6cf22bf

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

exporter/exporter/exporter.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def export_environment_as_onnx(
2222
filename: str = "policy.onnx",
2323
model_source: dict | None = None,
2424
verbose: bool = False,
25+
opset_version: int = 20,
26+
ir_version: int = 11,
2527
):
2628
"""Export policy into a Torch ONNX file.
2729
@@ -33,6 +35,8 @@ def export_environment_as_onnx(
3335
filename: The name of exported ONNX file. Defaults to "policy.onnx".
3436
model_source: Information about the policy's origin (e.g., wandb, local file, etc.), added to the ONNX metadata.
3537
verbose: Whether to print the model summary. Defaults to False.
38+
opset_version: Version of the operator specification referenced by the ONNX graph. Needs to be compatible with ONNX Runtime in deployment environment, check https://onnxruntime.ai/docs/reference/compatibility.html
39+
ir_version: Version of the intermediate representation specifications. Needs to be compatible with ONNX Runtime in deployment environment, check https://onnxruntime.ai/docs/reference/compatibility.html
3640
"""
3741
if model_source is None:
3842
model_source = {}
@@ -43,6 +47,8 @@ def export_environment_as_onnx(
4347
actor=actor,
4448
normalizer=normalizer,
4549
verbose=verbose,
50+
opset_version=opset_version,
51+
ir_version=ir_version,
4652
)
4753

4854
policy_exporter.export(
@@ -69,6 +75,8 @@ def __init__(
6975
self,
7076
env: ExportableEnvironment,
7177
actor: torch.nn.Module,
78+
opset_version: int,
79+
ir_version: int,
7280
normalizer: torch.nn.Module | None = None,
7381
verbose: bool = False,
7482
):
@@ -86,10 +94,8 @@ def __init__(
8694
else:
8795
self.normalizer = torch.nn.Identity()
8896

89-
# Compatible versions with onnxruntime used in control (1.17)
90-
# See https://onnxruntime.ai/docs/reference/compatibility.html
91-
self._opset_version = 20
92-
self._ir_version = 9
97+
self._opset_version = opset_version
98+
self._ir_version = ir_version
9399

94100
def forward(
95101
self,
@@ -98,29 +104,16 @@ def forward(
98104
"""Use the robot's state to compute policy actions, joint position targets, and policy observations, and outputs
99105
that support history.
100106
101-
This method sets the environment's data sources (e.g., the articulation data and the IMU sensor data) such that
102-
computing this method's outputs results in embedding the task's observation and action managers to be part of
103-
the computational graph. This implementation's design is discussed in this design doc:
104-
https://docs.google.com/document/d/1mOz2VPSpYvOUTK6sjLT_JNLZAldyzEnNievXJTpQvPs/
107+
Args:
108+
input_data: A dictionary containing all input tensors required for the forward pass. The expected keys and
109+
shapes of the tensors depend on the environment's context manager and the policy's computational graph.
105110
106111
Notes:
107112
- Dictionary inputs are flattened by the torch ONNX exporter implementation.
108-
- As discussed in the design doc above, only inputs that are part of the computational graph will be
109-
required when using the resulting ONNX file for inference.
113+
- Only inputs that are part of the computational graph will be required when using the resulting ONNX file for inference.
110114
For example, if `pos_base_in_w` is not used by any of the observation functions, it will not be a required
111115
input. This can be verified by querying the ONNX input names when using the ONNX runtime framework.
112116
113-
Assumptions:
114-
- Processed actions are joint targets, and all joints are actuated.
115-
116-
Args:
117-
imu_data: A dictionary of IMU poses and angular velocities, for each available IMU.
118-
sensor_data: A dictionary of sensor values. IMU data is handled separately.
119-
command_data: A dictionary of command values.
120-
art_data: A dictionary of articulation data values.
121-
rigid_object_data: A dictionary of rigid-body objects in the scene.
122-
memory_data: A dictionary of inputs used to support history.
123-
124117
Returns:
125118
joint_targets, actions, output_memory:
126119
A tuple of desired joint positions (i.e., processed actions), actions (i.e., unprocessed actions),

exporter/exporter/tests/test_exporter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def test_forward_default_mode(self, mock_env, mock_actor):
5555
actor=mock_actor,
5656
normalizer=None,
5757
verbose=False,
58+
opset_version=20,
59+
ir_version=11,
5860
)
5961
exporter.export_mode = ExportMode.Default
6062

@@ -79,6 +81,8 @@ def test_forward_process_actions_mode(self, mock_env, mock_actor):
7981
actor=mock_actor,
8082
normalizer=None,
8183
verbose=False,
84+
opset_version=20,
85+
ir_version=11,
8286
)
8387
exporter.export_mode = ExportMode.ProcessActions
8488

0 commit comments

Comments
 (0)