(
self,
exported_program: export_serialize.ExportedProgram,
state_dict: Union[Dict[str, torch.Tensor], bytes],
constants: Union[Dict[str, torch.Tensor], bytes],
example_inputs: Optional[
Union[Tuple[Tuple[torch.Tensor, ...], Dict[str, Any]], bytes]
] = None,
)
| 624 | |
| 625 | class ExportedProgramDeserializer(export_serialize.ExportedProgramDeserializer): |
| 626 | def deserialize( |
| 627 | self, |
| 628 | exported_program: export_serialize.ExportedProgram, |
| 629 | state_dict: Union[Dict[str, torch.Tensor], bytes], |
| 630 | constants: Union[Dict[str, torch.Tensor], bytes], |
| 631 | example_inputs: Optional[ |
| 632 | Union[Tuple[Tuple[torch.Tensor, ...], Dict[str, Any]], bytes] |
| 633 | ] = None, |
| 634 | ) -> ep.ExportedProgram: |
| 635 | assert isinstance(exported_program, export_serialize.ExportedProgram) |
| 636 | version = exported_program.schema_version |
| 637 | |
| 638 | # TODO(zhxchen17) blocked on thrift schema refactor |
| 639 | if version.major != SCHEMA_VERSION[0] and not ( |
| 640 | version.major == 0 and version.minor == 0 |
| 641 | ): |
| 642 | raise SerializeError( |
| 643 | f"Serialized schema version {exported_program.schema_version} " |
| 644 | f"does not match our current schema version {SCHEMA_VERSION}." |
| 645 | ) |
| 646 | |
| 647 | symbol_name_to_range = { |
| 648 | k: symbolic_shapes.ValueRanges( |
| 649 | export_serialize._int_to_sympy_int(v.min_val), |
| 650 | export_serialize._int_to_sympy_int(v.max_val), |
| 651 | ) |
| 652 | for k, v in exported_program.range_constraints.items() |
| 653 | } |
| 654 | res = GraphModuleDeserializer().deserialize( |
| 655 | exported_program.graph_module, |
| 656 | state_dict, |
| 657 | constants, |
| 658 | example_inputs, |
| 659 | symbol_name_to_range, |
| 660 | ) |
| 661 | range_constraints = self.deserialize_range_constraints( |
| 662 | symbol_name_to_range, |
| 663 | res.names_to_symbols, |
| 664 | ) |
| 665 | |
| 666 | dummy_g = torch.fx.Graph() |
| 667 | dummy_g.output(()) |
| 668 | additional_kwargs = {} |
| 669 | if hasattr(exported_program, "verifiers"): |
| 670 | additional_kwargs["verifiers"] = [ |
| 671 | load_verifier(v) for v in exported_program.verifiers # pyre-ignore |
| 672 | ] |
| 673 | elif hasattr(exported_program, "dialect"): |
| 674 | additional_kwargs["verifier"] = load_verifier( |
| 675 | exported_program.dialect # pyre-ignore |
| 676 | ) |
| 677 | exported_program = ep.ExportedProgram( |
| 678 | root=res.graph_module, |
| 679 | graph=dummy_g, |
| 680 | graph_signature=ep.ExportGraphSignature(input_specs=[], output_specs=[]), |
| 681 | state_dict=res.state_dict, # type: ignore[arg-type] |
| 682 | range_constraints=range_constraints, |
| 683 | module_call_graph=res.module_call_graph, |
no test coverage detected