9
9
from typing import Dict , List , Optional , Sequence , Type , Union
10
10
11
11
import executorch .devtools .bundled_program .schema as bp_schema
12
- from pyre_extensions import none_throws
13
12
14
13
import executorch .exir .schema as core_schema
15
14
20
19
from executorch .devtools .bundled_program .version import BUNDLED_PROGRAM_SCHEMA_VERSION
21
20
22
21
from executorch .exir import ExecutorchProgram , ExecutorchProgramManager
23
- from executorch .exir ._serialize import _deserialize_pte_binary , _serialize_pte_binary
22
+ from executorch .exir ._serialize import _serialize_pte_binary
24
23
from executorch .exir .tensor import get_scalar_type , scalar_type_enum , TensorSpec
25
24
26
25
# pyre-ignore
@@ -44,35 +43,23 @@ class BundledProgram:
44
43
45
44
def __init__ (
46
45
self ,
47
- executorch_program : Optional [ Union [
46
+ executorch_program : Union [
48
47
ExecutorchProgram ,
49
48
ExecutorchProgramManager ,
50
- ]] ,
49
+ ],
51
50
method_test_suites : Sequence [MethodTestSuite ],
52
- pte_file_path : Optional [str ] = None ,
53
51
):
54
52
"""Create BundledProgram by bundling the given program and method_test_suites together.
55
53
56
54
Args:
57
55
executorch_program: The program to be bundled.
58
56
method_test_suites: The testcases for certain methods to be bundled.
59
- pte_file_path: The path to pte file to deserialize program if executorch_program is not provided.
60
57
"""
61
- if not executorch_program and not pte_file_path :
62
- raise RuntimeError ("Either executorch_program or pte_file_path must be provided" )
63
-
64
- if executorch_program and pte_file_path :
65
- raise RuntimeError ("Only one of executorch_program or pte_file_path can be used" )
66
58
67
59
method_test_suites = sorted (method_test_suites , key = lambda x : x .method_name )
68
- if executorch_program :
69
- self ._assert_valid_bundle (executorch_program , method_test_suites )
70
- self .executorch_program : Optional [Union [
71
- ExecutorchProgram ,
72
- ExecutorchProgramManager ,
73
- ]] = executorch_program
74
- self ._pte_file_path : Optional [str ] = pte_file_path
60
+ self ._assert_valid_bundle (executorch_program , method_test_suites )
75
61
62
+ self .executorch_program = executorch_program
76
63
self .method_test_suites = method_test_suites
77
64
78
65
# This is the cache for bundled program in schema type.
@@ -85,13 +72,7 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
85
72
if self ._bundled_program_in_schema is not None :
86
73
return self ._bundled_program_in_schema
87
74
88
- if self .executorch_program :
89
- program = self ._extract_program (self .executorch_program )
90
- else :
91
- with open (none_throws (self ._pte_file_path ), "rb" ) as f :
92
- p_bytes = f .read ()
93
- program = _deserialize_pte_binary (p_bytes )
94
-
75
+ program = self ._extract_program (self .executorch_program )
95
76
bundled_method_test_suites : List [bp_schema .BundledMethodTestSuite ] = []
96
77
97
78
# Emit data and metadata of bundled tensor
0 commit comments