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

Function lower_to_executorch

examples/models/sortformer/export_sortformer.py:300–353  ·  view source on GitHub ↗
(programs, metadata=None, backend="portable")

Source from the content-addressed store, hash-verified

298
299
300def lower_to_executorch(programs, metadata=None, backend="portable"):
301 if backend == "xnnpack":
302 from executorch.backends.xnnpack.partition.xnnpack_partitioner import (
303 XnnpackPartitioner,
304 )
305
306 print("\nLowering to ExecuTorch with XNNPACK...")
307 partitioner = {}
308 for key in programs.keys():
309 if key == "preprocessor":
310 partitioner[key] = []
311 else:
312 partitioner[key] = [XnnpackPartitioner()]
313 elif backend in ("cuda", "cuda-windows"):
314 from executorch.backends.cuda.cuda_backend import CudaBackend
315 from executorch.backends.cuda.cuda_partitioner import CudaPartitioner
316 from executorch.exir.backend.compile_spec_schema import CompileSpec
317
318 print(
319 f"\nLowering to ExecuTorch with CUDA{' (Windows)' if backend == 'cuda-windows' else ''}..."
320 )
321 partitioner = {}
322 for key in programs.keys():
323 if key == "preprocessor":
324 partitioner[key] = []
325 continue
326 compile_specs = [CudaBackend.generate_method_name_compile_spec(key)]
327 if backend == "cuda-windows":
328 compile_specs.append(CompileSpec("platform", b"windows"))
329 partitioner[key] = [CudaPartitioner(compile_specs)]
330 else:
331 print("\nLowering to ExecuTorch...")
332 partitioner = []
333
334 constant_methods = {}
335 if metadata:
336 for key, value in metadata.items():
337 constant_methods[key] = value
338
339 et_prog = to_edge_transform_and_lower(
340 programs,
341 partitioner=partitioner,
342 compile_config=EdgeCompileConfig(
343 _check_ir_validity=False,
344 _skip_dim_order=True,
345 ),
346 constant_methods=constant_methods if constant_methods else None,
347 )
348 return et_prog.to_executorch(
349 config=ExecutorchBackendConfig(
350 extract_delegate_segments=True,
351 memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False),
352 ),
353 )
354
355
356def main():

Callers 1

mainFunction · 0.70

Calls 12

XnnpackPartitionerClass · 0.90
CompileSpecClass · 0.90
CudaPartitionerClass · 0.90
EdgeCompileConfigClass · 0.90
MemoryPlanningPassClass · 0.90
keysMethod · 0.80
itemsMethod · 0.80
appendMethod · 0.45
to_executorchMethod · 0.45

Tested by

no test coverage detected