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

Method serialize

exir/serde/export_serialize.py:1375–1426  ·  view source on GitHub ↗

Args: exported_program: Exported Program to serialize

(self, exported_program: ep.ExportedProgram)

Source from the content-addressed store, hash-verified

1373 self.opset_version["aten"] = torch._C._get_max_operator_version()
1374
1375 def serialize(self, exported_program: ep.ExportedProgram) -> _SerializedProgram:
1376 """
1377 Args:
1378 exported_program: Exported Program to serialize
1379 """
1380 exported_program._validate()
1381
1382 gm_serializer = GraphModuleSerializer(
1383 exported_program.graph_signature, exported_program.module_call_graph
1384 )
1385 serialized_graph_module = gm_serializer.serialize(exported_program.graph_module)
1386 serialized_range_constraints = serialize_range_constraints(
1387 exported_program.range_constraints
1388 )
1389
1390 # TODO: Directly serialize exported_program.constants once
1391 # CustomClassHolders get stored in the ExportedProgram rather than in
1392 # the graph
1393 constants = {}
1394 for n, c in gm_serializer.custom_objs.items():
1395 constants[n] = c
1396 for n, t in exported_program.constants.items():
1397 assert n not in constants
1398 constants[n] = t
1399
1400 additional_kwargs = {}
1401 if hasattr(exported_program, "verifiers"):
1402 additional_kwargs["verifiers"] = [
1403 v.dialect for v in exported_program.verifiers
1404 ]
1405 elif hasattr(exported_program, "dialect"):
1406 additional_kwargs["dialect"] = exported_program.dialect
1407 serialized_ep = ExportedProgram(
1408 graph_module=serialized_graph_module,
1409 opset_version=self.opset_version,
1410 range_constraints=serialized_range_constraints,
1411 schema_version=SchemaVersion(
1412 major=SCHEMA_VERSION[0],
1413 minor=SCHEMA_VERSION[1],
1414 ),
1415 **additional_kwargs,
1416 )
1417
1418 # Test canonical form is well defined.
1419 canonicalize(serialized_ep)
1420
1421 return _SerializedProgram(
1422 serialized_ep,
1423 serialize_torch_artifact(exported_program.state_dict),
1424 serialize_torch_artifact(constants),
1425 serialize_torch_artifact(exported_program.example_inputs),
1426 )
1427
1428
1429class GraphModuleDeserializer:

Callers

nothing calls this directly

Calls 10

serializeMethod · 0.95
SchemaVersionClass · 0.90
ExportedProgramClass · 0.85
canonicalizeFunction · 0.85
_SerializedProgramClass · 0.85
serialize_torch_artifactFunction · 0.85
itemsMethod · 0.80
_validateMethod · 0.45

Tested by

no test coverage detected