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

Function emit_program

exir/emit/_emit_program.py:118–216  ·  view source on GitHub ↗

Given a exported program, it returns the program in the format of the Python version of the flatbuffer Program schema. Args: methods: Either the exported program (Exported_Program) that we want to emit into the flatbuffer, or a dictionary of method names to

(
    methods: Union[ExportedProgram, Dict[str, ExportedProgram]],
    emit_stacktrace: bool = False,
    prim_getters: Optional[Dict[str, Any]] = None,
    emit_mutable_buffer_names: bool = False,
)

Source from the content-addressed store, hash-verified

116
117
118def emit_program(
119 methods: Union[ExportedProgram, Dict[str, ExportedProgram]],
120 emit_stacktrace: bool = False,
121 prim_getters: Optional[Dict[str, Any]] = None,
122 emit_mutable_buffer_names: bool = False,
123) -> EmitterOutput:
124 """
125 Given a exported program, it returns the program in the format
126 of the Python version of the flatbuffer Program schema.
127
128 Args:
129 methods: Either the exported program (Exported_Program) that we want to
130 emit into the flatbuffer, or a dictionary of method names to
131 ExportedPrograms.
132 emit_stacktrace: Flag to enable emission of a stacktrace for each
133 instruction for debugging purposes
134
135 Return:
136 The program in a Python class which mimics the flatbuffer schema
137 """
138
139 if isinstance(methods, ExportedProgram):
140 methods = {"forward": methods}
141
142 # validation
143 bad_methods = []
144 for name, exported_program in methods.items():
145 if not isinstance(exported_program, ExportedProgram):
146 bad_methods.append(name)
147 if len(bad_methods) != 0:
148 raise ExportError(
149 ExportErrorType.INVALID_INPUT_TYPE,
150 f"Did not receive ExportedProgram for the following methods {str(bad_methods)}",
151 )
152
153 plans = []
154 debug_handle_map = {}
155 method_to_delegate_debug_id_map = {}
156 instruction_id_to_num_outs_map = {}
157 program_state = _ProgramState()
158
159 # emit each entry point in order according to name.
160 for name, exported_program in sorted(methods.items()):
161 # create empty state
162 emitter_state = _EmitterState(
163 values=[],
164 operators=[],
165 delegates=[],
166 operator_cache={},
167 emit_stacktrace=emit_stacktrace,
168 emit_mutable_buffer_names=emit_mutable_buffer_names,
169 )
170
171 gm = _remove_non_user_outputs(exported_program)
172
173 emitter = _TopLevelEmitter(
174 name, exported_program, gm, program_state, emitter_state
175 )

Calls 14

ExportErrorClass · 0.90
_ProgramStateClass · 0.90
_EmitterStateClass · 0.90
_TopLevelEmitterClass · 0.90
ProgramClass · 0.90
SubsegmentOffsetsClass · 0.90
_remove_non_user_outputsFunction · 0.85
_get_training_metadataFunction · 0.85
EmitterOutputClass · 0.85
itemsMethod · 0.80
_emit_prim_gettersMethod · 0.80
appendMethod · 0.45