executorch 1.6.0__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- executorch/backends/__init__.py +0 -0
- executorch/backends/aoti/aoti_backend.py +493 -0
- executorch/backends/aoti/aoti_partitioner.py +141 -0
- executorch/backends/aoti/passes/replace_view_copy_with_view.py +137 -0
- executorch/backends/apple/__init__.py +0 -0
- executorch/backends/apple/coreai/__init__.py +52 -0
- executorch/backends/apple/coreai/compiler/__init__.py +5 -0
- executorch/backends/apple/coreai/compiler/constants.py +12 -0
- executorch/backends/apple/coreai/compiler/enumerated_shapes.py +246 -0
- executorch/backends/apple/coreai/compiler/io_compat.py +258 -0
- executorch/backends/apple/coreai/compiler/preprocess.py +550 -0
- executorch/backends/apple/coreai/palettizer/__init__.py +11 -0
- executorch/backends/apple/coreai/palettizer/palettizer.py +115 -0
- executorch/backends/apple/coreai/partition/__init__.py +5 -0
- executorch/backends/apple/coreai/partition/partitioner.py +324 -0
- executorch/backends/apple/coreai/passes/__init__.py +11 -0
- executorch/backends/apple/coreai/passes/narrow_dtypes.py +105 -0
- executorch/backends/apple/coreai/passes/replace_copy_ops.py +66 -0
- executorch/backends/apple/coreai/passes/test/__init__.py +5 -0
- executorch/backends/apple/coreai/quantizer/__init__.py +11 -0
- executorch/backends/apple/coreai/quantizer/quantizer.py +92 -0
- executorch/backends/apple/coreai/recipes/__init__.py +18 -0
- executorch/backends/apple/coreai/recipes/recipe_provider.py +97 -0
- executorch/backends/apple/coreai/recipes/recipe_types.py +26 -0
- executorch/backends/apple/coreai/test/__init__.py +5 -0
- executorch/backends/apple/coreml/compiler/__init__.py +9 -0
- executorch/backends/apple/coreml/compiler/coreml_preprocess.py +993 -0
- executorch/backends/apple/coreml/compiler/enumerated_shape_utils.py +244 -0
- executorch/backends/apple/coreml/compiler/torch_ops.py +240 -0
- executorch/backends/apple/coreml/executorchcoreml.pyi +10 -0
- executorch/backends/apple/coreml/logging.py +24 -0
- executorch/backends/apple/coreml/partition/__init__.py +9 -0
- executorch/backends/apple/coreml/partition/coreml_partitioner.py +477 -0
- executorch/backends/apple/coreml/quantizer/__init__.py +9 -0
- executorch/backends/apple/coreml/quantizer/_annotation_config.py +130 -0
- executorch/backends/apple/coreml/quantizer/_coreml_quantizer.py +628 -0
- executorch/backends/apple/coreml/quantizer/_coreml_quantizer_utils.py +800 -0
- executorch/backends/apple/coreml/quantizer/coreml_quantizer.py +7 -0
- executorch/backends/apple/coreml/recipes/__init__.py +17 -0
- executorch/backends/apple/coreml/recipes/coreml_recipe_provider.py +413 -0
- executorch/backends/apple/coreml/recipes/coreml_recipe_types.py +53 -0
- executorch/backends/apple/coreml/test/test_coreml_utils.py +19 -0
- executorch/backends/apple/coreml/test/tester.py +121 -0
- executorch/backends/apple/metal/metal_backend.py +127 -0
- executorch/backends/apple/metal/metal_partitioner.py +25 -0
- executorch/backends/apple/metal/ops/__init__.py +5 -0
- executorch/backends/apple/metal/ops/gated_delta_rule.py +92 -0
- executorch/backends/apple/metal/ops/gather_qmv.py +117 -0
- executorch/backends/apple/metal/passes/__init__.py +11 -0
- executorch/backends/apple/metal/passes/decompose_linear_pass.py +115 -0
- executorch/backends/apple/metal/tests/__init__.py +5 -0
- executorch/backends/arm/__init__.py +59 -0
- executorch/backends/arm/_passes/__init__.py +251 -0
- executorch/backends/arm/_passes/_debug_passes.py +59 -0
- executorch/backends/arm/_passes/accumulate_index_put_pass.py +65 -0
- executorch/backends/arm/_passes/arm_pass.py +305 -0
- executorch/backends/arm/_passes/arm_pass_manager.py +891 -0
- executorch/backends/arm/_passes/arm_pass_utils.py +830 -0
- executorch/backends/arm/_passes/aten_to_tosa_activation_functions.py +148 -0
- executorch/backends/arm/_passes/aten_to_tosa_comparison.py +27 -0
- executorch/backends/arm/_passes/aten_to_tosa_data_layout.py +98 -0
- executorch/backends/arm/_passes/aten_to_tosa_reduction.py +110 -0
- executorch/backends/arm/_passes/aten_to_tosa_tensor_operators.py +112 -0
- executorch/backends/arm/_passes/aten_to_tosa_ternary.py +25 -0
- executorch/backends/arm/_passes/broadcast_args_pass.py +90 -0
- executorch/backends/arm/_passes/canonicalize_gather_pass.py +203 -0
- executorch/backends/arm/_passes/canonicalize_view_copy_permute_pass.py +22 -0
- executorch/backends/arm/_passes/cast_int64_pass.py +100 -0
- executorch/backends/arm/_passes/cast_int_comparison_inputs_pass.py +61 -0
- executorch/backends/arm/_passes/cast_to_int32_pass.py +69 -0
- executorch/backends/arm/_passes/constant_folding_pass.py +70 -0
- executorch/backends/arm/_passes/control_flow_const_inline.py +78 -0
- executorch/backends/arm/_passes/convert_bool_sum_pass.py +81 -0
- executorch/backends/arm/_passes/convert_elu_params.py +88 -0
- executorch/backends/arm/_passes/convert_expand_copy_to_repeat.py +91 -0
- executorch/backends/arm/_passes/convert_full_like_to_full_pass.py +51 -0
- executorch/backends/arm/_passes/convert_int64_const_ops_to_int32.py +85 -0
- executorch/backends/arm/_passes/convert_int64_output_ops_to_int32.py +512 -0
- executorch/backends/arm/_passes/convert_minmax_pass.py +166 -0
- executorch/backends/arm/_passes/convert_split_to_slice.py +134 -0
- executorch/backends/arm/_passes/convert_squeezes_to_view.py +41 -0
- executorch/backends/arm/_passes/convert_to_clamp_pass.py +47 -0
- executorch/backends/arm/_passes/decompose_acosh_pass.py +75 -0
- executorch/backends/arm/_passes/decompose_adaptive_avg_pool2d_pass.py +457 -0
- executorch/backends/arm/_passes/decompose_adaptive_max_pool2d_pass.py +202 -0
- executorch/backends/arm/_passes/decompose_add_sub_alpha_pass.py +102 -0
- executorch/backends/arm/_passes/decompose_addmm_pass.py +75 -0
- executorch/backends/arm/_passes/decompose_any_pass.py +117 -0
- executorch/backends/arm/_passes/decompose_as_strided_copy_pass.py +116 -0
- executorch/backends/arm/_passes/decompose_asin_and_acos_pass.py +233 -0
- executorch/backends/arm/_passes/decompose_asinh_pass.py +72 -0
- executorch/backends/arm/_passes/decompose_atan_pass.py +149 -0
- executorch/backends/arm/_passes/decompose_atanh_pass.py +84 -0
- executorch/backends/arm/_passes/decompose_avg_pool2d_pass.py +178 -0
- executorch/backends/arm/_passes/decompose_batch_norm_no_stats.py +259 -0
- executorch/backends/arm/_passes/decompose_bool_equality_pass.py +31 -0
- executorch/backends/arm/_passes/decompose_choose_qparams_symmetric_pass.py +285 -0
- executorch/backends/arm/_passes/decompose_cosh_pass.py +69 -0
- executorch/backends/arm/_passes/decompose_cosine_similarity_pass.py +98 -0
- executorch/backends/arm/_passes/decompose_cumsum_pass.py +167 -0
- executorch/backends/arm/_passes/decompose_div_pass.py +59 -0
- executorch/backends/arm/_passes/decompose_div_tensor_mode.py +283 -0
- executorch/backends/arm/_passes/decompose_dynamic_adaptive_avg_pool2d_pass.py +57 -0
- executorch/backends/arm/_passes/decompose_dynamic_full_pass.py +56 -0
- executorch/backends/arm/_passes/decompose_einsum_pass.py +66 -0
- executorch/backends/arm/_passes/decompose_elu_pass.py +187 -0
- executorch/backends/arm/_passes/decompose_embedding_pass.py +132 -0
- executorch/backends/arm/_passes/decompose_erfinv_pass.py +374 -0
- executorch/backends/arm/_passes/decompose_expm1_pass.py +160 -0
- executorch/backends/arm/_passes/decompose_flip_pass.py +35 -0
- executorch/backends/arm/_passes/decompose_floor_divide_pass.py +76 -0
- executorch/backends/arm/_passes/decompose_gelu_pass.py +144 -0
- executorch/backends/arm/_passes/decompose_glu_pass.py +84 -0
- executorch/backends/arm/_passes/decompose_grouped_conv_pass.py +319 -0
- executorch/backends/arm/_passes/decompose_groupnorm_pass.py +223 -0
- executorch/backends/arm/_passes/decompose_gru_pass.py +337 -0
- executorch/backends/arm/_passes/decompose_index_copy_pass.py +33 -0
- executorch/backends/arm/_passes/decompose_index_select_to_gather_pass.py +237 -0
- executorch/backends/arm/_passes/decompose_index_tensor_to_gather_pass.py +553 -0
- executorch/backends/arm/_passes/decompose_int_pow_pass.py +87 -0
- executorch/backends/arm/_passes/decompose_isinf_isnan_pass.py +48 -0
- executorch/backends/arm/_passes/decompose_large_stride_maxpool2d_pass.py +207 -0
- executorch/backends/arm/_passes/decompose_layernorm_pass.py +214 -0
- executorch/backends/arm/_passes/decompose_leaky_relu_pass.py +80 -0
- executorch/backends/arm/_passes/decompose_linalg_vector_norm_pass.py +93 -0
- executorch/backends/arm/_passes/decompose_linear_pass.py +147 -0
- executorch/backends/arm/_passes/decompose_log1p_pass.py +110 -0
- executorch/backends/arm/_passes/decompose_logit_pass.py +119 -0
- executorch/backends/arm/_passes/decompose_lstm_pass.py +466 -0
- executorch/backends/arm/_passes/decompose_masked_fill_pass.py +60 -0
- executorch/backends/arm/_passes/decompose_matmul.py +47 -0
- executorch/backends/arm/_passes/decompose_max_pool1d_pass.py +106 -0
- executorch/backends/arm/_passes/decompose_maxpool2d_with_dilation_pass.py +241 -0
- executorch/backends/arm/_passes/decompose_meandim_pass.py +263 -0
- executorch/backends/arm/_passes/decompose_ne_pass.py +75 -0
- executorch/backends/arm/_passes/decompose_permute_for_u55_pass.py +370 -0
- executorch/backends/arm/_passes/decompose_pow_tensor_tensor_pass.py +186 -0
- executorch/backends/arm/_passes/decompose_prelu_pass.py +107 -0
- executorch/backends/arm/_passes/decompose_prod_pass.py +50 -0
- executorch/backends/arm/_passes/decompose_quant_nodes.py +184 -0
- executorch/backends/arm/_passes/decompose_remainder_pass.py +74 -0
- executorch/backends/arm/_passes/decompose_rnn_pass.py +300 -0
- executorch/backends/arm/_passes/decompose_roll_pass.py +131 -0
- executorch/backends/arm/_passes/decompose_round_pass.py +67 -0
- executorch/backends/arm/_passes/decompose_sdpa_pass.py +41 -0
- executorch/backends/arm/_passes/decompose_sdpa_with_regular_softmax_pass.py +111 -0
- executorch/backends/arm/_passes/decompose_select.py +88 -0
- executorch/backends/arm/_passes/decompose_select_scatter_pass.py +146 -0
- executorch/backends/arm/_passes/decompose_sign_pass.py +83 -0
- executorch/backends/arm/_passes/decompose_sinh_pass.py +74 -0
- executorch/backends/arm/_passes/decompose_slice_scatter_pass.py +201 -0
- executorch/backends/arm/_passes/decompose_softmax_pass.py +126 -0
- executorch/backends/arm/_passes/decompose_sqrt_pass.py +46 -0
- executorch/backends/arm/_passes/decompose_strided_slice_copy_pass.py +147 -0
- executorch/backends/arm/_passes/decompose_sum_pass.py +94 -0
- executorch/backends/arm/_passes/decompose_tan_pass.py +44 -0
- executorch/backends/arm/_passes/decompose_topk_pass.py +320 -0
- executorch/backends/arm/_passes/decompose_tosa_unsupported_clamp_pass.py +99 -0
- executorch/backends/arm/_passes/decompose_tril_pass.py +112 -0
- executorch/backends/arm/_passes/decompose_unfold_to_gather_pass.py +417 -0
- executorch/backends/arm/_passes/decompose_unsupported_bilinear_resize_pass.py +159 -0
- executorch/backends/arm/_passes/decompose_var_pass.py +107 -0
- executorch/backends/arm/_passes/decompose_where_scalar_other_pass.py +62 -0
- executorch/backends/arm/_passes/decorate_fp32_to_int32_casting_pass.py +90 -0
- executorch/backends/arm/_passes/deduplicate_const_shapes_pass.py +47 -0
- executorch/backends/arm/_passes/deduplicate_get_attr_pass.py +96 -0
- executorch/backends/arm/_passes/detect_dynamic_w8a8_linear_pass.py +588 -0
- executorch/backends/arm/_passes/ensure_unique_output_nodes_pass.py +82 -0
- executorch/backends/arm/_passes/exir_to_tosa_pass.py +176 -0
- executorch/backends/arm/_passes/fold_dyt_affine_into_conv_pass.py +890 -0
- executorch/backends/arm/_passes/fold_dyt_alpha_into_lut_pass.py +379 -0
- executorch/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py +521 -0
- executorch/backends/arm/_passes/fold_scalar_mul_into_conv_pass.py +335 -0
- executorch/backends/arm/_passes/fuse_batch_norm2d_pass.py +341 -0
- executorch/backends/arm/_passes/fuse_consecutive_clamps_pass.py +185 -0
- executorch/backends/arm/_passes/fuse_consecutive_concat_shapes.py +64 -0
- executorch/backends/arm/_passes/fuse_consecutive_concats_pass.py +107 -0
- executorch/backends/arm/_passes/fuse_consecutive_rescales_pass.py +175 -0
- executorch/backends/arm/_passes/fuse_consecutive_slices_pass.py +112 -0
- executorch/backends/arm/_passes/fuse_constant_ops_pass.py +374 -0
- executorch/backends/arm/_passes/fuse_duplicate_users_pass.py +27 -0
- executorch/backends/arm/_passes/fuse_equal_placeholders_pass.py +137 -0
- executorch/backends/arm/_passes/fuse_identical_input_transforms_pass.py +28 -0
- executorch/backends/arm/_passes/fuse_quantized_activation_pass.py +93 -0
- executorch/backends/arm/_passes/fuse_view_copy_transform_pass.py +14 -0
- executorch/backends/arm/_passes/get_decomposition_pass.py +149 -0
- executorch/backends/arm/_passes/insert_const_shapes.py +78 -0
- executorch/backends/arm/_passes/insert_data_layout_casts_pass.py +134 -0
- executorch/backends/arm/_passes/insert_dynamic_padding.py +77 -0
- executorch/backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py +133 -0
- executorch/backends/arm/_passes/insert_rescales_pass.py +682 -0
- executorch/backends/arm/_passes/insert_table_ops.py +430 -0
- executorch/backends/arm/_passes/int32_range_analysis.py +455 -0
- executorch/backends/arm/_passes/lower_dynamic_w8a8_linear_pass.py +353 -0
- executorch/backends/arm/_passes/match_arg_dtype_pass.py +105 -0
- executorch/backends/arm/_passes/match_arg_ranks_pass.py +133 -0
- executorch/backends/arm/_passes/mm_to_bmm_pass.py +114 -0
- executorch/backends/arm/_passes/move_data_movement_ops_to_smaller_dtype_pass.py +158 -0
- executorch/backends/arm/_passes/mutable_buffer_utils.py +231 -0
- executorch/backends/arm/_passes/normalize_delegate_io_layout_pass.py +138 -0
- executorch/backends/arm/_passes/normalize_index_put_bool_index_tensor_pass.py +102 -0
- executorch/backends/arm/_passes/normalize_index_put_none_indices_pass.py +144 -0
- executorch/backends/arm/_passes/normalize_max_pool2d_input_rank_pass.py +97 -0
- executorch/backends/arm/_passes/normalize_while_initial_args_pass.py +115 -0
- executorch/backends/arm/_passes/prepare_gather_indices_pass.py +174 -0
- executorch/backends/arm/_passes/promote_bool_operands_pass.py +84 -0
- executorch/backends/arm/_passes/propagate_view_copy_permute_pass.py +152 -0
- executorch/backends/arm/_passes/quant_args.py +131 -0
- executorch/backends/arm/_passes/remove_getitem_pass.py +25 -0
- executorch/backends/arm/_passes/remove_graph_asserts_pass.py +18 -0
- executorch/backends/arm/_passes/remove_noop_pass.py +260 -0
- executorch/backends/arm/_passes/remove_permutes_around_elementwise_tosa_ops.py +54 -0
- executorch/backends/arm/_passes/remove_redundant_type_as_pass.py +53 -0
- executorch/backends/arm/_passes/remove_safe_softmax_guard_pass.py +173 -0
- executorch/backends/arm/_passes/replace_inf_and_limit_values_pass.py +81 -0
- executorch/backends/arm/_passes/replace_scalar_with_tensor_pass.py +150 -0
- executorch/backends/arm/_passes/resolve_view_copy_inferred_dim_pass.py +76 -0
- executorch/backends/arm/_passes/rewrite_adaptive_avg_pool2d.py +170 -0
- executorch/backends/arm/_passes/rewrite_avg_pool2d_pass.py +106 -0
- executorch/backends/arm/_passes/rewrite_bool_bitwise_to_logical_pass.py +50 -0
- executorch/backends/arm/_passes/rewrite_bool_to_fp32_cast_via_int8_pass.py +77 -0
- executorch/backends/arm/_passes/rewrite_cat_slice_pass.py +304 -0
- executorch/backends/arm/_passes/rewrite_conv_pass.py +1285 -0
- executorch/backends/arm/_passes/rewrite_high_rank_singleton_permute_pass.py +114 -0
- executorch/backends/arm/_passes/rewrite_index_put_pass.py +198 -0
- executorch/backends/arm/_passes/rewrite_inplace_arithmetic_pass.py +41 -0
- executorch/backends/arm/_passes/rewrite_le_lt_to_ge_gt_pass.py +44 -0
- executorch/backends/arm/_passes/rewrite_matmul.py +125 -0
- executorch/backends/arm/_passes/rewrite_max_pool2d_pass.py +187 -0
- executorch/backends/arm/_passes/rewrite_mxfp_conv2d.py +407 -0
- executorch/backends/arm/_passes/rewrite_mxfp_linear.py +390 -0
- executorch/backends/arm/_passes/rewrite_pad.py +213 -0
- executorch/backends/arm/_passes/rewrite_slice.py +114 -0
- executorch/backends/arm/_passes/rewrite_upsample.py +306 -0
- executorch/backends/arm/_passes/scalars_to_attribute_pass.py +144 -0
- executorch/backends/arm/_passes/size_adjust_input_pass.py +409 -0
- executorch/backends/arm/_passes/symbolic_materialization_helper.py +109 -0
- executorch/backends/arm/_passes/symbolic_shape_utils.py +27 -0
- executorch/backends/arm/_passes/symbolic_to_tosa_shape_pass.py +239 -0
- executorch/backends/arm/_passes/symbolic_value_range.py +196 -0
- executorch/backends/arm/_passes/unsqueeze_before_repeat_pass.py +66 -0
- executorch/backends/arm/_passes/unsqueeze_scalar_placeholders_pass.py +101 -0
- executorch/backends/arm/ao_ext/__init__.py +12 -0
- executorch/backends/arm/ao_ext/mxfp.py +137 -0
- executorch/backends/arm/ao_ext/mxfp_tosa_lib.py +12 -0
- executorch/backends/arm/ao_ext/mxfp_transform.py +27 -0
- executorch/backends/arm/ao_ext/ops/__init__.py +12 -0
- executorch/backends/arm/ao_ext/ops/mxfp_conv2d_op.py +325 -0
- executorch/backends/arm/ao_ext/ops/mxfp_linear_op.py +236 -0
- executorch/backends/arm/arm_vela.py +331 -0
- executorch/backends/arm/cmsis_pack/scripts/generate_components.py +487 -0
- executorch/backends/arm/cmsis_pack/scripts/generate_register_all_kernels.py +485 -0
- executorch/backends/arm/cmsis_pack/scripts/op_guards.py +144 -0
- executorch/backends/arm/common/__init__.py +4 -0
- executorch/backends/arm/common/annotation_meta.py +39 -0
- executorch/backends/arm/common/arm_compile_spec.py +335 -0
- executorch/backends/arm/common/as_strided_utils.py +72 -0
- executorch/backends/arm/common/debug.py +79 -0
- executorch/backends/arm/common/pipeline_config.py +138 -0
- executorch/backends/arm/common/type.py +28 -0
- executorch/backends/arm/constants.py +54 -0
- executorch/backends/arm/debug/__init__.py +4 -0
- executorch/backends/arm/debug/schema.py +145 -0
- executorch/backends/arm/ethosu/__init__.py +16 -0
- executorch/backends/arm/ethosu/backend.py +150 -0
- executorch/backends/arm/ethosu/compile_spec.py +281 -0
- executorch/backends/arm/ethosu/partitioner.py +40 -0
- executorch/backends/arm/operator_support/__init__.py +32 -0
- executorch/backends/arm/operator_support/as_strided_copy_support.py +113 -0
- executorch/backends/arm/operator_support/bool_bitwise_support.py +45 -0
- executorch/backends/arm/operator_support/clone_dim_order_support.py +77 -0
- executorch/backends/arm/operator_support/control_flow_support.py +197 -0
- executorch/backends/arm/operator_support/convolution_support.py +326 -0
- executorch/backends/arm/operator_support/embedding_support.py +56 -0
- executorch/backends/arm/operator_support/ethos_u55_support.py +588 -0
- executorch/backends/arm/operator_support/gather_support.py +172 -0
- executorch/backends/arm/operator_support/index_put_support.py +86 -0
- executorch/backends/arm/operator_support/index_select_support.py +128 -0
- executorch/backends/arm/operator_support/index_tensor_support.py +235 -0
- executorch/backends/arm/operator_support/minmax_support.py +59 -0
- executorch/backends/arm/operator_support/pool_2d_support.py +289 -0
- executorch/backends/arm/operator_support/reduce_sum_support.py +71 -0
- executorch/backends/arm/operator_support/right_shift_support.py +47 -0
- executorch/backends/arm/operator_support/roll_support.py +59 -0
- executorch/backends/arm/operator_support/slice_copy_support.py +148 -0
- executorch/backends/arm/operator_support/symint_arithmetic_support.py +44 -0
- executorch/backends/arm/operator_support/to_dim_order_copy_support.py +124 -0
- executorch/backends/arm/operator_support/topk_support.py +40 -0
- executorch/backends/arm/operator_support/tosa_profile_supported_op_lists.py +373 -0
- executorch/backends/arm/operator_support/tosa_supported_operators.py +1738 -0
- executorch/backends/arm/operator_support/unfold_copy_support.py +146 -0
- executorch/backends/arm/operator_support/upsample_support.py +124 -0
- executorch/backends/arm/operator_support/where_support.py +76 -0
- executorch/backends/arm/operators/__init__.py +81 -0
- executorch/backends/arm/operators/node_visitor.py +259 -0
- executorch/backends/arm/operators/op_cond_if.py +67 -0
- executorch/backends/arm/operators/op_flip.py +76 -0
- executorch/backends/arm/operators/op_to_dim_order_copy.py +47 -0
- executorch/backends/arm/operators/op_tosa_abs.py +26 -0
- executorch/backends/arm/operators/op_tosa_add.py +26 -0
- executorch/backends/arm/operators/op_tosa_argmax.py +62 -0
- executorch/backends/arm/operators/op_tosa_avg_pool2d.py +73 -0
- executorch/backends/arm/operators/op_tosa_avg_pool2d_adaptive.py +69 -0
- executorch/backends/arm/operators/op_tosa_binary_ops.py +93 -0
- executorch/backends/arm/operators/op_tosa_bitwise_not.py +30 -0
- executorch/backends/arm/operators/op_tosa_cast_to_block_scaled.py +140 -0
- executorch/backends/arm/operators/op_tosa_ceil.py +30 -0
- executorch/backends/arm/operators/op_tosa_clamp.py +70 -0
- executorch/backends/arm/operators/op_tosa_clz.py +30 -0
- executorch/backends/arm/operators/op_tosa_concat.py +60 -0
- executorch/backends/arm/operators/op_tosa_conv2d.py +127 -0
- executorch/backends/arm/operators/op_tosa_conv2d_block_scaled.py +111 -0
- executorch/backends/arm/operators/op_tosa_conv3d.py +23 -0
- executorch/backends/arm/operators/op_tosa_cos.py +30 -0
- executorch/backends/arm/operators/op_tosa_custom.py +186 -0
- executorch/backends/arm/operators/op_tosa_depthwise_conv2d.py +25 -0
- executorch/backends/arm/operators/op_tosa_eq.py +29 -0
- executorch/backends/arm/operators/op_tosa_erf.py +30 -0
- executorch/backends/arm/operators/op_tosa_exp.py +30 -0
- executorch/backends/arm/operators/op_tosa_fft.py +76 -0
- executorch/backends/arm/operators/op_tosa_floor.py +30 -0
- executorch/backends/arm/operators/op_tosa_gather.py +72 -0
- executorch/backends/arm/operators/op_tosa_ge.py +31 -0
- executorch/backends/arm/operators/op_tosa_gt.py +31 -0
- executorch/backends/arm/operators/op_tosa_identity.py +38 -0
- executorch/backends/arm/operators/op_tosa_log.py +30 -0
- executorch/backends/arm/operators/op_tosa_logical_not.py +26 -0
- executorch/backends/arm/operators/op_tosa_matmul.py +108 -0
- executorch/backends/arm/operators/op_tosa_matmul_t_block_scaled.py +97 -0
- executorch/backends/arm/operators/op_tosa_max_pool2d.py +70 -0
- executorch/backends/arm/operators/op_tosa_max_pool2d_adaptive.py +58 -0
- executorch/backends/arm/operators/op_tosa_maximum.py +27 -0
- executorch/backends/arm/operators/op_tosa_minimum.py +27 -0
- executorch/backends/arm/operators/op_tosa_mul.py +59 -0
- executorch/backends/arm/operators/op_tosa_neg.py +79 -0
- executorch/backends/arm/operators/op_tosa_pad.py +68 -0
- executorch/backends/arm/operators/op_tosa_pow.py +30 -0
- executorch/backends/arm/operators/op_tosa_reciprocal.py +30 -0
- executorch/backends/arm/operators/op_tosa_reduce_all.py +47 -0
- executorch/backends/arm/operators/op_tosa_reduce_any.py +49 -0
- executorch/backends/arm/operators/op_tosa_reduce_max.py +68 -0
- executorch/backends/arm/operators/op_tosa_reduce_min.py +68 -0
- executorch/backends/arm/operators/op_tosa_reduce_product.py +51 -0
- executorch/backends/arm/operators/op_tosa_reduce_sum.py +55 -0
- executorch/backends/arm/operators/op_tosa_rescale.py +304 -0
- executorch/backends/arm/operators/op_tosa_reshape.py +59 -0
- executorch/backends/arm/operators/op_tosa_resize.py +57 -0
- executorch/backends/arm/operators/op_tosa_reverse.py +54 -0
- executorch/backends/arm/operators/op_tosa_rshift_tensor.py +56 -0
- executorch/backends/arm/operators/op_tosa_rsqrt.py +30 -0
- executorch/backends/arm/operators/op_tosa_scatter.py +59 -0
- executorch/backends/arm/operators/op_tosa_shapes.py +260 -0
- executorch/backends/arm/operators/op_tosa_sigmoid.py +30 -0
- executorch/backends/arm/operators/op_tosa_sin.py +30 -0
- executorch/backends/arm/operators/op_tosa_slice.py +56 -0
- executorch/backends/arm/operators/op_tosa_sub.py +26 -0
- executorch/backends/arm/operators/op_tosa_table.py +64 -0
- executorch/backends/arm/operators/op_tosa_tanh.py +30 -0
- executorch/backends/arm/operators/op_tosa_tile.py +55 -0
- executorch/backends/arm/operators/op_tosa_transpose.py +58 -0
- executorch/backends/arm/operators/op_tosa_transpose_conv2d.py +123 -0
- executorch/backends/arm/operators/op_where.py +68 -0
- executorch/backends/arm/operators/op_while.py +105 -0
- executorch/backends/arm/operators/operator_validation_utils.py +239 -0
- executorch/backends/arm/operators/ops_quant_utils.py +35 -0
- executorch/backends/arm/operators/simple_node_visitor.py +70 -0
- executorch/backends/arm/process_node.py +427 -0
- executorch/backends/arm/quantizer/__init__.py +38 -0
- executorch/backends/arm/quantizer/arm_quantizer.py +1545 -0
- executorch/backends/arm/quantizer/arm_quantizer_utils.py +806 -0
- executorch/backends/arm/quantizer/quantization_annotator.py +1072 -0
- executorch/backends/arm/quantizer/quantization_config.py +600 -0
- executorch/backends/arm/quantizer/quantizer_support.py +283 -0
- executorch/backends/arm/recipes/__init__.py +15 -0
- executorch/backends/arm/recipes/arm_recipe_provider.py +287 -0
- executorch/backends/arm/recipes/arm_recipe_types.py +52 -0
- executorch/backends/arm/scripts/aot_arm_compiler.py +1193 -0
- executorch/backends/arm/scripts/check_model_support.py +467 -0
- executorch/backends/arm/scripts/docgen/__init__.py +4 -0
- executorch/backends/arm/scripts/docgen/docgen.py +276 -0
- executorch/backends/arm/scripts/docgen/generate_op_support.py +3269 -0
- executorch/backends/arm/scripts/etdump_to_chrome_trace.py +109 -0
- executorch/backends/arm/scripts/evaluate_model.py +402 -0
- executorch/backends/arm/scripts/examples/fast_model_support_demo.py +26 -0
- executorch/backends/arm/scripts/generate_grid_sampler_spirv.py +81 -0
- executorch/backends/arm/scripts/generate_neural_graphics_test_data.py +738 -0
- executorch/backends/arm/scripts/get_ethosu_scratch_from_pte.py +77 -0
- executorch/backends/arm/scripts/neural_graphics_test_data.py +490 -0
- executorch/backends/arm/scripts/public_api_manifest/__init__.py +4 -0
- executorch/backends/arm/scripts/public_api_manifest/generate_public_api_manifest.py +209 -0
- executorch/backends/arm/scripts/public_api_manifest/validate_public_api_manifest.py +410 -0
- executorch/backends/arm/test/_custom_vgf_test_utils.py +999 -0
- executorch/backends/arm/test/common.py +487 -0
- executorch/backends/arm/test/conftest.py +265 -0
- executorch/backends/arm/test/misc/test_dw_convs_with_shared_weights.py +46 -0
- executorch/backends/arm/test/models/DeepSeek_R1_Distill_Qwen/deepseek_r1_distill_qwen_test_config.py +42 -0
- executorch/backends/arm/test/models/Gemma3n/gemma3n_test_config.py +37 -0
- executorch/backends/arm/test/models/Qwen3_VL/qwen3_vl_test_config.py +64 -0
- executorch/backends/arm/test/models/model_test_utils.py +73 -0
- executorch/backends/arm/test/models/phi3/phi3_module_test_configs.py +24 -0
- executorch/backends/arm/test/models/stable_diffusion/stable_diffusion_module_test_configs.py +113 -0
- executorch/backends/arm/test/models/stable_diffusion_3_5_large/test_configs_sd35_large.py +311 -0
- executorch/backends/arm/test/ops/mxfp/__init__.py +4 -0
- executorch/backends/arm/test/ops/mxfp/common.py +122 -0
- executorch/backends/arm/test/ops/test_conv1d.py +500 -0
- executorch/backends/arm/test/ops/test_conv2d.py +873 -0
- executorch/backends/arm/test/runner_utils.py +1332 -0
- executorch/backends/arm/test/runtime/_vgf_runtime_test_utils.py +364 -0
- executorch/backends/arm/test/tester/__init__.py +6 -0
- executorch/backends/arm/test/tester/analyze_output_utils.py +478 -0
- executorch/backends/arm/test/tester/arm_tester.py +1409 -0
- executorch/backends/arm/test/tester/pte_diff_utils.py +421 -0
- executorch/backends/arm/test/tester/quantize.py +67 -0
- executorch/backends/arm/test/tester/serialize.py +96 -0
- executorch/backends/arm/test/tester/test_pipeline.py +1539 -0
- executorch/backends/arm/tosa/__init__.py +16 -0
- executorch/backends/arm/tosa/backend.py +424 -0
- executorch/backends/arm/tosa/cast_support.py +175 -0
- executorch/backends/arm/tosa/compile_spec.py +35 -0
- executorch/backends/arm/tosa/constant_pool.py +59 -0
- executorch/backends/arm/tosa/dialect/__init__.py +35 -0
- executorch/backends/arm/tosa/dialect/lib.py +83 -0
- executorch/backends/arm/tosa/dialect/ops/_common.py +134 -0
- executorch/backends/arm/tosa/dialect/ops/activation.py +118 -0
- executorch/backends/arm/tosa/dialect/ops/argmax.py +65 -0
- executorch/backends/arm/tosa/dialect/ops/avg_pool2d.py +133 -0
- executorch/backends/arm/tosa/dialect/ops/avg_pool2d_adaptive.py +82 -0
- executorch/backends/arm/tosa/dialect/ops/binary_elementwise.py +296 -0
- executorch/backends/arm/tosa/dialect/ops/comparison.py +78 -0
- executorch/backends/arm/tosa/dialect/ops/conv2d.py +139 -0
- executorch/backends/arm/tosa/dialect/ops/conv2d_block_scaled.py +218 -0
- executorch/backends/arm/tosa/dialect/ops/conv3d.py +69 -0
- executorch/backends/arm/tosa/dialect/ops/conversion_ops.py +213 -0
- executorch/backends/arm/tosa/dialect/ops/custom.py +159 -0
- executorch/backends/arm/tosa/dialect/ops/data_layout_ops.py +284 -0
- executorch/backends/arm/tosa/dialect/ops/depthwise_conv2d.py +49 -0
- executorch/backends/arm/tosa/dialect/ops/fft.py +144 -0
- executorch/backends/arm/tosa/dialect/ops/gather.py +101 -0
- executorch/backends/arm/tosa/dialect/ops/identity.py +16 -0
- executorch/backends/arm/tosa/dialect/ops/matmul.py +76 -0
- executorch/backends/arm/tosa/dialect/ops/matmul_t_block_scaled.py +162 -0
- executorch/backends/arm/tosa/dialect/ops/max_pool2d.py +89 -0
- executorch/backends/arm/tosa/dialect/ops/max_pool2d_adaptive.py +70 -0
- executorch/backends/arm/tosa/dialect/ops/reduction_ops.py +186 -0
- executorch/backends/arm/tosa/dialect/ops/resize.py +118 -0
- executorch/backends/arm/tosa/dialect/ops/scatter.py +23 -0
- executorch/backends/arm/tosa/dialect/ops/shape_ops.py +506 -0
- executorch/backends/arm/tosa/dialect/ops/table.py +51 -0
- executorch/backends/arm/tosa/dialect/ops/ternary_elementwise.py +77 -0
- executorch/backends/arm/tosa/dialect/ops/transpose_conv2d.py +58 -0
- executorch/backends/arm/tosa/dialect/ops/unary_elementwise.py +187 -0
- executorch/backends/arm/tosa/dialect/ops_registration.py +92 -0
- executorch/backends/arm/tosa/dialect/real_impl.py +174 -0
- executorch/backends/arm/tosa/dialect/shape.py +21 -0
- executorch/backends/arm/tosa/mapping.py +336 -0
- executorch/backends/arm/tosa/partitioner.py +1050 -0
- executorch/backends/arm/tosa/resize_utils.py +341 -0
- executorch/backends/arm/tosa/schemas/__init__.py +4 -0
- executorch/backends/arm/tosa/schemas/tosa_1.0.fbs +559 -0
- executorch/backends/arm/tosa/schemas/tosa_1.1.fbs +701 -0
- executorch/backends/arm/tosa/specification.py +514 -0
- executorch/backends/arm/tosa/utils.py +173 -0
- executorch/backends/arm/util/_factory.py +59 -0
- executorch/backends/arm/util/arm_model_evaluator.py +277 -0
- executorch/backends/arm/vgf/__init__.py +11 -0
- executorch/backends/arm/vgf/_passes/__init__.py +13 -0
- executorch/backends/arm/vgf/_passes/fuse_grid_sampler_flow_offset.py +548 -0
- executorch/backends/arm/vgf/_passes/group_independent_custom_shaders.py +87 -0
- executorch/backends/arm/vgf/_passes/insert_grid_sampler_grid_dequant_pass.py +151 -0
- executorch/backends/arm/vgf/_passes/rewrite_grid_sampler_to_tosa_custom.py +488 -0
- executorch/backends/arm/vgf/backend.py +491 -0
- executorch/backends/arm/vgf/check_env.py +707 -0
- executorch/backends/arm/vgf/compile_spec.py +132 -0
- executorch/backends/arm/vgf/model_converter.py +420 -0
- executorch/backends/arm/vgf/partitioner.py +42 -0
- executorch/backends/arm/vgf/quantization_assessment.py +824 -0
- executorch/backends/arm/vgf/quantization_quality.py +170 -0
- executorch/backends/arm/vgf/quantization_sensitivity.py +847 -0
- executorch/backends/arm/vgf/quantization_visualization.py +320 -0
- executorch/backends/arm/vgf/shaders/__init__.py +4 -0
- executorch/backends/arm/vgf/shaders/flow_offset_grid_sampler_int8_align_corners.glsl +60 -0
- executorch/backends/arm/vgf/shaders/grid_sampler.glsl +41 -0
- executorch/backends/arm/vgf/shaders/grid_sampler.py +504 -0
- executorch/backends/arm/vgf/shaders/grid_sampler.spirv.b64 +1 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler.glsl +35 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler.spirv.b64 +1 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_align_corners.glsl +40 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_align_corners.spirv.b64 +1 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_int8.glsl +44 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_int8.spirv.b64 +1 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_int8_align_corners.glsl +49 -0
- executorch/backends/arm/vgf/shaders/grid_sampler_sampler_int8_align_corners.spirv.b64 +1 -0
- executorch/backends/cadence/aot/__init__.py +5 -0
- executorch/backends/cadence/aot/compiler.py +547 -0
- executorch/backends/cadence/aot/compiler_funcs.py +758 -0
- executorch/backends/cadence/aot/compiler_utils.py +271 -0
- executorch/backends/cadence/aot/decompose_ops.py +115 -0
- executorch/backends/cadence/aot/export_example.py +123 -0
- executorch/backends/cadence/aot/functions.yaml +510 -0
- executorch/backends/cadence/aot/functions_fusion_g3.yaml +191 -0
- executorch/backends/cadence/aot/functions_hifi.yaml +607 -0
- executorch/backends/cadence/aot/functions_vision.yaml +275 -0
- executorch/backends/cadence/aot/fuse_ops.py +1170 -0
- executorch/backends/cadence/aot/graph_builder.py +32 -0
- executorch/backends/cadence/aot/memory_constraints.py +759 -0
- executorch/backends/cadence/aot/memory_planning.py +562 -0
- executorch/backends/cadence/aot/memory_planning_algo.py +342 -0
- executorch/backends/cadence/aot/ops_registrations.py +3533 -0
- executorch/backends/cadence/aot/pass_utils.py +172 -0
- executorch/backends/cadence/aot/passes.py +226 -0
- executorch/backends/cadence/aot/program_builder.py +28 -0
- executorch/backends/cadence/aot/quantizer/fusion_pass.py +843 -0
- executorch/backends/cadence/aot/quantizer/passes/fuse_ops.py +391 -0
- executorch/backends/cadence/aot/quantizer/pattern_utils.py +460 -0
- executorch/backends/cadence/aot/quantizer/patterns.py +1567 -0
- executorch/backends/cadence/aot/quantizer/quantizer.py +555 -0
- executorch/backends/cadence/aot/quantizer/utils.py +286 -0
- executorch/backends/cadence/aot/ref_implementations.py +3126 -0
- executorch/backends/cadence/aot/remove_ops.py +1025 -0
- executorch/backends/cadence/aot/reorder_ops.py +1463 -0
- executorch/backends/cadence/aot/replace_ops.py +2657 -0
- executorch/backends/cadence/aot/simplify_ops.py +218 -0
- executorch/backends/cadence/aot/to_out_var_pass.py +24 -0
- executorch/backends/cadence/aot/type_dispatch.py +179 -0
- executorch/backends/cadence/aot/typing_stubs.py +22 -0
- executorch/backends/cadence/aot/utils.py +372 -0
- executorch/backends/cadence/aot/weight_packing.py +390 -0
- executorch/backends/cadence/runtime/__init__.py +13 -0
- executorch/backends/cadence/runtime/etdump.py +173 -0
- executorch/backends/cadence/runtime/executor.py +208 -0
- executorch/backends/cadence/runtime/runtime.py +167 -0
- executorch/backends/cadence/runtime/utils.py +100 -0
- executorch/backends/cadence/utils/facto_util.py +612 -0
- executorch/backends/cadence/utils/gen_header.py +49 -0
- executorch/backends/cadence/utils/post_compilation.py +173 -0
- executorch/backends/cortex_m/edge_compile_config.py +40 -0
- executorch/backends/cortex_m/library/__init__.py +4 -0
- executorch/backends/cortex_m/library/_cmsis_nn/cmsis_nn.cp315-win_amd64.pyd +0 -0
- executorch/backends/cortex_m/library/cmsis_nn.py +281 -0
- executorch/backends/cortex_m/ops/operators.py +1985 -0
- executorch/backends/cortex_m/ops/operators.yaml +145 -0
- executorch/backends/cortex_m/passes/__init__.py +15 -0
- executorch/backends/cortex_m/passes/activation_fusion_pass.py +210 -0
- executorch/backends/cortex_m/passes/aten_to_cortex_m_pass.py +1300 -0
- executorch/backends/cortex_m/passes/clamp_hardswish_pass.py +37 -0
- executorch/backends/cortex_m/passes/cortex_m_pass.py +35 -0
- executorch/backends/cortex_m/passes/cortex_m_pass_manager.py +221 -0
- executorch/backends/cortex_m/passes/decompose_hardswish_pass.py +128 -0
- executorch/backends/cortex_m/passes/decompose_mean_pass.py +104 -0
- executorch/backends/cortex_m/passes/decompose_sdpa_pass.py +92 -0
- executorch/backends/cortex_m/passes/explicit_layout_pass.py +157 -0
- executorch/backends/cortex_m/passes/fuse_conv_padding_pass.py +81 -0
- executorch/backends/cortex_m/passes/initialize_scratch_buffers_pass.py +37 -0
- executorch/backends/cortex_m/passes/matmul_to_bmm_pass.py +82 -0
- executorch/backends/cortex_m/passes/quantized_clamp_activation_pass.py +126 -0
- executorch/backends/cortex_m/passes/replace_quant_nodes_pass.py +76 -0
- executorch/backends/cortex_m/passes/scratch_buffer_sizes.py +328 -0
- executorch/backends/cortex_m/quantizer/__init__.py +19 -0
- executorch/backends/cortex_m/quantizer/node_finders.py +165 -0
- executorch/backends/cortex_m/quantizer/pattern_checkers.py +409 -0
- executorch/backends/cortex_m/quantizer/pattern_matcher.py +214 -0
- executorch/backends/cortex_m/quantizer/quantization_configs.py +226 -0
- executorch/backends/cortex_m/quantizer/quantizer.py +121 -0
- executorch/backends/cortex_m/quantizer/quantizer_support.py +260 -0
- executorch/backends/cortex_m/quantizer_reporter.py +443 -0
- executorch/backends/cortex_m/target_config.py +117 -0
- executorch/backends/cortex_m/test/models/__init__.py +4 -0
- executorch/backends/cortex_m/test/ops/__init__.py +4 -0
- executorch/backends/cortex_m/test/ops/nhwc_test_utils.py +42 -0
- executorch/backends/cortex_m/test/test_helpers_passes_utils.py +103 -0
- executorch/backends/cortex_m/test/tester.py +256 -0
- executorch/backends/cortex_m/utils.py +428 -0
- executorch/backends/cpu/__init__.py +5 -0
- executorch/backends/cpu/partitioner.py +110 -0
- executorch/backends/cpu/preprocess.py +89 -0
- executorch/backends/cpu/recipes/__init__.py +14 -0
- executorch/backends/cpu/recipes/cpu_recipe_provider.py +37 -0
- executorch/backends/cpu/recipes/cpu_recipe_types.py +15 -0
- executorch/backends/cpu/test/tester.py +43 -0
- executorch/backends/cuda/__init__.py +5 -0
- executorch/backends/cuda/aoti_packed_int4_tensor.py +178 -0
- executorch/backends/cuda/autotune/__init__.py +8 -0
- executorch/backends/cuda/autotune/cuda_graph_timing.py +367 -0
- executorch/backends/cuda/autotune/inputs.py +214 -0
- executorch/backends/cuda/autotune/launch_params.py +413 -0
- executorch/backends/cuda/batching/__init__.py +0 -0
- executorch/backends/cuda/batching/test/__init__.py +0 -0
- executorch/backends/cuda/batching/test/export_toy_decoder.py +346 -0
- executorch/backends/cuda/benchmarks/benchmark_moe.py +423 -0
- executorch/backends/cuda/benchmarks/benchmark_sdpa.py +308 -0
- executorch/backends/cuda/coalesced_int4_tensor.py +243 -0
- executorch/backends/cuda/cuda_backend.py +1578 -0
- executorch/backends/cuda/cuda_partitioner.py +53 -0
- executorch/backends/cuda/cuda_weight_collector.py +641 -0
- executorch/backends/cuda/dp4a_planar_int5_tensor.py +323 -0
- executorch/backends/cuda/dp4a_planar_int6_tensor.py +307 -0
- executorch/backends/cuda/merge_ptes.py +750 -0
- executorch/backends/cuda/passes/__init__.py +0 -0
- executorch/backends/cuda/passes/lower_offgraph_kv.py +689 -0
- executorch/backends/cuda/passes/move_cond_predicate_to_cpu.py +94 -0
- executorch/backends/cuda/passes/remove_assert_async.py +50 -0
- executorch/backends/cuda/passes/replace_complex_with_real.py +398 -0
- executorch/backends/cuda/passes/replace_fused_sdpa.py +136 -0
- executorch/backends/cuda/passes/replace_int64_floordiv.py +153 -0
- executorch/backends/cuda/passes/replace_masked_copy_with_where.py +220 -0
- executorch/backends/cuda/passes/tests/__init__.py +0 -0
- executorch/backends/cuda/passes/tests/test_replace_fused_sdpa.py +124 -0
- executorch/backends/cuda/quantize_op_dispatch/__init__.py +31 -0
- executorch/backends/cuda/quantize_op_dispatch/_gemm_family_dispatch.py +118 -0
- executorch/backends/cuda/quantize_op_dispatch/int4_dispatch.py +121 -0
- executorch/backends/cuda/quantize_op_dispatch/int5_dispatch.py +127 -0
- executorch/backends/cuda/quantize_op_dispatch/int6_dispatch.py +115 -0
- executorch/backends/cuda/quantize_op_dispatch/int8_dispatch.py +113 -0
- executorch/backends/cuda/target_smem.py +63 -0
- executorch/backends/cuda/tests/__init__.py +5 -0
- executorch/backends/cuda/tests/autotune_test_utils.py +236 -0
- executorch/backends/cuda/tests/test_int5_dispatch.py +432 -0
- executorch/backends/cuda/tests/test_int6_dispatch.py +462 -0
- executorch/backends/cuda/triton/__init__.py +17 -0
- executorch/backends/cuda/triton/kernels/__init__.py +64 -0
- executorch/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +273 -0
- executorch/backends/cuda/triton/kernels/fused_deltanet_decode.py +358 -0
- executorch/backends/cuda/triton/kernels/fused_moe.py +1604 -0
- executorch/backends/cuda/triton/kernels/int4_matmul.py +558 -0
- executorch/backends/cuda/triton/kernels/int4_quantized_gemm.py +1964 -0
- executorch/backends/cuda/triton/kernels/int5_quantized_gemm.py +1675 -0
- executorch/backends/cuda/triton/kernels/int6_quantized_gemm.py +1501 -0
- executorch/backends/cuda/triton/kernels/int8_quantized_gemm.py +1275 -0
- executorch/backends/cuda/triton/kernels/quantized_gemm_family.py +579 -0
- executorch/backends/cuda/triton/kernels/quantized_gemm_utils.py +505 -0
- executorch/backends/cuda/triton/kernels/sdpa.py +2496 -0
- executorch/backends/cuda/triton/kernels/topk.py +220 -0
- executorch/backends/cuda/triton/kernels/tq4_sdpa.py +1216 -0
- executorch/backends/cuda/triton/kernels/triton_mutation_cache.py +131 -0
- executorch/backends/cuda/triton/replacement_pass.py +232 -0
- executorch/backends/example/example_backend.py +41 -0
- executorch/backends/example/example_backend_delegate_passes/merge_to_dim_pass.py +83 -0
- executorch/backends/example/example_backend_delegate_passes/permute_memory_formats_pass.py +143 -0
- executorch/backends/example/example_operators/adaptive_avg_pool2d.py +47 -0
- executorch/backends/example/example_operators/add.py +44 -0
- executorch/backends/example/example_operators/conv2d.py +52 -0
- executorch/backends/example/example_operators/conv_relu.py +49 -0
- executorch/backends/example/example_operators/dropout.py +44 -0
- executorch/backends/example/example_operators/flatten.py +40 -0
- executorch/backends/example/example_operators/linear.py +62 -0
- executorch/backends/example/example_operators/op_base.py +15 -0
- executorch/backends/example/example_operators/ops.py +32 -0
- executorch/backends/example/example_operators/utils.py +34 -0
- executorch/backends/example/example_partitioner.py +88 -0
- executorch/backends/example/example_quantizer.py +108 -0
- executorch/backends/example/test_example_delegate.py +112 -0
- executorch/backends/mediatek/__init__.py +5 -0
- executorch/backends/mediatek/_passes/__init__.py +0 -0
- executorch/backends/mediatek/_passes/decompose_scaled_dot_product_attention.py +79 -0
- executorch/backends/mediatek/partitioner.py +107 -0
- executorch/backends/mediatek/preprocess.py +214 -0
- executorch/backends/mediatek/quantizer/__init__.py +4 -0
- executorch/backends/mediatek/quantizer/annotator.py +263 -0
- executorch/backends/mediatek/quantizer/qconfig.py +174 -0
- executorch/backends/mediatek/quantizer/quantizer.py +45 -0
- executorch/backends/mlx/__init__.py +17 -0
- executorch/backends/mlx/_logging.py +40 -0
- executorch/backends/mlx/_memprofile.py +188 -0
- executorch/backends/mlx/builder/__init__.py +16 -0
- executorch/backends/mlx/builder/op_helpers.py +885 -0
- executorch/backends/mlx/builder/op_registry.py +223 -0
- executorch/backends/mlx/builder/pattern_matcher.py +64 -0
- executorch/backends/mlx/builder/program_builder.py +1281 -0
- executorch/backends/mlx/builder/slot_manager.py +252 -0
- executorch/backends/mlx/custom_kernel_ops/__init__.py +7 -0
- executorch/backends/mlx/custom_kernel_ops/gated_delta_rule.py +596 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/__init__.py +18 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/patterns.py +209 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/__init__.py +32 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/common.py +151 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/embedding.py +147 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/embedding_mlx_native.py +57 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/linear.py +500 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/linear_mlx_native.py +85 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/__init__.py +37 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/common.py +167 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/embedding.py +144 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/embedding_mlx_native.py +57 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/linear.py +534 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/linear_mlx_native.py +85 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/__init__.py +40 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/common.py +142 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/embedding.py +151 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/embedding_mlx_native.py +61 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/linear.py +511 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/linear_mlx_native.py +86 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/repack_mlx.py +132 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/test/__init__.py +5 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/test/test_embedding.py +270 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/test/test_linear.py +647 -0
- executorch/backends/mlx/custom_kernel_ops/test/__init__.py +5 -0
- executorch/backends/mlx/custom_kernel_ops/test/test_gated_delta_rule.py +1037 -0
- executorch/backends/mlx/custom_kernel_ops/test/test_tq4_compress.py +183 -0
- executorch/backends/mlx/custom_kernel_ops/test/test_tq_dequant.py +166 -0
- executorch/backends/mlx/custom_kernel_ops/test/test_tq_norm.py +150 -0
- executorch/backends/mlx/custom_kernel_ops/tq4_compress.py +189 -0
- executorch/backends/mlx/custom_kernel_ops/tq_dequant.py +216 -0
- executorch/backends/mlx/custom_kernel_ops/tq_norm.py +170 -0
- executorch/backends/mlx/custom_ops.py +546 -0
- executorch/backends/mlx/examples/__init__.py +6 -0
- executorch/backends/mlx/examples/llm/__init__.py +6 -0
- executorch/backends/mlx/examples/llm/dflash/__init__.py +26 -0
- executorch/backends/mlx/examples/llm/dflash/adapters.py +71 -0
- executorch/backends/mlx/examples/llm/dflash/arch.py +109 -0
- executorch/backends/mlx/examples/llm/dflash/cache.py +60 -0
- executorch/backends/mlx/examples/llm/dflash/export.py +270 -0
- executorch/backends/mlx/examples/llm/dflash/model.py +368 -0
- executorch/backends/mlx/examples/llm/dflash/run.py +305 -0
- executorch/backends/mlx/examples/llm/export_llm_hf.py +758 -0
- executorch/backends/mlx/examples/llm/run_llm_hf.py +217 -0
- executorch/backends/mlx/examples/llm/runtime_meta.py +238 -0
- executorch/backends/mlx/examples/voxtral/__init__.py +5 -0
- executorch/backends/mlx/examples/voxtral/export_voxtral_hf.py +201 -0
- executorch/backends/mlx/examples/whisper/__init__.py +7 -0
- executorch/backends/mlx/examples/whisper/args.py +151 -0
- executorch/backends/mlx/examples/whisper/export_whisper.py +620 -0
- executorch/backends/mlx/examples/whisper/run_whisper.py +276 -0
- executorch/backends/mlx/llm/__init__.py +6 -0
- executorch/backends/mlx/llm/cache.py +721 -0
- executorch/backends/mlx/llm/et_attention.py +252 -0
- executorch/backends/mlx/llm/exportable.py +379 -0
- executorch/backends/mlx/llm/hf_attention.py +413 -0
- executorch/backends/mlx/llm/quantization.py +57 -0
- executorch/backends/mlx/llm/sampling.py +44 -0
- executorch/backends/mlx/llm/source_transformation.py +309 -0
- executorch/backends/mlx/llm/switch.py +329 -0
- executorch/backends/mlx/llm/turboquant_cache.py +244 -0
- executorch/backends/mlx/ops.py +5759 -0
- executorch/backends/mlx/partitioner.py +386 -0
- executorch/backends/mlx/passes.py +360 -0
- executorch/backends/mlx/pattern_utils.py +360 -0
- executorch/backends/mlx/patterns.py +1423 -0
- executorch/backends/mlx/preprocess.py +226 -0
- executorch/backends/mlx/pte_inspector.py +902 -0
- executorch/backends/mlx/serialization/__init__.py +32 -0
- executorch/backends/mlx/serialization/generate.py +1581 -0
- executorch/backends/mlx/serialization/mlx_graph_serialize.py +417 -0
- executorch/backends/mlx/serialization/schema.fbs +1314 -0
- executorch/backends/mlx/test/__init__.py +5 -0
- executorch/backends/mlx/test/run_all_tests.py +496 -0
- executorch/backends/mlx/test/test_ops.py +9052 -0
- executorch/backends/mlx/test/test_sample.py +295 -0
- executorch/backends/mlx/test/test_slot_recycling.py +198 -0
- executorch/backends/mlx/test/test_utils.py +1184 -0
- executorch/backends/mlx/test/tester.py +78 -0
- executorch/backends/native/__init__.py +23 -0
- executorch/backends/native/custom_ops.py +107 -0
- executorch/backends/native/examples/hf_llm/convert_meta_llama.py +93 -0
- executorch/backends/native/examples/hf_llm/export_hf_llm.py +316 -0
- executorch/backends/native/examples/hf_llm/gguf_hf.py +145 -0
- executorch/backends/native/examples/hf_llm/test_export_hf_llm.py +235 -0
- executorch/backends/native/partitioner.py +294 -0
- executorch/backends/native/passes/__init__.py +86 -0
- executorch/backends/native/passes/_utils.py +34 -0
- executorch/backends/native/passes/fuse_rope.py +488 -0
- executorch/backends/native/passes/reinplace.py +74 -0
- executorch/backends/native/passes/remove_runtime_asserts.py +114 -0
- executorch/backends/native/passes/replace_copy_with_alias.py +185 -0
- executorch/backends/native/preprocess.py +157 -0
- executorch/backends/native/serialization/__init__.py +27 -0
- executorch/backends/native/serialization/graph_serialize.py +1705 -0
- executorch/backends/native/serialization/native_graph.fbs +448 -0
- executorch/backends/native/serialization/schema.py +343 -0
- executorch/backends/native/test/__init__.py +0 -0
- executorch/backends/native/test/utils.py +44 -0
- executorch/backends/nxp/__init__.py +0 -0
- executorch/backends/nxp/aten_passes/add_batch_size_for_3d_input_pool_2d_ops.py +116 -0
- executorch/backends/nxp/aten_passes/convert_1d_conv_to_2d.py +489 -0
- executorch/backends/nxp/aten_passes/convert_div_to_mul.py +177 -0
- executorch/backends/nxp/aten_passes/convert_scalar_to_attr.py +119 -0
- executorch/backends/nxp/aten_passes/decompose_split_to_slices_pass.py +196 -0
- executorch/backends/nxp/aten_passes/fuse_batch_norm_with_conv_pass.py +145 -0
- executorch/backends/nxp/aten_passes/fuse_batch_norm_with_linear_pass.py +188 -0
- executorch/backends/nxp/aten_passes/fuse_linear_and_add_pass.py +202 -0
- executorch/backends/nxp/aten_passes/move_activation_before_concat.py +101 -0
- executorch/backends/nxp/aten_passes/neutron_aten_pass_manager.py +90 -0
- executorch/backends/nxp/aten_passes/remove_nodes_with_known_outputs.py +196 -0
- executorch/backends/nxp/aten_passes/simulated_linear_bn_fusion_passes/__init__.py +16 -0
- executorch/backends/nxp/aten_passes/simulated_linear_bn_fusion_passes/add_simulated_linear_bn_fusion_qat_pass.py +395 -0
- executorch/backends/nxp/aten_passes/simulated_linear_bn_fusion_passes/remove_simulated_linear_bn_fusion_qat_pass.py +245 -0
- executorch/backends/nxp/aten_passes/split_group_convolution.py +300 -0
- executorch/backends/nxp/aten_passes/split_gru_based_on_num_layers.py +307 -0
- executorch/backends/nxp/backend/custom_delegation_options.py +17 -0
- executorch/backends/nxp/backend/data_format.py +49 -0
- executorch/backends/nxp/backend/edge_helper.py +527 -0
- executorch/backends/nxp/backend/edge_program_converter.py +363 -0
- executorch/backends/nxp/backend/graph_utils.py +129 -0
- executorch/backends/nxp/backend/ir/conversion_config.py +54 -0
- executorch/backends/nxp/backend/ir/conversion_context.py +43 -0
- executorch/backends/nxp/backend/ir/converter/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/converter/builder/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/converter/builder/aten_model_builder_director.py +156 -0
- executorch/backends/nxp/backend/ir/converter/builder/model_builder.py +1806 -0
- executorch/backends/nxp/backend/ir/converter/builder/quantization_verification.py +387 -0
- executorch/backends/nxp/backend/ir/converter/conversion/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/converter/conversion/aten_translator.py +71 -0
- executorch/backends/nxp/backend/ir/converter/conversion/common.py +177 -0
- executorch/backends/nxp/backend/ir/converter/conversion/translator.py +689 -0
- executorch/backends/nxp/backend/ir/converter/node_converter.py +538 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/__init__.py +4 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/__init__.py +179 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/abs_converter.py +53 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/adaptive_avg_pool_2d_converter.py +113 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/add_tensor_converter.py +67 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/addmm_converter.py +160 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/amax_converter.py +82 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/amin_converter.py +82 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/avg_pool_2d_converter.py +144 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/bmm_converter.py +102 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/cat_converter.py +123 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/clamp_converter.py +290 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/clone_converter.py +118 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/constant_pad_nd_converter.py +163 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/convolution_converter.py +548 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/exp_converter.py +60 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/getitem_converter.py +60 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/hardswish_converter.py +51 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/hardtanh_converter.py +37 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/leaky_relu_converter.py +64 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/log_converter.py +60 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/max_pool2d_with_indices_converter.py +183 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/maximum_converter.py +69 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mean_dim_converter.py +108 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/minimum_converter.py +69 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mm_converter.py +95 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mul_tensor_converter.py +64 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/neg_converter.py +77 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/pad_converter.py +118 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/permute_copy_converter.py +435 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/prelu_converter.py +67 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/qdq_dequantize_converter.py +127 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/qdq_quantize_converter.py +46 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/relu_converter.py +67 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/rsqrt_converter.py +63 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sigmoid_converter.py +63 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/slice_copy_tensor_converter.py +116 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/softmax_converter.py +143 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sub_tensor_converter.py +72 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sum_dim_int_list_converter.py +84 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/tanh_converter.py +61 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/upsample_bilinear2d_converter.py +153 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/upsample_nearest2d_converter.py +137 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/view_copy_converter.py +99 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/shared/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/shared/conv_utils.py +123 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/shared/recurrent_utils.py +64 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/shared/reduce_utils.py +173 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/shared/reshape_transposition.py +233 -0
- executorch/backends/nxp/backend/ir/converter/quantization_utils.py +161 -0
- executorch/backends/nxp/backend/ir/converter/tensor_utils.py +55 -0
- executorch/backends/nxp/backend/ir/lib/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ATan2Options.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/AbsOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ActivationFunctionType.py +12 -0
- executorch/backends/nxp/backend/ir/lib/tflite/AddNOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/AddOptions.py +82 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ArgMaxOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ArgMinOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/AssignVariableOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BatchMatMulOptions.py +101 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BatchToSpaceNDOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BidirectionalSequenceLSTMOptions.py +160 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BidirectionalSequenceRNNOptions.py +126 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BitcastOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BitwiseXorOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BroadcastToOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BucketizeOptions.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Buffer.py +132 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOperator.py +212 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOptions.py +133 -0
- executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOptions2.py +27 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CallOnceOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CallOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CastOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CombinerType.py +9 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ConcatEmbeddingsOptions.py +163 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ConcatenationOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Conv2DOptions.py +155 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Conv3DOptions.py +170 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CosOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CumsumOptions.py +84 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CustomOptionsFormat.py +7 -0
- executorch/backends/nxp/backend/ir/lib/tflite/CustomQuantization.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DensifyOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DepthToSpaceOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DepthwiseConv2DOptions.py +157 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DequantizeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DilateOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DimensionMetadata.py +152 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DimensionType.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DivOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/DynamicUpdateSliceOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/EmbeddingLookupSparseOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/EqualOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ExpOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ExpandDimsOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FakeQuantOptions.py +116 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FillOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FloorDivOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FloorModOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FullyConnectedOptions.py +129 -0
- executorch/backends/nxp/backend/ir/lib/tflite/FullyConnectedOptionsWeightsFormat.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/GatherNdOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/GatherOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/GeluOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/GreaterEqualOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/GreaterOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/HardSwishOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/HashtableFindOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/HashtableImportOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/HashtableOptions.py +95 -0
- executorch/backends/nxp/backend/ir/lib/tflite/HashtableSizeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/IfOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Int32Vector.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/L2NormOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LSHProjectionOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LSHProjectionType.py +9 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LSTMKernelType.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LSTMOptions.py +131 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LeakyReluOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LessEqualOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LessOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LocalResponseNormalizationOptions.py +118 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LogSoftmaxOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LogicalAndOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LogicalNotOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/LogicalOrOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MatrixDiagOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MatrixSetDiagOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MaximumMinimumOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Metadata.py +84 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MirrorPadMode.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MirrorPadOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Model.py +352 -0
- executorch/backends/nxp/backend/ir/lib/tflite/MulOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/NegOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/NonMaxSuppressionV4Options.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/NonMaxSuppressionV5Options.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/NotEqualOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/OneHotOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Operator.py +428 -0
- executorch/backends/nxp/backend/ir/lib/tflite/OperatorCode.py +112 -0
- executorch/backends/nxp/backend/ir/lib/tflite/PackOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/PadOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/PadV2Options.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Padding.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Pool2DOptions.py +140 -0
- executorch/backends/nxp/backend/ir/lib/tflite/PowOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/QuantizationDetails.py +8 -0
- executorch/backends/nxp/backend/ir/lib/tflite/QuantizationParameters.py +295 -0
- executorch/backends/nxp/backend/ir/lib/tflite/QuantizeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RNNOptions.py +82 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RandomOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RangeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RankOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReadVariableOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReduceWindowFunction.py +13 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReduceWindowOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReducerOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReshapeOptions.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ResizeBilinearOptions.py +84 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ResizeNearestNeighborOptions.py +86 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReverseSequenceOptions.py +82 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ReverseV2Options.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Rfft2dOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RightShiftOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/RngAlgorithm.py +9 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SVDFOptions.py +97 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ScatterNdOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SegmentSumOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SelectOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SelectV2Options.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SequenceRNNOptions.py +99 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ShapeOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SignOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SignatureDef.py +172 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SkipGramOptions.py +97 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SliceOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SoftmaxOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SpaceToBatchNDOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SpaceToDepthOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SparseIndexVector.py +10 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SparseToDenseOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SparsityParameters.py +190 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SplitOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SplitVOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SquareOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SquaredDifferenceOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SqueezeOptions.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloBroadcastInDimOptions.py +102 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloCompareOptions.py +86 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloComparisonDirection.py +12 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloComparisonType.py +11 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloConcatenateOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloConvolutionOptions.py +634 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloCustomCallOptions.py +214 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloDotGeneralOptions.py +304 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloDynamicSliceOptions.py +100 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloGatherOptions.py +276 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloIotaOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloPadOptions.py +194 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloPrecisionConfig.py +9 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloReduceOptions.py +115 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloReduceWindowOptions.py +307 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloRngBitGeneratorOptions.py +67 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloScatterOptions.py +268 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloSliceOptions.py +194 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloSortOptions.py +97 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloTransposeOptions.py +100 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StablehloWhileOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/StridedSliceOptions.py +142 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SubGraph.py +251 -0
- executorch/backends/nxp/backend/ir/lib/tflite/SubOptions.py +82 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Tensor.py +317 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TensorMap.py +84 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TensorType.py +24 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TileOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TopKV2Options.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TransposeConvOptions.py +125 -0
- executorch/backends/nxp/backend/ir/lib/tflite/TransposeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Uint16Vector.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/Uint8Vector.py +98 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnidirectionalSequenceLSTMOptions.py +164 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UniqueOptions.py +65 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnpackOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentMaxOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentMinOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentProdOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentSumOptions.py +52 -0
- executorch/backends/nxp/backend/ir/lib/tflite/VarHandleOptions.py +84 -0
- executorch/backends/nxp/backend/ir/lib/tflite/VariantSubType.py +130 -0
- executorch/backends/nxp/backend/ir/lib/tflite/WhereOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/WhileOptions.py +80 -0
- executorch/backends/nxp/backend/ir/lib/tflite/ZerosLikeOptions.py +50 -0
- executorch/backends/nxp/backend/ir/lib/tflite/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/logger.py +341 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/graph_utils.py +115 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/operator_rules.py +102 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/base_optimization.py +41 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/permute_fully_connected_weights_after_reshape.py +121 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/prune_transpose_operators.py +177 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizer.py +127 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/pattern_matcher.py +925 -0
- executorch/backends/nxp/backend/ir/neutron_ir_post_processing/tensor_rules.py +710 -0
- executorch/backends/nxp/backend/ir/tflite_generator/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/abs_options.py +25 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/add_n_options.py +32 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/add_options.py +46 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/arg_max_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/arg_min_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/average_pool_2d_options.py +63 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/batch_mat_mul_options.py +45 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bidirectional_sequence_lstm_options.py +65 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bidirectional_sequence_rnn_options.py +53 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bitwise_xor_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/broadcast_to_options.py +25 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/cast_options.py +32 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/concatenation_options.py +38 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/conv_2d_options.py +59 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/conv_3d_options.py +67 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/cum_sum_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/depth_to_space_options.py +29 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/depthwise_conv_2d_options.py +69 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/dequantize_options.py +24 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/div_options.py +43 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/equal_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/exp_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/floor_mod_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/fully_connected_options.py +57 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gather_nd_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gather_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gelu_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/greater_equal_options.py +25 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/greater_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/hard_swish_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/leaky_relu_options.py +32 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/less_equal_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/less_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/log_softmax_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_and_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_not_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_or_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/lrn_options.py +45 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/lstm_options.py +60 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/max_pool_2d_options.py +63 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/maximum_options.py +21 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mean_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/minimum_options.py +21 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mirror_pad_options.py +60 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mul_options.py +36 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/multinomial_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/neg_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/not_equal_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/one_hot_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pad_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pad_v2_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pow_options.py +24 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/quantize_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/range_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_max_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_min_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_prod_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reshape_options.py +53 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/resize_bilinear_options.py +34 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/resize_nearest_neighbor_options.py +37 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reverse_sequence_options.py +32 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/scatter_nd_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/select_v2_options.py +24 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/shape_options.py +34 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sign_options.py +22 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/slice_options.py +29 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/softmax_options.py +36 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/space_to_depth_options.py +29 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/split_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/split_v_options.py +27 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/square_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/squared_difference_options.py +25 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/squeeze_options.py +42 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/strided_slice_options.py +35 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sub_options.py +46 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sum_options.py +28 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/tile_options.py +23 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/transpose_conv_options.py +50 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/transpose_options.py +30 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/unidirectional_sequence_lstm_options.py +67 -0
- executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/unidirectional_sequence_rnn_options.py +49 -0
- executorch/backends/nxp/backend/ir/tflite_generator/custom_options/flex_transpose_options.py +78 -0
- executorch/backends/nxp/backend/ir/tflite_generator/meta/__init__.py +0 -0
- executorch/backends/nxp/backend/ir/tflite_generator/meta/meta.py +255 -0
- executorch/backends/nxp/backend/ir/tflite_generator/meta/types.py +198 -0
- executorch/backends/nxp/backend/ir/tflite_generator/tflite_model.py +819 -0
- executorch/backends/nxp/backend/neutron_compiler_manager.py +213 -0
- executorch/backends/nxp/backend/neutron_map.py +877 -0
- executorch/backends/nxp/backend/neutron_operator_support.py +57 -0
- executorch/backends/nxp/backend/neutron_target_spec.py +161 -0
- executorch/backends/nxp/backend/node_format_inference.py +396 -0
- executorch/backends/nxp/backend/ops_aliases.py +83 -0
- executorch/backends/nxp/edge_passes/convert_reshaping_nodes_to_view.py +103 -0
- executorch/backends/nxp/edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py +310 -0
- executorch/backends/nxp/edge_passes/neutron_edge_pass.py +55 -0
- executorch/backends/nxp/edge_passes/neutron_edge_pass_manager.py +38 -0
- executorch/backends/nxp/edge_passes/remove_additional_quantize_dequantize_nodes_pass.py +120 -0
- executorch/backends/nxp/edge_passes/remove_as_strided_copy_nodes.py +66 -0
- executorch/backends/nxp/edge_passes/remove_io_quant_ops_pass.py +76 -0
- executorch/backends/nxp/neutron_node_extraction.py +152 -0
- executorch/backends/nxp/neutron_partitioner.py +570 -0
- executorch/backends/nxp/nxp_backend.py +484 -0
- executorch/backends/nxp/quantizer/neutron_quantizer.py +406 -0
- executorch/backends/nxp/quantizer/patterns.py +1429 -0
- executorch/backends/nxp/quantizer/utils.py +300 -0
- executorch/backends/nxp/recipes/__init__.py +18 -0
- executorch/backends/nxp/recipes/nxp_recipe_provider.py +424 -0
- executorch/backends/nxp/recipes/nxp_recipe_types.py +40 -0
- executorch/backends/nxp/tests/__init__.py +0 -0
- executorch/backends/nxp/tests/calibration_dataset.py +77 -0
- executorch/backends/nxp/tests/config.py +56 -0
- executorch/backends/nxp/tests/config_importer.py +17 -0
- executorch/backends/nxp/tests/cortex_m_benchmarking.py +79 -0
- executorch/backends/nxp/tests/dataset_creator.py +432 -0
- executorch/backends/nxp/tests/executorch_pipeline.py +320 -0
- executorch/backends/nxp/tests/executors.py +433 -0
- executorch/backends/nxp/tests/generic_tests/__init__.py +0 -0
- executorch/backends/nxp/tests/graph_verifier.py +264 -0
- executorch/backends/nxp/tests/ir/__init__.py +0 -0
- executorch/backends/nxp/tests/ir/converter/__init__.py +0 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/__init__.py +0 -0
- executorch/backends/nxp/tests/ir/edge_passes/__init__.py +0 -0
- executorch/backends/nxp/tests/ir/edge_passes/test_remove_io_quant_ops_pass.py +128 -0
- executorch/backends/nxp/tests/model_output_comparator.py +576 -0
- executorch/backends/nxp/tests/models/__init__.py +0 -0
- executorch/backends/nxp/tests/nsys_testing.py +940 -0
- executorch/backends/nxp/tests/outputs_dir.py +10 -0
- executorch/backends/nxp/tests/outputs_dir_importer.py +17 -0
- executorch/backends/nxp/tests/profiling_utils.py +139 -0
- executorch/backends/nxp/tests/simple_models.py +1156 -0
- executorch/backends/nxp/tests/tester/__init__.py +8 -0
- executorch/backends/nxp/tests/tester/tester.py +637 -0
- executorch/backends/nxp/tests/use_qat.py +22 -0
- executorch/backends/nxp/tests/utils.py +232 -0
- executorch/backends/openvino/__init__.py +5 -0
- executorch/backends/openvino/_passes/__init__.py +15 -0
- executorch/backends/openvino/_passes/cast_reduction_input_pass.py +45 -0
- executorch/backends/openvino/_passes/decompose_floor_divide_pass.py +106 -0
- executorch/backends/openvino/_passes/fold_constant_cumsum_pass.py +161 -0
- executorch/backends/openvino/partitioner.py +334 -0
- executorch/backends/openvino/preprocess.py +174 -0
- executorch/backends/openvino/quantizer/__init__.py +9 -0
- executorch/backends/openvino/quantizer/llm_compression.py +133 -0
- executorch/backends/openvino/quantizer/observers.py +206 -0
- executorch/backends/openvino/quantizer/quantizer.py +675 -0
- executorch/backends/openvino/test/tester/__init__.py +19 -0
- executorch/backends/openvino/test/tester/tester.py +94 -0
- executorch/backends/openvino/tests/ops/base_openvino_op_test.py +109 -0
- executorch/backends/qualcomm/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/__init__.py +153 -0
- executorch/backends/qualcomm/_passes/annotate_avg_pool1d.py +64 -0
- executorch/backends/qualcomm/_passes/annotate_get_attr.py +54 -0
- executorch/backends/qualcomm/_passes/annotate_quant_attrs.py +139 -0
- executorch/backends/qualcomm/_passes/annotate_stack.py +42 -0
- executorch/backends/qualcomm/_passes/annotate_unbind.py +40 -0
- executorch/backends/qualcomm/_passes/backends/__init__.py +5 -0
- executorch/backends/qualcomm/_passes/backends/gpu/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/backends/gpu/qnn_gpu_pass_manager.py +46 -0
- executorch/backends/qualcomm/_passes/backends/htp/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/backends/htp/qnn_htp_pass_manager.py +54 -0
- executorch/backends/qualcomm/_passes/backends/lpai/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/backends/lpai/qnn_lpai_pass_manager.py +97 -0
- executorch/backends/qualcomm/_passes/build_quant_io.py +53 -0
- executorch/backends/qualcomm/_passes/canonicalize_conv.py +201 -0
- executorch/backends/qualcomm/_passes/convert_bmm_to_matmul.py +83 -0
- executorch/backends/qualcomm/_passes/convert_complex_stft.py +116 -0
- executorch/backends/qualcomm/_passes/convert_linear_to_conv2d.py +301 -0
- executorch/backends/qualcomm/_passes/convert_mha_to_sha.py +626 -0
- executorch/backends/qualcomm/_passes/convert_square_to_pow.py +38 -0
- executorch/backends/qualcomm/_passes/decompose_acos.py +75 -0
- executorch/backends/qualcomm/_passes/decompose_addmm.py +115 -0
- executorch/backends/qualcomm/_passes/decompose_any.py +69 -0
- executorch/backends/qualcomm/_passes/decompose_as_strided.py +226 -0
- executorch/backends/qualcomm/_passes/decompose_atan2.py +210 -0
- executorch/backends/qualcomm/_passes/decompose_binary_alpha.py +61 -0
- executorch/backends/qualcomm/_passes/decompose_cdist.py +86 -0
- executorch/backends/qualcomm/_passes/decompose_col_im.py +273 -0
- executorch/backends/qualcomm/_passes/decompose_diagonal.py +234 -0
- executorch/backends/qualcomm/_passes/decompose_div_mode.py +91 -0
- executorch/backends/qualcomm/_passes/decompose_einsum.py +51 -0
- executorch/backends/qualcomm/_passes/decompose_empty.py +128 -0
- executorch/backends/qualcomm/_passes/decompose_expm1.py +49 -0
- executorch/backends/qualcomm/_passes/decompose_fill.py +61 -0
- executorch/backends/qualcomm/_passes/decompose_floor_divide.py +62 -0
- executorch/backends/qualcomm/_passes/decompose_glu.py +55 -0
- executorch/backends/qualcomm/_passes/decompose_hardsigmoid.py +59 -0
- executorch/backends/qualcomm/_passes/decompose_hyperbolic_variants.py +202 -0
- executorch/backends/qualcomm/_passes/decompose_linalg_vector_norm.py +81 -0
- executorch/backends/qualcomm/_passes/decompose_log_variants.py +114 -0
- executorch/backends/qualcomm/_passes/decompose_maxpool3d.py +145 -0
- executorch/backends/qualcomm/_passes/decompose_minmaxdim.py +109 -0
- executorch/backends/qualcomm/_passes/decompose_pad.py +128 -0
- executorch/backends/qualcomm/_passes/decompose_pdist.py +123 -0
- executorch/backends/qualcomm/_passes/decompose_reciprocal.py +39 -0
- executorch/backends/qualcomm/_passes/decompose_remainder.py +118 -0
- executorch/backends/qualcomm/_passes/decompose_roll.py +78 -0
- executorch/backends/qualcomm/_passes/decompose_select_scatter.py +96 -0
- executorch/backends/qualcomm/_passes/decompose_silu.py +45 -0
- executorch/backends/qualcomm/_passes/decompose_tan.py +71 -0
- executorch/backends/qualcomm/_passes/decompose_threshold.py +61 -0
- executorch/backends/qualcomm/_passes/decompose_triu.py +71 -0
- executorch/backends/qualcomm/_passes/decompose_trunc.py +93 -0
- executorch/backends/qualcomm/_passes/decompose_var.py +139 -0
- executorch/backends/qualcomm/_passes/decompose_wrap_with_autocast.py +95 -0
- executorch/backends/qualcomm/_passes/expand_broadcast_tensor_shape.py +80 -0
- executorch/backends/qualcomm/_passes/fixed_linear_keep_dim.py +94 -0
- executorch/backends/qualcomm/_passes/fold_qdq.py +85 -0
- executorch/backends/qualcomm/_passes/fuse_batch_norm_with_conv.py +36 -0
- executorch/backends/qualcomm/_passes/fuse_consecutive_cast.py +115 -0
- executorch/backends/qualcomm/_passes/fuse_consecutive_reshape.py +53 -0
- executorch/backends/qualcomm/_passes/fuse_consecutive_transpose.py +108 -0
- executorch/backends/qualcomm/_passes/i64_to_i32.py +204 -0
- executorch/backends/qualcomm/_passes/insert_cast_for_fp_act_quantized_weight.py +141 -0
- executorch/backends/qualcomm/_passes/insert_io_qdq.py +85 -0
- executorch/backends/qualcomm/_passes/insert_requantize.py +111 -0
- executorch/backends/qualcomm/_passes/insert_reshape_for_reduce_ops.py +58 -0
- executorch/backends/qualcomm/_passes/layout_transform.py +373 -0
- executorch/backends/qualcomm/_passes/lift_constant_scalar_operands.py +202 -0
- executorch/backends/qualcomm/_passes/lpai_partition_fallback_support.py +336 -0
- executorch/backends/qualcomm/_passes/qnn_pass_manager.py +554 -0
- executorch/backends/qualcomm/_passes/recompose_hadamard.py +185 -0
- executorch/backends/qualcomm/_passes/recompose_pad_maxpool2d.py +144 -0
- executorch/backends/qualcomm/_passes/recompose_pixel_unshuffle.py +81 -0
- executorch/backends/qualcomm/_passes/recompose_rms_norm.py +170 -0
- executorch/backends/qualcomm/_passes/remove_0d_tensor.py +62 -0
- executorch/backends/qualcomm/_passes/remove_redundancy.py +72 -0
- executorch/backends/qualcomm/_passes/replace_arange_args.py +48 -0
- executorch/backends/qualcomm/_passes/resolve_debug_handle.py +47 -0
- executorch/backends/qualcomm/_passes/seq_mse.py +240 -0
- executorch/backends/qualcomm/_passes/tag_quant_io.py +45 -0
- executorch/backends/qualcomm/_passes/utils.py +407 -0
- executorch/backends/qualcomm/builders/__init__.py +243 -0
- executorch/backends/qualcomm/builders/custom_ops.py +69 -0
- executorch/backends/qualcomm/builders/node_visitor.py +612 -0
- executorch/backends/qualcomm/builders/node_visitor_manager.py +81 -0
- executorch/backends/qualcomm/builders/op_abs.py +57 -0
- executorch/backends/qualcomm/builders/op_adaptive_avg_pool2d.py +126 -0
- executorch/backends/qualcomm/builders/op_adaptive_max_pool2d.py +151 -0
- executorch/backends/qualcomm/builders/op_add.py +62 -0
- executorch/backends/qualcomm/builders/op_amax.py +90 -0
- executorch/backends/qualcomm/builders/op_amin.py +90 -0
- executorch/backends/qualcomm/builders/op_and.py +60 -0
- executorch/backends/qualcomm/builders/op_arange.py +41 -0
- executorch/backends/qualcomm/builders/op_argmax.py +78 -0
- executorch/backends/qualcomm/builders/op_argmin.py +78 -0
- executorch/backends/qualcomm/builders/op_asin.py +56 -0
- executorch/backends/qualcomm/builders/op_atan.py +55 -0
- executorch/backends/qualcomm/builders/op_avg_pool2d.py +151 -0
- executorch/backends/qualcomm/builders/op_avg_pool3d.py +293 -0
- executorch/backends/qualcomm/builders/op_batch_norm.py +156 -0
- executorch/backends/qualcomm/builders/op_binary.py +84 -0
- executorch/backends/qualcomm/builders/op_bmm.py +59 -0
- executorch/backends/qualcomm/builders/op_cat.py +89 -0
- executorch/backends/qualcomm/builders/op_ceil.py +56 -0
- executorch/backends/qualcomm/builders/op_channel_shuffle.py +73 -0
- executorch/backends/qualcomm/builders/op_clamp.py +80 -0
- executorch/backends/qualcomm/builders/op_conv.py +263 -0
- executorch/backends/qualcomm/builders/op_copy.py +112 -0
- executorch/backends/qualcomm/builders/op_cos.py +56 -0
- executorch/backends/qualcomm/builders/op_cum_sum.py +87 -0
- executorch/backends/qualcomm/builders/op_custom_op.py +138 -0
- executorch/backends/qualcomm/builders/op_depth_to_space.py +78 -0
- executorch/backends/qualcomm/builders/op_dequantize.py +72 -0
- executorch/backends/qualcomm/builders/op_div.py +62 -0
- executorch/backends/qualcomm/builders/op_elu.py +68 -0
- executorch/backends/qualcomm/builders/op_embedding.py +252 -0
- executorch/backends/qualcomm/builders/op_eq.py +62 -0
- executorch/backends/qualcomm/builders/op_exp.py +60 -0
- executorch/backends/qualcomm/builders/op_expand.py +84 -0
- executorch/backends/qualcomm/builders/op_flip.py +80 -0
- executorch/backends/qualcomm/builders/op_floor.py +56 -0
- executorch/backends/qualcomm/builders/op_full.py +42 -0
- executorch/backends/qualcomm/builders/op_full_like.py +41 -0
- executorch/backends/qualcomm/builders/op_gather.py +75 -0
- executorch/backends/qualcomm/builders/op_ge.py +62 -0
- executorch/backends/qualcomm/builders/op_gelu.py +57 -0
- executorch/backends/qualcomm/builders/op_grid_sampler_2d.py +162 -0
- executorch/backends/qualcomm/builders/op_group_norm.py +96 -0
- executorch/backends/qualcomm/builders/op_gt.py +62 -0
- executorch/backends/qualcomm/builders/op_hadamard_transform.py +66 -0
- executorch/backends/qualcomm/builders/op_hardsigmoid.py +78 -0
- executorch/backends/qualcomm/builders/op_hardswish.py +57 -0
- executorch/backends/qualcomm/builders/op_hardtanh.py +79 -0
- executorch/backends/qualcomm/builders/op_index.py +85 -0
- executorch/backends/qualcomm/builders/op_index_put.py +481 -0
- executorch/backends/qualcomm/builders/op_index_select.py +80 -0
- executorch/backends/qualcomm/builders/op_instance_norm.py +112 -0
- executorch/backends/qualcomm/builders/op_is_inf.py +71 -0
- executorch/backends/qualcomm/builders/op_is_nan.py +66 -0
- executorch/backends/qualcomm/builders/op_layer_norm.py +139 -0
- executorch/backends/qualcomm/builders/op_le.py +62 -0
- executorch/backends/qualcomm/builders/op_linear.py +98 -0
- executorch/backends/qualcomm/builders/op_log.py +58 -0
- executorch/backends/qualcomm/builders/op_log_softmax.py +81 -0
- executorch/backends/qualcomm/builders/op_logical_not.py +56 -0
- executorch/backends/qualcomm/builders/op_lt.py +62 -0
- executorch/backends/qualcomm/builders/op_matmul.py +59 -0
- executorch/backends/qualcomm/builders/op_max.py +62 -0
- executorch/backends/qualcomm/builders/op_max_dim.py +89 -0
- executorch/backends/qualcomm/builders/op_max_pool2d.py +145 -0
- executorch/backends/qualcomm/builders/op_mean_dim.py +100 -0
- executorch/backends/qualcomm/builders/op_min.py +62 -0
- executorch/backends/qualcomm/builders/op_min_dim.py +89 -0
- executorch/backends/qualcomm/builders/op_mul.py +62 -0
- executorch/backends/qualcomm/builders/op_ne.py +62 -0
- executorch/backends/qualcomm/builders/op_neg.py +54 -0
- executorch/backends/qualcomm/builders/op_or.py +60 -0
- executorch/backends/qualcomm/builders/op_pad.py +107 -0
- executorch/backends/qualcomm/builders/op_pow.py +75 -0
- executorch/backends/qualcomm/builders/op_prelu.py +69 -0
- executorch/backends/qualcomm/builders/op_quantize.py +73 -0
- executorch/backends/qualcomm/builders/op_rand.py +79 -0
- executorch/backends/qualcomm/builders/op_randn.py +79 -0
- executorch/backends/qualcomm/builders/op_relu.py +58 -0
- executorch/backends/qualcomm/builders/op_repeat.py +68 -0
- executorch/backends/qualcomm/builders/op_reshape.py +55 -0
- executorch/backends/qualcomm/builders/op_resize.py +85 -0
- executorch/backends/qualcomm/builders/op_rms_norm.py +149 -0
- executorch/backends/qualcomm/builders/op_round.py +58 -0
- executorch/backends/qualcomm/builders/op_rsqrt.py +58 -0
- executorch/backends/qualcomm/builders/op_scalar_tensor.py +51 -0
- executorch/backends/qualcomm/builders/op_scatter_elements.py +183 -0
- executorch/backends/qualcomm/builders/op_select_copy.py +89 -0
- executorch/backends/qualcomm/builders/op_sigmoid.py +58 -0
- executorch/backends/qualcomm/builders/op_sign.py +56 -0
- executorch/backends/qualcomm/builders/op_sin.py +56 -0
- executorch/backends/qualcomm/builders/op_skip_ops.py +55 -0
- executorch/backends/qualcomm/builders/op_slice_copy.py +95 -0
- executorch/backends/qualcomm/builders/op_slice_scatter.py +122 -0
- executorch/backends/qualcomm/builders/op_softmax.py +79 -0
- executorch/backends/qualcomm/builders/op_sort.py +124 -0
- executorch/backends/qualcomm/builders/op_space_to_depth.py +83 -0
- executorch/backends/qualcomm/builders/op_split_with_sizes.py +99 -0
- executorch/backends/qualcomm/builders/op_sqrt.py +60 -0
- executorch/backends/qualcomm/builders/op_squeeze.py +57 -0
- executorch/backends/qualcomm/builders/op_stack.py +71 -0
- executorch/backends/qualcomm/builders/op_stft.py +183 -0
- executorch/backends/qualcomm/builders/op_sub.py +62 -0
- executorch/backends/qualcomm/builders/op_sum_int_list.py +84 -0
- executorch/backends/qualcomm/builders/op_tanh.py +57 -0
- executorch/backends/qualcomm/builders/op_to.py +149 -0
- executorch/backends/qualcomm/builders/op_topk.py +112 -0
- executorch/backends/qualcomm/builders/op_transpose.py +76 -0
- executorch/backends/qualcomm/builders/op_unary.py +66 -0
- executorch/backends/qualcomm/builders/op_unbind.py +73 -0
- executorch/backends/qualcomm/builders/op_unsqueeze.py +57 -0
- executorch/backends/qualcomm/builders/op_upsample_bilinear2d.py +68 -0
- executorch/backends/qualcomm/builders/op_upsample_nearest2d.py +68 -0
- executorch/backends/qualcomm/builders/op_where.py +82 -0
- executorch/backends/qualcomm/builders/op_xor.py +60 -0
- executorch/backends/qualcomm/builders/qnn_constants.py +720 -0
- executorch/backends/qualcomm/builders/utils.py +196 -0
- executorch/backends/qualcomm/custom_op/annotator.py +137 -0
- executorch/backends/qualcomm/custom_op/interface.py +115 -0
- executorch/backends/qualcomm/debugger/format_outputs.py +235 -0
- executorch/backends/qualcomm/debugger/qcom_numerical_comparator_base.py +194 -0
- executorch/backends/qualcomm/debugger/qcom_numerical_comparator_sample.py +75 -0
- executorch/backends/qualcomm/debugger/qnn_intermediate_debugger.py +101 -0
- executorch/backends/qualcomm/debugger/utils.py +708 -0
- executorch/backends/qualcomm/export_utils.py +1053 -0
- executorch/backends/qualcomm/genai_pipeline/__init__.py +99 -0
- executorch/backends/qualcomm/genai_pipeline/artifact_keys.py +69 -0
- executorch/backends/qualcomm/genai_pipeline/compilation/__init__.py +17 -0
- executorch/backends/qualcomm/genai_pipeline/compilation/compile_spec_builder.py +311 -0
- executorch/backends/qualcomm/genai_pipeline/configs/__init__.py +41 -0
- executorch/backends/qualcomm/genai_pipeline/configs/compilation_input_config.py +71 -0
- executorch/backends/qualcomm/genai_pipeline/configs/compilation_output_config.py +32 -0
- executorch/backends/qualcomm/genai_pipeline/configs/inference_input_config.py +38 -0
- executorch/backends/qualcomm/genai_pipeline/configs/inference_output_config.py +35 -0
- executorch/backends/qualcomm/genai_pipeline/configs/model_preparation_input_config.py +23 -0
- executorch/backends/qualcomm/genai_pipeline/configs/model_preparation_output_config.py +48 -0
- executorch/backends/qualcomm/genai_pipeline/configs/quantization_input_config.py +65 -0
- executorch/backends/qualcomm/genai_pipeline/configs/quantization_output_config.py +19 -0
- executorch/backends/qualcomm/genai_pipeline/control_args.py +419 -0
- executorch/backends/qualcomm/genai_pipeline/datasets/__init__.py +34 -0
- executorch/backends/qualcomm/genai_pipeline/datasets/calibration_data_adapter.py +54 -0
- executorch/backends/qualcomm/genai_pipeline/datasets/default_calibration_data_adapter.py +89 -0
- executorch/backends/qualcomm/genai_pipeline/datasets/default_training_data_adapter.py +65 -0
- executorch/backends/qualcomm/genai_pipeline/datasets/training_data_adapter.py +44 -0
- executorch/backends/qualcomm/genai_pipeline/engine_proxy.py +77 -0
- executorch/backends/qualcomm/genai_pipeline/exceptions.py +52 -0
- executorch/backends/qualcomm/genai_pipeline/genai_pipeline.py +302 -0
- executorch/backends/qualcomm/genai_pipeline/graph_bundle.py +131 -0
- executorch/backends/qualcomm/genai_pipeline/graph_names.py +56 -0
- executorch/backends/qualcomm/genai_pipeline/pipeline_context.py +116 -0
- executorch/backends/qualcomm/genai_pipeline/pipeline_stage.py +33 -0
- executorch/backends/qualcomm/genai_pipeline/pipeline_types.py +29 -0
- executorch/backends/qualcomm/genai_pipeline/stages/__init__.py +25 -0
- executorch/backends/qualcomm/genai_pipeline/stages/compilation_stage.py +35 -0
- executorch/backends/qualcomm/genai_pipeline/stages/inference_stage.py +35 -0
- executorch/backends/qualcomm/genai_pipeline/stages/model_preparation_stage.py +37 -0
- executorch/backends/qualcomm/genai_pipeline/stages/quantization_stage.py +37 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/__init__.py +25 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/compilation/__init__.py +23 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/compilation/compilation_strategy.py +34 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/compilation/compiler_adapter.py +115 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/compilation/default_compiler_adapter.py +299 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/compilation/executorch_compilation_strategy.py +218 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/inference/__init__.py +23 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/inference/default_device_runner_adapter.py +154 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/inference/device_runner_adapter.py +88 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/inference/executorch_inference_strategy.py +159 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/inference/inference_strategy.py +34 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/model_preparation/__init__.py +21 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/model_preparation/default_model_loader_adapter.py +222 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/model_preparation/executorch_model_preparation_strategy.py +240 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/model_preparation/model_loader_adapter.py +130 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/model_preparation/model_preparation_strategy.py +34 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/quantization/__init__.py +21 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/quantization/default_quantizer_adapter.py +167 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/quantization/executorch_quantization_strategy.py +233 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/quantization/quantization_strategy.py +34 -0
- executorch/backends/qualcomm/genai_pipeline/strategies/quantization/quantizer_adapter.py +130 -0
- executorch/backends/qualcomm/genai_pipeline/tests/compilation/__init__.py +5 -0
- executorch/backends/qualcomm/genai_pipeline/tests/test_utils.py +44 -0
- executorch/backends/qualcomm/partition/common_defs.py +40 -0
- executorch/backends/qualcomm/partition/qnn_partitioner.py +402 -0
- executorch/backends/qualcomm/partition/utils.py +274 -0
- executorch/backends/qualcomm/qnn_preprocess.py +347 -0
- executorch/backends/qualcomm/quantizer/annotators/__init__.py +0 -0
- executorch/backends/qualcomm/quantizer/annotators/htp_rules.py +1929 -0
- executorch/backends/qualcomm/quantizer/annotators/lpai_rules.py +1088 -0
- executorch/backends/qualcomm/quantizer/backend_opinfo_adapter.py +184 -0
- executorch/backends/qualcomm/quantizer/conv_bn.py +222 -0
- executorch/backends/qualcomm/quantizer/custom_annotation.py +466 -0
- executorch/backends/qualcomm/quantizer/observers/concat_observer.py +76 -0
- executorch/backends/qualcomm/quantizer/observers/per_block_param_observer.py +146 -0
- executorch/backends/qualcomm/quantizer/observers/per_channel_param_observer.py +157 -0
- executorch/backends/qualcomm/quantizer/qconfig.py +1051 -0
- executorch/backends/qualcomm/quantizer/quant_recipe.py +514 -0
- executorch/backends/qualcomm/quantizer/quantizer.py +819 -0
- executorch/backends/qualcomm/quantizer/registry_loader.py +26 -0
- executorch/backends/qualcomm/quantizer/rules.py +258 -0
- executorch/backends/qualcomm/quantizer/validators.py +461 -0
- executorch/backends/qualcomm/recipes/__init__.py +16 -0
- executorch/backends/qualcomm/recipes/qnn_recipe_provider.py +198 -0
- executorch/backends/qualcomm/recipes/qnn_recipe_types.py +28 -0
- executorch/backends/qualcomm/scripts/download_qnn_sdk.py +863 -0
- executorch/backends/qualcomm/serialization/qc_compiler_spec.fbs +399 -0
- executorch/backends/qualcomm/serialization/qc_schema.py +337 -0
- executorch/backends/qualcomm/serialization/qc_schema_serialize.py +59 -0
- executorch/backends/qualcomm/tests/models.py +3244 -0
- executorch/backends/qualcomm/tests/rework/conftest.py +637 -0
- executorch/backends/qualcomm/tests/rework/gpu/conftest.py +42 -0
- executorch/backends/qualcomm/tests/rework/htp/conftest.py +102 -0
- executorch/backends/qualcomm/tests/rework/lpai/conftest.py +102 -0
- executorch/backends/qualcomm/tests/rework/passes/__init__.py +0 -0
- executorch/backends/qualcomm/tests/rework/passes/conftest.py +183 -0
- executorch/backends/qualcomm/tests/rework/passes/passes_helper.py +317 -0
- executorch/backends/qualcomm/tests/rework/src/fcb_utils.py +60 -0
- executorch/backends/qualcomm/tests/rework/src/feature.py +1048 -0
- executorch/backends/qualcomm/tests/rework/src/op.py +5757 -0
- executorch/backends/qualcomm/tests/rework/src/pattern.py +5207 -0
- executorch/backends/qualcomm/tests/rework/src/utils.py +831 -0
- executorch/backends/qualcomm/tests/test_qnn_delegate.py +12439 -0
- executorch/backends/qualcomm/tests/tester.py +117 -0
- executorch/backends/qualcomm/tests/utils.py +972 -0
- executorch/backends/qualcomm/utils/check_qnn_version.py +110 -0
- executorch/backends/qualcomm/utils/constants.py +64 -0
- executorch/backends/qualcomm/utils/qnn_manager_lifecycle.py +139 -0
- executorch/backends/qualcomm/utils/qnn_sdk_setup.py +199 -0
- executorch/backends/qualcomm/utils/utils.py +1585 -0
- executorch/backends/samsung/_passes/__init__.py +43 -0
- executorch/backends/samsung/_passes/annotate_qparams.py +394 -0
- executorch/backends/samsung/_passes/annotate_scalar_parameters.py +74 -0
- executorch/backends/samsung/_passes/compose_rms_norm.py +99 -0
- executorch/backends/samsung/_passes/compute_const_attrs.py +138 -0
- executorch/backends/samsung/_passes/conv1d_to_conv2d.py +110 -0
- executorch/backends/samsung/_passes/customized_constant_prop.py +113 -0
- executorch/backends/samsung/_passes/decompose_einsum.py +52 -0
- executorch/backends/samsung/_passes/decompose_glu.py +56 -0
- executorch/backends/samsung/_passes/decompose_linalg_vector_norm.py +83 -0
- executorch/backends/samsung/_passes/decompose_remainder.py +126 -0
- executorch/backends/samsung/_passes/decompose_roll.py +84 -0
- executorch/backends/samsung/_passes/enn_pass_manager.py +85 -0
- executorch/backends/samsung/_passes/fold_qdq.py +36 -0
- executorch/backends/samsung/_passes/fuse_activation.py +77 -0
- executorch/backends/samsung/_passes/insert_qdq.py +185 -0
- executorch/backends/samsung/_passes/remove_useless_ops.py +95 -0
- executorch/backends/samsung/_passes/replace_inf_values.py +67 -0
- executorch/backends/samsung/_passes/replace_scalar_ops.py +53 -0
- executorch/backends/samsung/_passes/utils.py +96 -0
- executorch/backends/samsung/builders/__init__.py +147 -0
- executorch/backends/samsung/builders/node_visitor.py +118 -0
- executorch/backends/samsung/builders/op_add.py +48 -0
- executorch/backends/samsung/builders/op_amax.py +49 -0
- executorch/backends/samsung/builders/op_avg_pool2d.py +68 -0
- executorch/backends/samsung/builders/op_batch_norm.py +70 -0
- executorch/backends/samsung/builders/op_bmm.py +45 -0
- executorch/backends/samsung/builders/op_cat.py +52 -0
- executorch/backends/samsung/builders/op_clamp.py +55 -0
- executorch/backends/samsung/builders/op_constant_pad_nd.py +58 -0
- executorch/backends/samsung/builders/op_conv2d.py +107 -0
- executorch/backends/samsung/builders/op_cos.py +33 -0
- executorch/backends/samsung/builders/op_dequantize.py +19 -0
- executorch/backends/samsung/builders/op_div.py +44 -0
- executorch/backends/samsung/builders/op_embedding.py +44 -0
- executorch/backends/samsung/builders/op_exp.py +33 -0
- executorch/backends/samsung/builders/op_expand_copy.py +86 -0
- executorch/backends/samsung/builders/op_flip.py +51 -0
- executorch/backends/samsung/builders/op_floor_divide.py +45 -0
- executorch/backends/samsung/builders/op_gather.py +46 -0
- executorch/backends/samsung/builders/op_gelu.py +42 -0
- executorch/backends/samsung/builders/op_getitem.py +32 -0
- executorch/backends/samsung/builders/op_group_norm.py +48 -0
- executorch/backends/samsung/builders/op_hardsigmoid.py +37 -0
- executorch/backends/samsung/builders/op_hardswish.py +37 -0
- executorch/backends/samsung/builders/op_hardtanh.py +44 -0
- executorch/backends/samsung/builders/op_index.py +47 -0
- executorch/backends/samsung/builders/op_layer_norm.py +55 -0
- executorch/backends/samsung/builders/op_leaky_relu.py +45 -0
- executorch/backends/samsung/builders/op_linear.py +53 -0
- executorch/backends/samsung/builders/op_log.py +34 -0
- executorch/backends/samsung/builders/op_log_softmax.py +41 -0
- executorch/backends/samsung/builders/op_max_dim.py +56 -0
- executorch/backends/samsung/builders/op_max_pool2d.py +94 -0
- executorch/backends/samsung/builders/op_maximum.py +39 -0
- executorch/backends/samsung/builders/op_mean_dim.py +60 -0
- executorch/backends/samsung/builders/op_minimum.py +41 -0
- executorch/backends/samsung/builders/op_mul.py +45 -0
- executorch/backends/samsung/builders/op_neg.py +34 -0
- executorch/backends/samsung/builders/op_pad.py +76 -0
- executorch/backends/samsung/builders/op_permute.py +41 -0
- executorch/backends/samsung/builders/op_pixel_shuffle.py +40 -0
- executorch/backends/samsung/builders/op_pixel_unshuffle.py +44 -0
- executorch/backends/samsung/builders/op_placeholder.py +39 -0
- executorch/backends/samsung/builders/op_pow.py +41 -0
- executorch/backends/samsung/builders/op_prelu.py +43 -0
- executorch/backends/samsung/builders/op_quantize.py +67 -0
- executorch/backends/samsung/builders/op_relu.py +39 -0
- executorch/backends/samsung/builders/op_reshape.py +50 -0
- executorch/backends/samsung/builders/op_rms_norm.py +63 -0
- executorch/backends/samsung/builders/op_rsqrt.py +37 -0
- executorch/backends/samsung/builders/op_select.py +55 -0
- executorch/backends/samsung/builders/op_sigmoid.py +37 -0
- executorch/backends/samsung/builders/op_silu.py +36 -0
- executorch/backends/samsung/builders/op_sin.py +33 -0
- executorch/backends/samsung/builders/op_skip.py +32 -0
- executorch/backends/samsung/builders/op_slice_copy.py +65 -0
- executorch/backends/samsung/builders/op_softmax.py +41 -0
- executorch/backends/samsung/builders/op_split_with_sizes_copy.py +78 -0
- executorch/backends/samsung/builders/op_sqrt.py +37 -0
- executorch/backends/samsung/builders/op_squeeze.py +39 -0
- executorch/backends/samsung/builders/op_sub.py +50 -0
- executorch/backends/samsung/builders/op_sum_int_list.py +42 -0
- executorch/backends/samsung/builders/op_tanh.py +34 -0
- executorch/backends/samsung/builders/op_to_copy.py +46 -0
- executorch/backends/samsung/builders/op_topk.py +96 -0
- executorch/backends/samsung/builders/op_unsqueeze.py +37 -0
- executorch/backends/samsung/builders/op_upsample_bilinear2d.py +60 -0
- executorch/backends/samsung/builders/op_upsample_nearest2d.py +54 -0
- executorch/backends/samsung/builders/utils.py +64 -0
- executorch/backends/samsung/enn_preprocess.py +178 -0
- executorch/backends/samsung/partition/enn_partitioner.py +206 -0
- executorch/backends/samsung/quantizer/__init__.py +10 -0
- executorch/backends/samsung/quantizer/annotator.py +920 -0
- executorch/backends/samsung/quantizer/qconfig.py +142 -0
- executorch/backends/samsung/quantizer/quantizer.py +64 -0
- executorch/backends/samsung/serialization/compile_options.py +231 -0
- executorch/backends/samsung/serialization/compile_options_def.fbs +37 -0
- executorch/backends/samsung/serialization/enn_graph_schema.py +145 -0
- executorch/backends/samsung/test/tester/__init__.py +11 -0
- executorch/backends/samsung/test/tester/samsung_tester.py +182 -0
- executorch/backends/samsung/test/utils/__init__.py +11 -0
- executorch/backends/samsung/test/utils/quant_checkers.py +241 -0
- executorch/backends/samsung/test/utils/run_tests.py +58 -0
- executorch/backends/samsung/test/utils/runtime_executor.py +186 -0
- executorch/backends/samsung/test/utils/utils.py +42 -0
- executorch/backends/samsung/utils/constants.py +45 -0
- executorch/backends/samsung/utils/export_utils.py +82 -0
- executorch/backends/samsung/utils/utils.py +125 -0
- executorch/backends/test/facto/__init__.py +0 -0
- executorch/backends/test/facto/facto_specs.py +59 -0
- executorch/backends/test/facto/test_facto.py +850 -0
- executorch/backends/test/graph_builder.py +158 -0
- executorch/backends/test/harness/__init__.py +3 -0
- executorch/backends/test/harness/error_statistics.py +99 -0
- executorch/backends/test/harness/stages/__init__.py +23 -0
- executorch/backends/test/harness/stages/export.py +32 -0
- executorch/backends/test/harness/stages/partition.py +26 -0
- executorch/backends/test/harness/stages/quantize.py +130 -0
- executorch/backends/test/harness/stages/run_passes.py +68 -0
- executorch/backends/test/harness/stages/serialize.py +59 -0
- executorch/backends/test/harness/stages/stage.py +91 -0
- executorch/backends/test/harness/stages/to_edge.py +27 -0
- executorch/backends/test/harness/stages/to_edge_transform_and_lower.py +50 -0
- executorch/backends/test/harness/stages/to_executorch.py +54 -0
- executorch/backends/test/harness/tester.py +548 -0
- executorch/backends/test/program_builder.py +138 -0
- executorch/backends/test/suite/__init__.py +74 -0
- executorch/backends/test/suite/buck_runner.py +66 -0
- executorch/backends/test/suite/conftest.py +228 -0
- executorch/backends/test/suite/context.py +34 -0
- executorch/backends/test/suite/discovery.py +100 -0
- executorch/backends/test/suite/flow.py +250 -0
- executorch/backends/test/suite/flows/__init__.py +7 -0
- executorch/backends/test/suite/flows/arm.py +98 -0
- executorch/backends/test/suite/flows/coreml.py +31 -0
- executorch/backends/test/suite/flows/cortex_m.py +127 -0
- executorch/backends/test/suite/flows/cpu.py +10 -0
- executorch/backends/test/suite/flows/mlx.py +14 -0
- executorch/backends/test/suite/flows/nxp.py +86 -0
- executorch/backends/test/suite/flows/openvino.py +60 -0
- executorch/backends/test/suite/flows/portable.py +19 -0
- executorch/backends/test/suite/flows/qualcomm.py +61 -0
- executorch/backends/test/suite/flows/samsung.py +43 -0
- executorch/backends/test/suite/flows/vulkan.py +44 -0
- executorch/backends/test/suite/flows/webgpu.py +26 -0
- executorch/backends/test/suite/flows/xnnpack.py +79 -0
- executorch/backends/test/suite/generate_markdown_summary.py +249 -0
- executorch/backends/test/suite/generate_markdown_summary_json.py +229 -0
- executorch/backends/test/suite/models/__init__.py +7 -0
- executorch/backends/test/suite/models/test_torchaudio.py +110 -0
- executorch/backends/test/suite/models/test_torchvision.py +194 -0
- executorch/backends/test/suite/operators/__init__.py +108 -0
- executorch/backends/test/suite/operators/test_abs.py +60 -0
- executorch/backends/test/suite/operators/test_adaptive_avgpool1d.py +102 -0
- executorch/backends/test/suite/operators/test_adaptive_avgpool2d.py +112 -0
- executorch/backends/test/suite/operators/test_adaptive_avgpool3d.py +112 -0
- executorch/backends/test/suite/operators/test_adaptive_maxpool1d.py +125 -0
- executorch/backends/test/suite/operators/test_adaptive_maxpool2d.py +135 -0
- executorch/backends/test/suite/operators/test_adaptive_maxpool3d.py +135 -0
- executorch/backends/test/suite/operators/test_add.py +76 -0
- executorch/backends/test/suite/operators/test_amax.py +257 -0
- executorch/backends/test/suite/operators/test_amin.py +259 -0
- executorch/backends/test/suite/operators/test_argmax.py +201 -0
- executorch/backends/test/suite/operators/test_argmin.py +201 -0
- executorch/backends/test/suite/operators/test_avgpool1d.py +155 -0
- executorch/backends/test/suite/operators/test_avgpool2d.py +168 -0
- executorch/backends/test/suite/operators/test_avgpool3d.py +163 -0
- executorch/backends/test/suite/operators/test_cat.py +176 -0
- executorch/backends/test/suite/operators/test_ceil.py +60 -0
- executorch/backends/test/suite/operators/test_clamp.py +86 -0
- executorch/backends/test/suite/operators/test_conv1d.py +144 -0
- executorch/backends/test/suite/operators/test_conv2d.py +167 -0
- executorch/backends/test/suite/operators/test_conv3d.py +162 -0
- executorch/backends/test/suite/operators/test_convtranspose1d.py +144 -0
- executorch/backends/test/suite/operators/test_convtranspose2d.py +171 -0
- executorch/backends/test/suite/operators/test_convtranspose3d.py +166 -0
- executorch/backends/test/suite/operators/test_div.py +110 -0
- executorch/backends/test/suite/operators/test_elu.py +49 -0
- executorch/backends/test/suite/operators/test_embedding.py +89 -0
- executorch/backends/test/suite/operators/test_embedding_bag.py +118 -0
- executorch/backends/test/suite/operators/test_exp.py +65 -0
- executorch/backends/test/suite/operators/test_expand.py +122 -0
- executorch/backends/test/suite/operators/test_floor.py +57 -0
- executorch/backends/test/suite/operators/test_floor_divide.py +216 -0
- executorch/backends/test/suite/operators/test_gelu.py +52 -0
- executorch/backends/test/suite/operators/test_glu.py +52 -0
- executorch/backends/test/suite/operators/test_hardsigmoid.py +50 -0
- executorch/backends/test/suite/operators/test_hardswish.py +50 -0
- executorch/backends/test/suite/operators/test_hardtanh.py +57 -0
- executorch/backends/test/suite/operators/test_index_put.py +455 -0
- executorch/backends/test/suite/operators/test_index_select.py +128 -0
- executorch/backends/test/suite/operators/test_leaky_relu.py +56 -0
- executorch/backends/test/suite/operators/test_linear.py +124 -0
- executorch/backends/test/suite/operators/test_log.py +80 -0
- executorch/backends/test/suite/operators/test_log10.py +60 -0
- executorch/backends/test/suite/operators/test_log1p.py +60 -0
- executorch/backends/test/suite/operators/test_log2.py +60 -0
- executorch/backends/test/suite/operators/test_logsigmoid.py +40 -0
- executorch/backends/test/suite/operators/test_lstm.py +247 -0
- executorch/backends/test/suite/operators/test_masked_fill.py +101 -0
- executorch/backends/test/suite/operators/test_maxpool1d.py +185 -0
- executorch/backends/test/suite/operators/test_maxpool2d.py +191 -0
- executorch/backends/test/suite/operators/test_maxpool3d.py +189 -0
- executorch/backends/test/suite/operators/test_mean.py +305 -0
- executorch/backends/test/suite/operators/test_median.py +188 -0
- executorch/backends/test/suite/operators/test_mul.py +66 -0
- executorch/backends/test/suite/operators/test_neg.py +70 -0
- executorch/backends/test/suite/operators/test_permute.py +109 -0
- executorch/backends/test/suite/operators/test_pow.py +149 -0
- executorch/backends/test/suite/operators/test_prelu.py +55 -0
- executorch/backends/test/suite/operators/test_relu.py +45 -0
- executorch/backends/test/suite/operators/test_reshape.py +82 -0
- executorch/backends/test/suite/operators/test_round.py +129 -0
- executorch/backends/test/suite/operators/test_rsqrt.py +76 -0
- executorch/backends/test/suite/operators/test_select.py +89 -0
- executorch/backends/test/suite/operators/test_sigmoid.py +40 -0
- executorch/backends/test/suite/operators/test_silu.py +50 -0
- executorch/backends/test/suite/operators/test_slice.py +146 -0
- executorch/backends/test/suite/operators/test_split.py +119 -0
- executorch/backends/test/suite/operators/test_sqrt.py +71 -0
- executorch/backends/test/suite/operators/test_square.py +67 -0
- executorch/backends/test/suite/operators/test_squeeze.py +86 -0
- executorch/backends/test/suite/operators/test_stack.py +114 -0
- executorch/backends/test/suite/operators/test_sub.py +84 -0
- executorch/backends/test/suite/operators/test_tanh.py +40 -0
- executorch/backends/test/suite/operators/test_threshold.py +72 -0
- executorch/backends/test/suite/operators/test_transpose.py +143 -0
- executorch/backends/test/suite/operators/test_trunc.py +73 -0
- executorch/backends/test/suite/operators/test_unsqueeze.py +110 -0
- executorch/backends/test/suite/operators/test_upsample_bilinear2d.py +273 -0
- executorch/backends/test/suite/operators/test_upsample_nearest2d.py +137 -0
- executorch/backends/test/suite/operators/test_view.py +82 -0
- executorch/backends/test/suite/reporting.py +427 -0
- executorch/backends/test/suite/runner.py +331 -0
- executorch/backends/test/suite/tests/__init__.py +0 -0
- executorch/backends/test/suite/tests/test_reporting.py +144 -0
- executorch/backends/transforms/__init__.py +12 -0
- executorch/backends/transforms/addmm_mm_to_linear.py +170 -0
- executorch/backends/transforms/aten_to_dialect_pass.py +121 -0
- executorch/backends/transforms/canonicalize_view_copy_permute_pass.py +443 -0
- executorch/backends/transforms/channels_last_layout.py +22 -0
- executorch/backends/transforms/channels_last_ops.py +187 -0
- executorch/backends/transforms/collapse_view_copy.py +74 -0
- executorch/backends/transforms/convert_conv1d_to_conv2d_pass.py +322 -0
- executorch/backends/transforms/convert_dtype_pass.py +139 -0
- executorch/backends/transforms/decompose_channels_last_pass.py +97 -0
- executorch/backends/transforms/decompose_sdpa.py +208 -0
- executorch/backends/transforms/dim_maps.py +1088 -0
- executorch/backends/transforms/duplicate_dynamic_quant_chain.py +195 -0
- executorch/backends/transforms/enforce_contiguous_dim_order.py +216 -0
- executorch/backends/transforms/fuse_batch_norm_with_conv.py +220 -0
- executorch/backends/transforms/fuse_cascaded_transpose_or_permute_ops.py +185 -0
- executorch/backends/transforms/fuse_cascaded_view_ops.py +43 -0
- executorch/backends/transforms/fuse_conv_with_clamp.py +78 -0
- executorch/backends/transforms/fuse_duplicate_users_pass.py +218 -0
- executorch/backends/transforms/fuse_gqa_with_sdpa.py +217 -0
- executorch/backends/transforms/fuse_identical_input_transforms_pass.py +461 -0
- executorch/backends/transforms/fuse_rms_norm.py +540 -0
- executorch/backends/transforms/fuse_transpose_or_permute_op_pairs_pass.py +111 -0
- executorch/backends/transforms/fuse_view_copy.py +209 -0
- executorch/backends/transforms/mean_to_sum_div.py +41 -0
- executorch/backends/transforms/merge_split_concat_chain.py +153 -0
- executorch/backends/transforms/normalize_sdpa_input_rank.py +100 -0
- executorch/backends/transforms/permute_pass_utils.py +282 -0
- executorch/backends/transforms/permute_view_meta.py +56 -0
- executorch/backends/transforms/postpone_permute_below_squeeze_view.py +208 -0
- executorch/backends/transforms/propagate_view_copy_permute_pass.py +1418 -0
- executorch/backends/transforms/quantize_fused_convbn_bias_pass.py +363 -0
- executorch/backends/transforms/rank_0_to_rank_1.py +18 -0
- executorch/backends/transforms/remove_clone_ops.py +109 -0
- executorch/backends/transforms/remove_getitem_op.py +109 -0
- executorch/backends/transforms/remove_permutes_around_elementwise_ops.py +1059 -0
- executorch/backends/transforms/remove_unused_constants_pass.py +79 -0
- executorch/backends/transforms/replace_channels_last_input_clones.py +133 -0
- executorch/backends/transforms/replace_nop_transpose_or_permute_with_view.py +91 -0
- executorch/backends/transforms/replace_ops_with_channels_last_variants.py +283 -0
- executorch/backends/transforms/replace_scalar_with_tensor.py +99 -0
- executorch/backends/transforms/replace_squeeze_unsqueeze_with_view.py +53 -0
- executorch/backends/transforms/test/common.py +69 -0
- executorch/backends/transforms/utils.py +474 -0
- executorch/backends/transforms/view_copy_to_squeeze_unsqueeze.py +135 -0
- executorch/backends/vulkan/__init__.py +14 -0
- executorch/backends/vulkan/_passes/__init__.py +43 -0
- executorch/backends/vulkan/_passes/conv1d_as_conv2d.py +169 -0
- executorch/backends/vulkan/_passes/fold_qdq.py +40 -0
- executorch/backends/vulkan/_passes/fuse_patterns.py +34 -0
- executorch/backends/vulkan/_passes/fuse_quantized_ops.py +236 -0
- executorch/backends/vulkan/_passes/insert_dtype_promotion.py +102 -0
- executorch/backends/vulkan/_passes/insert_prepack_nodes.py +105 -0
- executorch/backends/vulkan/_passes/remove_asserts.py +52 -0
- executorch/backends/vulkan/_passes/remove_redundant_ops.py +89 -0
- executorch/backends/vulkan/_passes/squeeze_unsqueeze_inputs.py +93 -0
- executorch/backends/vulkan/_passes/tag_memory_meta_pass.py +549 -0
- executorch/backends/vulkan/custom_ops_lib.py +1333 -0
- executorch/backends/vulkan/op_registry.py +2023 -0
- executorch/backends/vulkan/partitioner/vulkan_partitioner.py +515 -0
- executorch/backends/vulkan/patterns/__init__.py +153 -0
- executorch/backends/vulkan/patterns/pattern_registry.py +135 -0
- executorch/backends/vulkan/patterns/quantized_binary.py +161 -0
- executorch/backends/vulkan/patterns/quantized_convolution.py +347 -0
- executorch/backends/vulkan/patterns/quantized_embedding.py +342 -0
- executorch/backends/vulkan/patterns/quantized_linear.py +645 -0
- executorch/backends/vulkan/patterns/quantized_pixel_shuffle.py +180 -0
- executorch/backends/vulkan/patterns/quantized_unary.py +121 -0
- executorch/backends/vulkan/patterns/rms_norm.py +280 -0
- executorch/backends/vulkan/patterns/rope.py +173 -0
- executorch/backends/vulkan/patterns/rope_hf.py +188 -0
- executorch/backends/vulkan/patterns/sdpa.py +155 -0
- executorch/backends/vulkan/patterns/select_as_symint.py +104 -0
- executorch/backends/vulkan/patterns/swiglu.py +65 -0
- executorch/backends/vulkan/patterns/weight_packing_utils.py +51 -0
- executorch/backends/vulkan/quantizer/vulkan_quantizer.py +198 -0
- executorch/backends/vulkan/quantizer/vulkan_quantizer_utils.py +228 -0
- executorch/backends/vulkan/runtime/gen_vulkan_spv.py +1747 -0
- executorch/backends/vulkan/serialization/schema.fbs +162 -0
- executorch/backends/vulkan/serialization/vulkan_graph_builder.py +608 -0
- executorch/backends/vulkan/serialization/vulkan_graph_schema.py +165 -0
- executorch/backends/vulkan/serialization/vulkan_graph_serialize.py +348 -0
- executorch/backends/vulkan/test/op_tests/cases.py +2444 -0
- executorch/backends/vulkan/test/op_tests/utils/aten_types.py +31 -0
- executorch/backends/vulkan/test/op_tests/utils/gen_benchmark_vk.py +363 -0
- executorch/backends/vulkan/test/op_tests/utils/gen_computegraph.py +836 -0
- executorch/backends/vulkan/test/op_tests/utils/gen_correctness_base.py +427 -0
- executorch/backends/vulkan/test/op_tests/utils/gen_correctness_vk.py +177 -0
- executorch/backends/vulkan/test/op_tests/utils/test_suite.py +53 -0
- executorch/backends/vulkan/test/tester.py +91 -0
- executorch/backends/vulkan/test/utils.py +1172 -0
- executorch/backends/vulkan/utils.py +2056 -0
- executorch/backends/vulkan/vulkan_preprocess.py +293 -0
- executorch/backends/webgpu/__init__.py +5 -0
- executorch/backends/webgpu/partitioner/__init__.py +9 -0
- executorch/backends/webgpu/partitioner/partitioner.py +66 -0
- executorch/backends/webgpu/scripts/gen_wgsl_headers.py +859 -0
- executorch/backends/webgpu/test/conftest.py +28 -0
- executorch/backends/webgpu/test/op_tests/__init__.py +5 -0
- executorch/backends/webgpu/test/op_tests/cases.py +2548 -0
- executorch/backends/webgpu/test/op_tests/generate_op_tests.py +278 -0
- executorch/backends/webgpu/test/op_tests/test_generator.py +248 -0
- executorch/backends/webgpu/test/op_tests/test_schema.py +84 -0
- executorch/backends/webgpu/test/op_tests/test_suite.py +101 -0
- executorch/backends/webgpu/test/ops/__init__.py +0 -0
- executorch/backends/webgpu/test/ops/dynamic_shape/test_dynamic_shape_export.py +1708 -0
- executorch/backends/webgpu/test/ops/index/__init__.py +0 -0
- executorch/backends/webgpu/test/ops/index/test_index.py +109 -0
- executorch/backends/webgpu/test/ops/test_adamw.py +142 -0
- executorch/backends/webgpu/test/ops/test_add.py +116 -0
- executorch/backends/webgpu/test/ops/test_addmm.py +28 -0
- executorch/backends/webgpu/test/ops/test_arange.py +103 -0
- executorch/backends/webgpu/test/ops/test_argmax.py +46 -0
- executorch/backends/webgpu/test/ops/test_avg_pool2d.py +98 -0
- executorch/backends/webgpu/test/ops/test_batch_norm.py +42 -0
- executorch/backends/webgpu/test/ops/test_bitwise.py +95 -0
- executorch/backends/webgpu/test/ops/test_bmm.py +104 -0
- executorch/backends/webgpu/test/ops/test_cat.py +82 -0
- executorch/backends/webgpu/test/ops/test_compare.py +169 -0
- executorch/backends/webgpu/test/ops/test_constant_pad_nd.py +23 -0
- executorch/backends/webgpu/test/ops/test_conv1d_dw.py +102 -0
- executorch/backends/webgpu/test/ops/test_conv1d_pw.py +162 -0
- executorch/backends/webgpu/test/ops/test_conv2d.py +95 -0
- executorch/backends/webgpu/test/ops/test_conv_with_clamp.py +106 -0
- executorch/backends/webgpu/test/ops/test_dim_order.py +95 -0
- executorch/backends/webgpu/test/ops/test_dispatch_order.py +119 -0
- executorch/backends/webgpu/test/ops/test_div.py +94 -0
- executorch/backends/webgpu/test/ops/test_embedding.py +103 -0
- executorch/backends/webgpu/test/ops/test_embedding_q4gsw.py +161 -0
- executorch/backends/webgpu/test/ops/test_et_vk_sdpa.py +131 -0
- executorch/backends/webgpu/test/ops/test_expand_copy.py +120 -0
- executorch/backends/webgpu/test/ops/test_fill.py +91 -0
- executorch/backends/webgpu/test/ops/test_flip.py +76 -0
- executorch/backends/webgpu/test/ops/test_floor_divide.py +21 -0
- executorch/backends/webgpu/test/ops/test_fused_ce.py +130 -0
- executorch/backends/webgpu/test/ops/test_gather.py +123 -0
- executorch/backends/webgpu/test/ops/test_gelu.py +59 -0
- executorch/backends/webgpu/test/ops/test_grid_priors.py +80 -0
- executorch/backends/webgpu/test/ops/test_grid_sampler_2d.py +76 -0
- executorch/backends/webgpu/test/ops/test_group_norm.py +83 -0
- executorch/backends/webgpu/test/ops/test_index_select.py +79 -0
- executorch/backends/webgpu/test/ops/test_layer_norm.py +78 -0
- executorch/backends/webgpu/test/ops/test_leaky_relu.py +21 -0
- executorch/backends/webgpu/test/ops/test_linear.py +116 -0
- executorch/backends/webgpu/test/ops/test_linear_dW.py +88 -0
- executorch/backends/webgpu/test/ops/test_linear_dq8ca_q4gsw.py +38 -0
- executorch/backends/webgpu/test/ops/test_linear_fp32.py +77 -0
- executorch/backends/webgpu/test/ops/test_linear_q8ta_q8csw.py +65 -0
- executorch/backends/webgpu/test/ops/test_linear_qcs4w.py +60 -0
- executorch/backends/webgpu/test/ops/test_log_softmax.py +97 -0
- executorch/backends/webgpu/test/ops/test_logical_and.py +79 -0
- executorch/backends/webgpu/test/ops/test_logical_not.py +116 -0
- executorch/backends/webgpu/test/ops/test_logical_or.py +67 -0
- executorch/backends/webgpu/test/ops/test_matmul.py +67 -0
- executorch/backends/webgpu/test/ops/test_max_pool2d.py +42 -0
- executorch/backends/webgpu/test/ops/test_minimum.py +18 -0
- executorch/backends/webgpu/test/ops/test_mul.py +69 -0
- executorch/backends/webgpu/test/ops/test_permute.py +76 -0
- executorch/backends/webgpu/test/ops/test_pixel_shuffle.py +76 -0
- executorch/backends/webgpu/test/ops/test_pow.py +18 -0
- executorch/backends/webgpu/test/ops/test_prepack.py +142 -0
- executorch/backends/webgpu/test/ops/test_q4gsw_requant.py +123 -0
- executorch/backends/webgpu/test/ops/test_q8ta_add.py +70 -0
- executorch/backends/webgpu/test/ops/test_q8ta_conv2d.py +62 -0
- executorch/backends/webgpu/test/ops/test_q8ta_conv2d_dw.py +63 -0
- executorch/backends/webgpu/test/ops/test_q8ta_conv2d_pw.py +58 -0
- executorch/backends/webgpu/test/ops/test_q8ta_conv2d_transposed.py +68 -0
- executorch/backends/webgpu/test/ops/test_q8ta_linear.py +61 -0
- executorch/backends/webgpu/test/ops/test_q8ta_pixel_shuffle.py +64 -0
- executorch/backends/webgpu/test/ops/test_q8ta_relu.py +60 -0
- executorch/backends/webgpu/test/ops/test_quant.py +70 -0
- executorch/backends/webgpu/test/ops/test_quantized_linear.py +406 -0
- executorch/backends/webgpu/test/ops/test_quantized_linear_backward.py +157 -0
- executorch/backends/webgpu/test/ops/test_reduce.py +249 -0
- executorch/backends/webgpu/test/ops/test_relu.py +27 -0
- executorch/backends/webgpu/test/ops/test_repeat.py +77 -0
- executorch/backends/webgpu/test/ops/test_rms_norm.py +192 -0
- executorch/backends/webgpu/test/ops/test_rope.py +129 -0
- executorch/backends/webgpu/test/ops/test_rope_hf.py +388 -0
- executorch/backends/webgpu/test/ops/test_rope_interleaved.py +77 -0
- executorch/backends/webgpu/test/ops/test_sdpa.py +637 -0
- executorch/backends/webgpu/test/ops/test_select.py +67 -0
- executorch/backends/webgpu/test/ops/test_sigmoid.py +80 -0
- executorch/backends/webgpu/test/ops/test_slice.py +66 -0
- executorch/backends/webgpu/test/ops/test_softmax.py +116 -0
- executorch/backends/webgpu/test/ops/test_split_with_sizes_copy.py +39 -0
- executorch/backends/webgpu/test/ops/test_squeeze.py +75 -0
- executorch/backends/webgpu/test/ops/test_sub.py +114 -0
- executorch/backends/webgpu/test/ops/test_to_copy.py +196 -0
- executorch/backends/webgpu/test/ops/test_unary_activations.py +110 -0
- executorch/backends/webgpu/test/ops/test_unsqueeze.py +75 -0
- executorch/backends/webgpu/test/ops/test_update_cache.py +196 -0
- executorch/backends/webgpu/test/ops/test_upsample_bilinear2d.py +29 -0
- executorch/backends/webgpu/test/ops/test_upsample_nearest2d.py +33 -0
- executorch/backends/webgpu/test/ops/test_view_copy.py +66 -0
- executorch/backends/webgpu/test/ops/test_where.py +86 -0
- executorch/backends/webgpu/test/test_cmake_configuration.py +87 -0
- executorch/backends/webgpu/test/test_native_ci_contract.py +79 -0
- executorch/backends/webgpu/test/test_webgpu_partitioner.py +240 -0
- executorch/backends/webgpu/test/test_wgsl_codegen.py +1178 -0
- executorch/backends/webgpu/test/tester.py +145 -0
- executorch/backends/xnnpack/__init__.py +28 -0
- executorch/backends/xnnpack/_passes/__init__.py +116 -0
- executorch/backends/xnnpack/_passes/channels_last_tagged_reshape_pass.py +642 -0
- executorch/backends/xnnpack/_passes/conv1d_unsqueeze_pass.py +206 -0
- executorch/backends/xnnpack/_passes/convert_to_linear.py +202 -0
- executorch/backends/xnnpack/_passes/convert_to_sdpa.py +114 -0
- executorch/backends/xnnpack/_passes/convert_to_upsample_bilinear2d.py +65 -0
- executorch/backends/xnnpack/_passes/decompose_batch_norm.py +294 -0
- executorch/backends/xnnpack/_passes/decompose_cat.py +109 -0
- executorch/backends/xnnpack/_passes/fuse_activation_pass.py +87 -0
- executorch/backends/xnnpack/_passes/fuse_batch_norm.py +294 -0
- executorch/backends/xnnpack/_passes/insert_pad_qdq.py +88 -0
- executorch/backends/xnnpack/_passes/prelu_reshape_pass.py +75 -0
- executorch/backends/xnnpack/_passes/propagate_custom_meta_pass.py +44 -0
- executorch/backends/xnnpack/_passes/remove_noop_expand_copy_pass.py +59 -0
- executorch/backends/xnnpack/_passes/remove_redundant_copy_pass.py +158 -0
- executorch/backends/xnnpack/_passes/rewrite_fp16_silu.py +44 -0
- executorch/backends/xnnpack/_passes/xnnpack_pass.py +22 -0
- executorch/backends/xnnpack/operators/__init__.py +61 -0
- executorch/backends/xnnpack/operators/node_visitor.py +780 -0
- executorch/backends/xnnpack/operators/op_abs.py +52 -0
- executorch/backends/xnnpack/operators/op_add.py +77 -0
- executorch/backends/xnnpack/operators/op_addmm.py +70 -0
- executorch/backends/xnnpack/operators/op_avg_pooling2d.py +70 -0
- executorch/backends/xnnpack/operators/op_bmm.py +54 -0
- executorch/backends/xnnpack/operators/op_cat.py +121 -0
- executorch/backends/xnnpack/operators/op_ceiling.py +52 -0
- executorch/backends/xnnpack/operators/op_clamp.py +64 -0
- executorch/backends/xnnpack/operators/op_clone.py +71 -0
- executorch/backends/xnnpack/operators/op_conv2d.py +189 -0
- executorch/backends/xnnpack/operators/op_cos.py +52 -0
- executorch/backends/xnnpack/operators/op_div.py +56 -0
- executorch/backends/xnnpack/operators/op_dynamic_dequantize_ops.py +114 -0
- executorch/backends/xnnpack/operators/op_dynamic_quantize_ops.py +179 -0
- executorch/backends/xnnpack/operators/op_elu.py +58 -0
- executorch/backends/xnnpack/operators/op_exp.py +52 -0
- executorch/backends/xnnpack/operators/op_floor.py +48 -0
- executorch/backends/xnnpack/operators/op_gelu.py +60 -0
- executorch/backends/xnnpack/operators/op_hardswish.py +52 -0
- executorch/backends/xnnpack/operators/op_hardtanh.py +67 -0
- executorch/backends/xnnpack/operators/op_leaky_relu.py +65 -0
- executorch/backends/xnnpack/operators/op_linear.py +115 -0
- executorch/backends/xnnpack/operators/op_log.py +52 -0
- executorch/backends/xnnpack/operators/op_matrix_multiplication.py +66 -0
- executorch/backends/xnnpack/operators/op_max_dim.py +206 -0
- executorch/backends/xnnpack/operators/op_max_pool2d.py +124 -0
- executorch/backends/xnnpack/operators/op_maximum.py +55 -0
- executorch/backends/xnnpack/operators/op_mean_dim.py +87 -0
- executorch/backends/xnnpack/operators/op_minimum.py +54 -0
- executorch/backends/xnnpack/operators/op_multiply.py +77 -0
- executorch/backends/xnnpack/operators/op_negate.py +51 -0
- executorch/backends/xnnpack/operators/op_permute.py +87 -0
- executorch/backends/xnnpack/operators/op_prelu.py +56 -0
- executorch/backends/xnnpack/operators/op_quant_dequant.py +196 -0
- executorch/backends/xnnpack/operators/op_relu.py +61 -0
- executorch/backends/xnnpack/operators/op_rsqrt.py +52 -0
- executorch/backends/xnnpack/operators/op_sigmoid.py +48 -0
- executorch/backends/xnnpack/operators/op_sin.py +52 -0
- executorch/backends/xnnpack/operators/op_skip_ops.py +89 -0
- executorch/backends/xnnpack/operators/op_slice_copy.py +100 -0
- executorch/backends/xnnpack/operators/op_softmax.py +58 -0
- executorch/backends/xnnpack/operators/op_square.py +52 -0
- executorch/backends/xnnpack/operators/op_square_root.py +52 -0
- executorch/backends/xnnpack/operators/op_squeeze.py +147 -0
- executorch/backends/xnnpack/operators/op_static_constant_pad.py +145 -0
- executorch/backends/xnnpack/operators/op_static_resize_bilinear_2d.py +61 -0
- executorch/backends/xnnpack/operators/op_sub.py +77 -0
- executorch/backends/xnnpack/operators/op_tanh.py +52 -0
- executorch/backends/xnnpack/operators/op_to_copy.py +91 -0
- executorch/backends/xnnpack/operators/op_view_copy.py +96 -0
- executorch/backends/xnnpack/operators/quant_params.py +412 -0
- executorch/backends/xnnpack/partition/config/__init__.py +136 -0
- executorch/backends/xnnpack/partition/config/gemm_configs.py +621 -0
- executorch/backends/xnnpack/partition/config/generic_node_configs.py +925 -0
- executorch/backends/xnnpack/partition/config/node_configs.py +151 -0
- executorch/backends/xnnpack/partition/config/quant_affine_configs.py +56 -0
- executorch/backends/xnnpack/partition/config/xnnpack_config.py +310 -0
- executorch/backends/xnnpack/partition/graphs/bilinear_2d.py +55 -0
- executorch/backends/xnnpack/partition/graphs/sdpa.py +86 -0
- executorch/backends/xnnpack/partition/xnnpack_partitioner.py +166 -0
- executorch/backends/xnnpack/quantizer/xnnpack_quantizer.py +461 -0
- executorch/backends/xnnpack/quantizer/xnnpack_quantizer_utils.py +1214 -0
- executorch/backends/xnnpack/recipes/__init__.py +19 -0
- executorch/backends/xnnpack/recipes/xnnpack_recipe_provider.py +200 -0
- executorch/backends/xnnpack/recipes/xnnpack_recipe_types.py +37 -0
- executorch/backends/xnnpack/serialization/runtime_schema.fbs +390 -0
- executorch/backends/xnnpack/serialization/schema.fbs +382 -0
- executorch/backends/xnnpack/serialization/xnnpack_graph_schema.py +548 -0
- executorch/backends/xnnpack/serialization/xnnpack_graph_serialize.py +393 -0
- executorch/backends/xnnpack/test/__init__.py +0 -0
- executorch/backends/xnnpack/test/passes/__init__.py +0 -0
- executorch/backends/xnnpack/test/test_xnnpack_utils.py +533 -0
- executorch/backends/xnnpack/test/test_xnnpack_utils_classes.py +44 -0
- executorch/backends/xnnpack/test/tester/__init__.py +29 -0
- executorch/backends/xnnpack/test/tester/tester.py +134 -0
- executorch/backends/xnnpack/utils/configs.py +41 -0
- executorch/backends/xnnpack/utils/quant_utils.py +301 -0
- executorch/backends/xnnpack/utils/utils.py +241 -0
- executorch/backends/xnnpack/utils/xnnpack_constants.py +37 -0
- executorch/backends/xnnpack/xnnpack_preprocess.py +194 -0
- executorch/codegen/__init__.py +0 -0
- executorch/codegen/api/__init__.py +0 -0
- executorch/codegen/api/custom_ops.py +151 -0
- executorch/codegen/api/et_cpp.py +367 -0
- executorch/codegen/api/types/__init__.py +5 -0
- executorch/codegen/api/types/signatures.py +77 -0
- executorch/codegen/api/types/types.py +76 -0
- executorch/codegen/api/unboxing.py +232 -0
- executorch/codegen/gen.py +1055 -0
- executorch/codegen/model.py +220 -0
- executorch/codegen/parse.py +158 -0
- executorch/codegen/tools/__init__.py +20 -0
- executorch/codegen/tools/combine_prim_ops_headers.py +164 -0
- executorch/codegen/tools/gen_all_oplist.py +252 -0
- executorch/codegen/tools/gen_max_kernel_num.py +174 -0
- executorch/codegen/tools/gen_oplist.py +370 -0
- executorch/codegen/tools/gen_ops_def.py +96 -0
- executorch/codegen/tools/gen_selected_op_variants.py +135 -0
- executorch/codegen/tools/gen_selected_prim_ops.py +133 -0
- executorch/codegen/tools/merge_yaml.py +125 -0
- executorch/codegen/tools/selective_build.cp315-win_amd64.pyd +0 -0
- executorch/codegen/tools/selective_build.pyi +23 -0
- executorch/codegen/tools/yaml_util.py +15 -0
- executorch/data/bin/__init__.py +44 -0
- executorch/data/bin/flatc.exe +0 -0
- executorch/devtools/__init__.py +19 -0
- executorch/devtools/backend_debug/__init__.py +13 -0
- executorch/devtools/backend_debug/delegation_info.py +183 -0
- executorch/devtools/bundled_program/config.py +120 -0
- executorch/devtools/bundled_program/core.py +395 -0
- executorch/devtools/bundled_program/schema/__init__.py +9 -0
- executorch/devtools/bundled_program/schema/bundled_program_schema.fbs +97 -0
- executorch/devtools/bundled_program/schema/bundled_program_schema.py +99 -0
- executorch/devtools/bundled_program/schema/scalar_type.fbs +43 -0
- executorch/devtools/bundled_program/serialize/__init__.py +298 -0
- executorch/devtools/bundled_program/serialize/bundled_program_schema.fbs +97 -0
- executorch/devtools/bundled_program/serialize/generate_bundled_program.py +174 -0
- executorch/devtools/bundled_program/serialize/generated/__init__.py +9 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/Bool.py +92 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/BundledMethodTestCase.py +194 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/BundledMethodTestSuite.py +158 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/BundledProgram.py +212 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/Double.py +92 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/Int.py +92 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/Tensor.py +267 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/Value.py +125 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/ValueUnion.py +29 -0
- executorch/devtools/bundled_program/serialize/generated/bundled_program_flatbuffer/__init__.py +23 -0
- executorch/devtools/bundled_program/serialize/generated/executorch_flatbuffer/ScalarType.py +28 -0
- executorch/devtools/bundled_program/serialize/generated/executorch_flatbuffer/__init__.py +7 -0
- executorch/devtools/bundled_program/serialize/scalar_type.fbs +43 -0
- executorch/devtools/bundled_program/util/test_util.py +289 -0
- executorch/devtools/bundled_program/version.py +13 -0
- executorch/devtools/debug_format/base_schema.py +61 -0
- executorch/devtools/debug_format/et_schema.py +432 -0
- executorch/devtools/etdump/etdump_schema_flatcc.fbs +181 -0
- executorch/devtools/etdump/scalar_type.fbs +43 -0
- executorch/devtools/etdump/schema_flatcc.py +154 -0
- executorch/devtools/etdump/serialize.py +118 -0
- executorch/devtools/etrecord/__init__.py +13 -0
- executorch/devtools/etrecord/_etrecord.py +929 -0
- executorch/devtools/etrecord/tests/etrecord_test.py +1936 -0
- executorch/devtools/inspector/__init__.py +31 -0
- executorch/devtools/inspector/_inspector.py +1702 -0
- executorch/devtools/inspector/_inspector_utils.py +1264 -0
- executorch/devtools/inspector/_intermediate_output_capturer.py +62 -0
- executorch/devtools/inspector/inspector_cli.py +84 -0
- executorch/devtools/inspector/numerical_comparator/__init__.py +55 -0
- executorch/devtools/inspector/numerical_comparator/l1_numerical_comparator.py +35 -0
- executorch/devtools/inspector/numerical_comparator/mse_numerical_comparator.py +37 -0
- executorch/devtools/inspector/numerical_comparator/numerical_comparator_base.py +266 -0
- executorch/devtools/inspector/numerical_comparator/snr_numerical_comparator.py +47 -0
- executorch/devtools/inspector/tests/inspector_test_utils.py +189 -0
- executorch/devtools/inspector/vgf_neural_statistics.py +183 -0
- executorch/devtools/intermediate_output_tap/__init__.py +93 -0
- executorch/devtools/intermediate_output_tap/_convenience.py +191 -0
- executorch/devtools/intermediate_output_tap/_reducers.py +319 -0
- executorch/devtools/intermediate_output_tap/_selectors.py +231 -0
- executorch/devtools/intermediate_output_tap/_spec.py +55 -0
- executorch/devtools/intermediate_output_tap/_strip_pass.py +92 -0
- executorch/devtools/intermediate_output_tap/_tap_pass.py +278 -0
- executorch/devtools/intermediate_output_tap/custom_ops_lib.py +24 -0
- executorch/devtools/pte_tool/diff_pte.py +895 -0
- executorch/devtools/scripts/generate_profiling_csv.py +62 -0
- executorch/devtools/size_analysis_tool/size_analysis_tool.py +194 -0
- executorch/devtools/size_analysis_tool/size_analysis_tool_test.py +107 -0
- executorch/devtools/visualization/__init__.py +13 -0
- executorch/devtools/visualization/visualization_utils.py +313 -0
- executorch/devtools/visualization/visualization_utils_test.py +177 -0
- executorch/examples/apple/coreml/llama/export.py +224 -0
- executorch/examples/apple/coreml/llama/export_static_llm_coreml.py +717 -0
- executorch/examples/apple/coreml/llama/llama_transformer.py +899 -0
- executorch/examples/apple/coreml/llama/run.py +206 -0
- executorch/examples/apple/coreml/llama/run_lookahead.py +284 -0
- executorch/examples/apple/coreml/llama/run_static_llm.py +293 -0
- executorch/examples/apple/coreml/llama/run_static_llm_multifunction.py +325 -0
- executorch/examples/apple/coreml/llama/test.py +48 -0
- executorch/examples/apple/coreml/llama/utils.py +334 -0
- executorch/examples/apple/coreml/scripts/coreml_compute_plan.py +236 -0
- executorch/examples/apple/coreml/scripts/debugger_cli.py +181 -0
- executorch/examples/apple/coreml/scripts/export.py +280 -0
- executorch/examples/apple/coreml/scripts/extract_coreml_models.py +143 -0
- executorch/examples/apple/coreml/scripts/inspector_cli.py +64 -0
- executorch/examples/apple/coreml/scripts/inspector_utils.py +425 -0
- executorch/examples/apple/coreml/scripts/test_coreml_compute_plan.py +161 -0
- executorch/examples/cuda/scripts/__init__.py +0 -0
- executorch/examples/cuda/scripts/export.py +124 -0
- executorch/examples/cuda/scripts/export_amd_pointwise.py +142 -0
- executorch/examples/llm_pte_finetuning/__init__.py +19 -0
- executorch/examples/llm_pte_finetuning/llama3_config.yaml +96 -0
- executorch/examples/llm_pte_finetuning/model_exporter.py +87 -0
- executorch/examples/llm_pte_finetuning/model_loading_lib.py +143 -0
- executorch/examples/llm_pte_finetuning/phi3_alpaca_code_config.yaml +44 -0
- executorch/examples/llm_pte_finetuning/phi3_config.yaml +42 -0
- executorch/examples/llm_pte_finetuning/qwen_05b_config.yaml +43 -0
- executorch/examples/llm_pte_finetuning/runner.py +135 -0
- executorch/examples/llm_pte_finetuning/training_lib.py +157 -0
- executorch/examples/llm_server/__init__.py +5 -0
- executorch/examples/llm_server/conformance/test_openai_contract.py +207 -0
- executorch/examples/llm_server/evals/__init__.py +5 -0
- executorch/examples/llm_server/evals/terminal_bench/__init__.py +5 -0
- executorch/examples/llm_server/evals/terminal_bench/runner.py +501 -0
- executorch/examples/llm_server/evals/terminal_bench/sessions.py +80 -0
- executorch/examples/llm_server/python/__init__.py +7 -0
- executorch/examples/llm_server/python/chat_template.py +345 -0
- executorch/examples/llm_server/python/errors.py +105 -0
- executorch/examples/llm_server/python/multiplexed_worker_client.py +844 -0
- executorch/examples/llm_server/python/openai_transcript.py +385 -0
- executorch/examples/llm_server/python/protocol.py +165 -0
- executorch/examples/llm_server/python/serve.py +185 -0
- executorch/examples/llm_server/python/server.py +347 -0
- executorch/examples/llm_server/python/serving_chat.py +966 -0
- executorch/examples/llm_server/python/session_runtime.py +873 -0
- executorch/examples/llm_server/python/tests/test_multiplexed_worker_client.py +1681 -0
- executorch/examples/llm_server/python/tests/test_worker_client.py +712 -0
- executorch/examples/llm_server/python/tool_parsers/__init__.py +29 -0
- executorch/examples/llm_server/python/tool_parsers/gemma.py +258 -0
- executorch/examples/llm_server/python/tool_parsers/hermes.py +119 -0
- executorch/examples/llm_server/python/tool_parsers/qwen.py +193 -0
- executorch/examples/llm_server/python/tool_parsers/types.py +33 -0
- executorch/examples/llm_server/python/worker_client.py +660 -0
- executorch/examples/models/__init__.py +125 -0
- executorch/examples/models/checkpoint.py +142 -0
- executorch/examples/models/codegen/__init__.py +16 -0
- executorch/examples/models/codegen/convert_weight.py +93 -0
- executorch/examples/models/deeplab_v3/__init__.py +9 -0
- executorch/examples/models/deeplab_v3/model.py +50 -0
- executorch/examples/models/deepseek-r1-distill-llama-8B/config/deepseek_xnnpack_q8da4w.yaml +16 -0
- executorch/examples/models/deit_tiny/__init__.py +8 -0
- executorch/examples/models/deit_tiny/model.py +36 -0
- executorch/examples/models/dinov2/__init__.py +0 -0
- executorch/examples/models/dinov2/export_dinov2.py +187 -0
- executorch/examples/models/edsr/__init__.py +11 -0
- executorch/examples/models/edsr/model.py +28 -0
- executorch/examples/models/efficient_sam/__init__.py +11 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/build_efficient_sam.py +25 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam.py +316 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam_decoder.py +373 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam_encoder.py +261 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/mlp.py +31 -0
- executorch/examples/models/efficient_sam/efficient_sam_core/two_way_transformer.py +268 -0
- executorch/examples/models/efficient_sam/model.py +34 -0
- executorch/examples/models/emformer_rnnt/__init__.py +17 -0
- executorch/examples/models/emformer_rnnt/model.py +132 -0
- executorch/examples/models/gemma/__init__.py +16 -0
- executorch/examples/models/gemma/convert_weights.py +104 -0
- executorch/examples/models/gemma2/__init__.py +19 -0
- executorch/examples/models/gemma2/convert_weights.py +113 -0
- executorch/examples/models/gemma3/__init__.py +16 -0
- executorch/examples/models/gemma3/convert_weights.py +110 -0
- executorch/examples/models/gemma4/__init__.py +13 -0
- executorch/examples/models/gemma4/export_gemma4.py +884 -0
- executorch/examples/models/gemma4/image_utils.py +155 -0
- executorch/examples/models/gemma4/quant_utils.py +93 -0
- executorch/examples/models/gemma4/run_gemma4.py +365 -0
- executorch/examples/models/gemma4/speech_transform.py +149 -0
- executorch/examples/models/gemma4/text_decoder/__init__.py +17 -0
- executorch/examples/models/gemma4/text_decoder/convert_weights.py +314 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_attention.py +629 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_config.py +299 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_cross_decoder.py +83 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_decoder_layer.py +185 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_model.py +207 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_self_decoder.py +229 -0
- executorch/examples/models/gemma4/text_decoder/gemma4_transformer.py +171 -0
- executorch/examples/models/gemma4_31b/__init__.py +5 -0
- executorch/examples/models/gemma4_31b/cuda_packers.py +160 -0
- executorch/examples/models/gemma4_31b/cuda_source_transformations.py +361 -0
- executorch/examples/models/gemma4_31b/export.py +612 -0
- executorch/examples/models/gemma4_31b/gguf_loader.py +60 -0
- executorch/examples/models/gemma4_31b/inference.py +263 -0
- executorch/examples/models/gemma4_31b/mlx_source_transformations.py +234 -0
- executorch/examples/models/gemma4_31b/model.py +645 -0
- executorch/examples/models/gemma4_31b/quant/quantize.py +340 -0
- executorch/examples/models/gemma4_31b/quant/recipe.py +62 -0
- executorch/examples/models/gemma4_31b/quantize_and_save.py +158 -0
- executorch/examples/models/gemma4_31b/sampler.py +37 -0
- executorch/examples/models/gemma4_31b/serve.py +214 -0
- executorch/examples/models/gemma4_31b/test_ondevice_serving.py +62 -0
- executorch/examples/models/gemma4_31b/test_serve.py +184 -0
- executorch/examples/models/gemma4_31b/tests/test_pipeline.py +504 -0
- executorch/examples/models/glm/__init__.py +16 -0
- executorch/examples/models/glm/convert_weights.py +79 -0
- executorch/examples/models/granite/__init__.py +16 -0
- executorch/examples/models/granite/convert_weights.py +106 -0
- executorch/examples/models/granite_speech/__init__.py +16 -0
- executorch/examples/models/granite_speech/convert_weights.py +111 -0
- executorch/examples/models/inception_v3/__init__.py +11 -0
- executorch/examples/models/inception_v3/model.py +28 -0
- executorch/examples/models/inception_v4/__init__.py +11 -0
- executorch/examples/models/inception_v4/model.py +26 -0
- executorch/examples/models/internvl3/__init__.py +16 -0
- executorch/examples/models/internvl3/convert_weights.py +82 -0
- executorch/examples/models/lfm2/__init__.py +10 -0
- executorch/examples/models/lfm2/config/lfm2_coreml_fp32.yaml +15 -0
- executorch/examples/models/lfm2/config/lfm2_mlx_4w.yaml +15 -0
- executorch/examples/models/lfm2/config/lfm2_xnnpack_fp32.yaml +12 -0
- executorch/examples/models/lfm2/config/lfm2_xnnpack_q8da4w.yaml +15 -0
- executorch/examples/models/lfm2/convert_weights.py +92 -0
- executorch/examples/models/lfm2/short_conv.py +124 -0
- executorch/examples/models/lfm2/test_lfm2_5_mlx.py +102 -0
- executorch/examples/models/llama/__init__.py +20 -0
- executorch/examples/models/llama/attention.py +981 -0
- executorch/examples/models/llama/config/llama_attention_sink.yaml +30 -0
- executorch/examples/models/llama/config/llama_bf16.yaml +7 -0
- executorch/examples/models/llama/config/llama_q8da4w.yaml +11 -0
- executorch/examples/models/llama/config/llama_xnnpack.yaml +17 -0
- executorch/examples/models/llama/config/llama_xnnpack_qat.yaml +23 -0
- executorch/examples/models/llama/config/llama_xnnpack_spinquant.yaml +22 -0
- executorch/examples/models/llama/config/test_llm_config.py +145 -0
- executorch/examples/models/llama/convert_weights.py +135 -0
- executorch/examples/models/llama/eval_llama.py +38 -0
- executorch/examples/models/llama/eval_llama_lib.py +441 -0
- executorch/examples/models/llama/evaluate/__init__.py +11 -0
- executorch/examples/models/llama/evaluate/eager_eval.py +93 -0
- executorch/examples/models/llama/experimental/__init__.py +0 -0
- executorch/examples/models/llama/experimental/generate.py +190 -0
- executorch/examples/models/llama/experimental/load_gguf_q4_0.py +184 -0
- executorch/examples/models/llama/experimental/subclass.py +413 -0
- executorch/examples/models/llama/experimental/test_subclass.py +28 -0
- executorch/examples/models/llama/export_llama.py +56 -0
- executorch/examples/models/llama/export_llama_lib.py +2378 -0
- executorch/examples/models/llama/fairseq2.py +63 -0
- executorch/examples/models/llama/feed_forward.py +73 -0
- executorch/examples/models/llama/hf_download.py +169 -0
- executorch/examples/models/llama/install_requirement_helper.py +70 -0
- executorch/examples/models/llama/llama_transformer.py +604 -0
- executorch/examples/models/llama/lora.py +80 -0
- executorch/examples/models/llama/model.py +402 -0
- executorch/examples/models/llama/model_args.py +243 -0
- executorch/examples/models/llama/norm.py +250 -0
- executorch/examples/models/llama/rope.py +402 -0
- executorch/examples/models/llama/runner/eager.py +142 -0
- executorch/examples/models/llama/runner/generation.py +234 -0
- executorch/examples/models/llama/runner/native.py +145 -0
- executorch/examples/models/llama/source_transformation/__init__.py +0 -0
- executorch/examples/models/llama/source_transformation/apply_spin_quant_r1_r2.py +202 -0
- executorch/examples/models/llama/source_transformation/attention.py +223 -0
- executorch/examples/models/llama/source_transformation/attention_sink.py +375 -0
- executorch/examples/models/llama/source_transformation/custom_kv_cache.py +1034 -0
- executorch/examples/models/llama/source_transformation/lora.py +153 -0
- executorch/examples/models/llama/source_transformation/moe.py +359 -0
- executorch/examples/models/llama/source_transformation/pre_quantization.py +348 -0
- executorch/examples/models/llama/source_transformation/prune_vocab.py +119 -0
- executorch/examples/models/llama/source_transformation/quantize.py +913 -0
- executorch/examples/models/llama/source_transformation/rms_norm.py +23 -0
- executorch/examples/models/llama/source_transformation/rope.py +39 -0
- executorch/examples/models/llama/source_transformation/sdpa.py +553 -0
- executorch/examples/models/llama/source_transformation/spin_quant.py +88 -0
- executorch/examples/models/llama/source_transformation/test_attention_sink.py +624 -0
- executorch/examples/models/llama/source_transformation/test_quantized_kv_cache.py +126 -0
- executorch/examples/models/llama/source_transformation/test_quantized_sdpa.py +167 -0
- executorch/examples/models/llama/source_transformation/test_sdpa_with_quantized_kv_cache.py +170 -0
- executorch/examples/models/llama/static_attention.py +1663 -0
- executorch/examples/models/llama/tokenizer/tiktoken.py +224 -0
- executorch/examples/models/llama3_2_vision/__init__.py +14 -0
- executorch/examples/models/llama3_2_vision/preprocess/__init__.py +0 -0
- executorch/examples/models/llama3_2_vision/preprocess/export_preprocess.py +45 -0
- executorch/examples/models/llama3_2_vision/preprocess/model.py +72 -0
- executorch/examples/models/llama3_2_vision/preprocess/test_preprocess.py +338 -0
- executorch/examples/models/llama3_2_vision/runner/eager.py +59 -0
- executorch/examples/models/llama3_2_vision/runner/exported.py +94 -0
- executorch/examples/models/llama3_2_vision/runner/generation.py +102 -0
- executorch/examples/models/llama3_2_vision/runner/native.py +143 -0
- executorch/examples/models/llama3_2_vision/text_decoder/model.py +199 -0
- executorch/examples/models/llama3_2_vision/vision_encoder/__init__.py +12 -0
- executorch/examples/models/llama3_2_vision/vision_encoder/model.py +96 -0
- executorch/examples/models/llama3_2_vision/vision_encoder/test/__init__.py +0 -0
- executorch/examples/models/llava/__init__.py +11 -0
- executorch/examples/models/llava/export_llava.py +365 -0
- executorch/examples/models/llava/model.py +415 -0
- executorch/examples/models/llava/test/test_llava.py +151 -0
- executorch/examples/models/llava/test/test_pte.py +105 -0
- executorch/examples/models/lstm/__init__.py +12 -0
- executorch/examples/models/lstm/model.py +31 -0
- executorch/examples/models/mlperf_tiny/__init__.py +23 -0
- executorch/examples/models/mlperf_tiny/deep_autoencoder.py +40 -0
- executorch/examples/models/mlperf_tiny/ds_cnn.py +90 -0
- executorch/examples/models/mlperf_tiny/mobilenet_v1_025.py +102 -0
- executorch/examples/models/mlperf_tiny/resnet8.py +98 -0
- executorch/examples/models/mlperf_tiny/streaming_wakeword.py +87 -0
- executorch/examples/models/mobilebert/__init__.py +11 -0
- executorch/examples/models/mobilebert/model.py +31 -0
- executorch/examples/models/mobilenet_v2/__init__.py +12 -0
- executorch/examples/models/mobilenet_v2/model.py +41 -0
- executorch/examples/models/mobilenet_v3/__init__.py +11 -0
- executorch/examples/models/mobilenet_v3/model.py +30 -0
- executorch/examples/models/model_base.py +47 -0
- executorch/examples/models/model_factory.py +60 -0
- executorch/examples/models/moshi/mimi/test_mimi.py +245 -0
- executorch/examples/models/muse-glimmer/__init__.py +13 -0
- executorch/examples/models/muse-glimmer/export/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/export/common.py +169 -0
- executorch/examples/models/muse-glimmer/export/export_dflash.py +1171 -0
- executorch/examples/models/muse-glimmer/export/export_solo.py +1214 -0
- executorch/examples/models/muse-glimmer/inference.py +356 -0
- executorch/examples/models/muse-glimmer/loaders/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/loaders/checkpoint_loader.py +880 -0
- executorch/examples/models/muse-glimmer/loaders/dflash_loader.py +203 -0
- executorch/examples/models/muse-glimmer/loaders/quantize_and_save.py +199 -0
- executorch/examples/models/muse-glimmer/model/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/model/dflash_model.py +532 -0
- executorch/examples/models/muse-glimmer/model/dflash_token_sampler.py +336 -0
- executorch/examples/models/muse-glimmer/model/model.py +969 -0
- executorch/examples/models/muse-glimmer/model/vision_tower.py +197 -0
- executorch/examples/models/muse-glimmer/serving/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/serving/serve.py +512 -0
- executorch/examples/models/muse-glimmer/serving/serve_batching.py +228 -0
- executorch/examples/models/muse-glimmer/serving/stream_parser.py +164 -0
- executorch/examples/models/muse-glimmer/serving/tool_parsers/__init__.py +11 -0
- executorch/examples/models/muse-glimmer/serving/tool_parsers/atem.py +185 -0
- executorch/examples/models/muse-glimmer/source_transformations/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/source_transformations/cuda.py +1130 -0
- executorch/examples/models/muse-glimmer/source_transformations/mlx.py +707 -0
- executorch/examples/models/muse-glimmer/source_transformations/sampler.py +39 -0
- executorch/examples/models/muse-glimmer/tests/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/vision/__init__.py +5 -0
- executorch/examples/models/muse-glimmer/vision/precompute.py +297 -0
- executorch/examples/models/muse_glimmer/__init__.py +13 -0
- executorch/examples/models/muse_glimmer/export/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/export/common.py +169 -0
- executorch/examples/models/muse_glimmer/export/export_dflash.py +1171 -0
- executorch/examples/models/muse_glimmer/export/export_solo.py +1214 -0
- executorch/examples/models/muse_glimmer/inference.py +356 -0
- executorch/examples/models/muse_glimmer/loaders/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/loaders/checkpoint_loader.py +880 -0
- executorch/examples/models/muse_glimmer/loaders/dflash_loader.py +203 -0
- executorch/examples/models/muse_glimmer/loaders/quantize_and_save.py +199 -0
- executorch/examples/models/muse_glimmer/model/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/model/dflash_model.py +532 -0
- executorch/examples/models/muse_glimmer/model/dflash_token_sampler.py +336 -0
- executorch/examples/models/muse_glimmer/model/model.py +969 -0
- executorch/examples/models/muse_glimmer/model/vision_tower.py +197 -0
- executorch/examples/models/muse_glimmer/serving/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/serving/serve.py +512 -0
- executorch/examples/models/muse_glimmer/serving/serve_batching.py +228 -0
- executorch/examples/models/muse_glimmer/serving/stream_parser.py +164 -0
- executorch/examples/models/muse_glimmer/serving/tool_parsers/__init__.py +11 -0
- executorch/examples/models/muse_glimmer/serving/tool_parsers/atem.py +185 -0
- executorch/examples/models/muse_glimmer/source_transformations/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/source_transformations/cuda.py +1130 -0
- executorch/examples/models/muse_glimmer/source_transformations/mlx.py +707 -0
- executorch/examples/models/muse_glimmer/source_transformations/sampler.py +39 -0
- executorch/examples/models/muse_glimmer/tests/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/tests/gen_prompt_golden.py +59 -0
- executorch/examples/models/muse_glimmer/tests/gen_resize_golden.py +46 -0
- executorch/examples/models/muse_glimmer/tests/prompt_cases.py +193 -0
- executorch/examples/models/muse_glimmer/tests/test_mlx_pipeline.py +289 -0
- executorch/examples/models/muse_glimmer/tests/test_pipeline.py +1235 -0
- executorch/examples/models/muse_glimmer/tests/test_prompt_tokens.py +365 -0
- executorch/examples/models/muse_glimmer/tests/test_serve.py +1041 -0
- executorch/examples/models/muse_glimmer/vision/__init__.py +5 -0
- executorch/examples/models/muse_glimmer/vision/precompute.py +297 -0
- executorch/examples/models/nemotron3_diarization/__init__.py +5 -0
- executorch/examples/models/nemotron3_diarization/export_nemotron.py +295 -0
- executorch/examples/models/parakeet/export_parakeet_tdt.py +826 -0
- executorch/examples/models/parakeet/quantize.py +8 -0
- executorch/examples/models/phi-3-mini/__init__.py +11 -0
- executorch/examples/models/phi-3-mini-lora/export_model.py +144 -0
- executorch/examples/models/phi_4_mini/__init__.py +16 -0
- executorch/examples/models/phi_4_mini/config/phi_4_mini_xnnpack.yaml +12 -0
- executorch/examples/models/phi_4_mini/convert_weights.py +153 -0
- executorch/examples/models/qwen2_5/__init__.py +16 -0
- executorch/examples/models/qwen2_5/config/qwen2_5_coder_xnnpack_q8da4w.yaml +20 -0
- executorch/examples/models/qwen2_5/config/qwen2_5_xnnpack_q8da4w.yaml +14 -0
- executorch/examples/models/qwen2_5/convert_weights.py +105 -0
- executorch/examples/models/qwen3/__init__.py +16 -0
- executorch/examples/models/qwen3/config/qwen3_multimethod.yaml +34 -0
- executorch/examples/models/qwen3/config/qwen3_xnnpack_lora.yaml +21 -0
- executorch/examples/models/qwen3/config/qwen3_xnnpack_q8da4w.yaml +20 -0
- executorch/examples/models/qwen3/convert_weights.py +142 -0
- executorch/examples/models/qwen3_5/__init__.py +19 -0
- executorch/examples/models/qwen3_5/config/qwen3_5_xnnpack_fp32.yaml +21 -0
- executorch/examples/models/qwen3_5/convert_weights.py +165 -0
- executorch/examples/models/qwen3_5/tests/__init__.py +2 -0
- executorch/examples/models/qwen3_5_moe/__init__.py +0 -0
- executorch/examples/models/qwen3_5_moe/export.py +1379 -0
- executorch/examples/models/qwen3_5_moe/inference.py +196 -0
- executorch/examples/models/qwen3_5_moe/metal_source_transformations.py +336 -0
- executorch/examples/models/qwen3_5_moe/mlx_source_transformations.py +371 -0
- executorch/examples/models/qwen3_5_moe/model.py +955 -0
- executorch/examples/models/qwen3_5_moe/quantize_and_save.py +570 -0
- executorch/examples/models/qwen3_5_moe/run.py +329 -0
- executorch/examples/models/qwen3_5_moe/sampler.py +60 -0
- executorch/examples/models/qwen3_5_moe/serve.py +182 -0
- executorch/examples/models/qwen3_5_moe/test_chunked_prefill.py +124 -0
- executorch/examples/models/qwen3_5_moe/test_quantize_roundtrip.py +323 -0
- executorch/examples/models/qwen3_5_moe/test_sampler.py +142 -0
- executorch/examples/models/qwen3_5_moe/test_serve.py +158 -0
- executorch/examples/models/qwen3_5_moe/test_turboquant.py +211 -0
- executorch/examples/models/resnet/__init__.py +12 -0
- executorch/examples/models/resnet/model.py +48 -0
- executorch/examples/models/silero_vad/export_silero_vad.py +232 -0
- executorch/examples/models/smollm2/__init__.py +16 -0
- executorch/examples/models/smollm2/convert_weights.py +84 -0
- executorch/examples/models/smollm3/__init__.py +16 -0
- executorch/examples/models/smollm3/convert_weights.py +112 -0
- executorch/examples/models/smolvlm/__init__.py +16 -0
- executorch/examples/models/smolvlm/convert_weights.py +77 -0
- executorch/examples/models/sortformer/export_sortformer.py +409 -0
- executorch/examples/models/sortformer/validate_pte.py +136 -0
- executorch/examples/models/spark_x2_5/__init__.py +5 -0
- executorch/examples/models/spark_x2_5/config/spark_x2_5_xnnpack_fp32.yaml +12 -0
- executorch/examples/models/spark_x2_5/config/spark_x2_5_xnnpack_q8da4w.yaml +15 -0
- executorch/examples/models/spark_x2_5/convert_weights.py +136 -0
- executorch/examples/models/spark_x2_5/test_spark_x2_5.py +125 -0
- executorch/examples/models/stable_diffusion/__init__.py +21 -0
- executorch/examples/models/stable_diffusion/model.py +202 -0
- executorch/examples/models/stable_diffusion_3_5_large/__init__.py +28 -0
- executorch/examples/models/stable_diffusion_3_5_large/export_sd3_5_large.py +445 -0
- executorch/examples/models/stable_diffusion_3_5_large/model.py +415 -0
- executorch/examples/models/supertonic/__init__.py +5 -0
- executorch/examples/models/supertonic/export/__init__.py +5 -0
- executorch/examples/models/supertonic/export/common.py +348 -0
- executorch/examples/models/supertonic/export/export_supertonic.py +147 -0
- executorch/examples/models/supertonic/loaders/__init__.py +5 -0
- executorch/examples/models/supertonic/loaders/checkpoint_loader.py +549 -0
- executorch/examples/models/supertonic/loaders/voice_style_loader.py +57 -0
- executorch/examples/models/supertonic/model/__init__.py +5 -0
- executorch/examples/models/supertonic/model/config.py +62 -0
- executorch/examples/models/supertonic/model/duration_predictor.py +153 -0
- executorch/examples/models/supertonic/model/layers.py +200 -0
- executorch/examples/models/supertonic/model/text_encoder.py +346 -0
- executorch/examples/models/supertonic/model/vector_estimator.py +576 -0
- executorch/examples/models/supertonic/model/vocoder.py +204 -0
- executorch/examples/models/supertonic/preprocessing.py +207 -0
- executorch/examples/models/supertonic/source_transformations/__init__.py +5 -0
- executorch/examples/models/supertonic/source_transformations/mlx.py +245 -0
- executorch/examples/models/supertonic/tests/__init__.py +5 -0
- executorch/examples/models/test/__init__.py +0 -0
- executorch/examples/models/torchvision_vit/__init__.py +11 -0
- executorch/examples/models/torchvision_vit/model.py +28 -0
- executorch/examples/models/toy_model/__init__.py +25 -0
- executorch/examples/models/toy_model/model.py +143 -0
- executorch/examples/models/voxtral_realtime/__init__.py +5 -0
- executorch/examples/models/voxtral_realtime/export_voxtral_rt.py +798 -0
- executorch/examples/models/voxtral_realtime/model.py +1517 -0
- executorch/examples/models/voxtral_tts/__init__.py +5 -0
- executorch/examples/models/voxtral_tts/export_voxtral_tts.py +720 -0
- executorch/examples/models/voxtral_tts/model.py +1609 -0
- executorch/examples/models/voxtral_tts/voice.py +91 -0
- executorch/examples/models/wav2letter/__init__.py +11 -0
- executorch/examples/models/wav2letter/model.py +29 -0
- executorch/examples/models/whisper/__init__.py +8 -0
- executorch/examples/models/whisper/model.py +43 -0
- executorch/examples/models/yolo26/__init__.py +8 -0
- executorch/examples/models/yolo26/export_and_validate.py +400 -0
- executorch/examples/models/yolo26/model.py +31 -0
- executorch/examples/nxp/__init__.py +4 -0
- executorch/examples/nxp/analyzing_with_inspector.py +90 -0
- executorch/examples/nxp/aot_neutron_compile.py +511 -0
- executorch/examples/nxp/experimental/__init__.py +4 -0
- executorch/examples/nxp/experimental/cifar_net/__init__.py +4 -0
- executorch/examples/nxp/experimental/cifar_net/cifar_net.py +301 -0
- executorch/examples/nxp/models/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/anomaly_detection/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/anomaly_detection/mlperf_tiny_anomaly_detection.py +182 -0
- executorch/examples/nxp/models/mlperf_tiny/image_classification/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/image_classification/mlperf_tiny_image_classification.py +52 -0
- executorch/examples/nxp/models/mlperf_tiny/keyword_spotting/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/keyword_spotting/mlperf_tiny_keyword_spotting.py +60 -0
- executorch/examples/nxp/models/mlperf_tiny/visual_wake_words/__init__.py +4 -0
- executorch/examples/nxp/models/mlperf_tiny/visual_wake_words/mlperf_tiny_visual_wake_words.py +64 -0
- executorch/examples/nxp/models/mobilenet_v2.py +103 -0
- executorch/examples/nxp/models/nxp_test_base_model.py +202 -0
- executorch/examples/qualcomm/__init__.py +5 -0
- executorch/examples/qualcomm/custom_op/custom_ops_1.py +307 -0
- executorch/examples/qualcomm/custom_op/custom_ops_2.py +317 -0
- executorch/examples/qualcomm/custom_op/custom_ops_lpai.py +511 -0
- executorch/examples/qualcomm/oss_scripts/__init__.py +5 -0
- executorch/examples/qualcomm/oss_scripts/albert.py +175 -0
- executorch/examples/qualcomm/oss_scripts/bert.py +163 -0
- executorch/examples/qualcomm/oss_scripts/conv_former.py +135 -0
- executorch/examples/qualcomm/oss_scripts/convnext_small.py +139 -0
- executorch/examples/qualcomm/oss_scripts/cvt.py +201 -0
- executorch/examples/qualcomm/oss_scripts/deit.py +153 -0
- executorch/examples/qualcomm/oss_scripts/depthanything_v2_small.py +214 -0
- executorch/examples/qualcomm/oss_scripts/dino_v2.py +139 -0
- executorch/examples/qualcomm/oss_scripts/distilbert.py +164 -0
- executorch/examples/qualcomm/oss_scripts/dit.py +153 -0
- executorch/examples/qualcomm/oss_scripts/efficientSAM/efficientSAM.py +329 -0
- executorch/examples/qualcomm/oss_scripts/efficientSAM/source_transformation/__init__.py +17 -0
- executorch/examples/qualcomm/oss_scripts/efficientSAM/source_transformation/mask_decoder.py +125 -0
- executorch/examples/qualcomm/oss_scripts/efficientSAM/source_transformation/pos_emb.py +64 -0
- executorch/examples/qualcomm/oss_scripts/efficientnet.py +144 -0
- executorch/examples/qualcomm/oss_scripts/esrgan.py +172 -0
- executorch/examples/qualcomm/oss_scripts/eurobert.py +173 -0
- executorch/examples/qualcomm/oss_scripts/fastvit.py +218 -0
- executorch/examples/qualcomm/oss_scripts/fbnet.py +137 -0
- executorch/examples/qualcomm/oss_scripts/focalnet.py +138 -0
- executorch/examples/qualcomm/oss_scripts/gMLP_image_classification.py +127 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/model_wrapper.py +232 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/__init__.py +9 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/attention.py +253 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/convert_weights.py +26 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/cross_decoder.py +80 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/decoder_layer.py +114 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/feed_forward.py +56 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/self_decoder.py +80 -0
- executorch/examples/qualcomm/oss_scripts/gemma4/text_decoder/text_model.py +128 -0
- executorch/examples/qualcomm/oss_scripts/hf_causal_lm.py +288 -0
- executorch/examples/qualcomm/oss_scripts/llama/__init__.py +632 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/__init__.py +69 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/builders.py +549 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/collators.py +127 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/config.py +61 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/constants.py +7 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/datasets.py +48 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/loaders.py +192 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/preprocessors.py +122 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/schema.py +34 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/targets.py +43 -0
- executorch/examples/qualcomm/oss_scripts/llama/decoder_constants.py +67 -0
- executorch/examples/qualcomm/oss_scripts/llama/encoder/__init__.py +31 -0
- executorch/examples/qualcomm/oss_scripts/llama/encoder/encoder_config.py +120 -0
- executorch/examples/qualcomm/oss_scripts/llama/encoder/encoder_quant_recipe.py +118 -0
- executorch/examples/qualcomm/oss_scripts/llama/evaluator/__init__.py +25 -0
- executorch/examples/qualcomm/oss_scripts/llama/evaluator/device_evaluator.py +795 -0
- executorch/examples/qualcomm/oss_scripts/llama/evaluator/lm_eval_adapter.py +99 -0
- executorch/examples/qualcomm/oss_scripts/llama/inference/__init__.py +25 -0
- executorch/examples/qualcomm/oss_scripts/llama/inference/decoder.py +164 -0
- executorch/examples/qualcomm/oss_scripts/llama/inference/encoder.py +22 -0
- executorch/examples/qualcomm/oss_scripts/llama/inference/model.py +59 -0
- executorch/examples/qualcomm/oss_scripts/llama/llama.py +990 -0
- executorch/examples/qualcomm/oss_scripts/llama/masking_utils.py +312 -0
- executorch/examples/qualcomm/oss_scripts/llama/mix_precision_analyzer.py +694 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/__init__.py +18 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/apply_rope.py +52 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/audio_encoder.py +163 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/embedding.py +39 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/feed_forward.py +141 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/layernorm.py +50 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/static_llama.py +1093 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/vision_encoder.py +374 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/__init__.py +13 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/ptq.py +77 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/qat.py +105 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/strategy.py +34 -0
- executorch/examples/qualcomm/oss_scripts/llama/range_setting_pt2e.py +279 -0
- executorch/examples/qualcomm/oss_scripts/llama/static_llm_quant_recipe.py +802 -0
- executorch/examples/qualcomm/oss_scripts/llama/tokenizer.py +417 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/__init__.py +25 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/config/__init__.py +11 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/config/config.py +45 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/config/lr_config.yaml +49 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/config/qad.yaml +20 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/loss.py +66 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/trainer.py +303 -0
- executorch/examples/qualcomm/oss_scripts/llama/train/utils.py +96 -0
- executorch/examples/qualcomm/oss_scripts/llama/utils.py +70 -0
- executorch/examples/qualcomm/oss_scripts/llama/wrappers/__init__.py +23 -0
- executorch/examples/qualcomm/oss_scripts/llama/wrappers/attention_sink_wrappers.py +469 -0
- executorch/examples/qualcomm/oss_scripts/llama/wrappers/base_component.py +201 -0
- executorch/examples/qualcomm/oss_scripts/llama/wrappers/llm_wrappers.py +1534 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/decoder_model_wrapper.py +283 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/eval_decoder_model_qnn.py +299 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/llm_quant_recipe.py +314 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/qnn_decoder_model_manager.py +423 -0
- executorch/examples/qualcomm/oss_scripts/maxvit_t.py +247 -0
- executorch/examples/qualcomm/oss_scripts/mobilevit_v1.py +166 -0
- executorch/examples/qualcomm/oss_scripts/mobilevit_v2.py +171 -0
- executorch/examples/qualcomm/oss_scripts/moshi/mimi.py +525 -0
- executorch/examples/qualcomm/oss_scripts/moshi/model/static_conv.py +145 -0
- executorch/examples/qualcomm/oss_scripts/moshi/model/static_convtr.py +175 -0
- executorch/examples/qualcomm/oss_scripts/moshi/model/static_mimi.py +679 -0
- executorch/examples/qualcomm/oss_scripts/moshi/model/static_seanet_decoder.py +313 -0
- executorch/examples/qualcomm/oss_scripts/pvt.py +137 -0
- executorch/examples/qualcomm/oss_scripts/regnet.py +144 -0
- executorch/examples/qualcomm/oss_scripts/retinanet.py +319 -0
- executorch/examples/qualcomm/oss_scripts/roberta.py +191 -0
- executorch/examples/qualcomm/oss_scripts/squeezenet.py +129 -0
- executorch/examples/qualcomm/oss_scripts/ssd300_vgg16.py +275 -0
- executorch/examples/qualcomm/oss_scripts/swin_transformer.py +191 -0
- executorch/examples/qualcomm/oss_scripts/swin_v2_t.py +189 -0
- executorch/examples/qualcomm/oss_scripts/t5/t5.py +380 -0
- executorch/examples/qualcomm/oss_scripts/t5/t5_model.py +550 -0
- executorch/examples/qualcomm/oss_scripts/vit_b_16.py +140 -0
- executorch/examples/qualcomm/oss_scripts/whisper/whisper.py +543 -0
- executorch/examples/qualcomm/oss_scripts/whisper/whisper_model.py +114 -0
- executorch/examples/qualcomm/qaihub_scripts/llama/llama2/qaihub_llama2_7b.py +241 -0
- executorch/examples/qualcomm/qaihub_scripts/llama/llama3/qaihub_llama3_8b.py +248 -0
- executorch/examples/qualcomm/qaihub_scripts/stable_diffusion/qaihub_stable_diffusion.py +403 -0
- executorch/examples/qualcomm/qaihub_scripts/stable_diffusion/stable_diffusion_lib.py +22 -0
- executorch/examples/qualcomm/qaihub_scripts/utils/export.py +509 -0
- executorch/examples/qualcomm/qaihub_scripts/utils/utils.py +82 -0
- executorch/examples/qualcomm/scripts/deeplab_v3.py +199 -0
- executorch/examples/qualcomm/scripts/edsr.py +231 -0
- executorch/examples/qualcomm/scripts/export_example.py +127 -0
- executorch/examples/qualcomm/scripts/inception_v3.py +133 -0
- executorch/examples/qualcomm/scripts/inception_v4.py +132 -0
- executorch/examples/qualcomm/scripts/mobilebert_fine_tune.py +378 -0
- executorch/examples/qualcomm/scripts/mobilenet_v2.py +133 -0
- executorch/examples/qualcomm/scripts/mobilenet_v3.py +140 -0
- executorch/examples/qualcomm/scripts/torchvision_vit.py +180 -0
- executorch/examples/qualcomm/scripts/wav2letter.py +218 -0
- executorch/examples/qualcomm/util_scripts/cli.py +731 -0
- executorch/examples/qualcomm/util_scripts/fcb.py +347 -0
- executorch/examples/qualcomm/util_scripts/gen_etrecord.py +104 -0
- executorch/examples/qualcomm/util_scripts/htp_profiling_on_device_op_trace_offline.py +132 -0
- executorch/examples/qualcomm/util_scripts/htp_profiling_on_device_op_trace_online.py +130 -0
- executorch/examples/qualcomm/util_scripts/htp_profiling_on_host_hextimate.py +112 -0
- executorch/examples/qualcomm/util_scripts/qnn_intermediate_debugger_demo.py +217 -0
- executorch/examples/qualcomm/utils.py +364 -0
- executorch/examples/xnnpack/__init__.py +51 -0
- executorch/examples/xnnpack/aot_compiler.py +151 -0
- executorch/examples/xnnpack/quantization/example.py +205 -0
- executorch/examples/xnnpack/quantization/utils.py +42 -0
- executorch/exir/__init__.py +57 -0
- executorch/exir/_program_utils.py +109 -0
- executorch/exir/_serialize/__init__.py +20 -0
- executorch/exir/_serialize/_cord.py +140 -0
- executorch/exir/_serialize/_dataclass.py +145 -0
- executorch/exir/_serialize/_flatbuffer.py +467 -0
- executorch/exir/_serialize/_flatbuffer_program.py +359 -0
- executorch/exir/_serialize/_named_data_store.py +358 -0
- executorch/exir/_serialize/_program.py +809 -0
- executorch/exir/_serialize/_ptn.py +370 -0
- executorch/exir/_serialize/_serialize.py +123 -0
- executorch/exir/_serialize/data_serializer.py +120 -0
- executorch/exir/_serialize/generate_program.py +167 -0
- executorch/exir/_serialize/generated/__init__.py +7 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/AllocationDetails.py +130 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/BackendDelegate.py +189 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/BackendDelegateDataReference.py +113 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/BackendDelegateInlineData.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Bool.py +96 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/BoolList.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Buffer.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Chain.py +317 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/CompileSpec.py +162 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/ContainerMetadata.py +120 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DataLocation.py +7 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DataSegment.py +113 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DelegateCall.py +218 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DelegateScratch.py +128 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DeviceType.py +7 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Double.py +96 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/DoubleList.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/EValue.py +137 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/ExecutionPlan.py +595 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/ExtraTensorInfo.py +168 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Frame.py +157 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/FrameList.py +143 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/FreeCall.py +96 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Instruction.py +131 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/InstructionArguments.py +33 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Int.py +96 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/IntList.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/JumpFalseCall.py +113 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/KernelCall.py +158 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/KernelTypes.py +57 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/MoveCall.py +113 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/NamedData.py +117 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/NonConstBufferDevice.py +130 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Null.py +80 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Operator.py +120 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/OptionalTensorList.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Program.py +474 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/ScalarType.py +28 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/String.py +100 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/SubsegmentOffsets.py +158 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/Tensor.py +355 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/TensorDataLocation.py +7 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/TensorList.py +141 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/TensorShapeDynamism.py +8 -0
- executorch/exir/_serialize/generated/executorch_flatbuffer/__init__.py +93 -0
- executorch/exir/_serialize/padding.py +39 -0
- executorch/exir/_serialize/program.fbs +551 -0
- executorch/exir/_serialize/scalar_type.fbs +43 -0
- executorch/exir/_serialize/test/__init__.py +0 -0
- executorch/exir/_warnings.py +44 -0
- executorch/exir/backend/backend_api.py +808 -0
- executorch/exir/backend/backend_details.py +206 -0
- executorch/exir/backend/canonical_partitioners/all_node_partitioner.py +55 -0
- executorch/exir/backend/canonical_partitioners/config_partitioner.py +262 -0
- executorch/exir/backend/canonical_partitioners/duplicate_constant_node_pass.py +154 -0
- executorch/exir/backend/canonical_partitioners/duplicate_dequant_node_pass.py +111 -0
- executorch/exir/backend/canonical_partitioners/group_partitioner.py +495 -0
- executorch/exir/backend/canonical_partitioners/pattern_op_partitioner.py +188 -0
- executorch/exir/backend/compile_spec_schema.py +17 -0
- executorch/exir/backend/operator_support.py +127 -0
- executorch/exir/backend/partitioner.py +139 -0
- executorch/exir/backend/test/backend_with_compiler_demo.py +144 -0
- executorch/exir/backend/test/backend_with_delegate_mapping_demo.py +210 -0
- executorch/exir/backend/test/backend_with_named_data_map.py +115 -0
- executorch/exir/backend/test/backend_with_preprocess_all_demo.py +297 -0
- executorch/exir/backend/test/demo_backend.py +35 -0
- executorch/exir/backend/test/demos/rpc/executor_backend_partitioner.py +77 -0
- executorch/exir/backend/test/demos/rpc/executor_backend_preprocess.py +39 -0
- executorch/exir/backend/test/device_util.py +112 -0
- executorch/exir/backend/test/hta_partitioner_demo.py +247 -0
- executorch/exir/backend/test/op_partitioner_demo.py +266 -0
- executorch/exir/backend/utils.py +750 -0
- executorch/exir/banked_memory_planning.py +490 -0
- executorch/exir/capture/__init__.py +28 -0
- executorch/exir/capture/_capture.py +381 -0
- executorch/exir/capture/_config.py +140 -0
- executorch/exir/capture/_unlift.py +159 -0
- executorch/exir/common.py +140 -0
- executorch/exir/control_flow.py +204 -0
- executorch/exir/debug_handle_utils.py +29 -0
- executorch/exir/delegate.py +171 -0
- executorch/exir/delegate.pyi +21 -0
- executorch/exir/dialects/__init__.py +0 -0
- executorch/exir/dialects/_ops.py +166 -0
- executorch/exir/dialects/backend/_ops.py +123 -0
- executorch/exir/dialects/edge/_ops.py +405 -0
- executorch/exir/dialects/edge/arg/model.py +238 -0
- executorch/exir/dialects/edge/arg/type.py +46 -0
- executorch/exir/dialects/edge/dtype/runner.py +122 -0
- executorch/exir/dialects/edge/dtype/supported.py +49 -0
- executorch/exir/dialects/edge/dtype/utils.py +36 -0
- executorch/exir/dialects/edge/edge.yaml +8388 -0
- executorch/exir/dialects/edge/op/api.py +86 -0
- executorch/exir/dialects/edge/op/sample_input.py +1283 -0
- executorch/exir/dialects/edge/spec/gen.py +523 -0
- executorch/exir/dialects/edge/spec/utils.py +328 -0
- executorch/exir/dim_order_utils.py +85 -0
- executorch/exir/dynamic_shape.py +12 -0
- executorch/exir/emit/__init__.py +11 -0
- executorch/exir/emit/_emit_program.py +216 -0
- executorch/exir/emit/_emitter.py +2220 -0
- executorch/exir/error.py +55 -0
- executorch/exir/graph.py +86 -0
- executorch/exir/graph_module.py +181 -0
- executorch/exir/inplace_aliasing.py +197 -0
- executorch/exir/lowered_backend_module.py +1134 -0
- executorch/exir/memory.py +91 -0
- executorch/exir/memory_planning.py +1567 -0
- executorch/exir/native/__init__.py +14 -0
- executorch/exir/native/native.py +449 -0
- executorch/exir/native/test/__init__.py +0 -0
- executorch/exir/operator/convert.py +371 -0
- executorch/exir/operator/manip.py +89 -0
- executorch/exir/operator/util.py +68 -0
- executorch/exir/pass_base.py +1141 -0
- executorch/exir/pass_manager.py +280 -0
- executorch/exir/passes/__init__.py +553 -0
- executorch/exir/passes/_device_copy_ops_registry.py +58 -0
- executorch/exir/passes/_quant_patterns_and_replacements.py +1564 -0
- executorch/exir/passes/const_prop_pass.py +84 -0
- executorch/exir/passes/constant_prop_pass.py +563 -0
- executorch/exir/passes/convert_constant_dim_order_pass.py +159 -0
- executorch/exir/passes/cse_pass.py +201 -0
- executorch/exir/passes/debug_handle_generator_pass.py +81 -0
- executorch/exir/passes/delegate_scratch_pass.py +100 -0
- executorch/exir/passes/dim_order_ops_registry.py +90 -0
- executorch/exir/passes/dynamic_shape_prop_pass.py +301 -0
- executorch/exir/passes/executorch_prim_ops_registry.py +186 -0
- executorch/exir/passes/external_constants_pass.py +113 -0
- executorch/exir/passes/fold_redundant_qdq_pass.py +36 -0
- executorch/exir/passes/init_mutable_pass.py +32 -0
- executorch/exir/passes/insert_write_back_for_buffers_pass.py +481 -0
- executorch/exir/passes/legalize_portable_dim_order_pass.py +173 -0
- executorch/exir/passes/memory_format_ops_pass.py +187 -0
- executorch/exir/passes/memory_planning_pass.py +372 -0
- executorch/exir/passes/normalize_transpose_pass.py +24 -0
- executorch/exir/passes/normalize_view_copy_base_pass.py +62 -0
- executorch/exir/passes/pass_registry.py +89 -0
- executorch/exir/passes/propagate_device_config.py +133 -0
- executorch/exir/passes/propagate_device_pass.py +890 -0
- executorch/exir/passes/prune_empty_tensors_pass.py +68 -0
- executorch/exir/passes/quant_fusion_pass.py +174 -0
- executorch/exir/passes/quantize_io_pass.py +414 -0
- executorch/exir/passes/reinplace.py +532 -0
- executorch/exir/passes/remove_graph_asserts_pass.py +62 -0
- executorch/exir/passes/remove_mixed_type_operators.py +116 -0
- executorch/exir/passes/remove_noop_pass.py +128 -0
- executorch/exir/passes/remove_unused_parameters_pass.py +55 -0
- executorch/exir/passes/replace_aten_with_edge_pass.py +59 -0
- executorch/exir/passes/replace_broken_ops_with_function_ops_pass.py +42 -0
- executorch/exir/passes/replace_edge_with_backend_pass.py +56 -0
- executorch/exir/passes/replace_sym_size_op_pass.py +35 -0
- executorch/exir/passes/replace_view_copy_with_view_pass.py +516 -0
- executorch/exir/passes/scalar_to_tensor_pass.py +44 -0
- executorch/exir/passes/spec_prop_pass.py +136 -0
- executorch/exir/passes/sym_shape_eval_pass.py +289 -0
- executorch/exir/passes/sym_to_tensor_pass.py +64 -0
- executorch/exir/passes/to_device_pass.py +45 -0
- executorch/exir/passes/weights_to_outputs_pass.py +88 -0
- executorch/exir/print_program.py +435 -0
- executorch/exir/program/__init__.py +32 -0
- executorch/exir/program/_fake_program.py +67 -0
- executorch/exir/program/_program.py +2056 -0
- executorch/exir/program/test/__init__.py +0 -0
- executorch/exir/scalar_type.py +38 -0
- executorch/exir/schema.py +337 -0
- executorch/exir/serde/__init__.py +0 -0
- executorch/exir/serde/export_serialize.py +2897 -0
- executorch/exir/serde/schema.py +418 -0
- executorch/exir/serde/schema_check.py +293 -0
- executorch/exir/serde/serialize.py +859 -0
- executorch/exir/serde/union.py +77 -0
- executorch/exir/sym_util.py +105 -0
- executorch/exir/tensor.py +480 -0
- executorch/exir/tensor_layout.py +39 -0
- executorch/exir/tests/common.py +96 -0
- executorch/exir/tests/control_flow_models.py +105 -0
- executorch/exir/tests/dynamic_shape_models.py +51 -0
- executorch/exir/tests/models.py +576 -0
- executorch/exir/tests/test_memory_format_ops_pass_utils.py +266 -0
- executorch/exir/tests/transformer.py +122 -0
- executorch/exir/tracer.py +828 -0
- executorch/exir/types.py +18 -0
- executorch/exir/verification/arg_validator.py +148 -0
- executorch/exir/verification/dev_html.py +68 -0
- executorch/exir/verification/interpreter.py +425 -0
- executorch/exir/verification/verifier.py +372 -0
- executorch/exir/version.py +17 -0
- executorch/exir/wrap.py +32 -0
- executorch/export/__init__.py +40 -0
- executorch/export/export.py +759 -0
- executorch/export/huggingface/__init__.py +7 -0
- executorch/export/huggingface/diffusers/__init__.py +11 -0
- executorch/export/huggingface/diffusers/backends.py +68 -0
- executorch/export/huggingface/diffusers/config.py +88 -0
- executorch/export/huggingface/diffusers/export.py +296 -0
- executorch/export/huggingface/diffusers/pipeline_discovery.py +109 -0
- executorch/export/huggingface/diffusers/pipeline_specs/__init__.py +31 -0
- executorch/export/huggingface/diffusers/pipeline_specs/_stable_diffusion.py +85 -0
- executorch/export/huggingface/diffusers/pipeline_specs/base.py +118 -0
- executorch/export/huggingface/diffusers/pipeline_specs/sd15.py +169 -0
- executorch/export/huggingface/diffusers/pipeline_specs/sdxl.py +190 -0
- executorch/export/huggingface/diffusers/wrappers.py +226 -0
- executorch/export/recipe.py +721 -0
- executorch/export/recipe_provider.py +60 -0
- executorch/export/recipe_registry.py +86 -0
- executorch/export/stages.py +932 -0
- executorch/export/target_recipes.py +203 -0
- executorch/export/types.py +22 -0
- executorch/export/utils.py +63 -0
- executorch/extension/apple/ExecuTorch/__tests__/resources/generate_coreml_test_models.py +81 -0
- executorch/extension/audio/mel_spectrogram.py +332 -0
- executorch/extension/diffusers/__init__.py +19 -0
- executorch/extension/diffusers/metadata.py +147 -0
- executorch/extension/diffusers/pipeline_behaviors/__init__.py +23 -0
- executorch/extension/diffusers/pipeline_behaviors/_stable_diffusion.py +80 -0
- executorch/extension/diffusers/pipeline_behaviors/base.py +147 -0
- executorch/extension/diffusers/pipeline_behaviors/sd15.py +50 -0
- executorch/extension/diffusers/pipeline_behaviors/sdxl.py +57 -0
- executorch/extension/diffusers/runner.py +473 -0
- executorch/extension/diffusers/test/__init__.py +7 -0
- executorch/extension/export_util/__init__.py +13 -0
- executorch/extension/export_util/utils.py +154 -0
- executorch/extension/flat_tensor/__init__.py +0 -0
- executorch/extension/flat_tensor/serialize/__init__.py +0 -0
- executorch/extension/flat_tensor/serialize/flat_tensor.fbs +73 -0
- executorch/extension/flat_tensor/serialize/flat_tensor_schema.py +34 -0
- executorch/extension/flat_tensor/serialize/scalar_type.fbs +43 -0
- executorch/extension/flat_tensor/serialize/serialize.py +429 -0
- executorch/extension/gguf_util/convert_main.py +53 -0
- executorch/extension/gguf_util/converter.py +27 -0
- executorch/extension/gguf_util/converters/llama_converter.py +123 -0
- executorch/extension/gguf_util/load_gguf.py +103 -0
- executorch/extension/image/benchmark/compare_benchmarks.py +122 -0
- executorch/extension/llm/batching/sampler.py +118 -0
- executorch/extension/llm/cache/__init__.py +0 -0
- executorch/extension/llm/cache/reference_cache.py +871 -0
- executorch/extension/llm/cache/test_update_and_attend.py +1186 -0
- executorch/extension/llm/cache/update_and_attend.py +120 -0
- executorch/extension/llm/custom_ops/__init__.py +0 -0
- executorch/extension/llm/custom_ops/bench_gated_delta_rule.py +104 -0
- executorch/extension/llm/custom_ops/custom_ops.py +695 -0
- executorch/extension/llm/custom_ops/custom_ops_aot_lib.dll +0 -0
- executorch/extension/llm/custom_ops/model_sharding.py +130 -0
- executorch/extension/llm/custom_ops/op_fallback.py +29 -0
- executorch/extension/llm/custom_ops/op_tile_crop_aot.py +54 -0
- executorch/extension/llm/custom_ops/preprocess_custom_ops.py +69 -0
- executorch/extension/llm/custom_ops/spinquant/special_hadamard_code_gen.py +279 -0
- executorch/extension/llm/custom_ops/test_gated_delta.py +574 -0
- executorch/extension/llm/custom_ops/test_preprocess_custom_ops.py +34 -0
- executorch/extension/llm/custom_ops/test_quantized_moe.py +705 -0
- executorch/extension/llm/custom_ops/test_quantized_sdpa.py +550 -0
- executorch/extension/llm/custom_ops/test_sdpa_with_kv_cache.py +685 -0
- executorch/extension/llm/custom_ops/test_update_cache.py +433 -0
- executorch/extension/llm/custom_ops/test_update_cross_attn_cache.py +286 -0
- executorch/extension/llm/export/__init__.py +29 -0
- executorch/extension/llm/export/builder.py +600 -0
- executorch/extension/llm/export/config/llm_config.py +973 -0
- executorch/extension/llm/export/export_llm.py +106 -0
- executorch/extension/llm/export/export_passes.py +202 -0
- executorch/extension/llm/export/gguf.py +577 -0
- executorch/extension/llm/export/int4.py +193 -0
- executorch/extension/llm/export/load.py +329 -0
- executorch/extension/llm/export/model_metadata.py +118 -0
- executorch/extension/llm/export/mx.py +244 -0
- executorch/extension/llm/export/nvfp4.py +213 -0
- executorch/extension/llm/export/partitioner_lib.py +289 -0
- executorch/extension/llm/export/quant/__init__.py +20 -0
- executorch/extension/llm/export/quant/convert.py +247 -0
- executorch/extension/llm/export/quant/quantize.py +386 -0
- executorch/extension/llm/export/quant/recipe.py +62 -0
- executorch/extension/llm/export/quantize.py +286 -0
- executorch/extension/llm/export/quantizer_lib.py +443 -0
- executorch/extension/llm/export/test/__init__.py +0 -0
- executorch/extension/llm/export/test/test_gguf.py +409 -0
- executorch/extension/llm/export/test_export_passes.py +209 -0
- executorch/extension/llm/modules/__init__.py +24 -0
- executorch/extension/llm/modules/_position_embeddings.py +729 -0
- executorch/extension/llm/modules/attention.py +413 -0
- executorch/extension/llm/modules/kv_cache.py +151 -0
- executorch/extension/llm/modules/test/__init__.py +0 -0
- executorch/extension/llm/modules/turboquant/__init__.py +11 -0
- executorch/extension/llm/modules/turboquant/codebook.py +124 -0
- executorch/extension/llm/modules/turboquant/kv_cache.py +170 -0
- executorch/extension/llm/runner/__init__.py +267 -0
- executorch/extension/llm/runner/_llm_runner.pyi +606 -0
- executorch/extension/pybindings/_C.cp315-win_amd64.pyd +0 -0
- executorch/extension/pybindings/_C.pyi +486 -0
- executorch/extension/pybindings/data_loader.cp315-win_amd64.pyd +0 -0
- executorch/extension/pybindings/data_loader.pyi +12 -0
- executorch/extension/pybindings/portable_lib.py +159 -0
- executorch/extension/pybindings/py.typed +0 -0
- executorch/extension/pybindings/pybindings.pyi +486 -0
- executorch/extension/pybindings/test/make_test.py +237 -0
- executorch/extension/pybindings/test/test_pybindings.py +4062 -0
- executorch/extension/pytree/__init__.py +54 -0
- executorch/extension/training/__init__.py +22 -0
- executorch/extension/training/examples/CIFAR/data_utils.py +389 -0
- executorch/extension/training/examples/CIFAR/export.py +220 -0
- executorch/extension/training/examples/CIFAR/main.py +188 -0
- executorch/extension/training/examples/CIFAR/model.py +73 -0
- executorch/extension/training/examples/CIFAR/train_utils.py +622 -0
- executorch/extension/training/examples/XOR/export_model.py +77 -0
- executorch/extension/training/examples/XOR/model.py +34 -0
- executorch/extension/training/pybindings/_training_lib.pyi +45 -0
- executorch/extension/training/pybindings/_training_module.py +86 -0
- executorch/include/executorch/devtools/etdump/data_sinks/buffer_data_sink.h +127 -0
- executorch/include/executorch/devtools/etdump/data_sinks/data_sink_base.h +61 -0
- executorch/include/executorch/devtools/etdump/data_sinks/file_data_sink.h +95 -0
- executorch/include/executorch/devtools/etdump/emitter.h +28 -0
- executorch/include/executorch/devtools/etdump/etdump_flatcc.h +213 -0
- executorch/include/executorch/devtools/etdump/utils.h +39 -0
- executorch/include/executorch/extension/data_loader/buffer_data_loader.h +89 -0
- executorch/include/executorch/extension/data_loader/file_data_loader.h +114 -0
- executorch/include/executorch/extension/data_loader/mman.h +140 -0
- executorch/include/executorch/extension/data_loader/mman_windows.h +75 -0
- executorch/include/executorch/extension/data_loader/mmap_data_loader.h +149 -0
- executorch/include/executorch/extension/data_loader/shared_ptr_data_loader.h +89 -0
- executorch/include/executorch/extension/flat_tensor/flat_tensor_data_map.h +142 -0
- executorch/include/executorch/extension/flat_tensor/serialize/flat_tensor_header.h +90 -0
- executorch/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +260 -0
- executorch/include/executorch/extension/kernel_util/meta_programming.h +119 -0
- executorch/include/executorch/extension/kernel_util/type_list.h +145 -0
- executorch/include/executorch/extension/memory_allocator/malloc_memory_allocator.h +94 -0
- executorch/include/executorch/extension/memory_allocator/memory_allocator_utils.h +39 -0
- executorch/include/executorch/extension/module/module.h +810 -0
- executorch/include/executorch/extension/module/ptn_module.h +109 -0
- executorch/include/executorch/extension/named_data_map/merged_data_map.h +118 -0
- executorch/include/executorch/extension/tensor/tensor.h +14 -0
- executorch/include/executorch/extension/tensor/tensor_accessor.h +218 -0
- executorch/include/executorch/extension/tensor/tensor_ptr.h +650 -0
- executorch/include/executorch/extension/tensor/tensor_ptr_maker.h +811 -0
- executorch/include/executorch/extension/threadpool/threadpool_guard.h +37 -0
- executorch/include/executorch/runtime/backend/backend_execution_context.h +107 -0
- executorch/include/executorch/runtime/backend/backend_init_context.h +149 -0
- executorch/include/executorch/runtime/backend/backend_option_context.h +34 -0
- executorch/include/executorch/runtime/backend/backend_options_map.h +229 -0
- executorch/include/executorch/runtime/backend/interface.h +238 -0
- executorch/include/executorch/runtime/backend/options.h +208 -0
- executorch/include/executorch/runtime/core/array_ref.h +264 -0
- executorch/include/executorch/runtime/core/data_loader.h +206 -0
- executorch/include/executorch/runtime/core/defines.h +20 -0
- executorch/include/executorch/runtime/core/device_allocator.h +215 -0
- executorch/include/executorch/runtime/core/device_memory_buffer.h +129 -0
- executorch/include/executorch/runtime/core/error.h +264 -0
- executorch/include/executorch/runtime/core/evalue.h +877 -0
- executorch/include/executorch/runtime/core/event_tracer.h +592 -0
- executorch/include/executorch/runtime/core/event_tracer_hooks.h +340 -0
- executorch/include/executorch/runtime/core/event_tracer_hooks_delegate.h +204 -0
- executorch/include/executorch/runtime/core/exec_aten/exec_aten.h +208 -0
- executorch/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +290 -0
- executorch/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1430 -0
- executorch/include/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +23 -0
- executorch/include/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +68 -0
- executorch/include/executorch/runtime/core/exec_aten/util/tensor_util.h +1428 -0
- executorch/include/executorch/runtime/core/freeable_buffer.h +281 -0
- executorch/include/executorch/runtime/core/function_ref.h +108 -0
- executorch/include/executorch/runtime/core/hierarchical_allocator.h +167 -0
- executorch/include/executorch/runtime/core/memory_allocator.h +249 -0
- executorch/include/executorch/runtime/core/named_data_map.h +76 -0
- executorch/include/executorch/runtime/core/portable_type/bfloat16.h +27 -0
- executorch/include/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
- executorch/include/executorch/runtime/core/portable_type/bits_types.h +83 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +3 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +8 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +73 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +441 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +1 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +3 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +906 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +11 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +112 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +145 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h +830 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16-math.h +337 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h +481 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/Half.h +788 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h +100 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h +50 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex.h +676 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex_utils.h +48 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h +38 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/irange.h +137 -0
- executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/overflows.h +120 -0
- executorch/include/executorch/runtime/core/portable_type/complex.h +21 -0
- executorch/include/executorch/runtime/core/portable_type/device.h +85 -0
- executorch/include/executorch/runtime/core/portable_type/half.h +27 -0
- executorch/include/executorch/runtime/core/portable_type/optional.h +37 -0
- executorch/include/executorch/runtime/core/portable_type/qint_types.h +83 -0
- executorch/include/executorch/runtime/core/portable_type/scalar.h +123 -0
- executorch/include/executorch/runtime/core/portable_type/scalar_type.h +154 -0
- executorch/include/executorch/runtime/core/portable_type/string_view.h +31 -0
- executorch/include/executorch/runtime/core/portable_type/tensor.h +190 -0
- executorch/include/executorch/runtime/core/portable_type/tensor_impl.h +345 -0
- executorch/include/executorch/runtime/core/portable_type/tensor_options.h +60 -0
- executorch/include/executorch/runtime/core/result.h +333 -0
- executorch/include/executorch/runtime/core/span.h +110 -0
- executorch/include/executorch/runtime/core/tag.h +90 -0
- executorch/include/executorch/runtime/core/tensor_layout.h +93 -0
- executorch/include/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
- executorch/include/executorch/runtime/executor/memory_manager.h +149 -0
- executorch/include/executorch/runtime/executor/merged_data_map.h +150 -0
- executorch/include/executorch/runtime/executor/method.h +466 -0
- executorch/include/executorch/runtime/executor/method_meta.h +338 -0
- executorch/include/executorch/runtime/executor/platform_memory_allocator.h +125 -0
- executorch/include/executorch/runtime/executor/program.h +365 -0
- executorch/include/executorch/runtime/executor/program_validation.h +51 -0
- executorch/include/executorch/runtime/executor/pte_data_map.h +151 -0
- executorch/include/executorch/runtime/kernel/kernel_includes.h +62 -0
- executorch/include/executorch/runtime/kernel/kernel_runtime_context.h +131 -0
- executorch/include/executorch/runtime/kernel/operator_registry.h +308 -0
- executorch/include/executorch/runtime/kernel/thread_parallel_interface.h +121 -0
- executorch/include/executorch/runtime/platform/abort.h +36 -0
- executorch/include/executorch/runtime/platform/assert.h +124 -0
- executorch/include/executorch/runtime/platform/clock.h +43 -0
- executorch/include/executorch/runtime/platform/compat_unistd.h +75 -0
- executorch/include/executorch/runtime/platform/compiler.h +254 -0
- executorch/include/executorch/runtime/platform/log.h +216 -0
- executorch/include/executorch/runtime/platform/platform.h +276 -0
- executorch/include/executorch/runtime/platform/profiler.h +293 -0
- executorch/include/executorch/runtime/platform/runtime.h +35 -0
- executorch/include/executorch/runtime/platform/system.h +49 -0
- executorch/include/executorch/runtime/platform/types.h +24 -0
- executorch/kernels/portable/__init__.py +26 -0
- executorch/kernels/portable/custom_ops.yaml +32 -0
- executorch/kernels/portable/et_copy_ops.yaml +16 -0
- executorch/kernels/portable/functions.yaml +1096 -0
- executorch/kernels/portable/test/supported_features_def.yaml +1 -0
- executorch/kernels/quantized/__init__.py +36 -0
- executorch/kernels/quantized/quantized.yaml +113 -0
- executorch/kernels/quantized/quantized_ops_aot_lib.dll +0 -0
- executorch/kernels/quantized/test/supported_features_def.yaml +1 -0
- executorch/lib/cmake/executorch/executorch-config-version.cmake +60 -0
- executorch/lib/cmake/executorch/executorch-config.cmake +1056 -0
- executorch/lib/executorch.dll +0 -0
- executorch/lib/executorch.lib +0 -0
- executorch/lib/executorch_backend_openvino.dll +0 -0
- executorch/lib/executorch_backend_openvino.lib +0 -0
- executorch/lib/executorch_backend_xnnpack.dll +0 -0
- executorch/lib/executorch_backend_xnnpack.lib +0 -0
- executorch/lib/executorch_etdump.dll +0 -0
- executorch/lib/executorch_kernels_optimized.dll +0 -0
- executorch/lib/executorch_kernels_optimized.lib +0 -0
- executorch/lib/executorch_kernels_quantized.dll +0 -0
- executorch/lib/executorch_kernels_quantized.lib +0 -0
- executorch/lib/executorch_threadpool.dll +0 -0
- executorch/lib/executorch_threadpool.lib +0 -0
- executorch/runtime/__init__.py +390 -0
- executorch/runtime/cuda.py +222 -0
- executorch/runtime/kernel/test/functions.yaml +13 -0
- executorch/schema/program.fbs +551 -0
- executorch/schema/scalar_type.fbs +43 -0
- executorch/share/cmake/executorch-config-version.cmake +60 -0
- executorch/share/cmake/executorch-config.cmake +1056 -0
- executorch/util/activation_memory_profiler.py +177 -0
- executorch/util/collect_env.py +748 -0
- executorch/util/python_profiler.py +96 -0
- executorch/version.py +4 -0
- executorch-1.6.0.dist-info/METADATA +123 -0
- executorch-1.6.0.dist-info/RECORD +3166 -0
- executorch-1.6.0.dist-info/WHEEL +5 -0
- executorch-1.6.0.dist-info/entry_points.txt +2 -0
- executorch-1.6.0.dist-info/licenses/LICENSE +37 -0
- executorch-1.6.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2220 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This source code is licensed under the BSD-style license found in the
|
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
"""Takes an ExportedArtifact, or a collection of ExportedArtifacts, in execution dialect, and turns
|
|
8
|
+
them into a single ExecuTorch Program.
|
|
9
|
+
|
|
10
|
+
The provided ExportedArtifact's graph modules are in execution dialect and the emitter parses and
|
|
11
|
+
converts them into executorch instructions. The emitter walks the provided graphs and as it
|
|
12
|
+
encounters concrete values such as tensors or ints, it converts them to the serialized format and
|
|
13
|
+
stores them in a list for later use. The emitter walks the graph by traversing fx.nodes, these can
|
|
14
|
+
come in a variety of forms and are the primitives of execution at the graph module level. The most
|
|
15
|
+
common 3 we care about are 'call_function', 'place_holder', and 'output'. 'placeholder' and 'output'
|
|
16
|
+
handle io for the module and 'call_function' handles everything else. Within 'call_function' we may
|
|
17
|
+
encounter an operator or delegate call, in such case we parse the schema and emit all the inputs and
|
|
18
|
+
outputs (unless they have already previously been emitted), and then we convert the actual function
|
|
19
|
+
call into an executorch instruction such as KernelCall or DelegateCall.
|
|
20
|
+
|
|
21
|
+
When control flow is present in the graphmodule it will take the form of a few different types of
|
|
22
|
+
'call_function'. Today (June 14th 2023) only cond and map are supported. The actual operations of
|
|
23
|
+
these, such as the true/false branches of cond, or the mapping function of map, are stored as sub
|
|
24
|
+
graphmodules. When these are encountered during emission, the emitter will recursively emit them and
|
|
25
|
+
their instructions.
|
|
26
|
+
"""
|
|
27
|
+
# TODO(jakeszwe): add information here about how weights and other parameters are handled in the
|
|
28
|
+
# presence of aot autograd param lifting.
|
|
29
|
+
|
|
30
|
+
# pyre-strict
|
|
31
|
+
import ctypes
|
|
32
|
+
import hashlib
|
|
33
|
+
import operator
|
|
34
|
+
import typing
|
|
35
|
+
import warnings
|
|
36
|
+
from dataclasses import dataclass, field
|
|
37
|
+
from typing import Any, Callable, cast, Dict, List, Mapping, Optional, Tuple, Union
|
|
38
|
+
|
|
39
|
+
import executorch.exir.memory as memory
|
|
40
|
+
import executorch.extension.pytree as ex_pytree
|
|
41
|
+
import torch
|
|
42
|
+
import torch.fx
|
|
43
|
+
from executorch.exir.delegate import executorch_call_delegate, is_lowered_module
|
|
44
|
+
from executorch.exir.dialects.backend._ops import BackendOpOverload
|
|
45
|
+
from executorch.exir.dialects.edge._ops import EdgeOpOverload
|
|
46
|
+
from executorch.exir.error import ExportError, ExportErrorType, InternalError
|
|
47
|
+
from executorch.exir.operator.convert import is_out_variant
|
|
48
|
+
from executorch.exir.passes.executorch_prim_ops_registry import is_sym_op
|
|
49
|
+
from executorch.exir.print_program import _stacktrace_to_framelist, inspect_node
|
|
50
|
+
from executorch.exir.schema import (
|
|
51
|
+
AllocationDetails,
|
|
52
|
+
BackendDelegate,
|
|
53
|
+
BackendDelegateDataReference,
|
|
54
|
+
BackendDelegateInlineData,
|
|
55
|
+
Bool,
|
|
56
|
+
BoolList,
|
|
57
|
+
Buffer,
|
|
58
|
+
Chain,
|
|
59
|
+
ContainerMetadata,
|
|
60
|
+
DataLocation,
|
|
61
|
+
DelegateCall,
|
|
62
|
+
DelegateScratch,
|
|
63
|
+
Double,
|
|
64
|
+
DoubleList,
|
|
65
|
+
EValue,
|
|
66
|
+
ExecutionPlan,
|
|
67
|
+
ExtraTensorInfo,
|
|
68
|
+
FreeCall,
|
|
69
|
+
Instruction,
|
|
70
|
+
Int,
|
|
71
|
+
IntList,
|
|
72
|
+
JumpFalseCall,
|
|
73
|
+
KernelCall,
|
|
74
|
+
MoveCall,
|
|
75
|
+
Null,
|
|
76
|
+
Operator,
|
|
77
|
+
OptionalTensorList,
|
|
78
|
+
ScalarType,
|
|
79
|
+
String,
|
|
80
|
+
Tensor,
|
|
81
|
+
TensorDataLocation,
|
|
82
|
+
TensorList,
|
|
83
|
+
TensorShapeDynamism,
|
|
84
|
+
)
|
|
85
|
+
from executorch.exir.tensor import (
|
|
86
|
+
AddressSpaceOverflowException,
|
|
87
|
+
dim_order_from_stride,
|
|
88
|
+
layout_enum,
|
|
89
|
+
make_allocation_info,
|
|
90
|
+
make_tensor_value,
|
|
91
|
+
memory_format_enum,
|
|
92
|
+
scalar_type_enum,
|
|
93
|
+
TensorSpec,
|
|
94
|
+
)
|
|
95
|
+
from executorch.exir.types import LeafValueSpec, ValueSpec
|
|
96
|
+
from torch._subclasses.fake_tensor import FakeTensor
|
|
97
|
+
from torch.export.exported_program import ExportedProgram, ExportGraphSignature
|
|
98
|
+
from torch.fx.node import Node
|
|
99
|
+
from torch.utils import _pytree as pytree
|
|
100
|
+
from typing_extensions import TypeAlias
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass
|
|
104
|
+
class _ProgramState:
|
|
105
|
+
"""State shared between all methods of a program and the graph module it represents.
|
|
106
|
+
|
|
107
|
+
Initialized once within emit_program and then shared across each entry point as they are
|
|
108
|
+
emitted.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
# Parallel list of specs and the buffers that backed them, have to add + 1 to any index in here
|
|
112
|
+
# as index 0 in the constant_buffer is reserved.
|
|
113
|
+
allocated_specs: List[TensorSpec] = field(default_factory=list)
|
|
114
|
+
# Weights in any arbitrary graph_module only need to compare against weights from previously
|
|
115
|
+
# emitted graph modules, not any weights emitted from itself. This should speed up the lookup,
|
|
116
|
+
# from O(N) to O(1)
|
|
117
|
+
cached_spec_hash_values: Dict[str, int] = field(default_factory=dict)
|
|
118
|
+
cached_spec_mutable_hash_values: Dict[str, int] = field(default_factory=dict)
|
|
119
|
+
# The 0 index is reserved to be pointed to by non-constant tensors, so add an empty placeholder.
|
|
120
|
+
constant_buffer: List[Buffer] = field(default_factory=lambda: [Buffer(storage=b"")])
|
|
121
|
+
# The 0 index is reserved to be pointed to by non-constant tensors, so add an empty placeholder.
|
|
122
|
+
mutable_buffer: List[Buffer] = field(default_factory=lambda: [Buffer(storage=b"")])
|
|
123
|
+
# Delegate data stored directly in the flatbuffer. Pointed to by BackendDelegateDataReference,
|
|
124
|
+
# and should be copied to Program.backend_delegate_data.
|
|
125
|
+
backend_delegate_data: List[BackendDelegateInlineData] = field(default_factory=list)
|
|
126
|
+
# Delegate cache that is used across all entry points. Key is the hash of the delegated payload.
|
|
127
|
+
backend_delegate_data_cache: Dict[str, int] = field(default_factory=dict)
|
|
128
|
+
|
|
129
|
+
# Constants are optionally stored in external files.
|
|
130
|
+
# Aggregate unique external constants into one buffer.
|
|
131
|
+
external_constant_buffer: List[bytes] = field(default_factory=list)
|
|
132
|
+
external_constant_hash: Dict[str, int] = field(default_factory=dict)
|
|
133
|
+
# Each constant_tag groups a set of constants together.
|
|
134
|
+
# {constant_tag: {fqn: index into external_constant_buffer}}
|
|
135
|
+
external_constant_map: Dict[str, Dict[str, int]] = field(default_factory=dict)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@dataclass
|
|
139
|
+
class _EmitterState:
|
|
140
|
+
"""State of a single emitter.
|
|
141
|
+
|
|
142
|
+
Local to at least the entry point, and may be local to a subgraph of an entry point originating
|
|
143
|
+
from control flow.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
values: List[EValue]
|
|
147
|
+
operators: List[Operator]
|
|
148
|
+
delegates: List[BackendDelegate]
|
|
149
|
+
operator_cache: Dict[Tuple[str, str], int]
|
|
150
|
+
emit_stacktrace: bool
|
|
151
|
+
emit_mutable_buffer_names: bool
|
|
152
|
+
|
|
153
|
+
spec2id_dict: Dict[TensorSpec, int] = field(default_factory=dict)
|
|
154
|
+
# Only literal arguments with no schema aliasing enter this per-plan pool.
|
|
155
|
+
constant_cache: Dict[Union[int, Tuple[int, ...]], int] = field(default_factory=dict)
|
|
156
|
+
# pyre-ignore[11]: Annotation `LoweredBackendModule` is not defined as a type.
|
|
157
|
+
delegate_cache: Dict["LoweredBackendModule", int] = field( # noqa: F821
|
|
158
|
+
default_factory=dict
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
def spec2id(self, spec: TensorSpec) -> int:
|
|
162
|
+
"""Map a TensorSpec to value index in the values array."""
|
|
163
|
+
assert spec in self.spec2id_dict, f"Spec is not found: {spec.debug()}"
|
|
164
|
+
return self.spec2id_dict[spec]
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@dataclass
|
|
168
|
+
class _AbstractValue:
|
|
169
|
+
"""Represents an already emitted EValue"""
|
|
170
|
+
|
|
171
|
+
# Index in the values table of this EValue.
|
|
172
|
+
id: int
|
|
173
|
+
|
|
174
|
+
# Used for sanity checks for functions that expect to only receive AbstractValues.
|
|
175
|
+
tensor: Optional[Tensor]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
_EmitterValue: TypeAlias = Union[
|
|
179
|
+
_AbstractValue, List[_AbstractValue], Tuple[_AbstractValue, ...]
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
_PythonValue: TypeAlias = Union[bool, int, float, torch.Tensor, List["_PythonValue"]]
|
|
183
|
+
_SchemaType: TypeAlias = Union[
|
|
184
|
+
torch.OptionalType,
|
|
185
|
+
torch.ListType,
|
|
186
|
+
torch.FloatType,
|
|
187
|
+
torch.BoolType,
|
|
188
|
+
torch.IntType,
|
|
189
|
+
torch.StringType,
|
|
190
|
+
torch.TensorType,
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
_Target: TypeAlias = Union[Callable[..., _PythonValue], str]
|
|
194
|
+
|
|
195
|
+
_Argument: TypeAlias = Union[
|
|
196
|
+
_EmitterValue,
|
|
197
|
+
Tuple["_Argument", ...],
|
|
198
|
+
List["_Argument"],
|
|
199
|
+
Dict[str, "_Argument"],
|
|
200
|
+
str,
|
|
201
|
+
int,
|
|
202
|
+
float,
|
|
203
|
+
bool,
|
|
204
|
+
complex,
|
|
205
|
+
torch.dtype,
|
|
206
|
+
torch.Tensor,
|
|
207
|
+
torch.memory_format,
|
|
208
|
+
torch.layout,
|
|
209
|
+
None,
|
|
210
|
+
]
|
|
211
|
+
|
|
212
|
+
_DelegateDebugIdentifierMap: TypeAlias = Union[
|
|
213
|
+
Dict[int, Tuple[int]], Dict[str, Tuple[int]]
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class _Emitter(torch.fx.Interpreter):
|
|
218
|
+
"""An abstract interpreter (https://wiki.mozilla.org/Abstract_Interpretation) used to emit the
|
|
219
|
+
given traced torch.fx.GraphModule to the flatbuffer schema."""
|
|
220
|
+
|
|
221
|
+
# pyre-ignore[13]: Attribute `node` is never initialized.
|
|
222
|
+
node: torch.fx.Node
|
|
223
|
+
|
|
224
|
+
def __init__(
|
|
225
|
+
self,
|
|
226
|
+
graph_module: torch.fx.GraphModule,
|
|
227
|
+
emitter_state: _EmitterState,
|
|
228
|
+
program_state: _ProgramState,
|
|
229
|
+
instruction_start_offset: int = 0,
|
|
230
|
+
binding_input_values: Optional[List[_AbstractValue]] = None,
|
|
231
|
+
binding_output_values: Optional[List[_AbstractValue]] = None,
|
|
232
|
+
) -> None:
|
|
233
|
+
super().__init__(graph_module)
|
|
234
|
+
self.emitter_state = emitter_state
|
|
235
|
+
self.program_state = program_state
|
|
236
|
+
self.outputs: List[int] = []
|
|
237
|
+
|
|
238
|
+
self.chain = Chain(
|
|
239
|
+
inputs=[],
|
|
240
|
+
outputs=[],
|
|
241
|
+
instructions=[],
|
|
242
|
+
stacktrace=None,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
if "non_const_buffer_sizes" not in graph_module.meta.keys():
|
|
246
|
+
raise RuntimeError(
|
|
247
|
+
"Must set 'non_const_buffer_sizes' in graph meta in memory planning pass"
|
|
248
|
+
)
|
|
249
|
+
self.instruction_start_offset = instruction_start_offset
|
|
250
|
+
self.binding_input_values = binding_input_values
|
|
251
|
+
self.binding_output_values = binding_output_values
|
|
252
|
+
self.graph_module: torch.fx.GraphModule = graph_module
|
|
253
|
+
self.nodes: List[torch.fx.Node] = list(self.graph_module.graph.nodes)
|
|
254
|
+
|
|
255
|
+
# Marks the placeholder node with its order so that we can match them with the corresponding
|
|
256
|
+
# Abstract Value coming from top level.
|
|
257
|
+
self.placeholder_count = 0
|
|
258
|
+
|
|
259
|
+
self.concrete_output_ids: List[_AbstractValue] = []
|
|
260
|
+
self.debug_handle_map: Dict[int, Union[int, List[int]]] = {}
|
|
261
|
+
self.instruction_id_to_num_outs_map: Dict[int, int] = {}
|
|
262
|
+
self.instr_id_to_delegate_debug_id_map: Dict[
|
|
263
|
+
int, Dict[str, Union[str, _DelegateDebugIdentifierMap]]
|
|
264
|
+
] = {}
|
|
265
|
+
|
|
266
|
+
def _emit_node_specific_error(self, node: torch.fx.Node, err_msg: str) -> str:
|
|
267
|
+
"""Returns 'err_msg' with node specific information attached."""
|
|
268
|
+
err_msg = f"Failed with error: {str(err_msg)}\n" + inspect_node(
|
|
269
|
+
self.graph_module.graph, node
|
|
270
|
+
)
|
|
271
|
+
return err_msg
|
|
272
|
+
|
|
273
|
+
def _internal_assert_emitter(
|
|
274
|
+
self, pred: bool, node: torch.fx.Node, assert_msg: str
|
|
275
|
+
) -> None:
|
|
276
|
+
"""If pred is False, construct and raise a node specific error message."""
|
|
277
|
+
if not pred:
|
|
278
|
+
raise InternalError(self._emit_node_specific_error(node, assert_msg))
|
|
279
|
+
|
|
280
|
+
def _emit_int_list(
|
|
281
|
+
self, val: List[_Argument], *, immutable: bool = False
|
|
282
|
+
) -> EValue:
|
|
283
|
+
"""Emits a list of integers as a collection of EValues.
|
|
284
|
+
|
|
285
|
+
For every argument in 'val':
|
|
286
|
+
- If it is a concrete value, then emit it and then place its location in the boxed list
|
|
287
|
+
- If it is already an abstract value, then just place its location in the boxed list
|
|
288
|
+
|
|
289
|
+
Int lists are boxed to handle symints whose values are determined at runtime, but could
|
|
290
|
+
still end up inside lists for ops like view_copy(Tensor self, SymInt[] size)
|
|
291
|
+
"""
|
|
292
|
+
boxed_list = []
|
|
293
|
+
for item in val:
|
|
294
|
+
if isinstance(item, _AbstractValue):
|
|
295
|
+
boxed_list.append(item.id)
|
|
296
|
+
elif isinstance(item, int):
|
|
297
|
+
boxed_list.append(
|
|
298
|
+
self._emit_argument(item, None, immutable=immutable).id
|
|
299
|
+
)
|
|
300
|
+
else:
|
|
301
|
+
self._internal_assert_emitter(
|
|
302
|
+
False, self.node, "Unsupported type encountered in int list."
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
return EValue(IntList(boxed_list))
|
|
306
|
+
|
|
307
|
+
def _emit_list(
|
|
308
|
+
self,
|
|
309
|
+
val: List[_Argument],
|
|
310
|
+
val_type: _SchemaType,
|
|
311
|
+
*,
|
|
312
|
+
immutable: bool = False,
|
|
313
|
+
) -> EValue:
|
|
314
|
+
"""Emits a list type.
|
|
315
|
+
|
|
316
|
+
Emits the list stored in val. If the list is of Tensors, Optionals, or Ints the emitted list
|
|
317
|
+
is boxed, otherwise the values are constant at runtime and stored inline.
|
|
318
|
+
|
|
319
|
+
NOTE: When symbool and symfloat are supported bool and float lists will be stored boxed.
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
if isinstance(val_type, torch.BoolType):
|
|
323
|
+
return EValue(BoolList(typing.cast(List[bool], val)))
|
|
324
|
+
|
|
325
|
+
if isinstance(val_type, torch.IntType):
|
|
326
|
+
return self._emit_int_list(val, immutable=immutable)
|
|
327
|
+
|
|
328
|
+
if isinstance(val_type, torch.FloatType):
|
|
329
|
+
return EValue(DoubleList(typing.cast(List[float], val)))
|
|
330
|
+
|
|
331
|
+
if isinstance(val_type, torch.TensorType):
|
|
332
|
+
values = []
|
|
333
|
+
for v in val:
|
|
334
|
+
assert isinstance(v, _AbstractValue)
|
|
335
|
+
self._internal_assert_emitter(
|
|
336
|
+
v.tensor is not None,
|
|
337
|
+
self.node,
|
|
338
|
+
"AbstractValue corresponding to tensor type doesn't contain tensor value",
|
|
339
|
+
)
|
|
340
|
+
values.append(v.id)
|
|
341
|
+
return EValue(TensorList(values))
|
|
342
|
+
|
|
343
|
+
if isinstance(val_type, torch.OptionalType):
|
|
344
|
+
# refine further
|
|
345
|
+
actual_type = val_type.getElementType()
|
|
346
|
+
if isinstance(actual_type, torch.TensorType):
|
|
347
|
+
vals = []
|
|
348
|
+
for v in val:
|
|
349
|
+
if v is None:
|
|
350
|
+
vals.append(-1)
|
|
351
|
+
else:
|
|
352
|
+
assert isinstance(v, _AbstractValue)
|
|
353
|
+
vals.append(v.id)
|
|
354
|
+
return EValue(OptionalTensorList(vals))
|
|
355
|
+
|
|
356
|
+
raise ExportError(
|
|
357
|
+
ExportErrorType.NOT_SUPPORTED, f"Unknown list type: {val_type}"
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
def _get_allocation_info(self, spec: TensorSpec) -> AllocationDetails:
|
|
361
|
+
"""Returns the allocation info for a given TensorSpec."""
|
|
362
|
+
self._internal_assert_emitter(
|
|
363
|
+
isinstance(spec.mem_id, int) and spec.mem_id >= 0,
|
|
364
|
+
self.node,
|
|
365
|
+
f"Non-const tensor should be an activation tensor: mem_id {spec.mem_id}",
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
self._internal_assert_emitter(
|
|
369
|
+
isinstance(spec.mem_offset, int) and spec.mem_offset >= 0,
|
|
370
|
+
self.node,
|
|
371
|
+
f"Non-const tensor should be an activation tensor: mem_offset {spec.mem_offset}",
|
|
372
|
+
)
|
|
373
|
+
try:
|
|
374
|
+
allocation_info = make_allocation_info(spec.mem_id, spec.mem_offset)
|
|
375
|
+
except AddressSpaceOverflowException as e:
|
|
376
|
+
raise InternalError(
|
|
377
|
+
self._emit_node_specific_error(
|
|
378
|
+
self.node,
|
|
379
|
+
(
|
|
380
|
+
f"{e}\nHint: If you are using a memory pass based on dynamic shape bounds, "
|
|
381
|
+
f"such as ConstraintBasedSymShapeEvalPass, this may be the cause of an "
|
|
382
|
+
f"unbacked SymInt with its upper bound lazily set to 2^64-1 (uint64 max) "
|
|
383
|
+
"during torch.export()."
|
|
384
|
+
),
|
|
385
|
+
)
|
|
386
|
+
)
|
|
387
|
+
return allocation_info
|
|
388
|
+
|
|
389
|
+
def _save_to_external_constant_map(
|
|
390
|
+
self,
|
|
391
|
+
fqn: str,
|
|
392
|
+
buffer_idx: int,
|
|
393
|
+
constant_tag: str,
|
|
394
|
+
) -> None:
|
|
395
|
+
"""
|
|
396
|
+
Saves external constant to the map.
|
|
397
|
+
"""
|
|
398
|
+
# buffer data should be in the external_constant_buffer already.
|
|
399
|
+
assert buffer_idx < len(self.program_state.external_constant_buffer)
|
|
400
|
+
if constant_tag not in self.program_state.external_constant_map:
|
|
401
|
+
self.program_state.external_constant_map[constant_tag] = {}
|
|
402
|
+
self.program_state.external_constant_map[constant_tag][fqn] = buffer_idx
|
|
403
|
+
|
|
404
|
+
def _save_new_const_tensor(
|
|
405
|
+
self,
|
|
406
|
+
spec: TensorSpec,
|
|
407
|
+
buffer_data: bytes,
|
|
408
|
+
hashed: str,
|
|
409
|
+
allocation_info: Optional[AllocationDetails] = None,
|
|
410
|
+
constant_tag: Optional[str] = None,
|
|
411
|
+
) -> int:
|
|
412
|
+
"""Saves a new constant tensor to the constant buffer and returns the buffer idx"""
|
|
413
|
+
|
|
414
|
+
self.program_state.allocated_specs.append(spec)
|
|
415
|
+
# +1 because the first buffer location is reserved.
|
|
416
|
+
|
|
417
|
+
# Update buffer_idx to point to the end of the list where we are adding the new buffer.
|
|
418
|
+
buffer = Buffer(storage=buffer_data)
|
|
419
|
+
|
|
420
|
+
# Tensor is stored outside of the PTE file.
|
|
421
|
+
if (
|
|
422
|
+
spec.extra_tensor_info is not None
|
|
423
|
+
and spec.extra_tensor_info.fully_qualified_name is not None
|
|
424
|
+
and spec.extra_tensor_info.location == TensorDataLocation.EXTERNAL
|
|
425
|
+
):
|
|
426
|
+
assert (
|
|
427
|
+
constant_tag is not None
|
|
428
|
+
), "Constant tag is not set for external tensor"
|
|
429
|
+
# TODO (#7633): Handle case where we have both mutable and non mutable weights that we want to put in the same external file.
|
|
430
|
+
# We will need to create 2 segments in that case, but it'll be a bit until we see this case. LLM finetuning will probably require this.
|
|
431
|
+
|
|
432
|
+
buffer_idx = len(self.program_state.external_constant_buffer)
|
|
433
|
+
self.program_state.external_constant_hash[hashed] = buffer_idx
|
|
434
|
+
self.program_state.external_constant_buffer.append(buffer_data)
|
|
435
|
+
self._save_to_external_constant_map(
|
|
436
|
+
spec.extra_tensor_info.fully_qualified_name, buffer_idx, constant_tag
|
|
437
|
+
)
|
|
438
|
+
# Tensor is mutable with initial state. Place into mutable segment
|
|
439
|
+
elif allocation_info:
|
|
440
|
+
buffer_idx = len(self.program_state.mutable_buffer)
|
|
441
|
+
self.program_state.cached_spec_mutable_hash_values[hashed] = buffer_idx
|
|
442
|
+
self.program_state.mutable_buffer.append(buffer)
|
|
443
|
+
# Tensor is stored in the PTE file.
|
|
444
|
+
else:
|
|
445
|
+
buffer_idx = len(self.program_state.constant_buffer)
|
|
446
|
+
self.program_state.cached_spec_hash_values[hashed] = buffer_idx
|
|
447
|
+
self.program_state.constant_buffer.append(buffer)
|
|
448
|
+
|
|
449
|
+
return buffer_idx
|
|
450
|
+
|
|
451
|
+
def _tensor_spec_to_evalue(
|
|
452
|
+
self, spec: TensorSpec, constant_tag: Optional[str] = None
|
|
453
|
+
) -> EValue:
|
|
454
|
+
"""Constructs an EValue from the given TensorSpec."""
|
|
455
|
+
|
|
456
|
+
allocation_info = None
|
|
457
|
+
buffer_idx = 0
|
|
458
|
+
|
|
459
|
+
# Need to memory plan
|
|
460
|
+
# Some users set mem_id on all tensors and then rely on the
|
|
461
|
+
# default algos to set offsets, so need to check both.
|
|
462
|
+
if spec.mem_id is not None and spec.mem_offset is not None:
|
|
463
|
+
# Tensor is an activation.
|
|
464
|
+
allocation_info = self._get_allocation_info(spec)
|
|
465
|
+
|
|
466
|
+
# Tensor is either a constant tensor, or a mutable tensor with an initial state.
|
|
467
|
+
if spec.const:
|
|
468
|
+
# Tensor with a blob we need to serialize. May not actually be constant at runtime
|
|
469
|
+
# if it's a weight with an associated gradient.
|
|
470
|
+
spec_array_type = (
|
|
471
|
+
ctypes.c_char * typing.cast(torch.UntypedStorage, spec.storage).nbytes()
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
buffer_data = (
|
|
475
|
+
bytes(
|
|
476
|
+
ctypes.cast(
|
|
477
|
+
typing.cast(torch.UntypedStorage, spec.storage).data_ptr(),
|
|
478
|
+
ctypes.POINTER(spec_array_type),
|
|
479
|
+
).contents
|
|
480
|
+
)
|
|
481
|
+
if spec.allocated_memory != 0
|
|
482
|
+
else b""
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
hashed = hashlib.sha256(buffer_data).hexdigest()
|
|
486
|
+
|
|
487
|
+
if allocation_info and spec.extra_tensor_info is None:
|
|
488
|
+
buffer_idx = self.program_state.cached_spec_mutable_hash_values.get(
|
|
489
|
+
hashed, -1
|
|
490
|
+
)
|
|
491
|
+
elif (
|
|
492
|
+
spec.extra_tensor_info is not None
|
|
493
|
+
and spec.extra_tensor_info.location == TensorDataLocation.EXTERNAL
|
|
494
|
+
):
|
|
495
|
+
buffer_idx = self.program_state.external_constant_hash.get(hashed, -1)
|
|
496
|
+
if buffer_idx != -1:
|
|
497
|
+
# This constant already exists in the external_constant_buffer,
|
|
498
|
+
# And doesn't need to be duplicated. However, the fqn is unique
|
|
499
|
+
# and should be added. ie, we have the case: fqn0->data, fqn1->data.
|
|
500
|
+
# When buffer_idx == 1, the data is new and added with
|
|
501
|
+
# `_save_new_const_tensor` below.
|
|
502
|
+
assert spec.extra_tensor_info.fully_qualified_name is not None
|
|
503
|
+
assert constant_tag is not None
|
|
504
|
+
self._save_to_external_constant_map(
|
|
505
|
+
spec.extra_tensor_info.fully_qualified_name,
|
|
506
|
+
buffer_idx,
|
|
507
|
+
constant_tag,
|
|
508
|
+
)
|
|
509
|
+
else:
|
|
510
|
+
buffer_idx = self.program_state.cached_spec_hash_values.get(hashed, -1)
|
|
511
|
+
|
|
512
|
+
# Haven't seen this constant before.
|
|
513
|
+
if buffer_idx == -1:
|
|
514
|
+
buffer_idx = self._save_new_const_tensor(
|
|
515
|
+
spec, buffer_data, hashed, allocation_info, constant_tag
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
if spec.const and spec.nbytes() != len(buffer_data):
|
|
519
|
+
raise InternalError(
|
|
520
|
+
self._emit_node_specific_error(
|
|
521
|
+
self.node,
|
|
522
|
+
f"Tensor spec has buffer of size {len(buffer_data)}, but expected nbytes of {spec.nbytes()}",
|
|
523
|
+
)
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
# For constant tensors, allocation_info = None.
|
|
527
|
+
return EValue(make_tensor_value(buffer_idx, allocation_info, spec))
|
|
528
|
+
|
|
529
|
+
def _get_list_tuple_jit_type(
|
|
530
|
+
self, val: Union[Tuple[_Argument], List[_Argument]]
|
|
531
|
+
) -> _SchemaType:
|
|
532
|
+
"""Returns the JIT type for the given python type."""
|
|
533
|
+
assert isinstance(
|
|
534
|
+
val, (list, tuple)
|
|
535
|
+
), f"Input to _get_list_tuple_jit_type was expected to be an instance of a list or tuple but received {type(val)}"
|
|
536
|
+
is_tensor_type = all(
|
|
537
|
+
isinstance(v, _AbstractValue) and v.tensor is not None for v in val
|
|
538
|
+
)
|
|
539
|
+
if is_tensor_type:
|
|
540
|
+
return torch.TensorType.get()
|
|
541
|
+
elif isinstance(val[0], int):
|
|
542
|
+
return torch.IntType.get()
|
|
543
|
+
elif isinstance(val[0], bool):
|
|
544
|
+
return torch.BoolType.get()
|
|
545
|
+
elif isinstance(val[0], float):
|
|
546
|
+
return torch.FloatType.get()
|
|
547
|
+
|
|
548
|
+
raise InternalError(
|
|
549
|
+
self._emit_node_specific_error(
|
|
550
|
+
self.node,
|
|
551
|
+
"Couldn't determine JitType for list/tuple of elements. Only supports int, float, bool, and Tensor.",
|
|
552
|
+
)
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
def _constant_to_evalue( # noqa: C901
|
|
556
|
+
self,
|
|
557
|
+
val: _Argument,
|
|
558
|
+
val_type: Optional[_SchemaType],
|
|
559
|
+
*,
|
|
560
|
+
immutable: bool = False,
|
|
561
|
+
) -> EValue:
|
|
562
|
+
"""Converts a constant value to an EValue.
|
|
563
|
+
|
|
564
|
+
Returns an EValue given the Python representation and JIT type. On common paths there should
|
|
565
|
+
always be a JIT type provided. Users can pass in a None to infer the JIT type but this
|
|
566
|
+
should never be the default case due to the existence of container types.
|
|
567
|
+
"""
|
|
568
|
+
if val is None:
|
|
569
|
+
return EValue(Null())
|
|
570
|
+
|
|
571
|
+
if isinstance(val, (list, tuple)):
|
|
572
|
+
# Refine Optional[List[T]] -> List[T] This works because if the val was None it would
|
|
573
|
+
# have converted to Null before this function call.
|
|
574
|
+
if val_type is None:
|
|
575
|
+
val_type = torch.ListType(
|
|
576
|
+
self._get_list_tuple_jit_type(val) # pyre-ignore
|
|
577
|
+
)
|
|
578
|
+
if isinstance(val_type, torch.OptionalType):
|
|
579
|
+
val_type = val_type.getElementType()
|
|
580
|
+
assert isinstance(val_type, torch.ListType)
|
|
581
|
+
return self._emit_list(
|
|
582
|
+
typing.cast(List[_Argument], val),
|
|
583
|
+
typing.cast(_SchemaType, val_type.getElementType()),
|
|
584
|
+
immutable=immutable,
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
if isinstance(val, float):
|
|
588
|
+
return EValue(Double(val))
|
|
589
|
+
|
|
590
|
+
if isinstance(val, bool):
|
|
591
|
+
return EValue(Bool(val))
|
|
592
|
+
|
|
593
|
+
if isinstance(val, int):
|
|
594
|
+
return EValue(Int(val))
|
|
595
|
+
|
|
596
|
+
if isinstance(val, str):
|
|
597
|
+
return EValue(String(val))
|
|
598
|
+
|
|
599
|
+
if isinstance(val, torch.dtype):
|
|
600
|
+
return EValue(Int(scalar_type_enum(val)))
|
|
601
|
+
|
|
602
|
+
if isinstance(val, torch.layout):
|
|
603
|
+
return EValue(Int(layout_enum(val)))
|
|
604
|
+
|
|
605
|
+
if isinstance(val, torch.memory_format):
|
|
606
|
+
try:
|
|
607
|
+
return EValue(Int(memory_format_enum(val)))
|
|
608
|
+
except KeyError:
|
|
609
|
+
raise InternalError(
|
|
610
|
+
self._emit_node_specific_error(
|
|
611
|
+
self.node,
|
|
612
|
+
f"Tensor has a memory_format that is unsupported in ExecuTorch: {val}",
|
|
613
|
+
)
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
if isinstance(val, torch.Tensor):
|
|
617
|
+
raise ExportError(
|
|
618
|
+
ExportErrorType.NOT_SUPPORTED,
|
|
619
|
+
self._emit_node_specific_error(
|
|
620
|
+
self.node,
|
|
621
|
+
"constant_to_evalue should not be encountering constant tensors, they should be emitted through other codepaths.",
|
|
622
|
+
),
|
|
623
|
+
)
|
|
624
|
+
|
|
625
|
+
raise ExportError(
|
|
626
|
+
ExportErrorType.NOT_SUPPORTED,
|
|
627
|
+
self._emit_node_specific_error(
|
|
628
|
+
self.node, f"Unsupported constant type: {type(val).__name__}"
|
|
629
|
+
),
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
def _emit_evalue(self, val: EValue) -> _AbstractValue:
|
|
633
|
+
"""Writes an EValue to the emitter state.
|
|
634
|
+
|
|
635
|
+
Given an Evalue, adds it to the emitter_state's values table, and returns the AbstractValue
|
|
636
|
+
representing it.
|
|
637
|
+
"""
|
|
638
|
+
self.emitter_state.values.append(val)
|
|
639
|
+
tensor = val.val if isinstance(val.val, Tensor) else None
|
|
640
|
+
return _AbstractValue(len(self.emitter_state.values) - 1, tensor)
|
|
641
|
+
|
|
642
|
+
def _emit_spec(self, spec: ValueSpec) -> _EmitterValue:
|
|
643
|
+
"""Given the provided spec constructs the corresponding EValue from it and then emits it.
|
|
644
|
+
|
|
645
|
+
If `spec` was already emitted earlier (e.g., because two FX
|
|
646
|
+
nodes share the same TensorSpec object — typically because
|
|
647
|
+
`alias_inplace_result_specs` aliased an in-place
|
|
648
|
+
op's result onto its mutated input), reuse the existing
|
|
649
|
+
value_id. This keeps the invariant "one TensorSpec ↔ one
|
|
650
|
+
Value" so downstream emit doesn't create duplicate Values for
|
|
651
|
+
aliased FX nodes.
|
|
652
|
+
"""
|
|
653
|
+
|
|
654
|
+
def _process(spec: LeafValueSpec) -> _AbstractValue:
|
|
655
|
+
if isinstance(spec, (list, tuple)):
|
|
656
|
+
raise InternalError(
|
|
657
|
+
self.emit_node_specific_error(
|
|
658
|
+
self.node,
|
|
659
|
+
"Node spec should be either non-nested container or a scalar object",
|
|
660
|
+
)
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
# ScalarSpec can theoretically be handled fine, but it shouldn't be appearing so rather
|
|
664
|
+
# than handle it, assert that it isn't supposed to be present. In the future if it has a
|
|
665
|
+
# reason to appear we can relax this assert.
|
|
666
|
+
self._internal_assert_emitter(
|
|
667
|
+
isinstance(spec, TensorSpec),
|
|
668
|
+
self.node,
|
|
669
|
+
f"Invalid node spec expected TensorSpec received {spec}",
|
|
670
|
+
)
|
|
671
|
+
|
|
672
|
+
# Spec was already emitted — reuse the existing Value so
|
|
673
|
+
# two FX nodes sharing one TensorSpec also share one
|
|
674
|
+
# value_id in the lowered IR.
|
|
675
|
+
existing_id = self.emitter_state.spec2id_dict.get(spec)
|
|
676
|
+
if existing_id is not None:
|
|
677
|
+
existing_evalue = self.emitter_state.values[existing_id]
|
|
678
|
+
# Both insertion sites for `spec2id_dict` (this method
|
|
679
|
+
# and the placeholder emitter) only register ids whose
|
|
680
|
+
# EValue wraps a `Tensor` (built via
|
|
681
|
+
# `_tensor_spec_to_evalue` from a `TensorSpec`).
|
|
682
|
+
self._internal_assert_emitter(
|
|
683
|
+
isinstance(existing_evalue.val, Tensor),
|
|
684
|
+
self.node,
|
|
685
|
+
f"spec2id_dict entry for TensorSpec must point to a "
|
|
686
|
+
f"Tensor EValue, got "
|
|
687
|
+
f"{type(existing_evalue.val).__name__}",
|
|
688
|
+
)
|
|
689
|
+
return _AbstractValue(existing_id, existing_evalue.val)
|
|
690
|
+
|
|
691
|
+
ret = self._emit_evalue(self._tensor_spec_to_evalue(spec)) # pyre-ignore
|
|
692
|
+
self.emitter_state.spec2id_dict[spec] = ret.id # pyre-ignore
|
|
693
|
+
return ret
|
|
694
|
+
|
|
695
|
+
return pytree.tree_map(_process, spec)
|
|
696
|
+
|
|
697
|
+
def _merge_chain(self, chain: Chain) -> None:
|
|
698
|
+
"""Merges the chain generated from subgraphs (like those originating from control flow) back
|
|
699
|
+
into the main program chain."""
|
|
700
|
+
self.chain.instructions.extend(chain.instructions)
|
|
701
|
+
|
|
702
|
+
def _emit_cond(
|
|
703
|
+
self,
|
|
704
|
+
args: Tuple[_Argument, ...],
|
|
705
|
+
subemitter_binding_output_values: Optional[List[_AbstractValue]],
|
|
706
|
+
) -> List[_AbstractValue]:
|
|
707
|
+
"""Emits control_flow.cond.
|
|
708
|
+
|
|
709
|
+
Converts the higher order op into jumps and inlines the submodules of the true and false
|
|
710
|
+
branches. Control flow can be nested. The general emitted structure is: <Jump Instruction> -
|
|
711
|
+
decides which branch to take <True Branch> <Jump Instruction> - jumps to End Of Cond after
|
|
712
|
+
executing true branch <False Branch> <End Of Cond>
|
|
713
|
+
"""
|
|
714
|
+
pred, true_branch, false_branch, inputs = args
|
|
715
|
+
|
|
716
|
+
# Emit the true branch.
|
|
717
|
+
assert isinstance(true_branch, torch.fx.GraphModule)
|
|
718
|
+
true_branch_emitter = _Emitter(
|
|
719
|
+
true_branch,
|
|
720
|
+
self.emitter_state,
|
|
721
|
+
self.program_state,
|
|
722
|
+
instruction_start_offset=self.instruction_start_offset
|
|
723
|
+
+ len(self.chain.instructions)
|
|
724
|
+
+ 1,
|
|
725
|
+
binding_input_values=typing.cast(List[_AbstractValue], inputs),
|
|
726
|
+
binding_output_values=subemitter_binding_output_values,
|
|
727
|
+
)
|
|
728
|
+
true_branch_emitter.run()
|
|
729
|
+
|
|
730
|
+
# Emit the jump.
|
|
731
|
+
assert isinstance(pred, _AbstractValue)
|
|
732
|
+
jf_instruction_to_skip_true = Instruction(
|
|
733
|
+
JumpFalseCall(
|
|
734
|
+
cond_value_index=pred.id,
|
|
735
|
+
destination_instruction=self.instruction_start_offset
|
|
736
|
+
+ len(self.chain.instructions)
|
|
737
|
+
+ len(true_branch_emitter.chain.instructions)
|
|
738
|
+
# This jump instruction should point at instruction that is after all instructions
|
|
739
|
+
# for the true branch. The reason we add 2 is because we need to account for this
|
|
740
|
+
# instruction we are creating right now and the jump instruction that true branch
|
|
741
|
+
# will create.
|
|
742
|
+
+ 2,
|
|
743
|
+
)
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
# Insert the branch picking jump instruction to the main chain.
|
|
747
|
+
self.chain.instructions.append(jf_instruction_to_skip_true)
|
|
748
|
+
# Now that we created the true branch instructions, we move them to the main chain.
|
|
749
|
+
self._merge_chain(true_branch_emitter.chain)
|
|
750
|
+
|
|
751
|
+
# emit false branch
|
|
752
|
+
assert isinstance(false_branch, torch.fx.GraphModule)
|
|
753
|
+
false_branch_emitter = _Emitter(
|
|
754
|
+
false_branch,
|
|
755
|
+
self.emitter_state,
|
|
756
|
+
self.program_state,
|
|
757
|
+
instruction_start_offset=self.instruction_start_offset
|
|
758
|
+
+ len(self.chain.instructions)
|
|
759
|
+
+ 1,
|
|
760
|
+
binding_input_values=typing.cast(List[_AbstractValue], inputs),
|
|
761
|
+
binding_output_values=subemitter_binding_output_values,
|
|
762
|
+
)
|
|
763
|
+
false_branch_emitter.run()
|
|
764
|
+
|
|
765
|
+
# We bake in constant False because this will trigger the instruction to jump over all false
|
|
766
|
+
# branch instructions and point at the start of instruction right after control flow.
|
|
767
|
+
value = self._emit_evalue(EValue(Bool(False)))
|
|
768
|
+
jf_instruction_to_skip_false = Instruction(
|
|
769
|
+
JumpFalseCall(
|
|
770
|
+
cond_value_index=value.id,
|
|
771
|
+
destination_instruction=self.instruction_start_offset
|
|
772
|
+
+ len(self.chain.instructions)
|
|
773
|
+
+ len(false_branch_emitter.chain.instructions)
|
|
774
|
+
+ 1,
|
|
775
|
+
)
|
|
776
|
+
)
|
|
777
|
+
self.chain.instructions.append(jf_instruction_to_skip_false)
|
|
778
|
+
self._merge_chain(false_branch_emitter.chain)
|
|
779
|
+
return subemitter_binding_output_values
|
|
780
|
+
|
|
781
|
+
def _emit_map(
|
|
782
|
+
self,
|
|
783
|
+
args: Tuple[_Argument, ...],
|
|
784
|
+
subemitter_binding_output_values: List[_AbstractValue],
|
|
785
|
+
) -> List[_AbstractValue]:
|
|
786
|
+
"""Emits torch.map.
|
|
787
|
+
|
|
788
|
+
Converts the higher order op into a loop constructed from jump instructions and primitive
|
|
789
|
+
int operations. A concat-like custom op is also injected into the submodule code to handle
|
|
790
|
+
the construction of the map output.
|
|
791
|
+
|
|
792
|
+
Below is what the input graph that is provided to emit_map looks like. class
|
|
793
|
+
TestMapCond(torch.nn.Module): def __init__(self):
|
|
794
|
+
super().__init__()
|
|
795
|
+
|
|
796
|
+
def forward(self, x,y):
|
|
797
|
+
return control_flow.map(map_fn, x, y)
|
|
798
|
+
|
|
799
|
+
Corresponding graph: def forward(self, arg0_1, arg1_1):
|
|
800
|
+
submodule_0 = self.submodule_0 map_1 = torch.ops.higher_order.map_impl(submodule_0, arg0_1, arg1_1);
|
|
801
|
+
submodule_0 = arg0_1 = arg1_1 = None return [map_1]
|
|
802
|
+
|
|
803
|
+
submodule_0: def forward(self, arg0_1, arg1_1):
|
|
804
|
+
add_tensor = torch.ops.aten.add.Tensor(arg0_1, arg1_1); arg0_1 = arg1_1 = None return
|
|
805
|
+
add_tensor
|
|
806
|
+
|
|
807
|
+
Post the transformations done by emit_map this is what the submodule program looks like. def
|
|
808
|
+
forward(self, arg0_1, arg1_1):
|
|
809
|
+
sym_size = torch.ops.aten.sym_size(arg0_1) # Emitter creates a variable here to track
|
|
810
|
+
iteration index select_copy_tensor = torch.ops.aten.select(arg0_1, 0, iteration_index)
|
|
811
|
+
add_tensor = torch.ops.aten.add.Tensor(select_copy_tensor, arg1_1); arg0_1 = arg1_1 =
|
|
812
|
+
None output_of_map = torch.ops.executorch.prim.et_copy_index(output_of_map, add_tensor,
|
|
813
|
+
iteration_index) iteration_index = torch.ops.executorch.prim.add.int(iteration_index, 1,
|
|
814
|
+
iteration_index) done_bool = torch.ops.executorch.prim.eq.int(iteration_index, sym_size,
|
|
815
|
+
done_bool) # Emitter inserts a instruction here, if done_bool == False jump to
|
|
816
|
+
selcect_copy op # if not continue. return add_tensor
|
|
817
|
+
"""
|
|
818
|
+
assert isinstance(
|
|
819
|
+
subemitter_binding_output_values, (list, tuple)
|
|
820
|
+
), f"Expect a list for subemitter_binding_output_values for map. Got {subemitter_binding_output_values}."
|
|
821
|
+
|
|
822
|
+
if len(subemitter_binding_output_values) != 1:
|
|
823
|
+
raise RuntimeError(
|
|
824
|
+
f"Multiple outputs are not supported. Got {len(subemitter_binding_output_values)}."
|
|
825
|
+
)
|
|
826
|
+
f, mapped_args, inputs = args
|
|
827
|
+
assert isinstance(mapped_args, (list, tuple))
|
|
828
|
+
num_mapped_args: int = len(mapped_args)
|
|
829
|
+
if num_mapped_args != 1:
|
|
830
|
+
raise RuntimeError(
|
|
831
|
+
f"Emitting map with more than one mapped args is not supported. Got {num_mapped_args}."
|
|
832
|
+
)
|
|
833
|
+
x = mapped_args[0]
|
|
834
|
+
|
|
835
|
+
assert isinstance(f, torch.fx.GraphModule)
|
|
836
|
+
|
|
837
|
+
# Generate the EValue that we will use as our iterator index to keep track of which
|
|
838
|
+
# iteration we are currently on.
|
|
839
|
+
iter_idx = self._emit_evalue(EValue(Int(0)))
|
|
840
|
+
# Generate the kernel call that will output the number of iterations we need to run for this
|
|
841
|
+
# input tensor.
|
|
842
|
+
op_index, op = self._get_operator(
|
|
843
|
+
name="aten::sym_size",
|
|
844
|
+
overload="int",
|
|
845
|
+
)
|
|
846
|
+
sym_size = self._emit_evalue(EValue(Int(0)))
|
|
847
|
+
kernel = Instruction(
|
|
848
|
+
KernelCall(
|
|
849
|
+
op_index=op_index,
|
|
850
|
+
args=[x.id, self._emit_evalue(EValue(Int(0))).id, sym_size.id],
|
|
851
|
+
)
|
|
852
|
+
)
|
|
853
|
+
self.chain.instructions.append(kernel)
|
|
854
|
+
|
|
855
|
+
# This kernel call will slice the input tensor along the index specified in iter_idx to
|
|
856
|
+
# generate the input slice on which this iteration will be working on.
|
|
857
|
+
op_index, op = self._get_operator(
|
|
858
|
+
name="aten::select_copy",
|
|
859
|
+
overload="int_out",
|
|
860
|
+
)
|
|
861
|
+
# This select copy has to output to the tensor which is the input placeholder to the map
|
|
862
|
+
# sub-graph. That placeholder isn't allocated an EValue id until the map emitter is run, so
|
|
863
|
+
# we temporarily store -1 until the map emitter is run during which the placeholder will be
|
|
864
|
+
# allocated an EValue id. After the map emitter is run we will retrieve that id and replace
|
|
865
|
+
# the -1's.
|
|
866
|
+
kernel = Instruction(
|
|
867
|
+
KernelCall(
|
|
868
|
+
op_index=op_index,
|
|
869
|
+
args=[
|
|
870
|
+
x.id,
|
|
871
|
+
self._emit_evalue(EValue(Int(0))).id,
|
|
872
|
+
iter_idx.id,
|
|
873
|
+
-1, # input_tensor_value.id,
|
|
874
|
+
-1, # input_tensor_value.id,
|
|
875
|
+
],
|
|
876
|
+
)
|
|
877
|
+
)
|
|
878
|
+
# Store the index of this instruction as it will be where we will jump back to after the end
|
|
879
|
+
# of an iteration.
|
|
880
|
+
jump_to_instruction = self.instruction_start_offset + len(
|
|
881
|
+
self.chain.instructions
|
|
882
|
+
)
|
|
883
|
+
self.chain.instructions.append(kernel)
|
|
884
|
+
|
|
885
|
+
# Emit the map operator submodule.
|
|
886
|
+
map_emitter = _Emitter(
|
|
887
|
+
f,
|
|
888
|
+
self.emitter_state,
|
|
889
|
+
self.program_state,
|
|
890
|
+
instruction_start_offset=self.instruction_start_offset
|
|
891
|
+
+ len(self.chain.instructions),
|
|
892
|
+
# Only the first input is a placeholder, rest of the inputs are args to the map fn.
|
|
893
|
+
binding_input_values=[-1, *inputs],
|
|
894
|
+
binding_output_values=subemitter_binding_output_values,
|
|
895
|
+
)
|
|
896
|
+
map_emitter.run()
|
|
897
|
+
|
|
898
|
+
# Merge all the instructions from the map submodule.
|
|
899
|
+
self._merge_chain(map_emitter.chain)
|
|
900
|
+
# Get rid of the return instruction emitted by the map subemitter.
|
|
901
|
+
self.chain.instructions.pop()
|
|
902
|
+
# At the end of each submodule emit we insert a move call that moves the output of the
|
|
903
|
+
# submodule to a deterministic EValue, which is especially useful for if/else branches where
|
|
904
|
+
# we want the output of either branch to be in the same EValue, but we don't need a move
|
|
905
|
+
# here as our custom op executorch_prim::et_copy_index which is inserted later does that
|
|
906
|
+
# for us.
|
|
907
|
+
|
|
908
|
+
# Now that the map emitter has finished running retrieve the input placeholder EValue id and
|
|
909
|
+
# update the select_copy kernel call to output to those id's.
|
|
910
|
+
kernel.instr_args.args[-1] = map_emitter.binding_input_values[0].id
|
|
911
|
+
kernel.instr_args.args[-2] = kernel.instr_args.args[-1]
|
|
912
|
+
|
|
913
|
+
self._internal_assert_emitter(
|
|
914
|
+
len(map_emitter.concrete_output_ids) == 1,
|
|
915
|
+
self.node,
|
|
916
|
+
"Map should return only one element",
|
|
917
|
+
)
|
|
918
|
+
|
|
919
|
+
# Here we call the custom op, specially added for the map operator. The output of this
|
|
920
|
+
# iteration will be appended to the accumulator tensor that we are maintaining. This
|
|
921
|
+
# accumulator tensor is the actual output of the map submodule.
|
|
922
|
+
op_index, op = self._get_operator(
|
|
923
|
+
name="executorch_prim::et_copy_index",
|
|
924
|
+
overload="tensor",
|
|
925
|
+
)
|
|
926
|
+
kernel = Instruction(
|
|
927
|
+
KernelCall(
|
|
928
|
+
op_index,
|
|
929
|
+
args=[
|
|
930
|
+
subemitter_binding_output_values[0].id,
|
|
931
|
+
map_emitter.concrete_output_ids[0].id,
|
|
932
|
+
iter_idx.id,
|
|
933
|
+
],
|
|
934
|
+
)
|
|
935
|
+
)
|
|
936
|
+
self.chain.instructions.append(kernel)
|
|
937
|
+
|
|
938
|
+
# Increment iter_idx to mark that we have completed an iteration.
|
|
939
|
+
op_index, op = self._get_operator(
|
|
940
|
+
name="executorch_prim::add",
|
|
941
|
+
overload="Scalar",
|
|
942
|
+
)
|
|
943
|
+
kernel = Instruction(
|
|
944
|
+
KernelCall(
|
|
945
|
+
op_index,
|
|
946
|
+
args=[iter_idx.id, self._emit_evalue(EValue(Int(1))).id, iter_idx.id],
|
|
947
|
+
)
|
|
948
|
+
)
|
|
949
|
+
self.chain.instructions.append(kernel)
|
|
950
|
+
|
|
951
|
+
jump_bool_value = self._emit_evalue(EValue(Bool(False)))
|
|
952
|
+
|
|
953
|
+
# Generate the kernel call to check whether or not we have completed all the iterations. If
|
|
954
|
+
# not jump back to the select_copy instruction that we generated at the beginning of this
|
|
955
|
+
# section.
|
|
956
|
+
op_index, op = self._get_operator(
|
|
957
|
+
name="executorch_prim::eq",
|
|
958
|
+
overload="Scalar",
|
|
959
|
+
)
|
|
960
|
+
kernel = Instruction(
|
|
961
|
+
KernelCall(
|
|
962
|
+
op_index,
|
|
963
|
+
args=[iter_idx.id, sym_size.id, jump_bool_value.id],
|
|
964
|
+
)
|
|
965
|
+
)
|
|
966
|
+
self.chain.instructions.append(kernel)
|
|
967
|
+
|
|
968
|
+
jf_beginning_loop = Instruction(
|
|
969
|
+
JumpFalseCall(
|
|
970
|
+
cond_value_index=jump_bool_value.id,
|
|
971
|
+
destination_instruction=jump_to_instruction,
|
|
972
|
+
)
|
|
973
|
+
)
|
|
974
|
+
|
|
975
|
+
self.chain.instructions.append(jf_beginning_loop)
|
|
976
|
+
|
|
977
|
+
# Reset iter_idx in case we plan to run the model again.
|
|
978
|
+
op_index, op = self._get_operator(
|
|
979
|
+
name="executorch_prim::sub",
|
|
980
|
+
overload="Scalar",
|
|
981
|
+
)
|
|
982
|
+
kernel = Instruction(
|
|
983
|
+
KernelCall(
|
|
984
|
+
op_index,
|
|
985
|
+
args=[iter_idx.id, sym_size.id, iter_idx.id],
|
|
986
|
+
)
|
|
987
|
+
)
|
|
988
|
+
self.chain.instructions.append(kernel)
|
|
989
|
+
|
|
990
|
+
return subemitter_binding_output_values
|
|
991
|
+
|
|
992
|
+
def _emit_scan(
|
|
993
|
+
self,
|
|
994
|
+
args: Tuple[_Argument, ...],
|
|
995
|
+
subemitter_binding_output_values: List[_AbstractValue],
|
|
996
|
+
) -> List[_AbstractValue]:
|
|
997
|
+
"""Emits torch.scan.
|
|
998
|
+
|
|
999
|
+
Converts the higher order scan op into a loop constructed from jump instructions
|
|
1000
|
+
and primitive operations. Scan differs from map in that it maintains a carry state
|
|
1001
|
+
that evolves across iterations.
|
|
1002
|
+
|
|
1003
|
+
Scan signature: scan(combine_fn, init, xs, additional_inputs)
|
|
1004
|
+
- combine_fn: GraphModule that takes (carry, x_slice, *additional_inputs)
|
|
1005
|
+
and returns (next_carry, y_slice)
|
|
1006
|
+
- init: Initial carry state (list of tensors)
|
|
1007
|
+
- xs: Input tensors to scan over (list of tensors, scanned along dim 0)
|
|
1008
|
+
- additional_inputs: Additional arguments passed to combine_fn
|
|
1009
|
+
|
|
1010
|
+
Output: (final_carry, stacked_ys)
|
|
1011
|
+
- final_carry: The carry state after the last iteration
|
|
1012
|
+
- stacked_ys: All y outputs stacked along dim 0
|
|
1013
|
+
|
|
1014
|
+
Memory Layout:
|
|
1015
|
+
- carry_outputs (subemitter_binding_output_values[:num_carry]):
|
|
1016
|
+
Working carry buffers, initialized from init, updated each iteration
|
|
1017
|
+
- y_outputs (subemitter_binding_output_values[num_carry:]):
|
|
1018
|
+
Pre-allocated stacked output buffers, filled via et_copy_index
|
|
1019
|
+
|
|
1020
|
+
The combine_fn writes to its own temporary output buffers (concrete_output_ids).
|
|
1021
|
+
After each iteration:
|
|
1022
|
+
1. Copy combine_fn's carry output -> carry_outputs (for next iteration)
|
|
1023
|
+
2. et_copy_index(y_outputs, combine_fn's y output, iter_idx)
|
|
1024
|
+
|
|
1025
|
+
This explicit copy approach is used because in-place op.out(x, out=x) is unsafe.
|
|
1026
|
+
"""
|
|
1027
|
+
combine_fn, init, xs, additional_inputs = args
|
|
1028
|
+
|
|
1029
|
+
assert isinstance(subemitter_binding_output_values, (list, tuple)), (
|
|
1030
|
+
f"Expected list for subemitter_binding_output_values. "
|
|
1031
|
+
f"Got {type(subemitter_binding_output_values).__name__}: "
|
|
1032
|
+
f"{subemitter_binding_output_values}."
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
assert isinstance(combine_fn, torch.fx.GraphModule)
|
|
1036
|
+
assert isinstance(init, (list, tuple))
|
|
1037
|
+
assert isinstance(xs, (list, tuple))
|
|
1038
|
+
assert isinstance(additional_inputs, (list, tuple))
|
|
1039
|
+
|
|
1040
|
+
num_carry = len(init)
|
|
1041
|
+
num_xs = len(xs)
|
|
1042
|
+
|
|
1043
|
+
carry_outputs = list(subemitter_binding_output_values[:num_carry])
|
|
1044
|
+
y_outputs = list(subemitter_binding_output_values[num_carry:])
|
|
1045
|
+
|
|
1046
|
+
if num_xs < 1:
|
|
1047
|
+
raise RuntimeError(
|
|
1048
|
+
f"Scan requires at least one xs tensor to scan over but got {num_xs}"
|
|
1049
|
+
)
|
|
1050
|
+
|
|
1051
|
+
iter_idx = self._emit_evalue(EValue(Int(0)))
|
|
1052
|
+
|
|
1053
|
+
op_index, op = self._get_operator(
|
|
1054
|
+
name="aten::sym_size",
|
|
1055
|
+
overload="int",
|
|
1056
|
+
)
|
|
1057
|
+
sym_size = self._emit_evalue(EValue(Int(0)))
|
|
1058
|
+
kernel = Instruction(
|
|
1059
|
+
KernelCall(
|
|
1060
|
+
op_index=op_index,
|
|
1061
|
+
args=[xs[0].id, self._emit_evalue(EValue(Int(0))).id, sym_size.id],
|
|
1062
|
+
)
|
|
1063
|
+
)
|
|
1064
|
+
self.chain.instructions.append(kernel)
|
|
1065
|
+
|
|
1066
|
+
# Initialize carry_outputs from init
|
|
1067
|
+
op_index_copy, _ = self._get_operator(name="aten::copy_")
|
|
1068
|
+
for init_val, carry_out in zip(init, carry_outputs):
|
|
1069
|
+
kernel = Instruction(
|
|
1070
|
+
KernelCall(
|
|
1071
|
+
op_index=op_index_copy,
|
|
1072
|
+
args=[
|
|
1073
|
+
carry_out.id,
|
|
1074
|
+
init_val.id,
|
|
1075
|
+
self._emit_evalue(EValue(Bool(False))).id,
|
|
1076
|
+
carry_out.id,
|
|
1077
|
+
],
|
|
1078
|
+
)
|
|
1079
|
+
)
|
|
1080
|
+
self.chain.instructions.append(kernel)
|
|
1081
|
+
|
|
1082
|
+
# Slice each xs tensor for the current iteration
|
|
1083
|
+
op_index_select, _ = self._get_operator(
|
|
1084
|
+
name="aten::select_copy",
|
|
1085
|
+
overload="int_out",
|
|
1086
|
+
)
|
|
1087
|
+
xs_slice_instructions = []
|
|
1088
|
+
for x in xs:
|
|
1089
|
+
kernel = Instruction(
|
|
1090
|
+
KernelCall(
|
|
1091
|
+
op_index=op_index_select,
|
|
1092
|
+
args=[
|
|
1093
|
+
x.id,
|
|
1094
|
+
self._emit_evalue(EValue(Int(0))).id,
|
|
1095
|
+
iter_idx.id,
|
|
1096
|
+
-1,
|
|
1097
|
+
-1,
|
|
1098
|
+
],
|
|
1099
|
+
)
|
|
1100
|
+
)
|
|
1101
|
+
xs_slice_instructions.append(kernel)
|
|
1102
|
+
|
|
1103
|
+
jump_to_instruction = self.instruction_start_offset + len(
|
|
1104
|
+
self.chain.instructions
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
for kernel in xs_slice_instructions:
|
|
1108
|
+
self.chain.instructions.append(kernel)
|
|
1109
|
+
|
|
1110
|
+
# Emit combine_fn submodule
|
|
1111
|
+
binding_input_values: List[Any] = []
|
|
1112
|
+
binding_input_values.extend(carry_outputs)
|
|
1113
|
+
binding_input_values.extend([-1] * num_xs)
|
|
1114
|
+
binding_input_values.extend(additional_inputs)
|
|
1115
|
+
|
|
1116
|
+
scan_emitter = _Emitter(
|
|
1117
|
+
combine_fn,
|
|
1118
|
+
self.emitter_state,
|
|
1119
|
+
self.program_state,
|
|
1120
|
+
instruction_start_offset=self.instruction_start_offset
|
|
1121
|
+
+ len(self.chain.instructions),
|
|
1122
|
+
binding_input_values=binding_input_values,
|
|
1123
|
+
binding_output_values=None,
|
|
1124
|
+
)
|
|
1125
|
+
scan_emitter.run()
|
|
1126
|
+
|
|
1127
|
+
self._merge_chain(scan_emitter.chain)
|
|
1128
|
+
|
|
1129
|
+
for i, kernel in enumerate(xs_slice_instructions):
|
|
1130
|
+
xs_placeholder_id = scan_emitter.binding_input_values[num_carry + i].id
|
|
1131
|
+
kernel.instr_args.args[-1] = xs_placeholder_id
|
|
1132
|
+
kernel.instr_args.args[-2] = xs_placeholder_id
|
|
1133
|
+
|
|
1134
|
+
concrete_outputs = scan_emitter.concrete_output_ids
|
|
1135
|
+
carry_temp = concrete_outputs[:num_carry]
|
|
1136
|
+
y_temp = concrete_outputs[num_carry:]
|
|
1137
|
+
|
|
1138
|
+
self._internal_assert_emitter(
|
|
1139
|
+
len(carry_temp) == num_carry,
|
|
1140
|
+
self.node,
|
|
1141
|
+
f"Scan combine_fn should output {num_carry} carry values, got {len(carry_temp)}",
|
|
1142
|
+
)
|
|
1143
|
+
self._internal_assert_emitter(
|
|
1144
|
+
len(y_temp) == len(y_outputs),
|
|
1145
|
+
self.node,
|
|
1146
|
+
f"Scan combine_fn should output {len(y_outputs)} y values, got {len(y_temp)}",
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
# Copy carry_temp -> carry_outputs for next iteration
|
|
1150
|
+
for carry_t, carry_out in zip(carry_temp, carry_outputs):
|
|
1151
|
+
kernel = Instruction(
|
|
1152
|
+
KernelCall(
|
|
1153
|
+
op_index=op_index_copy,
|
|
1154
|
+
args=[
|
|
1155
|
+
carry_out.id,
|
|
1156
|
+
carry_t.id,
|
|
1157
|
+
self._emit_evalue(EValue(Bool(False))).id,
|
|
1158
|
+
carry_out.id,
|
|
1159
|
+
],
|
|
1160
|
+
)
|
|
1161
|
+
)
|
|
1162
|
+
self.chain.instructions.append(kernel)
|
|
1163
|
+
|
|
1164
|
+
# Copy y_temp to stacked y_outputs
|
|
1165
|
+
op_index_copy_index, _ = self._get_operator(
|
|
1166
|
+
name="executorch_prim::et_copy_index",
|
|
1167
|
+
overload="tensor",
|
|
1168
|
+
)
|
|
1169
|
+
for y_t, y_out in zip(y_temp, y_outputs):
|
|
1170
|
+
kernel = Instruction(
|
|
1171
|
+
KernelCall(
|
|
1172
|
+
op_index=op_index_copy_index,
|
|
1173
|
+
args=[y_out.id, y_t.id, iter_idx.id],
|
|
1174
|
+
)
|
|
1175
|
+
)
|
|
1176
|
+
self.chain.instructions.append(kernel)
|
|
1177
|
+
|
|
1178
|
+
# Increment iter_idx
|
|
1179
|
+
op_index_add, _ = self._get_operator(
|
|
1180
|
+
name="executorch_prim::add",
|
|
1181
|
+
overload="Scalar",
|
|
1182
|
+
)
|
|
1183
|
+
kernel = Instruction(
|
|
1184
|
+
KernelCall(
|
|
1185
|
+
op_index=op_index_add,
|
|
1186
|
+
args=[iter_idx.id, self._emit_evalue(EValue(Int(1))).id, iter_idx.id],
|
|
1187
|
+
)
|
|
1188
|
+
)
|
|
1189
|
+
self.chain.instructions.append(kernel)
|
|
1190
|
+
|
|
1191
|
+
# Check if iteration is complete
|
|
1192
|
+
jump_bool_value = self._emit_evalue(EValue(Bool(False)))
|
|
1193
|
+
op_index_eq, _ = self._get_operator(
|
|
1194
|
+
name="executorch_prim::eq",
|
|
1195
|
+
overload="Scalar",
|
|
1196
|
+
)
|
|
1197
|
+
kernel = Instruction(
|
|
1198
|
+
KernelCall(
|
|
1199
|
+
op_index=op_index_eq,
|
|
1200
|
+
args=[iter_idx.id, sym_size.id, jump_bool_value.id],
|
|
1201
|
+
)
|
|
1202
|
+
)
|
|
1203
|
+
self.chain.instructions.append(kernel)
|
|
1204
|
+
|
|
1205
|
+
jf_beginning_loop = Instruction(
|
|
1206
|
+
JumpFalseCall(
|
|
1207
|
+
cond_value_index=jump_bool_value.id,
|
|
1208
|
+
destination_instruction=jump_to_instruction,
|
|
1209
|
+
)
|
|
1210
|
+
)
|
|
1211
|
+
self.chain.instructions.append(jf_beginning_loop)
|
|
1212
|
+
|
|
1213
|
+
# Reset iter_idx for potential re-runs
|
|
1214
|
+
op_index_sub, _ = self._get_operator(
|
|
1215
|
+
name="executorch_prim::sub",
|
|
1216
|
+
overload="Scalar",
|
|
1217
|
+
)
|
|
1218
|
+
kernel = Instruction(
|
|
1219
|
+
KernelCall(
|
|
1220
|
+
op_index=op_index_sub,
|
|
1221
|
+
args=[iter_idx.id, sym_size.id, iter_idx.id],
|
|
1222
|
+
)
|
|
1223
|
+
)
|
|
1224
|
+
self.chain.instructions.append(kernel)
|
|
1225
|
+
|
|
1226
|
+
return subemitter_binding_output_values
|
|
1227
|
+
|
|
1228
|
+
def _emit_control_flow(
|
|
1229
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1230
|
+
) -> _EmitterValue:
|
|
1231
|
+
"""Wraps common logic for emitting all control flow operations.
|
|
1232
|
+
|
|
1233
|
+
See the more specific emission functions for more details on how cond, map, or scan get emitted.
|
|
1234
|
+
"""
|
|
1235
|
+
specs = self.node.meta["spec"]
|
|
1236
|
+
|
|
1237
|
+
# For scan/map, set the shape_dynamism for the stacked outputs (y_outputs) to DYNAMIC_BOUND
|
|
1238
|
+
# BEFORE emitting the specs. This is because et_copy_index has cat shape semantics but
|
|
1239
|
+
# stack memory behavior, so we need to be able to update the shape +1 for each iteration
|
|
1240
|
+
# which we can't do for tensors marked static.
|
|
1241
|
+
if target is torch.ops.higher_order.scan:
|
|
1242
|
+
combine_fn, init, xs, additional_inputs = args
|
|
1243
|
+
num_carry = len(init)
|
|
1244
|
+
if isinstance(specs, (list, tuple)):
|
|
1245
|
+
y_specs = specs[num_carry:]
|
|
1246
|
+
for y_spec in y_specs:
|
|
1247
|
+
if isinstance(y_spec, TensorSpec):
|
|
1248
|
+
y_spec.shape_dynamism = TensorShapeDynamism.DYNAMIC_BOUND
|
|
1249
|
+
elif target is torch.ops.higher_order.map_impl:
|
|
1250
|
+
assert len(specs) == 1
|
|
1251
|
+
assert isinstance(specs[0], TensorSpec)
|
|
1252
|
+
specs[0].shape_dynamism = TensorShapeDynamism.DYNAMIC_BOUND
|
|
1253
|
+
|
|
1254
|
+
subemitter_binding_output_values = pytree.tree_map(
|
|
1255
|
+
lambda spec: self._emit_spec(spec),
|
|
1256
|
+
specs,
|
|
1257
|
+
)
|
|
1258
|
+
|
|
1259
|
+
if target is torch.ops.higher_order.cond:
|
|
1260
|
+
return self._emit_cond(args, subemitter_binding_output_values)
|
|
1261
|
+
elif target is torch.ops.higher_order.map_impl:
|
|
1262
|
+
return self._emit_map(args, subemitter_binding_output_values)
|
|
1263
|
+
elif target is torch.ops.higher_order.scan:
|
|
1264
|
+
return self._emit_scan(args, subemitter_binding_output_values)
|
|
1265
|
+
else:
|
|
1266
|
+
raise InternalError(
|
|
1267
|
+
self._emit_node_specific_error(
|
|
1268
|
+
self.node, f"Unsupported control flow operator: {target}"
|
|
1269
|
+
)
|
|
1270
|
+
)
|
|
1271
|
+
|
|
1272
|
+
def _emit_view(self, args: Tuple[_Argument, ...]) -> _EmitterValue:
|
|
1273
|
+
assert len(args) == 2
|
|
1274
|
+
|
|
1275
|
+
# Elide the view if it is static and memory planned
|
|
1276
|
+
spec = self.node.meta["spec"]
|
|
1277
|
+
is_static = spec.is_static_shape_tensor
|
|
1278
|
+
is_memory_planned = (spec.mem_id is not None) and (spec.mem_offset is not None)
|
|
1279
|
+
is_memory_planned = is_memory_planned or (
|
|
1280
|
+
spec.const and spec.storage is not None
|
|
1281
|
+
)
|
|
1282
|
+
if is_static and is_memory_planned:
|
|
1283
|
+
return self._emit_spec(spec)
|
|
1284
|
+
|
|
1285
|
+
self_arg = self._emit_argument(args[0], torch.TensorType) # pyre-ignore[6]
|
|
1286
|
+
size_arg = self._emit_argument(args[1], torch.ListType.ofInts())
|
|
1287
|
+
out_arg = self._emit_argument(
|
|
1288
|
+
self._emit_spec(self.node.meta["spec"]), torch.TensorType # pyre-ignore[6]
|
|
1289
|
+
)
|
|
1290
|
+
|
|
1291
|
+
op_idx, op = self._get_operator(
|
|
1292
|
+
name="executorch_prim::et_view",
|
|
1293
|
+
overload="default",
|
|
1294
|
+
)
|
|
1295
|
+
kernel = Instruction(
|
|
1296
|
+
KernelCall(
|
|
1297
|
+
op_idx,
|
|
1298
|
+
args=[
|
|
1299
|
+
self_arg.id,
|
|
1300
|
+
size_arg.id,
|
|
1301
|
+
out_arg.id,
|
|
1302
|
+
],
|
|
1303
|
+
)
|
|
1304
|
+
)
|
|
1305
|
+
self.chain.instructions.append(kernel)
|
|
1306
|
+
return out_arg
|
|
1307
|
+
|
|
1308
|
+
def _add_debug_handle(
|
|
1309
|
+
self,
|
|
1310
|
+
emitter_id: int,
|
|
1311
|
+
target: _Target,
|
|
1312
|
+
# pyre-ignore[11]: Annotation `LoweredBackendModule` is not defined as a type.
|
|
1313
|
+
lowered_module: "Optional[LoweredBackendModule]" = None, # noqa: F821
|
|
1314
|
+
) -> None:
|
|
1315
|
+
"""Updates the debug handle information for the current node.
|
|
1316
|
+
|
|
1317
|
+
If the current node is a delegate we agregate the debug handles of the subgraph and store
|
|
1318
|
+
them in the map. If the current node is any other type we store the original information in
|
|
1319
|
+
the debug handle map and replace it with the executorch instruction index corresponding to
|
|
1320
|
+
this node.
|
|
1321
|
+
"""
|
|
1322
|
+
# If it's a delegate call, collect the list of debug handles that are consumed by this
|
|
1323
|
+
# delegate call and store it in the debug handle map.
|
|
1324
|
+
if target == executorch_call_delegate:
|
|
1325
|
+
debug_handle_list = []
|
|
1326
|
+
# Use the lowered_module to fetch the original graph and its debug
|
|
1327
|
+
# handles.
|
|
1328
|
+
for node in lowered_module.original_module.graph.nodes:
|
|
1329
|
+
if (
|
|
1330
|
+
node.op == "call_function"
|
|
1331
|
+
and node.meta.get("debug_handle") is not None
|
|
1332
|
+
):
|
|
1333
|
+
debug_handle_list.append(node.meta.get("debug_handle"))
|
|
1334
|
+
output_node = lowered_module.original_module.graph.output_node()
|
|
1335
|
+
outputs = output_node.args[0]
|
|
1336
|
+
num_outputs = len(outputs) if isinstance(outputs, (list, tuple)) else 1
|
|
1337
|
+
self.debug_handle_map[emitter_id] = debug_handle_list
|
|
1338
|
+
self.instruction_id_to_num_outs_map[emitter_id] = num_outputs
|
|
1339
|
+
# Debug handle for this node is the emitter_id which is essentially the index of the
|
|
1340
|
+
# instruction in the chain.
|
|
1341
|
+
self.node.meta["debug_handle"] = emitter_id
|
|
1342
|
+
return
|
|
1343
|
+
|
|
1344
|
+
if self.node.meta.get("debug_handle") is not None:
|
|
1345
|
+
# Store the original debug handle in the debug handle map.
|
|
1346
|
+
self.debug_handle_map[emitter_id] = self.node.meta.get("debug_handle")
|
|
1347
|
+
# Replace the debug handle in the metadata of the node with the emitter id which
|
|
1348
|
+
# represents the instruction index in the chain. We do this because in the runtime the
|
|
1349
|
+
# instruction index is what is logged during perf/debug data logging and hence we want
|
|
1350
|
+
# to store this in the node so that we can map the data logged by the runtime back to
|
|
1351
|
+
# the node.
|
|
1352
|
+
self.node.meta["debug_handle"] = emitter_id
|
|
1353
|
+
|
|
1354
|
+
def _add_delegate_map(
|
|
1355
|
+
self,
|
|
1356
|
+
lowered_module: "LoweredBackendModule", # noqa
|
|
1357
|
+
delegate_instruction_id: int,
|
|
1358
|
+
) -> None:
|
|
1359
|
+
"""
|
|
1360
|
+
Store the delegate map from this lowered module into the dictionary of delegate maps. It
|
|
1361
|
+
will later be used for various debugging purposes such as linking back to original source
|
|
1362
|
+
code, module hierarchy etc.
|
|
1363
|
+
"""
|
|
1364
|
+
delegate_map = {}
|
|
1365
|
+
if lowered_module.meta is not None:
|
|
1366
|
+
delegate_map = lowered_module.meta.get("debug_handle_map", {})
|
|
1367
|
+
|
|
1368
|
+
self.instr_id_to_delegate_debug_id_map[delegate_instruction_id] = {
|
|
1369
|
+
"name": lowered_module.backend_id,
|
|
1370
|
+
"delegate_map": delegate_map,
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
def _emit_argument(
|
|
1374
|
+
self,
|
|
1375
|
+
arg: _Argument,
|
|
1376
|
+
arg_type: Optional[_SchemaType],
|
|
1377
|
+
*,
|
|
1378
|
+
immutable: bool = False,
|
|
1379
|
+
) -> _AbstractValue:
|
|
1380
|
+
"""Emit an argument to an operator or delegate if it had not already been emitted otherwise
|
|
1381
|
+
return the previously emitted location"""
|
|
1382
|
+
if isinstance(arg, _AbstractValue):
|
|
1383
|
+
return arg
|
|
1384
|
+
value = self._constant_to_evalue(arg, arg_type, immutable=immutable)
|
|
1385
|
+
key: Optional[Union[int, Tuple[int, ...]]] = None
|
|
1386
|
+
if immutable:
|
|
1387
|
+
if isinstance(value.val, Int):
|
|
1388
|
+
key = value.val.int_val
|
|
1389
|
+
elif (
|
|
1390
|
+
isinstance(value.val, IntList)
|
|
1391
|
+
and isinstance(arg, (list, tuple))
|
|
1392
|
+
and all(type(item) is int for item in arg)
|
|
1393
|
+
):
|
|
1394
|
+
# Boxed lists can reference mutable SymInts. Only literal lists
|
|
1395
|
+
# may share their unboxed buffer; their elements are already pooled.
|
|
1396
|
+
key = tuple(value.val.items)
|
|
1397
|
+
if key is not None:
|
|
1398
|
+
index = self.emitter_state.constant_cache.get(key)
|
|
1399
|
+
if index is not None:
|
|
1400
|
+
return _AbstractValue(index, None)
|
|
1401
|
+
result = self._emit_evalue(value)
|
|
1402
|
+
if key is not None:
|
|
1403
|
+
self.emitter_state.constant_cache[key] = result.id
|
|
1404
|
+
return result
|
|
1405
|
+
|
|
1406
|
+
def _get_sym_ret(
|
|
1407
|
+
self,
|
|
1408
|
+
val: Tuple[Union[torch.SymInt, torch.BoolType, torch.FloatType, FakeTensor]],
|
|
1409
|
+
) -> Optional[_AbstractValue]:
|
|
1410
|
+
"""
|
|
1411
|
+
Returns the emit ret for sym value.
|
|
1412
|
+
"""
|
|
1413
|
+
ret = None
|
|
1414
|
+
if isinstance(val, torch.SymInt):
|
|
1415
|
+
ret = self._emit_evalue(EValue(Int(0)))
|
|
1416
|
+
elif isinstance(val, torch.BoolType):
|
|
1417
|
+
ret = self._emit_evalue(EValue(Bool(False)))
|
|
1418
|
+
elif isinstance(val, torch.FloatType):
|
|
1419
|
+
ret = self._emit_evalue(EValue(Double(0)))
|
|
1420
|
+
return ret
|
|
1421
|
+
|
|
1422
|
+
def _get_sym_and_fake_tensor_ret(
|
|
1423
|
+
self,
|
|
1424
|
+
val: Tuple[Union[torch.SymInt, torch.BoolType, torch.FloatType, FakeTensor]],
|
|
1425
|
+
spec: TensorSpec,
|
|
1426
|
+
) -> Union[List[_AbstractValue], _AbstractValue, Tuple[_AbstractValue, ...]]:
|
|
1427
|
+
# Try to get the ret if it's a sym value.
|
|
1428
|
+
ret = self._get_sym_ret(val)
|
|
1429
|
+
# If the ret is None, it means that the val is not a sym value, but a regular tensor
|
|
1430
|
+
if ret is None:
|
|
1431
|
+
ret = self._emit_spec(spec)
|
|
1432
|
+
assert ret is not None, "Can't have a None ret"
|
|
1433
|
+
return ret
|
|
1434
|
+
|
|
1435
|
+
def _emit_delegate(
|
|
1436
|
+
self,
|
|
1437
|
+
lowered_module: "LoweredBackendModule", # noqa
|
|
1438
|
+
args: Tuple[_Argument, ...],
|
|
1439
|
+
kwargs: Dict[str, _Argument],
|
|
1440
|
+
) -> _EmitterValue:
|
|
1441
|
+
"""Emit the delegates inputs and outputs as specified by the schema, then emit the
|
|
1442
|
+
delegate's blob."""
|
|
1443
|
+
processed_bytes = lowered_module.processed_bytes
|
|
1444
|
+
hashed = hashlib.sha256(processed_bytes).hexdigest()
|
|
1445
|
+
delegate_index = self.program_state.backend_delegate_data_cache.get(hashed)
|
|
1446
|
+
delegate_ret = None
|
|
1447
|
+
|
|
1448
|
+
if isinstance(self.node.meta["spec"], list):
|
|
1449
|
+
delegate_ret = []
|
|
1450
|
+
for index, _ in enumerate(self.node.meta["val"]):
|
|
1451
|
+
ret = self._get_sym_and_fake_tensor_ret(
|
|
1452
|
+
self.node.meta["val"][index], self.node.meta["spec"][index]
|
|
1453
|
+
)
|
|
1454
|
+
delegate_ret.append(ret)
|
|
1455
|
+
elif isinstance(self.node.meta["spec"], tuple):
|
|
1456
|
+
if isinstance(self.node.meta["val"], FakeTensor):
|
|
1457
|
+
# There is a case when node.meta["spec"] is (TensorSpec, ) while node.meta["val"] is FakeTensor
|
|
1458
|
+
ret = self._get_sym_and_fake_tensor_ret(
|
|
1459
|
+
self.node.meta["val"], self.node.meta["spec"][0]
|
|
1460
|
+
)
|
|
1461
|
+
delegate_ret = (ret,)
|
|
1462
|
+
else:
|
|
1463
|
+
delegate_ret = []
|
|
1464
|
+
for index, _ in enumerate(self.node.meta["val"]):
|
|
1465
|
+
ret = self._get_sym_and_fake_tensor_ret(
|
|
1466
|
+
self.node.meta["val"][index], self.node.meta["spec"][index]
|
|
1467
|
+
)
|
|
1468
|
+
delegate_ret.append(ret)
|
|
1469
|
+
delegate_ret = tuple(delegate_ret)
|
|
1470
|
+
elif isinstance(self.node.meta["spec"], TensorSpec):
|
|
1471
|
+
ret = self._get_sym_and_fake_tensor_ret(
|
|
1472
|
+
self.node.meta["val"], self.node.meta["spec"]
|
|
1473
|
+
)
|
|
1474
|
+
delegate_ret = ret
|
|
1475
|
+
else:
|
|
1476
|
+
raise NotImplementedError(
|
|
1477
|
+
f"self.node.meta['spec'] {type(self.node.meta['spec'])} is not supported"
|
|
1478
|
+
)
|
|
1479
|
+
assert delegate_ret is not None, "Can't have a None delegate_ret"
|
|
1480
|
+
if delegate_index is None:
|
|
1481
|
+
# Allocate an entry for the data. TODO(T150113674): Reuse any duplicate entries if
|
|
1482
|
+
# present.
|
|
1483
|
+
delegate_index = len(self.program_state.backend_delegate_data_cache)
|
|
1484
|
+
self.program_state.backend_delegate_data_cache[hashed] = delegate_index
|
|
1485
|
+
self.program_state.backend_delegate_data.append(
|
|
1486
|
+
BackendDelegateInlineData(data=processed_bytes)
|
|
1487
|
+
)
|
|
1488
|
+
|
|
1489
|
+
# Checked against the declaration so that an emit path the pass never
|
|
1490
|
+
# ran on, or a spec something else rewrote, fails here rather than
|
|
1491
|
+
# handing the backend a span the blob overruns.
|
|
1492
|
+
scratch_specs = memory.delegate_scratch_specs(self.node)
|
|
1493
|
+
declared = [spec.nbytes for spec in lowered_module.scratch_specs]
|
|
1494
|
+
if [spec.nbytes() for spec in scratch_specs] != declared:
|
|
1495
|
+
raise InternalError(
|
|
1496
|
+
self._emit_node_specific_error(
|
|
1497
|
+
self.node,
|
|
1498
|
+
f"Backend {lowered_module.backend_id} declared scratch buffers of "
|
|
1499
|
+
f"{declared} bytes but the graph carries "
|
|
1500
|
+
f"{[spec.nbytes() for spec in scratch_specs]}. "
|
|
1501
|
+
"DelegateScratchSpecPass must run before emission for a backend "
|
|
1502
|
+
"that declares scratch.",
|
|
1503
|
+
)
|
|
1504
|
+
)
|
|
1505
|
+
|
|
1506
|
+
backend_delegate_index = self.emitter_state.delegate_cache.get(lowered_module)
|
|
1507
|
+
if backend_delegate_index is None:
|
|
1508
|
+
backend_delegate = BackendDelegate(
|
|
1509
|
+
id=lowered_module.backend_id,
|
|
1510
|
+
processed=BackendDelegateDataReference(
|
|
1511
|
+
location=DataLocation.INLINE, index=delegate_index
|
|
1512
|
+
),
|
|
1513
|
+
compile_specs=lowered_module.compile_specs,
|
|
1514
|
+
)
|
|
1515
|
+
self.emitter_state.delegates.append(backend_delegate)
|
|
1516
|
+
backend_delegate_index = len(self.emitter_state.delegates) - 1
|
|
1517
|
+
# Scratch is planned per call site but the runtime keeps it on the
|
|
1518
|
+
# delegate, so a delegate with scratch cannot be shared.
|
|
1519
|
+
if (
|
|
1520
|
+
lowered_module.share_handle_across_calls
|
|
1521
|
+
and not lowered_module.scratch_specs
|
|
1522
|
+
):
|
|
1523
|
+
self.emitter_state.delegate_cache[lowered_module] = (
|
|
1524
|
+
backend_delegate_index
|
|
1525
|
+
)
|
|
1526
|
+
# TODO(angelayi) Will need to emit the kwargs too, in the correct order according to the
|
|
1527
|
+
# function's spec and with default arguments. This requires us to store the function's spec
|
|
1528
|
+
# in to_backend()
|
|
1529
|
+
delegate_args = [
|
|
1530
|
+
self._emit_argument(arg, None).id
|
|
1531
|
+
for arg in typing.cast(List[_Argument], args)
|
|
1532
|
+
]
|
|
1533
|
+
|
|
1534
|
+
for elem in pytree.tree_flatten(delegate_ret)[0]:
|
|
1535
|
+
delegate_args.append(elem.id)
|
|
1536
|
+
|
|
1537
|
+
self.chain.instructions.append(
|
|
1538
|
+
Instruction(
|
|
1539
|
+
DelegateCall(
|
|
1540
|
+
delegate_index=backend_delegate_index,
|
|
1541
|
+
args=delegate_args,
|
|
1542
|
+
scratch=self._emit_delegate_scratch(scratch_specs) or None,
|
|
1543
|
+
)
|
|
1544
|
+
)
|
|
1545
|
+
)
|
|
1546
|
+
|
|
1547
|
+
return delegate_ret
|
|
1548
|
+
|
|
1549
|
+
def _emit_delegate_scratch(self, specs: List[TensorSpec]) -> List[DelegateScratch]:
|
|
1550
|
+
"""Describes the delegate's scratch allocations for the instruction.
|
|
1551
|
+
|
|
1552
|
+
The buffers are planned like any other intermediate, but the backend
|
|
1553
|
+
receives raw bytes, so they are serialized as locations and sizes
|
|
1554
|
+
instead of as tensor values.
|
|
1555
|
+
"""
|
|
1556
|
+
scratch = []
|
|
1557
|
+
for index, spec in enumerate(specs):
|
|
1558
|
+
if spec.mem_id is None or spec.mem_offset is None:
|
|
1559
|
+
raise InternalError(
|
|
1560
|
+
self._emit_node_specific_error(
|
|
1561
|
+
self.node,
|
|
1562
|
+
f"Delegate scratch buffer {index} was not memory planned.",
|
|
1563
|
+
)
|
|
1564
|
+
)
|
|
1565
|
+
scratch.append(
|
|
1566
|
+
DelegateScratch(
|
|
1567
|
+
allocation=make_allocation_info(spec.mem_id, spec.mem_offset),
|
|
1568
|
+
size=spec.nbytes(),
|
|
1569
|
+
)
|
|
1570
|
+
)
|
|
1571
|
+
return scratch
|
|
1572
|
+
|
|
1573
|
+
def _get_operator(self, name: str, overload: str = "") -> Tuple[int, Operator]:
|
|
1574
|
+
"""Given a fully qualified name, lookups the operator in the ExecuTorch Program, or adds it
|
|
1575
|
+
if it is not already present"""
|
|
1576
|
+
key = (name, overload)
|
|
1577
|
+
op_index = self.emitter_state.operator_cache.get(key)
|
|
1578
|
+
if op_index is not None:
|
|
1579
|
+
return op_index, self.emitter_state.operators[op_index]
|
|
1580
|
+
|
|
1581
|
+
op_index, operator = len(self.emitter_state.operators), Operator(
|
|
1582
|
+
name=name, overload=overload
|
|
1583
|
+
)
|
|
1584
|
+
self.emitter_state.operators.append(operator)
|
|
1585
|
+
self.emitter_state.operator_cache[key] = op_index
|
|
1586
|
+
return op_index, operator
|
|
1587
|
+
|
|
1588
|
+
def _emit_operator( # noqa: C901
|
|
1589
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1590
|
+
) -> _EmitterValue:
|
|
1591
|
+
"""Emits an operator (aten or custom), directly translates to a call_kernel instruction."""
|
|
1592
|
+
assert isinstance(
|
|
1593
|
+
target, (torch._ops.OpOverload, EdgeOpOverload, BackendOpOverload)
|
|
1594
|
+
), f"target is {target}"
|
|
1595
|
+
|
|
1596
|
+
# grab the name
|
|
1597
|
+
op_name = target._overloadpacket._qualified_op_name
|
|
1598
|
+
op_overload = ""
|
|
1599
|
+
if target._overloadname != "default":
|
|
1600
|
+
op_overload = target._overloadname
|
|
1601
|
+
|
|
1602
|
+
def _get_empty_tensor_evalue() -> EValue:
|
|
1603
|
+
"""Constructs an EValue for an empty tensor."""
|
|
1604
|
+
return EValue(
|
|
1605
|
+
Tensor(
|
|
1606
|
+
scalar_type=ScalarType.BYTE,
|
|
1607
|
+
# The runtime currently only supports tensors with offset 0.
|
|
1608
|
+
storage_offset=0,
|
|
1609
|
+
sizes=[0],
|
|
1610
|
+
dim_order=[0],
|
|
1611
|
+
requires_grad=False,
|
|
1612
|
+
layout=0,
|
|
1613
|
+
data_buffer_idx=0,
|
|
1614
|
+
allocation_info=None,
|
|
1615
|
+
shape_dynamism=TensorShapeDynamism.STATIC,
|
|
1616
|
+
)
|
|
1617
|
+
)
|
|
1618
|
+
|
|
1619
|
+
op_index, operator = self._get_operator(name=op_name, overload=op_overload)
|
|
1620
|
+
|
|
1621
|
+
# Emit the args and kwargs in the order according to the function schema.
|
|
1622
|
+
kernel_args = []
|
|
1623
|
+
out_args = []
|
|
1624
|
+
for i, schema_arg in enumerate(target._schema.arguments):
|
|
1625
|
+
if schema_arg.name in kwargs:
|
|
1626
|
+
kernel_arg = kwargs[schema_arg.name]
|
|
1627
|
+
elif not schema_arg.kwarg_only and i < len(args):
|
|
1628
|
+
kernel_arg = args[i]
|
|
1629
|
+
else:
|
|
1630
|
+
# Emit default values
|
|
1631
|
+
kernel_arg = schema_arg.default_value
|
|
1632
|
+
|
|
1633
|
+
if kernel_arg is None and isinstance(schema_arg.type, torch.TensorType):
|
|
1634
|
+
kernel_arg = self._emit_evalue(_get_empty_tensor_evalue())
|
|
1635
|
+
|
|
1636
|
+
kernel_args.append(
|
|
1637
|
+
self._emit_argument(
|
|
1638
|
+
kernel_arg,
|
|
1639
|
+
schema_arg.type,
|
|
1640
|
+
immutable=not schema_arg.is_out and schema_arg.alias_info is None,
|
|
1641
|
+
).id
|
|
1642
|
+
)
|
|
1643
|
+
|
|
1644
|
+
if schema_arg.is_out:
|
|
1645
|
+
out_args.append((schema_arg.name, kernel_arg))
|
|
1646
|
+
|
|
1647
|
+
if is_out_variant(op_name, op_overload):
|
|
1648
|
+
ret = [val for _, val in out_args]
|
|
1649
|
+
ret = ret[0] if len(ret) == 1 else ret
|
|
1650
|
+
elif is_sym_op(target):
|
|
1651
|
+
assert (
|
|
1652
|
+
len(target._schema.returns) == 1
|
|
1653
|
+
), "Only returning a single Sym from symbolic ops is supported currently."
|
|
1654
|
+
assert type(target._schema.returns[0].type) in (
|
|
1655
|
+
torch.IntType,
|
|
1656
|
+
torch.FloatType,
|
|
1657
|
+
torch.BoolType,
|
|
1658
|
+
torch.NumberType,
|
|
1659
|
+
), f"Only symbolic ops that return a Int Bool Float are supported currently got {type(target._schema.returns[0].type)}."
|
|
1660
|
+
ret = self._get_sym_ret(target._schema.returns[0])
|
|
1661
|
+
if ret is None: # type(target._schema.returns[0].type) == torch.NumberType:
|
|
1662
|
+
# Cant definitively say what type this is, the runtime operator just overrides the EValue completely
|
|
1663
|
+
# though so we can just serialize whatever as a placeholder.
|
|
1664
|
+
ret = self._emit_evalue(EValue(Int(0)))
|
|
1665
|
+
else:
|
|
1666
|
+
ret = self._emit_spec(self.node.meta["spec"])
|
|
1667
|
+
|
|
1668
|
+
out_args = (
|
|
1669
|
+
self._emit_evalue(
|
|
1670
|
+
EValue(TensorList([cast(_AbstractValue, val).id for val in ret]))
|
|
1671
|
+
)
|
|
1672
|
+
if isinstance(ret, list)
|
|
1673
|
+
else ret
|
|
1674
|
+
)
|
|
1675
|
+
|
|
1676
|
+
for elem in pytree.tree_flatten(out_args)[0]:
|
|
1677
|
+
kernel_args.append(cast(_AbstractValue, elem).id)
|
|
1678
|
+
|
|
1679
|
+
self.chain.instructions.append(
|
|
1680
|
+
Instruction(KernelCall(op_index=op_index, args=kernel_args))
|
|
1681
|
+
)
|
|
1682
|
+
self._add_debug_handle(len(self.chain.instructions) - 1, target)
|
|
1683
|
+
|
|
1684
|
+
# Get the stacktrace if it exists for each instruction.
|
|
1685
|
+
if self.emitter_state.emit_stacktrace:
|
|
1686
|
+
stack_trace = self.node.meta["stack_trace"]
|
|
1687
|
+
chain_stacktrace = self.chain.stacktrace or []
|
|
1688
|
+
|
|
1689
|
+
chain_stacktrace.append(_stacktrace_to_framelist(stack_trace))
|
|
1690
|
+
self._internal_assert_emitter(
|
|
1691
|
+
len(chain_stacktrace) == len(self.chain.instructions),
|
|
1692
|
+
self.node,
|
|
1693
|
+
f"Each instruction should have corresponding stacktrace received {len(self.chain.instructions)} \
|
|
1694
|
+
instructions and {len(chain_stacktrace)} stacktraces",
|
|
1695
|
+
)
|
|
1696
|
+
self.chain.stacktrace = chain_stacktrace
|
|
1697
|
+
|
|
1698
|
+
return cast(_EmitterValue, ret)
|
|
1699
|
+
|
|
1700
|
+
def _emit_free(self, spec: TensorSpec) -> _AbstractValue:
|
|
1701
|
+
"""Emits a FreeCall instruction to release a given Unbounded Tensor's memory."""
|
|
1702
|
+
self.chain.instructions.append(
|
|
1703
|
+
Instruction(FreeCall(value_index=self.emitter_state.spec2id(spec)))
|
|
1704
|
+
)
|
|
1705
|
+
# The value is not used but the caller expects an AbstractValue returned.
|
|
1706
|
+
return _AbstractValue(None, None) # pyre-ignore
|
|
1707
|
+
|
|
1708
|
+
def _emit_prim_getters(self, prim_getters: Dict[str, Any]) -> List[ExecutionPlan]:
|
|
1709
|
+
"""
|
|
1710
|
+
Given a mapping of function names to return values, emit simple execution
|
|
1711
|
+
plans that just return these constant values.
|
|
1712
|
+
|
|
1713
|
+
Precondition: All the values are primitives (bool, float, int, str, enum)
|
|
1714
|
+
or structures (list, dict) of them.
|
|
1715
|
+
"""
|
|
1716
|
+
plans = []
|
|
1717
|
+
# flatten any structures
|
|
1718
|
+
for method, vals in prim_getters.items():
|
|
1719
|
+
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
|
|
1720
|
+
flattened_output, spec = ex_pytree.tree_flatten(vals)
|
|
1721
|
+
spec = spec.to_str()
|
|
1722
|
+
chain = Chain(
|
|
1723
|
+
inputs=[],
|
|
1724
|
+
outputs=[],
|
|
1725
|
+
instructions=[],
|
|
1726
|
+
stacktrace=None,
|
|
1727
|
+
)
|
|
1728
|
+
|
|
1729
|
+
# switch on type of prim
|
|
1730
|
+
values = []
|
|
1731
|
+
for val in flattened_output:
|
|
1732
|
+
if isinstance(val, float):
|
|
1733
|
+
values.append(EValue(Double(val)))
|
|
1734
|
+
|
|
1735
|
+
elif isinstance(val, bool):
|
|
1736
|
+
values.append(EValue(Bool(val)))
|
|
1737
|
+
|
|
1738
|
+
elif isinstance(val, int):
|
|
1739
|
+
values.append(EValue(Int(val)))
|
|
1740
|
+
|
|
1741
|
+
elif isinstance(val, str):
|
|
1742
|
+
values.append(EValue(String(val)))
|
|
1743
|
+
|
|
1744
|
+
elif isinstance(val, torch.dtype):
|
|
1745
|
+
values.append(EValue(Int(scalar_type_enum(val))))
|
|
1746
|
+
|
|
1747
|
+
elif isinstance(val, torch.layout):
|
|
1748
|
+
values.append(EValue(Int(layout_enum(val))))
|
|
1749
|
+
|
|
1750
|
+
elif isinstance(val, torch.Tensor):
|
|
1751
|
+
values.append(
|
|
1752
|
+
self._tensor_spec_to_evalue(
|
|
1753
|
+
TensorSpec.from_tensor(val, const=True)
|
|
1754
|
+
)
|
|
1755
|
+
)
|
|
1756
|
+
|
|
1757
|
+
else:
|
|
1758
|
+
raise ExportError(
|
|
1759
|
+
ExportErrorType.NOT_SUPPORTED,
|
|
1760
|
+
f"Error emitting {method} which returns a value of type {type(val)}. which is not a supported primitive",
|
|
1761
|
+
)
|
|
1762
|
+
|
|
1763
|
+
# add to plans
|
|
1764
|
+
plans.append(
|
|
1765
|
+
ExecutionPlan(
|
|
1766
|
+
name=method,
|
|
1767
|
+
values=values,
|
|
1768
|
+
inputs=[],
|
|
1769
|
+
outputs=list(range(0, len(values))),
|
|
1770
|
+
chains=[chain],
|
|
1771
|
+
operators=[],
|
|
1772
|
+
delegates=[],
|
|
1773
|
+
non_const_buffer_sizes=[0],
|
|
1774
|
+
container_meta_type=ContainerMetadata("", spec),
|
|
1775
|
+
)
|
|
1776
|
+
)
|
|
1777
|
+
return plans
|
|
1778
|
+
|
|
1779
|
+
def fetch_attr(self, target: _Target) -> _AbstractValue:
|
|
1780
|
+
"""Fetch weights and other module parameters. If the attribute is a tensor, emit it."""
|
|
1781
|
+
attr = super().fetch_attr(target) # pyre-fixme[6]
|
|
1782
|
+
|
|
1783
|
+
if isinstance(attr, torch.Tensor):
|
|
1784
|
+
return self._emit_evalue(
|
|
1785
|
+
self._tensor_spec_to_evalue(TensorSpec.from_tensor(attr, const=True))
|
|
1786
|
+
)
|
|
1787
|
+
|
|
1788
|
+
elif isinstance(attr, torch._C.ScriptObject):
|
|
1789
|
+
raise ExportError(
|
|
1790
|
+
ExportErrorType.NOT_SUPPORTED,
|
|
1791
|
+
f"Custom class {attr} is not supported in EXIR",
|
|
1792
|
+
)
|
|
1793
|
+
|
|
1794
|
+
else:
|
|
1795
|
+
return attr
|
|
1796
|
+
|
|
1797
|
+
def call_module( # pyre-fixme[14]
|
|
1798
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1799
|
+
) -> None:
|
|
1800
|
+
"""Unsupported in execution IR, so unhandled by the emitter."""
|
|
1801
|
+
raise InternalError(
|
|
1802
|
+
self._emit_node_specific_error(self.node, "call_module is not supported")
|
|
1803
|
+
)
|
|
1804
|
+
|
|
1805
|
+
def call_method( # pyre-fixme[14]
|
|
1806
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1807
|
+
) -> _EmitterValue:
|
|
1808
|
+
"""Unsupported in execution IR, so unhandled by the emitter."""
|
|
1809
|
+
raise InternalError(
|
|
1810
|
+
self._emit_node_specific_error(self.node, "call_method is not supported")
|
|
1811
|
+
)
|
|
1812
|
+
|
|
1813
|
+
def placeholder( # pyre-fixme[14]
|
|
1814
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1815
|
+
) -> _AbstractValue:
|
|
1816
|
+
"""Performs actions for the placeholder node of a graph module.
|
|
1817
|
+
|
|
1818
|
+
The placeholder node of the top level entry point is handled by TopLevelEmitter. This
|
|
1819
|
+
function only executes on control flow subgraphs. Takes the inputs of the subgraph that had
|
|
1820
|
+
not previously been emitted and emits them.
|
|
1821
|
+
"""
|
|
1822
|
+
# pyre-fixme[16]: `Optional` has no attribute `__getitem__`.
|
|
1823
|
+
value = self.binding_input_values[self.placeholder_count]
|
|
1824
|
+
# This indicates that the placeholder wasn't allocated an EValue id before this sub-emitter
|
|
1825
|
+
# was run, so we generate one now.
|
|
1826
|
+
if value == -1:
|
|
1827
|
+
value = self._emit_evalue(
|
|
1828
|
+
self._tensor_spec_to_evalue(self.node.meta["spec"])
|
|
1829
|
+
)
|
|
1830
|
+
# pyre-fixme[16]: `Optional` has no attribute `__getitem__`.
|
|
1831
|
+
self.binding_input_values[self.placeholder_count] = value
|
|
1832
|
+
self.placeholder_count += 1
|
|
1833
|
+
return value
|
|
1834
|
+
|
|
1835
|
+
def output( # pyre-fixme[14]
|
|
1836
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1837
|
+
) -> None:
|
|
1838
|
+
"""Performs actions for the output node of a graph module.
|
|
1839
|
+
|
|
1840
|
+
The output node of the top level entry point is handled by TopLevelEmitter. This function
|
|
1841
|
+
only executes on control flow subgraphs. Takes the outputs of the subgraph (if any) and
|
|
1842
|
+
inserts instructions to move them to the common output location between control flow
|
|
1843
|
+
branches.
|
|
1844
|
+
"""
|
|
1845
|
+
self.concrete_output_ids = list(pytree.tree_flatten(args[0])[0])
|
|
1846
|
+
binding_output_values = self.binding_output_values
|
|
1847
|
+
if binding_output_values is not None:
|
|
1848
|
+
binding_output_list, _ = pytree.tree_flatten(binding_output_values)
|
|
1849
|
+
|
|
1850
|
+
self._internal_assert_emitter(
|
|
1851
|
+
len(binding_output_list) == len(self.concrete_output_ids),
|
|
1852
|
+
self.node,
|
|
1853
|
+
"The number of binding output values should match the args to output",
|
|
1854
|
+
)
|
|
1855
|
+
|
|
1856
|
+
for move_from, move_to in zip(
|
|
1857
|
+
self.concrete_output_ids, binding_output_list
|
|
1858
|
+
):
|
|
1859
|
+
if move_from != move_to:
|
|
1860
|
+
instruction = Instruction(
|
|
1861
|
+
MoveCall(move_from=move_from.id, move_to=move_to.id)
|
|
1862
|
+
)
|
|
1863
|
+
self.chain.instructions.append(instruction)
|
|
1864
|
+
|
|
1865
|
+
def call_function( # pyre-fixme[14]
|
|
1866
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
1867
|
+
) -> _EmitterValue:
|
|
1868
|
+
"""Performs actions for the call_function node of a graph module.
|
|
1869
|
+
|
|
1870
|
+
Dispatches based on 'target' and emits the corresponding function. 'call_function' is a
|
|
1871
|
+
powerful node that contains many operations ranging from control_flow, to memory management,
|
|
1872
|
+
to delegate and operator calls.
|
|
1873
|
+
"""
|
|
1874
|
+
|
|
1875
|
+
# Delegate and operator calls are the only functions that should have a debug handle
|
|
1876
|
+
# associated with them. All the others such as memory.alloc, getitem should be ignored.
|
|
1877
|
+
# Default to none and let delegates and ops override.
|
|
1878
|
+
if target == operator.getitem:
|
|
1879
|
+
assert len(args) == 2
|
|
1880
|
+
head = typing.cast(Mapping[int, _EmitterValue], args[0])
|
|
1881
|
+
index = typing.cast(int, args[1])
|
|
1882
|
+
return head[index]
|
|
1883
|
+
|
|
1884
|
+
elif target == memory.alloc:
|
|
1885
|
+
assert len(args) == 1
|
|
1886
|
+
return self._emit_spec(self.node.meta["spec"])
|
|
1887
|
+
|
|
1888
|
+
elif target == memory.view:
|
|
1889
|
+
return self._emit_view(args)
|
|
1890
|
+
|
|
1891
|
+
elif target == memory.free:
|
|
1892
|
+
assert len(args) == 1
|
|
1893
|
+
# pyre-ignore
|
|
1894
|
+
return self._emit_free(args[0])
|
|
1895
|
+
|
|
1896
|
+
elif target in (
|
|
1897
|
+
torch.ops.higher_order.cond,
|
|
1898
|
+
torch.ops.higher_order.map_impl,
|
|
1899
|
+
torch.ops.higher_order.while_loop,
|
|
1900
|
+
torch.ops.higher_order.scan,
|
|
1901
|
+
):
|
|
1902
|
+
return self._emit_control_flow(target, args, kwargs)
|
|
1903
|
+
|
|
1904
|
+
elif target == executorch_call_delegate:
|
|
1905
|
+
lowered_module = args[0]
|
|
1906
|
+
assert is_lowered_module(lowered_module)
|
|
1907
|
+
v = self._emit_delegate(lowered_module, args[1:], kwargs)
|
|
1908
|
+
delegate_instruction_id = len(self.chain.instructions) - 1
|
|
1909
|
+
self._add_debug_handle(delegate_instruction_id, target, lowered_module)
|
|
1910
|
+
self._add_delegate_map(lowered_module, delegate_instruction_id)
|
|
1911
|
+
return v
|
|
1912
|
+
|
|
1913
|
+
elif isinstance(
|
|
1914
|
+
target, (torch._ops.OpOverload, EdgeOpOverload, BackendOpOverload)
|
|
1915
|
+
):
|
|
1916
|
+
return self._emit_operator(target, args, kwargs)
|
|
1917
|
+
|
|
1918
|
+
else:
|
|
1919
|
+
raise InternalError(
|
|
1920
|
+
self._emit_node_specific_error(
|
|
1921
|
+
self.node, f"invalid target for call_function {target}"
|
|
1922
|
+
)
|
|
1923
|
+
)
|
|
1924
|
+
|
|
1925
|
+
def run( # pyre-fixme[14]
|
|
1926
|
+
self,
|
|
1927
|
+
*args: _Argument,
|
|
1928
|
+
initial_env: Optional[Dict[torch.fx.Node, _Argument]] = None,
|
|
1929
|
+
) -> None:
|
|
1930
|
+
"""Traverses all nodes in the graph module and emits each one appropriately."""
|
|
1931
|
+
super().run(*args, initial_env, enable_io_processing=False)
|
|
1932
|
+
|
|
1933
|
+
def run_node(self, n: torch.fx.Node) -> None:
|
|
1934
|
+
"""Executes and emits the specified node.
|
|
1935
|
+
|
|
1936
|
+
For more context on what a node is and what execution means see
|
|
1937
|
+
https://pytorch.org/docs/stable/fx.html#torch.fx.Node
|
|
1938
|
+
"""
|
|
1939
|
+
self.node = n
|
|
1940
|
+
try:
|
|
1941
|
+
ret = super().run_node(n)
|
|
1942
|
+
except Exception as e:
|
|
1943
|
+
if isinstance(e, (InternalError, ExportError)):
|
|
1944
|
+
raise e
|
|
1945
|
+
else:
|
|
1946
|
+
raise InternalError(
|
|
1947
|
+
self._emit_node_specific_error(self.node, str(e))
|
|
1948
|
+
) from e
|
|
1949
|
+
return ret
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
class _TopLevelEmitter(_Emitter):
|
|
1953
|
+
"""An emitter that manages the root level operations within a graph module.
|
|
1954
|
+
|
|
1955
|
+
Exists as a separate class so that 'Emitter' can handle the special behavior of 'placeholder'
|
|
1956
|
+
and 'output' nodes in control flow submodules.
|
|
1957
|
+
"""
|
|
1958
|
+
|
|
1959
|
+
def __init__(
|
|
1960
|
+
self,
|
|
1961
|
+
name: str,
|
|
1962
|
+
exported_program: ExportedProgram,
|
|
1963
|
+
graph_module: torch.fx.GraphModule,
|
|
1964
|
+
program_state: _ProgramState,
|
|
1965
|
+
emitter_state: _EmitterState,
|
|
1966
|
+
) -> None:
|
|
1967
|
+
super().__init__(graph_module, emitter_state, program_state)
|
|
1968
|
+
self.name = name
|
|
1969
|
+
self.exported_program = exported_program
|
|
1970
|
+
|
|
1971
|
+
self.inputs: List[int] = []
|
|
1972
|
+
self.outputs: List[int] = []
|
|
1973
|
+
self.given_mutable_buffer_warning = False
|
|
1974
|
+
|
|
1975
|
+
def create_container_str(spec: Optional[pytree.TreeSpec]) -> str:
|
|
1976
|
+
if spec is None:
|
|
1977
|
+
return ""
|
|
1978
|
+
assert isinstance(spec, pytree.TreeSpec), type(spec)
|
|
1979
|
+
dummy_leaves = [0] * spec.num_leaves
|
|
1980
|
+
tree = torch.utils._pytree.tree_unflatten(dummy_leaves, spec)
|
|
1981
|
+
# pyre-fixme[16]: Module `pytree` has no attribute `tree_flatten`.
|
|
1982
|
+
_, tree = ex_pytree.tree_flatten(tree)
|
|
1983
|
+
return tree.to_str()
|
|
1984
|
+
|
|
1985
|
+
inp_container_str = create_container_str(exported_program.call_spec.in_spec)
|
|
1986
|
+
out_container_str = create_container_str(exported_program.call_spec.out_spec)
|
|
1987
|
+
|
|
1988
|
+
self.container_meta_type = ContainerMetadata(
|
|
1989
|
+
inp_container_str, out_container_str
|
|
1990
|
+
)
|
|
1991
|
+
|
|
1992
|
+
def _find_fqn_for_placeholder(
|
|
1993
|
+
self, target: _Target, spec: Any # pyre-ignore[2]
|
|
1994
|
+
) -> Tuple[Optional[str], bool]:
|
|
1995
|
+
# Find the fully qualified name
|
|
1996
|
+
fqn = None
|
|
1997
|
+
is_mutable_buffer = False
|
|
1998
|
+
if target in self.exported_program.graph_signature.inputs_to_parameters:
|
|
1999
|
+
fqn = self.exported_program.graph_signature.inputs_to_parameters[target]
|
|
2000
|
+
|
|
2001
|
+
elif target in self.exported_program.graph_signature.inputs_to_buffers:
|
|
2002
|
+
fqn = self.exported_program.graph_signature.inputs_to_buffers[target]
|
|
2003
|
+
|
|
2004
|
+
# if the buffer is mutated then record that
|
|
2005
|
+
if fqn in self.exported_program.graph_signature.buffers_to_mutate.values():
|
|
2006
|
+
is_mutable_buffer = True
|
|
2007
|
+
if not self.given_mutable_buffer_warning:
|
|
2008
|
+
warnings.warn(
|
|
2009
|
+
"Mutation on a buffer in the model is detected. ExecuTorch assumes "
|
|
2010
|
+
"buffers that are mutated in the graph have a meaningless initial state, "
|
|
2011
|
+
"only the shape and dtype will be serialized, unless a pass which sets "
|
|
2012
|
+
'meta["et_init_buffer"] to True such as InitializedMutableBufferPass is run.',
|
|
2013
|
+
UserWarning,
|
|
2014
|
+
stacklevel=1,
|
|
2015
|
+
)
|
|
2016
|
+
self.given_mutable_buffer_warning = True
|
|
2017
|
+
|
|
2018
|
+
elif (
|
|
2019
|
+
target
|
|
2020
|
+
in self.exported_program.graph_signature.inputs_to_lifted_tensor_constants
|
|
2021
|
+
):
|
|
2022
|
+
fqn = (
|
|
2023
|
+
self.exported_program.graph_signature.inputs_to_lifted_tensor_constants[
|
|
2024
|
+
target
|
|
2025
|
+
]
|
|
2026
|
+
)
|
|
2027
|
+
return fqn, is_mutable_buffer
|
|
2028
|
+
|
|
2029
|
+
def placeholder( # noqa: C901
|
|
2030
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
2031
|
+
) -> _AbstractValue:
|
|
2032
|
+
"""Emits the value within the placeholder node.
|
|
2033
|
+
|
|
2034
|
+
For more information on placeholder nodes see
|
|
2035
|
+
https://pytorch.org/docs/stable/fx.html#torch.fx.Graph.placeholder
|
|
2036
|
+
"""
|
|
2037
|
+
spec = self.node.meta["spec"]
|
|
2038
|
+
constant_tag = self.node.meta.get("constant_tag", None)
|
|
2039
|
+
initialize_buffer = self.node.meta.get("et_init_buffer", None)
|
|
2040
|
+
is_user_input = True
|
|
2041
|
+
|
|
2042
|
+
if isinstance(target, str) and isinstance(spec, TensorSpec):
|
|
2043
|
+
fqn, is_mutable_buffer = self._find_fqn_for_placeholder(target, spec)
|
|
2044
|
+
|
|
2045
|
+
def _is_buffer(node: Node, graph_signature: ExportGraphSignature) -> bool:
|
|
2046
|
+
"""
|
|
2047
|
+
Check if the node is buffer according to the provided graph signature.
|
|
2048
|
+
If it is one return its fqn as well
|
|
2049
|
+
"""
|
|
2050
|
+
if node.op == "placeholder":
|
|
2051
|
+
if isinstance(node.target, str):
|
|
2052
|
+
if node.target in graph_signature.inputs_to_buffers:
|
|
2053
|
+
return True
|
|
2054
|
+
return False
|
|
2055
|
+
|
|
2056
|
+
# If the spec does not appear in the mutable section of the graph signature it still might
|
|
2057
|
+
# overall be considered a mutable buffer if it has already been memory planned. This would
|
|
2058
|
+
# suggest that the same abstract buffer is mutable in another entry point so we should
|
|
2059
|
+
# compel it to be considered mutable in all entry points at emission just as the user did with
|
|
2060
|
+
# memory planning. A device resident constant is planned too, but
|
|
2061
|
+
# it is not mutable.
|
|
2062
|
+
is_mutable_buffer |= (
|
|
2063
|
+
_is_buffer(self.node, self.exported_program.graph_signature)
|
|
2064
|
+
and spec.mem_id is not None
|
|
2065
|
+
and spec.mem_offset is not None
|
|
2066
|
+
and not self.node.meta.get("device_resident_constant", False)
|
|
2067
|
+
)
|
|
2068
|
+
|
|
2069
|
+
# If the placeholder has a constant_tag, it is external to the PTE file
|
|
2070
|
+
# and requires a fqn and location=TensorDataLocation.EXTERNAL
|
|
2071
|
+
if constant_tag is not None:
|
|
2072
|
+
assert (
|
|
2073
|
+
fqn is not None
|
|
2074
|
+
), "constant tagged tensors require a fully qualified name"
|
|
2075
|
+
if spec.extra_tensor_info is None:
|
|
2076
|
+
spec.extra_tensor_info = ExtraTensorInfo(
|
|
2077
|
+
fully_qualified_name=fqn, location=TensorDataLocation.EXTERNAL
|
|
2078
|
+
)
|
|
2079
|
+
else:
|
|
2080
|
+
spec.extra_tensor_info.fully_qualified_name = fqn
|
|
2081
|
+
spec.extra_tensor_info.location = TensorDataLocation.EXTERNAL
|
|
2082
|
+
|
|
2083
|
+
if is_mutable_buffer:
|
|
2084
|
+
# Emit names if we are supposed to.
|
|
2085
|
+
if self.emitter_state.emit_mutable_buffer_names:
|
|
2086
|
+
if spec.extra_tensor_info is None:
|
|
2087
|
+
spec.extra_tensor_info = ExtraTensorInfo(
|
|
2088
|
+
fully_qualified_name=fqn,
|
|
2089
|
+
location=TensorDataLocation.SEGMENT,
|
|
2090
|
+
)
|
|
2091
|
+
else:
|
|
2092
|
+
spec.extra_tensor_info.fully_qualified_name = fqn
|
|
2093
|
+
# if We aren't emitting the name then it needs to be memory planned.
|
|
2094
|
+
elif spec.mem_id is None or spec.mem_offset is None:
|
|
2095
|
+
raise InternalError(
|
|
2096
|
+
self._emit_node_specific_error(
|
|
2097
|
+
self.node,
|
|
2098
|
+
# [2:] to remove the b_ prefix buffers get
|
|
2099
|
+
f'Mutable buffer "{target[2:]}" must have a memory id and offset if we are emitting it without a name. Please either memory plan your mutable buffers or call to_executorch with config=ExecutorchBackendConfig(emit_mutable_buffer_names=True)',
|
|
2100
|
+
)
|
|
2101
|
+
)
|
|
2102
|
+
|
|
2103
|
+
# From the fqn find the corresponding tensor
|
|
2104
|
+
real_tensor = None
|
|
2105
|
+
if fqn in self.exported_program.state_dict:
|
|
2106
|
+
real_tensor = self.exported_program.state_dict[fqn]
|
|
2107
|
+
is_user_input = False
|
|
2108
|
+
|
|
2109
|
+
elif fqn in self.exported_program.constants:
|
|
2110
|
+
real_tensor = self.exported_program.constants[fqn]
|
|
2111
|
+
is_user_input = False
|
|
2112
|
+
elif fqn is not None:
|
|
2113
|
+
buffers = self.exported_program.named_buffers()
|
|
2114
|
+
buf = next((x[1] for x in buffers if x[0] == fqn), None)
|
|
2115
|
+
if buf is not None:
|
|
2116
|
+
real_tensor = buf
|
|
2117
|
+
is_user_input = False
|
|
2118
|
+
else:
|
|
2119
|
+
raise InternalError(
|
|
2120
|
+
self._emit_node_specific_error(
|
|
2121
|
+
self.node,
|
|
2122
|
+
f"Could not find buffer with fqn {fqn} in state_dict or named_buffers",
|
|
2123
|
+
)
|
|
2124
|
+
)
|
|
2125
|
+
|
|
2126
|
+
# assign the storage of the placeholder spec to the storage of the real tensor if there is one
|
|
2127
|
+
if real_tensor is not None:
|
|
2128
|
+
# For tensors that are neither contiguous nor channels-last, convert to contiguous format.
|
|
2129
|
+
if not (
|
|
2130
|
+
real_tensor.is_contiguous()
|
|
2131
|
+
or real_tensor.is_contiguous(memory_format=torch.channels_last)
|
|
2132
|
+
):
|
|
2133
|
+
real_tensor = real_tensor.contiguous()
|
|
2134
|
+
|
|
2135
|
+
# Weights cannot be views during emission or serialization
|
|
2136
|
+
if real_tensor.nbytes != real_tensor.untyped_storage().nbytes():
|
|
2137
|
+
real_tensor = real_tensor.clone()
|
|
2138
|
+
|
|
2139
|
+
spec.storage = real_tensor.untyped_storage()
|
|
2140
|
+
spec.stride = real_tensor.stride()
|
|
2141
|
+
spec.dim_order = dim_order_from_stride(spec.stride, tuple(spec.shape))
|
|
2142
|
+
# User inputs and mutable buffers are not constants, other buffers or parameters are.
|
|
2143
|
+
if initialize_buffer and is_mutable_buffer:
|
|
2144
|
+
spec.const = True
|
|
2145
|
+
else:
|
|
2146
|
+
spec.const = not (is_user_input or is_mutable_buffer)
|
|
2147
|
+
|
|
2148
|
+
evalue = (
|
|
2149
|
+
self._tensor_spec_to_evalue(spec, constant_tag)
|
|
2150
|
+
if isinstance(spec, TensorSpec)
|
|
2151
|
+
else self._constant_to_evalue(spec, None)
|
|
2152
|
+
)
|
|
2153
|
+
value = self._emit_evalue(evalue)
|
|
2154
|
+
|
|
2155
|
+
# Populate spec2id_dict so downstream `_emit_spec` calls (e.g.,
|
|
2156
|
+
# for in-place op result FX nodes whose spec was aliased onto
|
|
2157
|
+
# this placeholder's spec by `alias_inplace_result_specs`) reuse
|
|
2158
|
+
# this placeholder's value_id rather than creating a new Value.
|
|
2159
|
+
if isinstance(spec, TensorSpec):
|
|
2160
|
+
self.emitter_state.spec2id_dict[spec] = value.id
|
|
2161
|
+
|
|
2162
|
+
# Only user inputs should remain as inputs.
|
|
2163
|
+
if is_user_input:
|
|
2164
|
+
self.inputs.append(value.id)
|
|
2165
|
+
|
|
2166
|
+
return value
|
|
2167
|
+
|
|
2168
|
+
def output(
|
|
2169
|
+
self, target: _Target, args: Tuple[_Argument, ...], kwargs: Dict[str, _Argument]
|
|
2170
|
+
) -> None:
|
|
2171
|
+
"""Records the ExecutionPlan's outputs based on the output node in the graph."""
|
|
2172
|
+
if isinstance(args[0], dict):
|
|
2173
|
+
args_tuple, _ = pytree.tree_flatten(args[0])
|
|
2174
|
+
else:
|
|
2175
|
+
args_tuple = typing.cast(Tuple[_AbstractValue, ...], args[0])
|
|
2176
|
+
if isinstance(args_tuple, _AbstractValue):
|
|
2177
|
+
self.outputs.append(args_tuple.id)
|
|
2178
|
+
else:
|
|
2179
|
+
for arg in args_tuple:
|
|
2180
|
+
if isinstance(arg, (int, float, bool, type(None))):
|
|
2181
|
+
arg = self._emit_evalue(self._constant_to_evalue(arg, None))
|
|
2182
|
+
elif isinstance(arg, str):
|
|
2183
|
+
# TODO(jackkhuu): T181599879 Add support for string outputs IFF compiler supports
|
|
2184
|
+
raise InternalError(
|
|
2185
|
+
self._emit_node_specific_error(
|
|
2186
|
+
self.node,
|
|
2187
|
+
f"Returning {arg} is not yet supported in the emitter.",
|
|
2188
|
+
)
|
|
2189
|
+
)
|
|
2190
|
+
else:
|
|
2191
|
+
# Every other output should already have its value emitted.
|
|
2192
|
+
# They should only be abstract IDs at this point.
|
|
2193
|
+
assert isinstance(arg, _AbstractValue)
|
|
2194
|
+
self.outputs.append(arg.id)
|
|
2195
|
+
|
|
2196
|
+
def plan(self) -> ExecutionPlan:
|
|
2197
|
+
"""Returns the execution plan emitted from this entry point."""
|
|
2198
|
+
return ExecutionPlan(
|
|
2199
|
+
name=self.name,
|
|
2200
|
+
values=self.emitter_state.values,
|
|
2201
|
+
inputs=self.inputs,
|
|
2202
|
+
outputs=self.outputs,
|
|
2203
|
+
chains=[self.chain],
|
|
2204
|
+
operators=self.emitter_state.operators,
|
|
2205
|
+
delegates=self.emitter_state.delegates,
|
|
2206
|
+
# non_const_buffer_sizes field is set by the memory_planning_pass. In case the field is
|
|
2207
|
+
# missing in scenarios like unit test that does not enable memory planning, assume an
|
|
2208
|
+
# empty list.
|
|
2209
|
+
non_const_buffer_sizes=typing.cast(
|
|
2210
|
+
List[int],
|
|
2211
|
+
# pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorB...
|
|
2212
|
+
self.module.meta["non_const_buffer_sizes"],
|
|
2213
|
+
),
|
|
2214
|
+
container_meta_type=self.container_meta_type,
|
|
2215
|
+
# non_const_buffer_device is set by apply_algo in memory_planning.py
|
|
2216
|
+
# when device tensors are present. None for CPU-only programs.
|
|
2217
|
+
non_const_buffer_device=self.module.meta.get(
|
|
2218
|
+
"non_const_buffer_device", None
|
|
2219
|
+
),
|
|
2220
|
+
)
|