feat(executorch): expose composable Edge export API - #4440
Open
shoumikhin wants to merge 1 commit into
Open
Conversation
Add torch_tensorrt.executorch.export() for advanced workflows that need an EdgeProgramManager before final ExecuTorch memory planning and serialization. Keep save(output_format="executorch") as the one-shot wrapper, preserve TensorRT-first partitioning, and stage graph structure before rewriting engine calls so failures do not consume caller-owned ExportedPrograms. Share immutable tensor and engine payloads to avoid large copies, while removing lifted engine placeholders and deduplicating shared engine materialization. Support independent multi-method programs and caller-provided partitioners, compile specs, transform passes, Edge compile configuration, constant methods, and ETRecord generation.
shoumikhin
force-pushed
the
executorch-composable-export
branch
from
July 29, 2026 18:48
cd55b95 to
4dc2d25
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR is needed
torch_tensorrt.save(..., output_format="executorch")is the easiest way to create an ExecuTorch.ptefile. It completes the whole export pipeline immediately:That remains the recommended API for common one-step exports.
Some workflows need to stop before final ExecuTorch memory planning and serialization. For example, users may want to:
prefillanddecode;This PR adds
torch_tensorrt.executorch.export(). It returns ExecuTorch's standardEdgeProgramManager, which is the supported boundary for inspecting and customizing an Edge program before callingto_executorch().Which API should I use?
Use
torch_tensorrt.save()when you want a.ptein one step.Use
torch_tensorrt.executorch.export()when you need control before the final.pteis created:save()now delegates to the same implementation, so the simple and advanced paths do not maintain separate lowering logic.Example: TensorRT with a fallback backend
TensorRT always receives the first chance to claim its prebuilt engine nodes. Additional partitioners run afterward and can claim operations that TensorRT does not support.
Assume
cuda_partitioneris an ExecuTorch partitioner configured for your target:This can produce one ExecuTorch program containing both TensorRT and CUDA delegates.
Example: multiple methods
Assume
prefill_programanddecode_programare independent, engine-bearingExportedProgramobjects, and the two spec lists are configured for their methods:The mapping preserves method names and allows per-method partitioner and compile-spec pipelines. It does not imply that mutable state is shared between methods.
Example: transforms, metadata, and ETRecord
Assume the transform passes and Edge configuration below are provided by the caller:
Accepted inputs
The new API accepts:
torch.fx.GraphModule;torch.export.ExportedProgram;ExportedProgramobjects.A plain
torch.nn.Modulemust be compiled with Torch-TensorRT first.Safety and memory behavior
Engine rewriting changes the exported graph. The new API stages an independent copy of graph structure, signatures, state containers, constants, and metadata before rewriting anything. Rewrite and lowering failures therefore do not consume or structurally modify the caller's original program.
Tensor and TensorRT engine payload storage is treated as immutable and shared with the staged structure. This avoids deep-copying potentially multi-gigabyte engines. Custom transform passes must not mutate shared payload objects.
When a lifted TensorRT engine is replaced, the old placeholder, graph-signature entry, and constant are removed. Multiple calls that share one engine reuse one materialized
uint8payload buffer.Compatibility
save(..., output_format="executorch")behavior is preserved..pteserialization and external.ptdpersistence are preserved.Input(shared_dims=...)remain shared.Validation
Validated with Torch, TensorRT, and ExecuTorch available:
.pteserialization;.ptdpersistence;.ptd;prefillanddecodemethods retaining TensorRT delegates;GraphModuleand liftedExportedProgramsources unchanged.Additional checks:
git diff --check;Related work
PR #4433 forwards additional Edge-lowering options through one-step
save(). After this PR lands, #4433 can keepsave()as a thin wrapper overtorch_tensorrt.executorch.export()instead of extending the previous private lowering path.