xref: /aosp_15_r20/external/executorch/exir/capture/_config.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1*523fa7a6SAndroid Build Coastguard Worker# Copyright (c) Meta Platforms, Inc. and affiliates.
2*523fa7a6SAndroid Build Coastguard Worker# All rights reserved.
3*523fa7a6SAndroid Build Coastguard Worker#
4*523fa7a6SAndroid Build Coastguard Worker# This source code is licensed under the BSD-style license found in the
5*523fa7a6SAndroid Build Coastguard Worker# LICENSE file in the root directory of this source tree.
6*523fa7a6SAndroid Build Coastguard Worker
7*523fa7a6SAndroid Build Coastguard Worker# pyre-unsafe
8*523fa7a6SAndroid Build Coastguard Workerfrom dataclasses import dataclass, field
9*523fa7a6SAndroid Build Coastguard Workerfrom typing import Dict, List, Optional, Union
10*523fa7a6SAndroid Build Coastguard Worker
11*523fa7a6SAndroid Build Coastguard Workerimport torch
12*523fa7a6SAndroid Build Coastguard Worker
13*523fa7a6SAndroid Build Coastguard Workerfrom executorch.exir.dynamic_shape import DynamicMemoryPlanningMode
14*523fa7a6SAndroid Build Coastguard Workerfrom executorch.exir.pass_manager import PassType
15*523fa7a6SAndroid Build Coastguard Workerfrom executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
16*523fa7a6SAndroid Build Coastguard Workerfrom executorch.exir.passes.sym_shape_eval_pass import ConstraintBasedSymShapeEvalPass
17*523fa7a6SAndroid Build Coastguard Workerfrom executorch.exir.tracer import ExirDynamoConfig
18*523fa7a6SAndroid Build Coastguard Workerfrom torch.fx._compatibility import compatibility
19*523fa7a6SAndroid Build Coastguard Worker
20*523fa7a6SAndroid Build Coastguard Worker
21*523fa7a6SAndroid Build Coastguard Worker@compatibility(is_backward_compatible=False)
22*523fa7a6SAndroid Build Coastguard Worker@dataclass
23*523fa7a6SAndroid Build Coastguard Workerclass CaptureConfig:
24*523fa7a6SAndroid Build Coastguard Worker    pt2_mode: bool = True
25*523fa7a6SAndroid Build Coastguard Worker    enable_functionalization: bool = True
26*523fa7a6SAndroid Build Coastguard Worker    enable_dynamic_shape: bool = False  # This flag does nothing if enable_aot is True
27*523fa7a6SAndroid Build Coastguard Worker    enable_aot: bool = (
28*523fa7a6SAndroid Build Coastguard Worker        False  # When it's true it implies automatic dynamic shapes via default dynamo config
29*523fa7a6SAndroid Build Coastguard Worker    )
30*523fa7a6SAndroid Build Coastguard Worker    _dynamo_config: "ExirDynamoConfig" = field(default_factory=ExirDynamoConfig)
31*523fa7a6SAndroid Build Coastguard Worker    _unlift: bool = False  # This flag does nothing if enable_aot is False.
32*523fa7a6SAndroid Build Coastguard Worker    _use_old_decomp_table: bool = False
33*523fa7a6SAndroid Build Coastguard Worker
34*523fa7a6SAndroid Build Coastguard Worker
35*523fa7a6SAndroid Build Coastguard Worker@compatibility(is_backward_compatible=False)
36*523fa7a6SAndroid Build Coastguard Worker@dataclass
37*523fa7a6SAndroid Build Coastguard Workerclass EdgeCompileConfig:
38*523fa7a6SAndroid Build Coastguard Worker    # TODO(qihan): remove ability to opt out
39*523fa7a6SAndroid Build Coastguard Worker    _check_ir_validity: bool = True
40*523fa7a6SAndroid Build Coastguard Worker    # TODO(larryliu): remove this
41*523fa7a6SAndroid Build Coastguard Worker    _use_edge_ops: bool = True
42*523fa7a6SAndroid Build Coastguard Worker    # Allow core ATen ops check to be skipped for certain ops, but continue with the rest of the checks.
43*523fa7a6SAndroid Build Coastguard Worker    _core_aten_ops_exception_list: List[torch._ops.OpOverload] = field(
44*523fa7a6SAndroid Build Coastguard Worker        default_factory=list
45*523fa7a6SAndroid Build Coastguard Worker    )
46*523fa7a6SAndroid Build Coastguard Worker    _skip_type_promotion: bool = False
47*523fa7a6SAndroid Build Coastguard Worker    # TODO(gasoonjia): remove this
48*523fa7a6SAndroid Build Coastguard Worker    # TODO(T192537614): reenanle dim order as default
49*523fa7a6SAndroid Build Coastguard Worker    _skip_dim_order: bool = True
50*523fa7a6SAndroid Build Coastguard Worker
51*523fa7a6SAndroid Build Coastguard Worker
52*523fa7a6SAndroid Build Coastguard Worker@compatibility(is_backward_compatible=False)
53*523fa7a6SAndroid Build Coastguard Worker@dataclass
54*523fa7a6SAndroid Build Coastguard Workerclass ExecutorchBackendConfig:
55*523fa7a6SAndroid Build Coastguard Worker    passes: List[PassType] = field(default_factory=list)
56*523fa7a6SAndroid Build Coastguard Worker
57*523fa7a6SAndroid Build Coastguard Worker    # A single memory planning pass can be defined for all the programs in the
58*523fa7a6SAndroid Build Coastguard Worker    # EdgeProgramManager or can be defined per program.
59*523fa7a6SAndroid Build Coastguard Worker    memory_planning_pass: Union[PassType, Dict[str, PassType]] = MemoryPlanningPass()
60*523fa7a6SAndroid Build Coastguard Worker    to_out_var_pass: PassType = ToOutVarPass(ignore_to_out_var_failure=False)
61*523fa7a6SAndroid Build Coastguard Worker    dynamic_memory_planning_mode: DynamicMemoryPlanningMode = (
62*523fa7a6SAndroid Build Coastguard Worker        DynamicMemoryPlanningMode.UPPER_BOUND
63*523fa7a6SAndroid Build Coastguard Worker    )
64*523fa7a6SAndroid Build Coastguard Worker    emit_stacktrace: bool = False
65*523fa7a6SAndroid Build Coastguard Worker
66*523fa7a6SAndroid Build Coastguard Worker    # Whether to move delegate data blobs from the Program into separate
67*523fa7a6SAndroid Build Coastguard Worker    # segments, rather than encoding those blobs in the flatbuffer data.
68*523fa7a6SAndroid Build Coastguard Worker    # This makes it possible to free those blobs at runtime.
69*523fa7a6SAndroid Build Coastguard Worker    extract_delegate_segments: bool = True
70*523fa7a6SAndroid Build Coastguard Worker
71*523fa7a6SAndroid Build Coastguard Worker    # When extracting segments, the starting offset of each segment will be
72*523fa7a6SAndroid Build Coastguard Worker    # aligned to this value (in bytes). Must be a power of two.
73*523fa7a6SAndroid Build Coastguard Worker    segment_alignment: int = 128
74*523fa7a6SAndroid Build Coastguard Worker
75*523fa7a6SAndroid Build Coastguard Worker    # If provided, the minimum alignment of tensor buffers in the program. Must
76*523fa7a6SAndroid Build Coastguard Worker    # be a power of 2. If not provided, uses the value in the schema file.
77*523fa7a6SAndroid Build Coastguard Worker    constant_tensor_alignment: Optional[int] = None
78*523fa7a6SAndroid Build Coastguard Worker
79*523fa7a6SAndroid Build Coastguard Worker    # If provided, the minimum alignment of delegate data in the program. Must
80*523fa7a6SAndroid Build Coastguard Worker    # be a power of 2. If not provided, uses the value in the schema file.
81*523fa7a6SAndroid Build Coastguard Worker    delegate_alignment: Optional[int] = None
82*523fa7a6SAndroid Build Coastguard Worker
83*523fa7a6SAndroid Build Coastguard Worker    # A single sym shape eval pass can be defined for all the programs in the
84*523fa7a6SAndroid Build Coastguard Worker    # EdgeProgramManager or can be defined per program.
85*523fa7a6SAndroid Build Coastguard Worker    sym_shape_eval_pass: Union[PassType, Dict[str, PassType]] = (
86*523fa7a6SAndroid Build Coastguard Worker        ConstraintBasedSymShapeEvalPass()
87*523fa7a6SAndroid Build Coastguard Worker    )
88*523fa7a6SAndroid Build Coastguard Worker
89*523fa7a6SAndroid Build Coastguard Worker    # If set to true, view_copy operations will be converted to lightweight
90*523fa7a6SAndroid Build Coastguard Worker    # view operations in the ET runtime
91*523fa7a6SAndroid Build Coastguard Worker    remove_view_copy: bool = True
92