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

Function _export_processor_model

extension/audio/mel_spectrogram.py:191–235  ·  view source on GitHub ↗
(
    model, output_file="whisper_preprocess.pte", backend="xnnpack"
)

Source from the content-addressed store, hash-verified

189
190
191def _export_processor_model(
192 model, output_file="whisper_preprocess.pte", backend="xnnpack"
193):
194
195 if model.streaming:
196 # Streaming processes small windows per step. 2 seconds gives
197 # comfortable headroom while keeping the memory plan tight.
198 max_samples = 2 * model.sampling_rate
199 else:
200 max_samples = model.max_audio_len * model.sampling_rate
201 audio_tensor = torch.randn(min(93680, max_samples))
202 shapes_collection = torch.export.ShapesCollection()
203 shapes_collection[audio_tensor] = {0: Dim.DYNAMIC(max=max_samples)}
204 with torch.no_grad(), torch.fx.experimental._config.patch(
205 backed_size_oblivious=True
206 ):
207 ep = torch.export.export(
208 model, (audio_tensor,), dynamic_shapes=shapes_collection, strict=True
209 )
210 logging.debug(ep)
211
212 if backend == "mlx":
213 from executorch.backends.mlx.partitioner import MLXPartitioner
214
215 partitioner = [MLXPartitioner()]
216 else:
217 partitioner = [XnnpackPartitioner()]
218
219 # to edge
220 edge: EdgeProgramManager = to_edge_transform_and_lower(
221 ep,
222 partitioner=partitioner,
223 compile_config=EdgeCompileConfig(
224 _check_ir_validity=False,
225 ),
226 )
227 logging.debug(edge.exported_program())
228
229 # to executorch
230 exec_prog = edge.to_executorch()
231 os.makedirs(os.path.dirname(output_file) or ".", exist_ok=True)
232 with open(output_file, "wb") as file:
233 exec_prog.write_to_file(file)
234
235 logging.debug("Done")
236
237
238def export_processor(

Callers 1

export_processorFunction · 0.85

Calls 9

MLXPartitionerClass · 0.90
XnnpackPartitionerClass · 0.90
EdgeCompileConfigClass · 0.90
debugMethod · 0.80
exportMethod · 0.45
exported_programMethod · 0.45
to_executorchMethod · 0.45
write_to_fileMethod · 0.45

Tested by

no test coverage detected