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

Function _

exir/backend/backend_api.py:69–134  ·  view source on GitHub ↗

Add overloaded implementations for to_backend: :: def to_backend( backend_id: str, edge_program: ExportedProgram, compile_specs: List[CompileSpec], ) -> LoweredBackendModule: Requires the passed in exported program in Edge dialect to be executed

(
    backend_id: str,
    edge_program: ExportedProgram,
    compile_specs: List[CompileSpec],
)

Source from the content-addressed store, hash-verified

67
68@to_backend.register
69def _(
70 backend_id: str,
71 edge_program: ExportedProgram,
72 compile_specs: List[CompileSpec],
73) -> LoweredBackendModule:
74 """
75 Add overloaded implementations for to_backend:
76
77 ::
78
79 def to_backend(
80 backend_id: str,
81 edge_program: ExportedProgram,
82 compile_specs: List[CompileSpec],
83 ) -> LoweredBackendModule:
84
85
86 Requires the passed in exported program in Edge dialect to be executed in
87 the backend identified by backend_id. The forward method of the given
88 edge_graph_module will be targeted for execution.
89
90 Args:
91 backend_id: The backend identifier.
92 exported_program: An exported program in Edge dialect to target for
93 lowering to the backend.
94 compile_specs: A list of backend-specific objects with static
95 metadata to configure the "compilation" process (e.g. it could be
96 another dictionary itself).
97
98 Returns:
99 LoweredBackendModule: A Module that has been lowered to the target backend.
100 Internally, the lowered Module contains these special attributes:
101 backend_id (str: backend id), __processed_module__ (str: a compiled module)
102 compile_spec, original_module (original exported program)
103
104 Raises:
105 NotImplementedError: The backend is not implemented (e.g. it was not found).
106 This exception is derived from RuntimeError and should be caught accordingly.
107 RuntimeError: The module cannot be processed by the backend.
108 """
109 assert isinstance(edge_program, ExportedProgram)
110
111 # All backend implementation are final, so we don't need to consider nested subclasses.
112 for cls in BackendDetails.__subclasses__():
113 if backend_id == cls.__name__:
114 copied_edge_program = copy.deepcopy(edge_program)
115 preprocess_result: PreprocessResult = cls.preprocess(
116 copied_edge_program,
117 compile_specs,
118 )
119 lowered_module = LoweredBackendModule(
120 edge_program=edge_program,
121 backend_id=backend_id,
122 processed_bytes=preprocess_result.processed_bytes,
123 compile_specs=compile_specs,
124 named_data_store_output=preprocess_result.data_store_output,
125 )
126 lowered_module.meta = {

Callers

nothing calls this directly

Calls 14

get_fake_programFunction · 0.90
is_identical_graphFunction · 0.90
update_to_real_programFunction · 0.90
_partition_and_lowerFunction · 0.85
ExportedProgramClass · 0.85
_create_partitionsFunction · 0.85
remove_used_metadataFunction · 0.85
itemsMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected