1212from typing import Dict , List , Optional
1313
1414from executorch .backends .apple .coreml import executorchcoreml
15- from executorch .backends .apple .coreml .compiler import CoreMLBackend
1615from executorch .exir ._serialize ._program import deserialize_pte_binary
1716from executorch .exir .schema import (
1817 BackendDelegate ,
1918 BackendDelegateDataReference ,
2019 DataLocation ,
2120)
2221
22+ COREML_BACKEND_ID = "CoreMLBackend"
23+
2324
2425def extract_coreml_models (pte_data : bytes ):
2526 pte_file = deserialize_pte_binary (pte_data )
@@ -39,7 +40,7 @@ def extract_coreml_models(pte_data: bytes):
3940 [execution_plan .delegates for execution_plan in program .execution_plan ], []
4041 )
4142 coreml_delegates : List [BackendDelegate ] = [
42- delegate for delegate in delegates if delegate .id == CoreMLBackend . __name__
43+ delegate for delegate in delegates if delegate .id == COREML_BACKEND_ID
4344 ]
4445
4546 # Track extracted models to avoid duplicates (multifunction models share partitions)
@@ -109,7 +110,7 @@ def extract_coreml_models(pte_data: bytes):
109110 print ("The model isn't delegated to Core ML." )
110111
111112
112- if __name__ == "__main__" :
113+ def main () -> None :
113114 """
114115 Extracts the Core ML models embedded in the ``.pte`` file and saves them to the
115116 file system.
@@ -127,3 +128,7 @@ def extract_coreml_models(pte_data: bytes):
127128 with open (model_path , mode = "rb" ) as pte_file :
128129 pte_data = pte_file .read ()
129130 extract_coreml_models (pte_data )
131+
132+
133+ if __name__ == "__main__" :
134+ main ()
0 commit comments