MCPcopy Create free account
hub / github.com/pytorch/executorch / serialize_to_schema

Method serialize_to_schema

devtools/bundled_program/core.py:88–155  ·  view source on GitHub ↗

Serialize the current Bundled Program into its schema format for further serialization..

(self)

Source from the content-addressed store, hash-verified

86 self._bundled_program_in_schema: Optional[bp_schema.BundledProgram] = None
87
88 def serialize_to_schema(self) -> bp_schema.BundledProgram:
89 """Serialize the current Bundled Program into its schema format for further serialization.."""
90 # Return cached value if exists
91 if self._bundled_program_in_schema is not None:
92 return self._bundled_program_in_schema
93
94 bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []
95
96 # Emit data and metadata of bundled tensor
97 for method_test_suite in self.method_test_suites:
98 bundled_test_cases: List[bp_schema.BundledMethodTestCase] = []
99
100 # emit I/O sets for each method test case
101 for i in range(len(method_test_suite.test_cases)):
102 inputs: List[bp_schema.Value] = []
103 expected_outputs: List[bp_schema.Value] = []
104
105 cur_plan_test_inputs = method_test_suite.test_cases[i].inputs
106 cur_plan_test_expected_outputs = method_test_suite.test_cases[
107 i
108 ].expected_outputs
109
110 for input_val in cur_plan_test_inputs:
111 if type(input_val) is torch.Tensor:
112 self._emit_bundled_tensor(
113 TensorSpec.from_tensor(input_val, const=True),
114 inputs,
115 )
116 else:
117 self._emit_prim(
118 input_val,
119 inputs,
120 )
121 for expected_output_tensor in cur_plan_test_expected_outputs:
122 assert (
123 type(expected_output_tensor) is torch.Tensor
124 ), "Only tensor outputs are currently supported."
125 self._emit_bundled_tensor(
126 TensorSpec.from_tensor(expected_output_tensor, const=True),
127 expected_outputs,
128 )
129 bundled_test_cases.append(
130 bp_schema.BundledMethodTestCase(
131 inputs=inputs, expected_outputs=expected_outputs
132 )
133 )
134
135 # emit the whole execution plan test
136 bundled_method_test_suites.append(
137 bp_schema.BundledMethodTestSuite(
138 method_name=method_test_suite.method_name,
139 test_cases=bundled_test_cases,
140 )
141 )
142
143 if self.executorch_program:
144 program_bytes = self.executorch_program.buffer
145 else:

Calls 4

_emit_bundled_tensorMethod · 0.95
_emit_primMethod · 0.95
from_tensorMethod · 0.45
appendMethod · 0.45