Rate this Page
★ ★ ★ ★ ★

Prerequisite | ETRecord - ExecuTorch Record#

Overview#

ETRecord is intended to be the debug artifact that is generated by users ahead of time (when they export their model to run on ExecuTorch). To draw a rough equivalent to conventional software development, ETRecord can be considered as the binary built with debug symbols that is used for debugging in GNU Debugger (gdb). It is expected that the user will supply this to the ExecuTorch Developer Tools in order for them to debug and visualize their model.

ETRecord contains numerous components such as:

  • Edge dialect graph with debug handles

  • Delegate debug handle maps

The ETRecord object itself is intended to be opaque to users and they should not access any components inside it directly. It should be provided to the Inspector API to link back performance and debug data sourced from the runtime back to the Python source code.

Generating an ETRecord#

There are multiple ways to generate an ETRecord for debugging purposes:

Method 2: Using the generate_etrecord() Function#

You can also use the standalone generate_etrecord() function to generate an ETRecord. This method requires you to provide the Edge Dialect program (returned by to_edge()), the ExecuTorch program (returned by to_executorch()), and optional models.

Warning

When using the standalone function, users should do a deepcopy of the output of to_edge() and pass in the deepcopy to the generate_etrecord API. This is needed because the subsequent call, to_executorch(), does an in-place mutation and will lose debug data in the process.

Example:

import copy
from executorch.devtools import generate_etrecord
from torch.export import export

# Export and convert to edge
aten_dialect = export(model, example_inputs, strict=True)
edge_program = to_edge(aten_dialect)

# Create copy for ETRecord (needed because to_executorch modifies in-place)
edge_program_copy = copy.deepcopy(edge_program)

# Convert to ExecutorchProgramManager
executorch_program = edge_program_copy.to_executorch()

# Generate ETRecord separately
generate_etrecord(
    "debug.etrecord",
    edge_program,
    executorch_program,
)
executorch.devtools.etrecord._etrecord.generate_etrecord(et_record, edge_dialect_program, executorch_program, exported_program=None, extra_recorded_export_modules=None)[source]#

Generates an ETRecord from the given objects, serializes it and saves it to the given path. The objects that will be serialized to an ETRecord are all the graph modules present in the extra_recorded_export_modules dict, the graph module present in the edge dialect program object, and also the graph module present in the ExecuTorch program object, which is the closest graph module representation of what is eventually run on the device. In addition to all the graph modules, we also serialize the program buffer, which the users can provide to the ExecuTorch runtime to run the model, and the debug handle map for Developer Tools usage.

Parameters:
  • et_record – Path to where the ETRecord file will be saved to.

  • edge_dialect_program – EdgeProgramManager for this model returned by the call to to_edge()

  • executorch_program – The ExecuTorch program for this model returned by the call to to_executorch() or the BundledProgram of this model

  • exported_program – Optional graph module for this model returned by the call to torch.export from nn.Module.

  • [Optional] (extra_recorded_export_modules) – Should be ignored by OSS users. A dictionary of graph modules with the key being the user provided name and the value being the corresponding exported module. The exported graph modules can be either the output of torch.export() or exir.to_edge().

Returns:

None

Using an ETRecord#

Pass the ETRecord as an optional argument into the Inspector API to access this data and do post-run analysis.

Delegate partition provenance#

Tools that need to construct delegate/partition structure before an ETDump is available can use get_delegate_partition_provenance. This exposes a backend-agnostic view of the existing ETRecord delegate and debug-handle metadata without requiring consumers to access private ETRecord fields.

from executorch.devtools.etrecord import (
    get_delegate_partition_provenance,
    parse_etrecord,
)

etrecord = parse_etrecord("model_debug.etrecord")
provenance = get_delegate_partition_provenance(etrecord)

for partition in provenance.get("forward", ()):
    print(partition.instruction_id)
    print(partition.backend_id)
    print(partition.source_debug_handles)
    print(partition.delegate_debug_map)  # backend debug ID -> source handles
executorch.devtools.etrecord._etrecord.get_delegate_partition_provenance(etrecord)[source]#

Return delegate partitions using existing ETRecord metadata.

This is a public consumer API; it does not alter the ETRecord wire format. Each method’s partitions are sorted by emitted delegate instruction ID. A method with no delegates maps to an empty tuple, while a record without delegate-map metadata returns an empty dictionary.

Delegates in nested cond, map or scan subgraphs may be absent: the emitter currently merges subgraph instructions without merging their debug-handle and delegate maps.

Raises:

ValueError – If present delegate metadata is internally inconsistent.

class executorch.devtools.etrecord._etrecord.DelegatePartitionProvenance(method_name, instruction_id, backend_id, source_debug_handles, delegate_debug_map=<factory>)[source]#

Backend-agnostic provenance for one emitted delegate partition.

instruction_id is local to method_name and identifies the emitted executorch_call_delegate instruction. source_debug_handles contains the debug handles of call_function nodes in the delegate’s original lowered graph. Handles are de-duplicated in encounter order, and may be empty; nodes without debug handles are omitted.

delegate_debug_map provides backend-operation debug ID -> source debug handles. IDs are canonical strings (including numeric IDs) for consistent results before and after ETRecord JSON serialization. The map is read-only and may be empty when a backend provides no operation-level identifiers.

The same source debug handle may appear in multiple partitions. Consumers must treat provenance as a many-to-many relationship.

The delegate instruction ID is scoped to its method and identifies the emitted executorch_call_delegate instruction. It is suitable as an artifact-local partition identity, but it is not guaranteed to remain stable after rebuilding or re-exporting the model. A source debug handle may also appear in more than one partition, so consumers should preserve the many-to-many provenance relationship rather than assuming a single partition per debug handle.

source_debug_handles are collected from the delegate’s original lowered FX module, not necessarily from the original Python model. Repeated handles are removed in encounter order; nodes without handles are skipped, so this tuple may be empty. The read-only delegate_debug_map maps backend-specific IDs (canonical strings, including numeric IDs) to tuples of source debug handles. Some backends do not provide operation-level identifiers, so the map may be empty. An empty overall dictionary means no delegate-map metadata is present; a known method with no partitions is represented by an empty tuple.

Note

Delegates inside higher-order control-flow subgraphs (such as cond, map and scan) may be absent from these maps because the emitter currently merges subgraph instructions without merging provenance maps. This is an existing limitation of the ETRecord emission path.