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,4062 @@
|
|
|
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
|
+
# pyre-unsafe
|
|
8
|
+
|
|
9
|
+
import ctypes
|
|
10
|
+
import gc
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import select
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tempfile
|
|
17
|
+
import time
|
|
18
|
+
import unittest
|
|
19
|
+
import weakref
|
|
20
|
+
from io import StringIO
|
|
21
|
+
|
|
22
|
+
import numpy as np
|
|
23
|
+
import torch
|
|
24
|
+
|
|
25
|
+
from executorch.exir import ExecutorchBackendConfig, to_edge
|
|
26
|
+
from executorch.exir.backend.test.device_util import DeviceAwarePartitioner
|
|
27
|
+
from executorch.exir.passes import MemoryPlanningPass
|
|
28
|
+
from executorch.exir.schema import DeviceType
|
|
29
|
+
from executorch.extension.pybindings.test.make_test import (
|
|
30
|
+
create_program,
|
|
31
|
+
ModuleAdd,
|
|
32
|
+
ModuleAddBFloat16,
|
|
33
|
+
ModuleAddConstReturn,
|
|
34
|
+
ModuleAddEmpty,
|
|
35
|
+
ModuleAddHalf,
|
|
36
|
+
ModuleAddScalar,
|
|
37
|
+
ModuleAddSingleInput,
|
|
38
|
+
ModuleAddWithAttributes,
|
|
39
|
+
ModuleChannelsLast,
|
|
40
|
+
ModuleChannelsLastInDefaultOut,
|
|
41
|
+
ModuleLinear,
|
|
42
|
+
ModuleMulti,
|
|
43
|
+
)
|
|
44
|
+
from torch.export import export
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class DLPackOnly:
|
|
48
|
+
def __init__(self, array) -> None:
|
|
49
|
+
self.array = array
|
|
50
|
+
|
|
51
|
+
def __dlpack__(self, stream=None):
|
|
52
|
+
return self.array.__dlpack__(stream=stream)
|
|
53
|
+
|
|
54
|
+
def __dlpack_device__(self):
|
|
55
|
+
return self.array.__dlpack_device__()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def write_llm_tokenizer(directory: str) -> str:
|
|
59
|
+
"""Writes a tokenizer that the LLM runner loads without printing anything,
|
|
60
|
+
so that its only lines come through the runtime, outside any call of these
|
|
61
|
+
bindings, while it finds that the model next to it is missing."""
|
|
62
|
+
path = os.path.join(directory, "tokenizer.json")
|
|
63
|
+
with open(path, "w") as file:
|
|
64
|
+
json.dump(
|
|
65
|
+
{
|
|
66
|
+
"added_tokens": [],
|
|
67
|
+
"model": {"type": "BPE", "vocab": {"a": 0, "b": 1}, "merges": []},
|
|
68
|
+
},
|
|
69
|
+
file,
|
|
70
|
+
)
|
|
71
|
+
return path
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class PybindingsTest(unittest.TestCase):
|
|
75
|
+
def setUp(self):
|
|
76
|
+
# Will test both portable and aten
|
|
77
|
+
kernel_mode = None
|
|
78
|
+
try:
|
|
79
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
80
|
+
|
|
81
|
+
kernel_mode = "portable"
|
|
82
|
+
except Exception:
|
|
83
|
+
print("can't load portable lib")
|
|
84
|
+
|
|
85
|
+
if kernel_mode is None:
|
|
86
|
+
try:
|
|
87
|
+
from executorch.extension.pybindings import ( # noqa: F811
|
|
88
|
+
aten_lib as runtime,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
kernel_mode = "aten"
|
|
92
|
+
except Exception:
|
|
93
|
+
print("can't load aten lib")
|
|
94
|
+
|
|
95
|
+
assert kernel_mode is not None
|
|
96
|
+
# Only the portable build converts an incoming tensor, so a test for
|
|
97
|
+
# that conversion has to skip under the aten build.
|
|
98
|
+
self.kernel_mode = kernel_mode
|
|
99
|
+
self.load_fn = runtime._load_for_executorch_from_buffer
|
|
100
|
+
self.load_prog_fn = runtime._load_program_from_buffer
|
|
101
|
+
self.runtime = runtime
|
|
102
|
+
|
|
103
|
+
def test_e2e(self):
|
|
104
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
105
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
106
|
+
executorch_output = executorch_module.forward(inputs)[0]
|
|
107
|
+
expected = inputs[0] + inputs[1]
|
|
108
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
109
|
+
|
|
110
|
+
def test_method_load_error_preserves_runtime_code(self):
|
|
111
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
112
|
+
from executorch.exir.schema import (
|
|
113
|
+
BackendDelegate,
|
|
114
|
+
BackendDelegateDataReference,
|
|
115
|
+
BackendDelegateInlineData,
|
|
116
|
+
DataLocation,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
120
|
+
schema = exported_program.executorch_program
|
|
121
|
+
schema.execution_plan[0].delegates.append(
|
|
122
|
+
BackendDelegate(
|
|
123
|
+
id="MissingBackendForErrorTest",
|
|
124
|
+
processed=BackendDelegateDataReference(
|
|
125
|
+
location=DataLocation.INLINE,
|
|
126
|
+
index=len(schema.backend_delegate_data),
|
|
127
|
+
),
|
|
128
|
+
compile_specs=[],
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
schema.backend_delegate_data.append(BackendDelegateInlineData(data=b""))
|
|
132
|
+
data = bytes(serialize_pte_binary(PTEFile(schema)))
|
|
133
|
+
for protocol, values in (
|
|
134
|
+
("torch", inputs),
|
|
135
|
+
("numpy", [value.numpy() for value in inputs]),
|
|
136
|
+
("dlpack", [DLPackOnly(value.numpy()) for value in inputs]),
|
|
137
|
+
):
|
|
138
|
+
with self.subTest(protocol=protocol):
|
|
139
|
+
module = self.load_fn(data)
|
|
140
|
+
with self.assertRaisesRegex(
|
|
141
|
+
RuntimeError, "Failed to execute method forward, error: 0x20"
|
|
142
|
+
):
|
|
143
|
+
module.run_method("forward", values)
|
|
144
|
+
module = self.load_fn(data)
|
|
145
|
+
with self.assertRaisesRegex(
|
|
146
|
+
RuntimeError, "Failed to execute method forward, error: 0x20"
|
|
147
|
+
):
|
|
148
|
+
module.run_method("forward")
|
|
149
|
+
|
|
150
|
+
def test_numpy_buffer_inputs(self):
|
|
151
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
152
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
153
|
+
|
|
154
|
+
output = executorch_module.forward([value.numpy() for value in inputs])[0]
|
|
155
|
+
|
|
156
|
+
self.assertTrue(torch.allclose(output, inputs[0] + inputs[1]))
|
|
157
|
+
|
|
158
|
+
def test_numpy_float16_buffer_input(self):
|
|
159
|
+
exported_program, inputs = create_program(ModuleAddHalf())
|
|
160
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
161
|
+
|
|
162
|
+
output = executorch_module(inputs[0].numpy())[0]
|
|
163
|
+
|
|
164
|
+
self.assertTrue(torch.equal(output, inputs[0] + inputs[0]))
|
|
165
|
+
|
|
166
|
+
def test_buffer_input_does_not_import_torch(self):
|
|
167
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
168
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
169
|
+
torch_module = sys.modules.pop("torch")
|
|
170
|
+
try:
|
|
171
|
+
output = executorch_module(inputs[0].numpy())[0]
|
|
172
|
+
self.assertNotIn("torch", sys.modules)
|
|
173
|
+
finally:
|
|
174
|
+
sys.modules["torch"] = torch_module
|
|
175
|
+
|
|
176
|
+
self.assertTrue(torch.equal(output, inputs[0] + inputs[0]))
|
|
177
|
+
|
|
178
|
+
def test_tensor_output_import_policy(self):
|
|
179
|
+
if self.kernel_mode != "portable":
|
|
180
|
+
self.skipTest("only portable bindings configure Python tensor outputs")
|
|
181
|
+
program, _ = create_program(ModuleAddSingleInput())
|
|
182
|
+
script = """
|
|
183
|
+
import importlib
|
|
184
|
+
import importlib.abc
|
|
185
|
+
import os
|
|
186
|
+
import sys
|
|
187
|
+
from pathlib import Path
|
|
188
|
+
|
|
189
|
+
class BlockTorch(importlib.abc.MetaPathFinder):
|
|
190
|
+
def find_spec(self, fullname, path=None, target=None):
|
|
191
|
+
if fullname == "torch" or fullname.startswith("torch."):
|
|
192
|
+
raise ImportError("torch is unavailable")
|
|
193
|
+
|
|
194
|
+
entrypoint, native_name, policy, available, program_path, native_path = sys.argv[1:]
|
|
195
|
+
if sys.platform == "win32":
|
|
196
|
+
native_directory = Path(native_path).parent
|
|
197
|
+
os.add_dll_directory(str(native_directory))
|
|
198
|
+
library_directory = native_directory.parent.parent / "lib"
|
|
199
|
+
if library_directory.is_dir():
|
|
200
|
+
os.add_dll_directory(str(library_directory))
|
|
201
|
+
blocker = BlockTorch()
|
|
202
|
+
if available == "no":
|
|
203
|
+
sys.meta_path.insert(0, blocker)
|
|
204
|
+
try:
|
|
205
|
+
bindings = importlib.import_module(entrypoint)
|
|
206
|
+
except (ImportError, SystemError) as error:
|
|
207
|
+
# Built-in extension loaders may wrap initialization errors.
|
|
208
|
+
assert policy == "torch" and available == "no"
|
|
209
|
+
while error.__cause__ is not None:
|
|
210
|
+
error = error.__cause__
|
|
211
|
+
assert isinstance(error, ImportError)
|
|
212
|
+
assert "torch is unavailable" in str(error)
|
|
213
|
+
else:
|
|
214
|
+
assert policy != "torch" or available == "yes"
|
|
215
|
+
native = sys.modules[native_name]
|
|
216
|
+
expected = "torch" if policy != "executorch" and available == "yes" else "executorch"
|
|
217
|
+
assert native._tensor_output == expected
|
|
218
|
+
assert ("torch" in sys.modules) == (expected == "torch")
|
|
219
|
+
import numpy as np
|
|
220
|
+
program_data = Path(program_path).read_bytes()
|
|
221
|
+
module = bindings._load_for_executorch_from_buffer(program_data)
|
|
222
|
+
output = module(np.ones((2, 2), dtype=np.float32))[0]
|
|
223
|
+
if expected == "executorch":
|
|
224
|
+
assert isinstance(output, bindings.ExecuTorchResult)
|
|
225
|
+
np.testing.assert_array_equal(np.asarray(output), np.full((2, 2), 2.0))
|
|
226
|
+
if available == "no":
|
|
227
|
+
sys.meta_path.remove(blocker)
|
|
228
|
+
import torch
|
|
229
|
+
assert isinstance(module(torch.ones(2, 2))[0], bindings.ExecuTorchResult)
|
|
230
|
+
else:
|
|
231
|
+
import torch
|
|
232
|
+
assert isinstance(output, torch.Tensor)
|
|
233
|
+
torch.testing.assert_close(output, torch.full((2, 2), 2.0))
|
|
234
|
+
"""
|
|
235
|
+
native_name = self.load_fn.__module__
|
|
236
|
+
native_path = sys.modules[native_name].__spec__.origin
|
|
237
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
238
|
+
program_path = os.path.join(directory, "add.pte")
|
|
239
|
+
with open(program_path, "wb") as handle:
|
|
240
|
+
handle.write(program.buffer)
|
|
241
|
+
for entrypoint in dict.fromkeys((self.runtime.__name__, native_name)):
|
|
242
|
+
for policy in (None, "torch", "executorch"):
|
|
243
|
+
for available in ("yes", "no"):
|
|
244
|
+
with self.subTest(
|
|
245
|
+
entrypoint=entrypoint, policy=policy, available=available
|
|
246
|
+
):
|
|
247
|
+
environment = os.environ.copy()
|
|
248
|
+
environment.pop("EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT", None)
|
|
249
|
+
if policy is not None:
|
|
250
|
+
environment["EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT"] = (
|
|
251
|
+
policy
|
|
252
|
+
)
|
|
253
|
+
completed = subprocess.run(
|
|
254
|
+
[
|
|
255
|
+
sys.executable,
|
|
256
|
+
"-c",
|
|
257
|
+
script,
|
|
258
|
+
entrypoint,
|
|
259
|
+
native_name,
|
|
260
|
+
str(policy),
|
|
261
|
+
available,
|
|
262
|
+
program_path,
|
|
263
|
+
native_path,
|
|
264
|
+
],
|
|
265
|
+
env=environment,
|
|
266
|
+
capture_output=True,
|
|
267
|
+
text=True,
|
|
268
|
+
timeout=60,
|
|
269
|
+
)
|
|
270
|
+
self.assertEqual(
|
|
271
|
+
completed.returncode,
|
|
272
|
+
0,
|
|
273
|
+
completed.stdout + completed.stderr,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
def test_empty_numpy_buffer_input(self):
|
|
277
|
+
exported_program, inputs = create_program(ModuleAddEmpty())
|
|
278
|
+
array = np.zeros((3, 0), dtype=np.float32)
|
|
279
|
+
|
|
280
|
+
module = self.load_fn(exported_program.buffer)
|
|
281
|
+
self.assertTrue(torch.equal(module(array)[0], inputs[0] + inputs[0]))
|
|
282
|
+
|
|
283
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
284
|
+
self.assertTrue(torch.equal(method(array)[0], inputs[0] + inputs[0]))
|
|
285
|
+
|
|
286
|
+
def test_empty_torch_output_preserves_layout_and_device(self):
|
|
287
|
+
if self.kernel_mode != "portable":
|
|
288
|
+
self.skipTest("only portable bindings convert outputs through Python")
|
|
289
|
+
|
|
290
|
+
class Identity(torch.nn.Module):
|
|
291
|
+
def forward(self, x):
|
|
292
|
+
return x
|
|
293
|
+
|
|
294
|
+
input_tensor = torch.empty(0, 2, 3, 4).to(memory_format=torch.channels_last)
|
|
295
|
+
program = to_edge(export(Identity(), (input_tensor,))).to_executorch(
|
|
296
|
+
ExecutorchBackendConfig(
|
|
297
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
input_tensor = input_tensor.as_strided(input_tensor.shape, (1000, 1, 100, 2))
|
|
301
|
+
module = self.load_fn(program.buffer)
|
|
302
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
303
|
+
for executor in (module, method):
|
|
304
|
+
for clone_outputs in (True, False):
|
|
305
|
+
with self.subTest(executor=type(executor), clone=clone_outputs):
|
|
306
|
+
with torch.device("meta"):
|
|
307
|
+
output = executor(input_tensor, clone_outputs=clone_outputs)[0]
|
|
308
|
+
self.assertEqual(output.device, input_tensor.device)
|
|
309
|
+
self.assertEqual(output.stride(), (24, 1, 8, 2))
|
|
310
|
+
self.assertEqual(executor(output)[0].stride(), (24, 1, 8, 2))
|
|
311
|
+
|
|
312
|
+
def test_torch_inputs_are_safe_across_threads(self):
|
|
313
|
+
if self.kernel_mode != "portable":
|
|
314
|
+
self.skipTest("only portable bindings use the Python torch adapter")
|
|
315
|
+
|
|
316
|
+
script = """
|
|
317
|
+
import threading
|
|
318
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
319
|
+
|
|
320
|
+
import torch
|
|
321
|
+
from executorch.exir import to_edge
|
|
322
|
+
from executorch.extension.pybindings import portable_lib
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
class Add(torch.nn.Module):
|
|
326
|
+
def forward(self, x, y):
|
|
327
|
+
return x + y
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
inputs = (torch.ones(2, 2), torch.ones(2, 2))
|
|
331
|
+
program = to_edge(torch.export.export(Add(), inputs)).to_executorch()
|
|
332
|
+
data = program.buffer
|
|
333
|
+
loaded = portable_lib._load_program_from_buffer(data)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
locks = {}
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def run(executor, separate_calls, locked=True):
|
|
340
|
+
for _ in range(300):
|
|
341
|
+
inputs = [torch.ones(2, 2), torch.ones(2, 2)]
|
|
342
|
+
if separate_calls and locked:
|
|
343
|
+
# Separate calls on a shared method need the caller's lock, or
|
|
344
|
+
# another thread's set_inputs() lands between them.
|
|
345
|
+
with locks.setdefault(id(executor), threading.Lock()):
|
|
346
|
+
executor.set_inputs(inputs)
|
|
347
|
+
executor.execute()
|
|
348
|
+
outputs = executor.get_outputs()
|
|
349
|
+
elif separate_calls:
|
|
350
|
+
# Without the lock, another thread's set_inputs() may hide the
|
|
351
|
+
# outputs, which must raise rather than crash or return garbage.
|
|
352
|
+
try:
|
|
353
|
+
executor.set_inputs(inputs)
|
|
354
|
+
executor.execute()
|
|
355
|
+
outputs = executor.get_outputs()
|
|
356
|
+
except RuntimeError as error:
|
|
357
|
+
assert "no outputs" in str(error), error
|
|
358
|
+
continue
|
|
359
|
+
else:
|
|
360
|
+
outputs = executor(inputs)
|
|
361
|
+
output = outputs[0]
|
|
362
|
+
if not isinstance(output, torch.Tensor):
|
|
363
|
+
output = torch.from_numpy(output.__array__())
|
|
364
|
+
torch.testing.assert_close(output, inputs[0] + inputs[1])
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
shared_method = loaded.load_method("forward")
|
|
368
|
+
shared_module = portable_lib._load_for_executorch_from_buffer(data)
|
|
369
|
+
for executors, separate_calls, locked in (
|
|
370
|
+
([loaded.load_method("forward") for _ in range(8)], True, True),
|
|
371
|
+
([shared_method] * 8, True, True),
|
|
372
|
+
([shared_method] * 8, True, False),
|
|
373
|
+
([shared_method] * 8, False, True),
|
|
374
|
+
([shared_module] * 8, False, True),
|
|
375
|
+
):
|
|
376
|
+
with ThreadPoolExecutor(max_workers=8) as pool:
|
|
377
|
+
futures = [
|
|
378
|
+
pool.submit(run, executor, separate_calls, locked)
|
|
379
|
+
for executor in executors
|
|
380
|
+
]
|
|
381
|
+
for future in futures:
|
|
382
|
+
future.result()
|
|
383
|
+
print("all calls finished")
|
|
384
|
+
"""
|
|
385
|
+
completed = subprocess.run(
|
|
386
|
+
[sys.executable, "-c", script],
|
|
387
|
+
capture_output=True,
|
|
388
|
+
text=True,
|
|
389
|
+
timeout=60,
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
self.assertEqual(
|
|
393
|
+
completed.returncode,
|
|
394
|
+
0,
|
|
395
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
396
|
+
)
|
|
397
|
+
self.assertIn("all calls finished", completed.stdout)
|
|
398
|
+
|
|
399
|
+
def test_backend_logs_do_not_deadlock_other_threads(self):
|
|
400
|
+
if self.kernel_mode != "portable":
|
|
401
|
+
self.skipTest("the script below uses the portable bindings")
|
|
402
|
+
if "XnnpackBackend" not in self.runtime._get_registered_backend_names():
|
|
403
|
+
self.skipTest("needs the XNNPACK backend")
|
|
404
|
+
|
|
405
|
+
script = """
|
|
406
|
+
import os
|
|
407
|
+
import sys
|
|
408
|
+
import threading
|
|
409
|
+
import time
|
|
410
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
411
|
+
|
|
412
|
+
import torch
|
|
413
|
+
from executorch.backends.xnnpack.partition.xnnpack_partitioner import (
|
|
414
|
+
XnnpackPartitioner,
|
|
415
|
+
)
|
|
416
|
+
from executorch.exir import to_edge_transform_and_lower
|
|
417
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
418
|
+
from executorch.exir.schema import (
|
|
419
|
+
BackendDelegateDataReference,
|
|
420
|
+
BackendDelegateInlineData,
|
|
421
|
+
DataLocation,
|
|
422
|
+
)
|
|
423
|
+
from executorch.extension.pybindings import portable_lib
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
class Add(torch.nn.Module):
|
|
427
|
+
def forward(self, x, y):
|
|
428
|
+
return x + y
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
inputs = [torch.ones(2, 2), torch.ones(2, 2)]
|
|
432
|
+
exported = torch.export.export(Add(), tuple(inputs))
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def broken_program(methods):
|
|
436
|
+
# XNNPACK logs a broken payload while it holds its workspace lock, which
|
|
437
|
+
# the global sharing mode shares between all methods.
|
|
438
|
+
schema = to_edge_transform_and_lower(
|
|
439
|
+
methods, partitioner=[XnnpackPartitioner()]
|
|
440
|
+
).to_executorch().executorch_program
|
|
441
|
+
schema.execution_plan[0].delegates[0].processed = BackendDelegateDataReference(
|
|
442
|
+
location=DataLocation.INLINE, index=len(schema.backend_delegate_data)
|
|
443
|
+
)
|
|
444
|
+
schema.backend_delegate_data.append(BackendDelegateInlineData(data=b"\\x01" * 64))
|
|
445
|
+
return bytes(serialize_pte_binary(PTEFile(schema)))
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
data = to_edge_transform_and_lower(
|
|
449
|
+
exported, partitioner=[XnnpackPartitioner()]
|
|
450
|
+
).to_executorch().buffer
|
|
451
|
+
if sys.argv[1] == "LLM runner":
|
|
452
|
+
try:
|
|
453
|
+
from executorch.extension.llm.runner import TextLLMRunner
|
|
454
|
+
except (ImportError, RuntimeError):
|
|
455
|
+
# The package raises RuntimeError when its extension is not built.
|
|
456
|
+
print("no LLM runner")
|
|
457
|
+
sys.exit()
|
|
458
|
+
# The LLM runner reads this method as it starts, outside any call of these
|
|
459
|
+
# bindings, on a thread that holds the GIL.
|
|
460
|
+
model = os.path.join(os.path.dirname(sys.argv[2]), "broken.pte")
|
|
461
|
+
with open(model, "wb") as file:
|
|
462
|
+
file.write(broken_program({"get_max_seq_len": exported}))
|
|
463
|
+
else:
|
|
464
|
+
broken = portable_lib._load_program_from_buffer(broken_program(exported))
|
|
465
|
+
portable_lib._set_option("XnnpackBackend", {"workspace_sharing_mode": 2})
|
|
466
|
+
method = portable_lib._load_program_from_buffer(data).load_method("forward")
|
|
467
|
+
|
|
468
|
+
running = threading.Event()
|
|
469
|
+
done = threading.Event()
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def run():
|
|
473
|
+
while not done.is_set():
|
|
474
|
+
method(inputs)
|
|
475
|
+
running.set()
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
class SlowStderr:
|
|
479
|
+
# A real write releases the GIL for its system call. Keep that window open
|
|
480
|
+
# so the other thread surely runs inside it.
|
|
481
|
+
def write(self, text):
|
|
482
|
+
time.sleep(0.5)
|
|
483
|
+
return len(text)
|
|
484
|
+
|
|
485
|
+
def flush(self):
|
|
486
|
+
pass
|
|
487
|
+
|
|
488
|
+
def fileno(self):
|
|
489
|
+
return 2
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
message = ""
|
|
493
|
+
process_stderr = sys.__stderr__
|
|
494
|
+
with ThreadPoolExecutor(max_workers=1) as pool:
|
|
495
|
+
worker = pool.submit(run)
|
|
496
|
+
while not running.wait(timeout=0.1):
|
|
497
|
+
if worker.done():
|
|
498
|
+
worker.result()
|
|
499
|
+
sys.stderr = SlowStderr()
|
|
500
|
+
if sys.argv[1] == "process":
|
|
501
|
+
# Stands in for the stream Python opened on fd 2, the default case.
|
|
502
|
+
sys.__stderr__ = sys.stderr
|
|
503
|
+
try:
|
|
504
|
+
if sys.argv[1] == "LLM runner":
|
|
505
|
+
TextLLMRunner(model, sys.argv[2])
|
|
506
|
+
else:
|
|
507
|
+
broken.load_method("forward")
|
|
508
|
+
except RuntimeError as error:
|
|
509
|
+
message = str(error)
|
|
510
|
+
finally:
|
|
511
|
+
sys.stderr = sys.__stderr__ = process_stderr
|
|
512
|
+
done.set()
|
|
513
|
+
worker.result()
|
|
514
|
+
# XNNPACK logged this while it held its workspace lock.
|
|
515
|
+
assert sys.argv[1] == "LLM runner" or "XNNCompiler::compileModel failed" in message, message
|
|
516
|
+
print("no deadlock")
|
|
517
|
+
"""
|
|
518
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
519
|
+
tokenizer = write_llm_tokenizer(directory)
|
|
520
|
+
for mode in ("replaced", "process", "LLM runner"):
|
|
521
|
+
completed = subprocess.run(
|
|
522
|
+
[sys.executable, "-c", script, mode, tokenizer],
|
|
523
|
+
capture_output=True,
|
|
524
|
+
text=True,
|
|
525
|
+
timeout=120,
|
|
526
|
+
)
|
|
527
|
+
self.assertEqual(
|
|
528
|
+
completed.returncode,
|
|
529
|
+
0,
|
|
530
|
+
f"{mode}:\nstdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
531
|
+
)
|
|
532
|
+
if "no LLM runner" not in completed.stdout:
|
|
533
|
+
self.assertIn("no deadlock", completed.stdout)
|
|
534
|
+
|
|
535
|
+
def test_daemon_threads_that_log_do_not_crash_at_exit(self):
|
|
536
|
+
if self.kernel_mode != "portable":
|
|
537
|
+
self.skipTest("the script below uses the portable bindings")
|
|
538
|
+
if not sys.platform.startswith("linux") or sys.version_info >= (3, 13, 8):
|
|
539
|
+
self.skipTest("the crash needs Linux and Python before 3.13.8")
|
|
540
|
+
|
|
541
|
+
script = """
|
|
542
|
+
import atexit
|
|
543
|
+
import os
|
|
544
|
+
import sys
|
|
545
|
+
import threading
|
|
546
|
+
import time
|
|
547
|
+
|
|
548
|
+
# Registered before the import, so it runs after the bindings' own exit hook,
|
|
549
|
+
# and the daemon threads log while it sleeps.
|
|
550
|
+
atexit.register(time.sleep, 0.1)
|
|
551
|
+
|
|
552
|
+
from executorch.extension.pybindings import portable_lib
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
# The daemon threads below. Python calls any thread it did not start a daemon.
|
|
556
|
+
spinners = set()
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
class Sink:
|
|
560
|
+
daemon_writes = 0
|
|
561
|
+
text = []
|
|
562
|
+
|
|
563
|
+
def write(self, text):
|
|
564
|
+
if threading.get_ident() in spinners:
|
|
565
|
+
Sink.daemon_writes += 1
|
|
566
|
+
Sink.text.append(text)
|
|
567
|
+
return len(text)
|
|
568
|
+
|
|
569
|
+
def flush(self):
|
|
570
|
+
pass
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def spin():
|
|
574
|
+
spinners.add(threading.get_ident())
|
|
575
|
+
while True:
|
|
576
|
+
try:
|
|
577
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
578
|
+
except RuntimeError:
|
|
579
|
+
pass
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
if "full" in sys.argv[1]:
|
|
583
|
+
# Nobody reads this pipe, so the lines that find it full are dropped.
|
|
584
|
+
read_end, write_end = os.pipe()
|
|
585
|
+
os.dup2(write_end, 2)
|
|
586
|
+
os.set_blocking(2, False)
|
|
587
|
+
try:
|
|
588
|
+
while True:
|
|
589
|
+
os.write(2, b"x" * 4096)
|
|
590
|
+
except BlockingIOError:
|
|
591
|
+
pass
|
|
592
|
+
os.set_blocking(2, True)
|
|
593
|
+
if "replaced" in sys.argv[1]:
|
|
594
|
+
sys.stderr = Sink()
|
|
595
|
+
for _ in range(2):
|
|
596
|
+
threading.Thread(target=spin, daemon=True).start()
|
|
597
|
+
time.sleep(0.3)
|
|
598
|
+
print("writes from daemon threads:", Sink.daemon_writes)
|
|
599
|
+
print("lines through Python:", "".join(Sink.text).count("Program identifier"))
|
|
600
|
+
"""
|
|
601
|
+
for mode in ("replaced", "full", "full and replaced"):
|
|
602
|
+
completed = subprocess.run(
|
|
603
|
+
[sys.executable, "-c", script, mode],
|
|
604
|
+
capture_output=True,
|
|
605
|
+
text=True,
|
|
606
|
+
timeout=120,
|
|
607
|
+
)
|
|
608
|
+
self.assertEqual(
|
|
609
|
+
completed.returncode, 0, f"{mode}: {completed.stderr[-2000:]}"
|
|
610
|
+
)
|
|
611
|
+
self.assertIn("writes from daemon threads: 0", completed.stdout)
|
|
612
|
+
if "replaced" in mode:
|
|
613
|
+
# Another thread wrote them, as a notebook shows only Python's
|
|
614
|
+
# stderr.
|
|
615
|
+
self.assertNotIn("lines through Python: 0", completed.stdout)
|
|
616
|
+
if mode == "replaced":
|
|
617
|
+
# The lines logged after the bindings' exit hook go to fd 2.
|
|
618
|
+
self.assertIn("Program identifier", completed.stderr)
|
|
619
|
+
|
|
620
|
+
def test_runtime_logs_outside_a_call_reach_sys_stderr(self):
|
|
621
|
+
if self.kernel_mode != "portable":
|
|
622
|
+
self.skipTest("the script below uses the portable bindings")
|
|
623
|
+
|
|
624
|
+
script = """
|
|
625
|
+
import contextlib
|
|
626
|
+
import io
|
|
627
|
+
import os
|
|
628
|
+
import sys
|
|
629
|
+
import threading
|
|
630
|
+
import time
|
|
631
|
+
|
|
632
|
+
captured = io.StringIO()
|
|
633
|
+
if sys.argv[1] == "replaced before import":
|
|
634
|
+
# As in a notebook, which replaces sys.stderr before any import.
|
|
635
|
+
sys.stderr = captured
|
|
636
|
+
from executorch.extension.pybindings import portable_lib
|
|
637
|
+
|
|
638
|
+
try:
|
|
639
|
+
from executorch.extension.llm.runner import TextLLMRunner
|
|
640
|
+
except (ImportError, RuntimeError):
|
|
641
|
+
# The package raises RuntimeError when its extension is not built.
|
|
642
|
+
print("no LLM runner")
|
|
643
|
+
sys.exit()
|
|
644
|
+
missing_program = os.path.join(os.path.dirname(sys.argv[2]), "missing.pte")
|
|
645
|
+
|
|
646
|
+
if sys.argv[1] == "replaced, another thread":
|
|
647
|
+
sys.stderr = captured
|
|
648
|
+
|
|
649
|
+
def log_twice():
|
|
650
|
+
try:
|
|
651
|
+
TextLLMRunner(missing_program, sys.argv[2])
|
|
652
|
+
except RuntimeError:
|
|
653
|
+
pass
|
|
654
|
+
try:
|
|
655
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
656
|
+
except RuntimeError:
|
|
657
|
+
pass
|
|
658
|
+
|
|
659
|
+
worker = threading.Thread(target=log_twice)
|
|
660
|
+
worker.start()
|
|
661
|
+
worker.join()
|
|
662
|
+
# A thread of the bindings writes the LLM runner's lines a moment later, and
|
|
663
|
+
# the call's line must follow them.
|
|
664
|
+
deadline = time.monotonic() + 10
|
|
665
|
+
while (
|
|
666
|
+
"Program identifier" not in captured.getvalue()
|
|
667
|
+
and time.monotonic() < deadline
|
|
668
|
+
):
|
|
669
|
+
time.sleep(0.01)
|
|
670
|
+
sys.stderr = sys.__stderr__
|
|
671
|
+
text = captured.getvalue()
|
|
672
|
+
first = text.find("[llm_runner_helper.cpp:")
|
|
673
|
+
print("in order:", 0 <= first < text.find("Program identifier"))
|
|
674
|
+
sys.exit()
|
|
675
|
+
|
|
676
|
+
if sys.argv[1] == "replaced, a call after a failed load":
|
|
677
|
+
in_order = True
|
|
678
|
+
# The first round comes out in order even without the wait, so it repeats.
|
|
679
|
+
for _ in range(5):
|
|
680
|
+
captured = io.StringIO()
|
|
681
|
+
sys.stderr = captured
|
|
682
|
+
try:
|
|
683
|
+
TextLLMRunner(missing_program, sys.argv[2])
|
|
684
|
+
except RuntimeError:
|
|
685
|
+
# A call that raised runs no pending call before the next call, yet
|
|
686
|
+
# this call's line must come after the runner's lines.
|
|
687
|
+
try:
|
|
688
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
689
|
+
except RuntimeError:
|
|
690
|
+
pass
|
|
691
|
+
sys.stderr = sys.__stderr__
|
|
692
|
+
text = captured.getvalue()
|
|
693
|
+
first = text.find("[llm_runner_helper.cpp:")
|
|
694
|
+
in_order = in_order and 0 <= first < text.find("Program identifier")
|
|
695
|
+
print("in order:", in_order)
|
|
696
|
+
sys.exit()
|
|
697
|
+
|
|
698
|
+
with (
|
|
699
|
+
contextlib.redirect_stderr(captured)
|
|
700
|
+
if sys.argv[1] == "replaced after import"
|
|
701
|
+
else contextlib.nullcontext()
|
|
702
|
+
):
|
|
703
|
+
try:
|
|
704
|
+
TextLLMRunner(missing_program, sys.argv[2])
|
|
705
|
+
except RuntimeError:
|
|
706
|
+
if sys.argv[1] == "process stderr":
|
|
707
|
+
# Ends the process before Python could write lines that waited.
|
|
708
|
+
os._exit(0)
|
|
709
|
+
# Python's main thread writes the lines it logged before its next bytecode,
|
|
710
|
+
# so they reach a redirect that ends right after the call.
|
|
711
|
+
sys.stderr = sys.__stderr__
|
|
712
|
+
print("lines through Python:", captured.getvalue().count("[llm_runner_helper.cpp:"))
|
|
713
|
+
"""
|
|
714
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
715
|
+
tokenizer = write_llm_tokenizer(directory)
|
|
716
|
+
for mode in (
|
|
717
|
+
"replaced before import",
|
|
718
|
+
"replaced after import",
|
|
719
|
+
"replaced, another thread",
|
|
720
|
+
"replaced, a call after a failed load",
|
|
721
|
+
"process stderr",
|
|
722
|
+
):
|
|
723
|
+
completed = subprocess.run(
|
|
724
|
+
[sys.executable, "-c", script, mode, tokenizer],
|
|
725
|
+
capture_output=True,
|
|
726
|
+
text=True,
|
|
727
|
+
timeout=120,
|
|
728
|
+
)
|
|
729
|
+
self.assertEqual(
|
|
730
|
+
completed.returncode, 0, f"{mode}: {completed.stderr[-2000:]}"
|
|
731
|
+
)
|
|
732
|
+
if "no LLM runner" in completed.stdout:
|
|
733
|
+
self.skipTest("the LLM runner bindings are not built")
|
|
734
|
+
if mode == "process stderr":
|
|
735
|
+
self.assertIn("[llm_runner_helper.cpp:", completed.stderr)
|
|
736
|
+
elif mode.startswith("replaced, a"):
|
|
737
|
+
self.assertIn("in order: True", completed.stdout, mode)
|
|
738
|
+
else:
|
|
739
|
+
self.assertIn("lines through Python:", completed.stdout, mode)
|
|
740
|
+
self.assertNotIn("lines through Python: 0", completed.stdout, mode)
|
|
741
|
+
|
|
742
|
+
def test_runtime_logs_when_writing_to_stderr_fails(self):
|
|
743
|
+
if self.kernel_mode != "portable":
|
|
744
|
+
self.skipTest("the script below uses the portable bindings")
|
|
745
|
+
|
|
746
|
+
script = """
|
|
747
|
+
import signal
|
|
748
|
+
import sys
|
|
749
|
+
|
|
750
|
+
from executorch.extension.pybindings import portable_lib
|
|
751
|
+
|
|
752
|
+
# Python installs no SIGINT handler when SIGINT starts ignored, as in a
|
|
753
|
+
# background job, and then a Ctrl-C cannot be raised again.
|
|
754
|
+
signal.signal(signal.SIGINT, signal.default_int_handler)
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
class FailingStderr:
|
|
758
|
+
def __init__(self, error):
|
|
759
|
+
self.error = error
|
|
760
|
+
|
|
761
|
+
def write(self, text):
|
|
762
|
+
raise self.error
|
|
763
|
+
|
|
764
|
+
def flush(self):
|
|
765
|
+
pass
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def load_broken_program():
|
|
769
|
+
try:
|
|
770
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
771
|
+
except RuntimeError:
|
|
772
|
+
pass
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
# A call made while sys.stderr is the process's own goes first, so that
|
|
776
|
+
# replacing sys.stderr afterwards must still be noticed.
|
|
777
|
+
load_broken_program()
|
|
778
|
+
|
|
779
|
+
# A write that fails sends the lines to the process's stderr instead.
|
|
780
|
+
sys.stderr = FailingStderr(ValueError("closed"))
|
|
781
|
+
try:
|
|
782
|
+
load_broken_program()
|
|
783
|
+
finally:
|
|
784
|
+
sys.stderr = sys.__stderr__
|
|
785
|
+
|
|
786
|
+
# An interrupt raised in the write still reaches the caller.
|
|
787
|
+
interrupted = False
|
|
788
|
+
sys.stderr = FailingStderr(KeyboardInterrupt())
|
|
789
|
+
try:
|
|
790
|
+
load_broken_program()
|
|
791
|
+
for _ in range(1000):
|
|
792
|
+
pass
|
|
793
|
+
except KeyboardInterrupt:
|
|
794
|
+
interrupted = True
|
|
795
|
+
finally:
|
|
796
|
+
sys.stderr = sys.__stderr__
|
|
797
|
+
assert interrupted
|
|
798
|
+
print("done")
|
|
799
|
+
"""
|
|
800
|
+
completed = subprocess.run(
|
|
801
|
+
[sys.executable, "-c", script],
|
|
802
|
+
capture_output=True,
|
|
803
|
+
text=True,
|
|
804
|
+
timeout=120,
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
self.assertEqual(
|
|
808
|
+
completed.returncode,
|
|
809
|
+
0,
|
|
810
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
811
|
+
)
|
|
812
|
+
self.assertIn("done", completed.stdout)
|
|
813
|
+
# The first load writes straight to the process's stderr. Neither
|
|
814
|
+
# write showed the other loads' lines, so they reach it too.
|
|
815
|
+
self.assertEqual(
|
|
816
|
+
completed.stderr.count("Program identifier 'xxxx'"), 3, completed.stderr
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
def test_fatal_runtime_log_reaches_process_stderr(self):
|
|
820
|
+
if self.kernel_mode != "portable":
|
|
821
|
+
self.skipTest("the script below uses the portable bindings")
|
|
822
|
+
if sys.platform == "win32":
|
|
823
|
+
self.skipTest("an abort can start Windows Error Reporting")
|
|
824
|
+
|
|
825
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
826
|
+
script = """
|
|
827
|
+
import io
|
|
828
|
+
import sys
|
|
829
|
+
|
|
830
|
+
import torch
|
|
831
|
+
from executorch.extension.pybindings import portable_lib
|
|
832
|
+
|
|
833
|
+
# Logging the first output to a debug buffer this small fails, and the runtime
|
|
834
|
+
# reports that with a fatal line before it aborts.
|
|
835
|
+
module = portable_lib._load_for_executorch(
|
|
836
|
+
sys.argv[1], enable_etdump=True, debug_buffer_size=8
|
|
837
|
+
)
|
|
838
|
+
sys.stderr = io.StringIO()
|
|
839
|
+
module.forward([torch.ones(2, 2)])
|
|
840
|
+
"""
|
|
841
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
842
|
+
path = os.path.join(directory, "add.pte")
|
|
843
|
+
with open(path, "wb") as file:
|
|
844
|
+
file.write(exported_program.buffer)
|
|
845
|
+
completed = subprocess.run(
|
|
846
|
+
[sys.executable, "-c", script, path],
|
|
847
|
+
capture_output=True,
|
|
848
|
+
text=True,
|
|
849
|
+
timeout=120,
|
|
850
|
+
)
|
|
851
|
+
|
|
852
|
+
self.assertNotEqual(completed.returncode, 0, completed.stderr)
|
|
853
|
+
# The abort skips the end of the call, where kept lines go to the
|
|
854
|
+
# replaced sys.stderr, so the fatal line went out at once, after the
|
|
855
|
+
# line the call kept before it.
|
|
856
|
+
kept = completed.stderr.find("Ran out of space to store intermediate outputs")
|
|
857
|
+
fatal = completed.stderr.find("failed to write tensor to debug buffer")
|
|
858
|
+
self.assertNotEqual(kept, -1, completed.stderr)
|
|
859
|
+
self.assertGreater(fatal, kept, completed.stderr)
|
|
860
|
+
|
|
861
|
+
def test_runtime_logs_reach_process_stderr_at_once(self):
|
|
862
|
+
if self.kernel_mode != "portable":
|
|
863
|
+
self.skipTest("the script below uses the portable bindings")
|
|
864
|
+
if sys.platform == "win32":
|
|
865
|
+
self.skipTest("uses a pseudo-terminal")
|
|
866
|
+
|
|
867
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
868
|
+
script = """
|
|
869
|
+
import os
|
|
870
|
+
import sys
|
|
871
|
+
|
|
872
|
+
import numpy as np
|
|
873
|
+
from executorch.extension.pybindings import portable_lib
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
class DiesDuringTheCall:
|
|
877
|
+
# Converting this input fills the terminal, logs from inside the call, and
|
|
878
|
+
# ends the process before the call returns.
|
|
879
|
+
def __dlpack__(self, stream=None):
|
|
880
|
+
os.set_blocking(2, False)
|
|
881
|
+
try:
|
|
882
|
+
while True:
|
|
883
|
+
os.write(2, b"." * 64)
|
|
884
|
+
except BlockingIOError:
|
|
885
|
+
pass
|
|
886
|
+
os.set_blocking(2, True)
|
|
887
|
+
print("filled", flush=True)
|
|
888
|
+
try:
|
|
889
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
890
|
+
except RuntimeError:
|
|
891
|
+
pass
|
|
892
|
+
os.write(2, b"still in the call\\n")
|
|
893
|
+
os._exit(3)
|
|
894
|
+
|
|
895
|
+
def __dlpack_device__(self):
|
|
896
|
+
return np.ones((2, 2), dtype=np.float32).__dlpack_device__()
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
with open(sys.argv[1], "rb") as file:
|
|
900
|
+
module = portable_lib._load_for_executorch_from_buffer(file.read())
|
|
901
|
+
module(DiesDuringTheCall())
|
|
902
|
+
"""
|
|
903
|
+
try:
|
|
904
|
+
terminal, child_end = os.openpty()
|
|
905
|
+
except OSError as error:
|
|
906
|
+
self.skipTest(f"no pseudo-terminal: {error}")
|
|
907
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
908
|
+
path = os.path.join(directory, "add.pte")
|
|
909
|
+
with open(path, "wb") as file:
|
|
910
|
+
file.write(exported_program.buffer)
|
|
911
|
+
child = subprocess.Popen(
|
|
912
|
+
[sys.executable, "-c", script, path],
|
|
913
|
+
stdout=subprocess.PIPE,
|
|
914
|
+
stderr=child_end,
|
|
915
|
+
text=True,
|
|
916
|
+
)
|
|
917
|
+
os.close(child_end)
|
|
918
|
+
# Like a busy terminal, start reading a little after the child has
|
|
919
|
+
# filled it and logged.
|
|
920
|
+
filled = (
|
|
921
|
+
child.stdout.readline()
|
|
922
|
+
if select.select([child.stdout], [], [], 120)[0]
|
|
923
|
+
else ""
|
|
924
|
+
)
|
|
925
|
+
time.sleep(0.5)
|
|
926
|
+
output = b""
|
|
927
|
+
while select.select([terminal], [], [], 120)[0]:
|
|
928
|
+
try:
|
|
929
|
+
chunk = os.read(terminal, 65536)
|
|
930
|
+
except OSError: # Linux reports the closed other end as EIO.
|
|
931
|
+
break
|
|
932
|
+
if not chunk:
|
|
933
|
+
break
|
|
934
|
+
output += chunk
|
|
935
|
+
child.kill()
|
|
936
|
+
child.wait()
|
|
937
|
+
child.stdout.close()
|
|
938
|
+
os.close(terminal)
|
|
939
|
+
|
|
940
|
+
text = output.decode(errors="replace")
|
|
941
|
+
self.assertEqual(filled, "filled\n", text)
|
|
942
|
+
self.assertEqual(child.returncode, 3, text)
|
|
943
|
+
# sys.stderr is the process's own stderr there, so the line went out as
|
|
944
|
+
# it was logged rather than with the call that never returned.
|
|
945
|
+
self.assertIn("Program identifier 'xxxx'", text)
|
|
946
|
+
self.assertLess(
|
|
947
|
+
text.index("Program identifier 'xxxx'"), text.index("still in the call")
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
def test_full_stderr_drained_by_a_thread_does_not_block_a_call(self):
|
|
951
|
+
if self.kernel_mode != "portable":
|
|
952
|
+
self.skipTest("the script below uses the portable bindings")
|
|
953
|
+
if sys.platform == "win32":
|
|
954
|
+
self.skipTest("uses POSIX pipes and sockets as fd 2")
|
|
955
|
+
|
|
956
|
+
script = """
|
|
957
|
+
import os
|
|
958
|
+
import socket
|
|
959
|
+
import sys
|
|
960
|
+
import threading
|
|
961
|
+
import time
|
|
962
|
+
|
|
963
|
+
from executorch.extension.pybindings import portable_lib
|
|
964
|
+
|
|
965
|
+
if "LLM runner" in sys.argv[1]:
|
|
966
|
+
try:
|
|
967
|
+
from executorch.extension.llm.runner import TextLLMRunner
|
|
968
|
+
except (ImportError, RuntimeError):
|
|
969
|
+
# The package raises RuntimeError when its extension is not built.
|
|
970
|
+
print("no LLM runner")
|
|
971
|
+
sys.exit()
|
|
972
|
+
missing_program = os.path.join(os.path.dirname(sys.argv[3]), "missing.pte")
|
|
973
|
+
if sys.argv[2] == "socket":
|
|
974
|
+
read_socket, write_socket = socket.socketpair()
|
|
975
|
+
read_end, write_end = read_socket.fileno(), write_socket.fileno()
|
|
976
|
+
else:
|
|
977
|
+
read_end, write_end = os.pipe()
|
|
978
|
+
# Fill it, so that a write that waits for room needs the reader below.
|
|
979
|
+
os.set_blocking(write_end, False)
|
|
980
|
+
for size in (4096, 512, 64, 1):
|
|
981
|
+
try:
|
|
982
|
+
while True:
|
|
983
|
+
os.write(write_end, b"x" * size)
|
|
984
|
+
except BlockingIOError:
|
|
985
|
+
pass
|
|
986
|
+
os.set_blocking(write_end, True)
|
|
987
|
+
saved_stderr = os.dup(2)
|
|
988
|
+
os.dup2(write_end, 2)
|
|
989
|
+
drained = bytearray()
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
def drain():
|
|
993
|
+
# Like a capture thread, this needs the GIL after every read. It starts
|
|
994
|
+
# after the call below has begun.
|
|
995
|
+
time.sleep(0.2)
|
|
996
|
+
while True:
|
|
997
|
+
drained.extend(os.read(read_end, 4096))
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
threading.Thread(target=drain, daemon=True).start()
|
|
1001
|
+
try:
|
|
1002
|
+
if sys.argv[1] == "LLM runner":
|
|
1003
|
+
# It holds the GIL and logs outside any call of these bindings.
|
|
1004
|
+
try:
|
|
1005
|
+
TextLLMRunner(missing_program, sys.argv[3])
|
|
1006
|
+
except RuntimeError:
|
|
1007
|
+
pass
|
|
1008
|
+
expected = b"[llm_runner_helper.cpp:"
|
|
1009
|
+
elif sys.argv[1] == "LLM runner and binding calls":
|
|
1010
|
+
# The LLM runner's lines wait for a thread of the bindings, which writes
|
|
1011
|
+
# them to fd 2 while the calls check it for room.
|
|
1012
|
+
stop = threading.Event()
|
|
1013
|
+
|
|
1014
|
+
def build_runners():
|
|
1015
|
+
while not stop.is_set():
|
|
1016
|
+
try:
|
|
1017
|
+
TextLLMRunner(missing_program, sys.argv[3])
|
|
1018
|
+
except RuntimeError:
|
|
1019
|
+
pass
|
|
1020
|
+
|
|
1021
|
+
builder = threading.Thread(target=build_runners)
|
|
1022
|
+
builder.start()
|
|
1023
|
+
end = time.monotonic() + 10
|
|
1024
|
+
while time.monotonic() < end:
|
|
1025
|
+
try:
|
|
1026
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
1027
|
+
except RuntimeError:
|
|
1028
|
+
pass
|
|
1029
|
+
stop.set()
|
|
1030
|
+
builder.join()
|
|
1031
|
+
expected = b"Program identifier"
|
|
1032
|
+
else:
|
|
1033
|
+
try:
|
|
1034
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
1035
|
+
except RuntimeError:
|
|
1036
|
+
pass
|
|
1037
|
+
expected = b"Program identifier"
|
|
1038
|
+
while expected not in drained:
|
|
1039
|
+
time.sleep(0.01)
|
|
1040
|
+
finally:
|
|
1041
|
+
# Lets an error here reach the test's stderr rather than fd 2.
|
|
1042
|
+
os.dup2(saved_stderr, 2)
|
|
1043
|
+
print("done")
|
|
1044
|
+
"""
|
|
1045
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
1046
|
+
tokenizer = write_llm_tokenizer(directory)
|
|
1047
|
+
for kind in ("pipe", "socket"):
|
|
1048
|
+
for mode in (
|
|
1049
|
+
"binding call",
|
|
1050
|
+
"LLM runner",
|
|
1051
|
+
"LLM runner and binding calls",
|
|
1052
|
+
):
|
|
1053
|
+
completed = subprocess.run(
|
|
1054
|
+
[sys.executable, "-c", script, mode, kind, tokenizer],
|
|
1055
|
+
capture_output=True,
|
|
1056
|
+
text=True,
|
|
1057
|
+
timeout=120,
|
|
1058
|
+
)
|
|
1059
|
+
self.assertEqual(
|
|
1060
|
+
completed.returncode,
|
|
1061
|
+
0,
|
|
1062
|
+
f"{mode}, {kind}:\nstdout:\n{completed.stdout}\n"
|
|
1063
|
+
f"stderr:\n{completed.stderr}",
|
|
1064
|
+
)
|
|
1065
|
+
if "no LLM runner" not in completed.stdout:
|
|
1066
|
+
self.assertIn("done", completed.stdout, f"{mode}, {kind}")
|
|
1067
|
+
|
|
1068
|
+
def test_lines_waiting_for_a_full_stderr(self):
|
|
1069
|
+
if self.kernel_mode != "portable":
|
|
1070
|
+
self.skipTest("the script below uses the portable bindings")
|
|
1071
|
+
if sys.platform == "win32":
|
|
1072
|
+
self.skipTest("uses a POSIX pipe as fd 2")
|
|
1073
|
+
|
|
1074
|
+
script = """
|
|
1075
|
+
import io
|
|
1076
|
+
import os
|
|
1077
|
+
import sys
|
|
1078
|
+
import threading
|
|
1079
|
+
import time
|
|
1080
|
+
|
|
1081
|
+
from executorch.extension.pybindings import portable_lib
|
|
1082
|
+
|
|
1083
|
+
try:
|
|
1084
|
+
from executorch.extension.llm.runner import TextLLMRunner
|
|
1085
|
+
except (ImportError, RuntimeError):
|
|
1086
|
+
# The package raises RuntimeError when its extension is not built.
|
|
1087
|
+
print("no LLM runner")
|
|
1088
|
+
sys.exit()
|
|
1089
|
+
missing_program = os.path.join(os.path.dirname(sys.argv[2]), "missing.pte")
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
def spin(seconds):
|
|
1093
|
+
rounds = 0
|
|
1094
|
+
end = time.perf_counter() + seconds
|
|
1095
|
+
while time.perf_counter() < end:
|
|
1096
|
+
for _ in range(100):
|
|
1097
|
+
rounds += 1
|
|
1098
|
+
return rounds
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
normal_speed = spin(0.5)
|
|
1102
|
+
read_end, write_end = os.pipe()
|
|
1103
|
+
os.set_blocking(write_end, False)
|
|
1104
|
+
for size in (4096, 512, 64, 1):
|
|
1105
|
+
try:
|
|
1106
|
+
while True:
|
|
1107
|
+
os.write(write_end, b"x" * size)
|
|
1108
|
+
except BlockingIOError:
|
|
1109
|
+
pass
|
|
1110
|
+
saved_stderr = os.dup(2)
|
|
1111
|
+
os.dup2(write_end, 2)
|
|
1112
|
+
if sys.argv[1] == "blocking":
|
|
1113
|
+
os.set_blocking(2, True)
|
|
1114
|
+
drained = bytearray()
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
def drain():
|
|
1118
|
+
# Starts once the lines below wait, and needs the GIL after every read.
|
|
1119
|
+
time.sleep(2)
|
|
1120
|
+
os.set_blocking(read_end, False)
|
|
1121
|
+
end = time.monotonic() + 3
|
|
1122
|
+
while time.monotonic() < end:
|
|
1123
|
+
try:
|
|
1124
|
+
drained.extend(os.read(read_end, 65536))
|
|
1125
|
+
except BlockingIOError:
|
|
1126
|
+
time.sleep(0.01)
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
drainer = threading.Thread(target=drain)
|
|
1130
|
+
drainer.start()
|
|
1131
|
+
try:
|
|
1132
|
+
# fd 2 is full, so these lines go to a thread of the bindings, which waits
|
|
1133
|
+
# to write them.
|
|
1134
|
+
try:
|
|
1135
|
+
TextLLMRunner(missing_program, sys.argv[2])
|
|
1136
|
+
except RuntimeError:
|
|
1137
|
+
pass
|
|
1138
|
+
if sys.argv[1] == "blocking":
|
|
1139
|
+
# The main thread's later lines must wait behind those without making
|
|
1140
|
+
# it spin.
|
|
1141
|
+
time.sleep(0.3)
|
|
1142
|
+
sys.stderr = io.StringIO()
|
|
1143
|
+
try:
|
|
1144
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
1145
|
+
except RuntimeError:
|
|
1146
|
+
pass
|
|
1147
|
+
print("speed:", round(spin(0.5) / normal_speed, 3))
|
|
1148
|
+
sys.stderr = sys.__stderr__
|
|
1149
|
+
drainer.join()
|
|
1150
|
+
finally:
|
|
1151
|
+
os.dup2(saved_stderr, 2)
|
|
1152
|
+
print("runner lines:", drained.count(b"[llm_runner_helper.cpp:"))
|
|
1153
|
+
"""
|
|
1154
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
1155
|
+
tokenizer = write_llm_tokenizer(directory)
|
|
1156
|
+
for mode in ("blocking", "non-blocking"):
|
|
1157
|
+
completed = subprocess.run(
|
|
1158
|
+
[sys.executable, "-c", script, mode, tokenizer],
|
|
1159
|
+
capture_output=True,
|
|
1160
|
+
text=True,
|
|
1161
|
+
timeout=120,
|
|
1162
|
+
)
|
|
1163
|
+
self.assertEqual(
|
|
1164
|
+
completed.returncode, 0, f"{mode}: {completed.stderr[-2000:]}"
|
|
1165
|
+
)
|
|
1166
|
+
if "no LLM runner" in completed.stdout:
|
|
1167
|
+
self.skipTest("the LLM runner bindings are not built")
|
|
1168
|
+
self.assertNotIn("runner lines: 0", completed.stdout, mode)
|
|
1169
|
+
if mode == "blocking":
|
|
1170
|
+
speed = float(completed.stdout.split("speed:")[1].split()[0])
|
|
1171
|
+
self.assertGreater(speed, 0.05, completed.stdout)
|
|
1172
|
+
|
|
1173
|
+
def test_deferred_runtime_logs_do_not_nest_in_a_stderr_write(self):
|
|
1174
|
+
if self.kernel_mode != "portable":
|
|
1175
|
+
self.skipTest("the script below uses the portable bindings")
|
|
1176
|
+
|
|
1177
|
+
script = """
|
|
1178
|
+
import os
|
|
1179
|
+
import queue
|
|
1180
|
+
import sys
|
|
1181
|
+
import threading
|
|
1182
|
+
import time
|
|
1183
|
+
|
|
1184
|
+
from executorch.extension.pybindings import portable_lib
|
|
1185
|
+
|
|
1186
|
+
if sys.argv[1] == "LLM runner":
|
|
1187
|
+
try:
|
|
1188
|
+
from executorch.extension.llm.runner import TextLLMRunner
|
|
1189
|
+
except (ImportError, RuntimeError):
|
|
1190
|
+
# The package raises RuntimeError when its extension is not built.
|
|
1191
|
+
print("no LLM runner")
|
|
1192
|
+
sys.exit()
|
|
1193
|
+
expected = "[llm_runner_helper.cpp:"
|
|
1194
|
+
else:
|
|
1195
|
+
expected = "Program identifier"
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
class QueuedStderr:
|
|
1199
|
+
# Like a logging queue, its write runs Python code while it holds a lock.
|
|
1200
|
+
def __init__(self):
|
|
1201
|
+
self.texts = queue.Queue()
|
|
1202
|
+
|
|
1203
|
+
def write(self, text):
|
|
1204
|
+
self.texts.put(text)
|
|
1205
|
+
return len(text)
|
|
1206
|
+
|
|
1207
|
+
def flush(self):
|
|
1208
|
+
pass
|
|
1209
|
+
|
|
1210
|
+
def text(self):
|
|
1211
|
+
return "".join(self.texts.queue)
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
def log():
|
|
1215
|
+
while not done.is_set():
|
|
1216
|
+
if sys.argv[1] == "LLM runner":
|
|
1217
|
+
# It holds the GIL and logs outside any call of these bindings.
|
|
1218
|
+
try:
|
|
1219
|
+
TextLLMRunner(
|
|
1220
|
+
os.path.join(os.path.dirname(sys.argv[2]), "missing.pte"),
|
|
1221
|
+
sys.argv[2],
|
|
1222
|
+
)
|
|
1223
|
+
except RuntimeError:
|
|
1224
|
+
pass
|
|
1225
|
+
else:
|
|
1226
|
+
try:
|
|
1227
|
+
portable_lib._load_program_from_buffer(b"x" * 128)
|
|
1228
|
+
except RuntimeError:
|
|
1229
|
+
pass
|
|
1230
|
+
started.set()
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
done, started = threading.Event(), threading.Event()
|
|
1234
|
+
stream = QueuedStderr()
|
|
1235
|
+
sys.stderr = stream
|
|
1236
|
+
thread = threading.Thread(target=log, daemon=sys.argv[1] == "daemon thread")
|
|
1237
|
+
thread.start()
|
|
1238
|
+
started.wait(60)
|
|
1239
|
+
# The other thread's lines must never be written from inside these writes.
|
|
1240
|
+
deadline = time.monotonic() + 2
|
|
1241
|
+
while time.monotonic() < deadline:
|
|
1242
|
+
print("main thread", file=sys.stderr)
|
|
1243
|
+
done.set()
|
|
1244
|
+
thread.join()
|
|
1245
|
+
deadline = time.monotonic() + 10
|
|
1246
|
+
while expected not in stream.text() and time.monotonic() < deadline:
|
|
1247
|
+
time.sleep(0.01)
|
|
1248
|
+
sys.stderr = sys.__stderr__
|
|
1249
|
+
print("lines through Python:", stream.text().count(expected))
|
|
1250
|
+
"""
|
|
1251
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
1252
|
+
tokenizer = write_llm_tokenizer(directory)
|
|
1253
|
+
for mode in ("LLM runner", "daemon thread"):
|
|
1254
|
+
completed = subprocess.run(
|
|
1255
|
+
[sys.executable, "-c", script, mode, tokenizer],
|
|
1256
|
+
capture_output=True,
|
|
1257
|
+
text=True,
|
|
1258
|
+
timeout=120,
|
|
1259
|
+
)
|
|
1260
|
+
self.assertEqual(
|
|
1261
|
+
completed.returncode, 0, f"{mode}: {completed.stderr[-2000:]}"
|
|
1262
|
+
)
|
|
1263
|
+
if "no LLM runner" not in completed.stdout:
|
|
1264
|
+
self.assertIn("lines through Python:", completed.stdout, mode)
|
|
1265
|
+
self.assertNotIn("lines through Python: 0", completed.stdout, mode)
|
|
1266
|
+
|
|
1267
|
+
def test_long_call_keeps_its_newest_runtime_logs(self):
|
|
1268
|
+
if self.kernel_mode != "portable":
|
|
1269
|
+
self.skipTest("only the portable bindings take DLPack inputs")
|
|
1270
|
+
|
|
1271
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
1272
|
+
module = self.load_fn(exported_program.buffer)
|
|
1273
|
+
runtime = self.runtime
|
|
1274
|
+
values = np.ones((2, 2), dtype=np.float32)
|
|
1275
|
+
|
|
1276
|
+
class LogsDuringTheCall:
|
|
1277
|
+
# Converting this input logs far more than one call keeps, ending
|
|
1278
|
+
# with a line that is not valid UTF-8.
|
|
1279
|
+
def __dlpack__(self, stream=None):
|
|
1280
|
+
for _ in range(20000):
|
|
1281
|
+
try:
|
|
1282
|
+
runtime._load_program_from_buffer(b"x" * 128)
|
|
1283
|
+
except RuntimeError:
|
|
1284
|
+
pass
|
|
1285
|
+
try:
|
|
1286
|
+
runtime._load_program_from_buffer(b"\xff" * 128)
|
|
1287
|
+
except RuntimeError:
|
|
1288
|
+
pass
|
|
1289
|
+
return values.__dlpack__(stream=stream)
|
|
1290
|
+
|
|
1291
|
+
def __dlpack_device__(self):
|
|
1292
|
+
return values.__dlpack_device__()
|
|
1293
|
+
|
|
1294
|
+
captured = StringIO()
|
|
1295
|
+
saved_stderr = sys.stderr
|
|
1296
|
+
sys.stderr = captured
|
|
1297
|
+
try:
|
|
1298
|
+
module(LogsDuringTheCall())
|
|
1299
|
+
finally:
|
|
1300
|
+
sys.stderr = saved_stderr
|
|
1301
|
+
|
|
1302
|
+
text = captured.getvalue()
|
|
1303
|
+
lines = text.splitlines()
|
|
1304
|
+
self.assertRegex(
|
|
1305
|
+
lines[0],
|
|
1306
|
+
r"^\[\d+ earlier bytes of the runtime log were left out\]$",
|
|
1307
|
+
)
|
|
1308
|
+
kept = len(text) - len(lines[0]) - 1
|
|
1309
|
+
self.assertGreater(kept, 512 * 1024 - 1024)
|
|
1310
|
+
self.assertLessEqual(kept, 1024 * 1024)
|
|
1311
|
+
self.assertIn("Program identifier '\\xff\\xff\\xff\\xff'", lines[-1])
|
|
1312
|
+
|
|
1313
|
+
def test_error_message_cut_in_a_character_raises_runtime_error(self):
|
|
1314
|
+
# An error message is cut at a fixed length. With these paths, the cut
|
|
1315
|
+
# falls inside a character for at least one of them.
|
|
1316
|
+
for prefix in ("", "a", "ab"):
|
|
1317
|
+
with self.assertRaises(RuntimeError):
|
|
1318
|
+
self.runtime._load_for_executorch(prefix + "\u4e2d" * 60 + ".pte")
|
|
1319
|
+
|
|
1320
|
+
def test_bfloat16_output_preserves_dtype(self):
|
|
1321
|
+
class ModuleAddBFloat16(ModuleAdd):
|
|
1322
|
+
def get_inputs(self):
|
|
1323
|
+
return (
|
|
1324
|
+
torch.ones(2, dtype=torch.bfloat16),
|
|
1325
|
+
torch.ones(2, dtype=torch.bfloat16),
|
|
1326
|
+
)
|
|
1327
|
+
|
|
1328
|
+
exported_program, inputs = create_program(ModuleAddBFloat16())
|
|
1329
|
+
output = self.load_fn(exported_program.buffer)(inputs)[0]
|
|
1330
|
+
|
|
1331
|
+
self.assertEqual(output.dtype, torch.bfloat16)
|
|
1332
|
+
torch.testing.assert_close(output, inputs[0] + inputs[1])
|
|
1333
|
+
|
|
1334
|
+
def test_default_numpy_integer_dtype_error_is_descriptive(self):
|
|
1335
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
1336
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1337
|
+
|
|
1338
|
+
with self.assertRaisesRegex(ValueError, "dtype Long.*expects Float"):
|
|
1339
|
+
executorch_module(np.ones((2, 2), dtype=int))
|
|
1340
|
+
|
|
1341
|
+
def test_refused_input_errors_say_why(self):
|
|
1342
|
+
exported_program, inputs = create_program(ModuleAddScalar())
|
|
1343
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1344
|
+
with self.assertRaises(RuntimeError) as error:
|
|
1345
|
+
executorch_module.forward([None, inputs[1]])
|
|
1346
|
+
self.assertIn("type Tensor but was None", str(error.exception))
|
|
1347
|
+
# Only the reason is reported, not lines about other inputs.
|
|
1348
|
+
self.assertNotIn("is not Tensor", str(error.exception))
|
|
1349
|
+
|
|
1350
|
+
# The portable runtime logs a static shape mismatch over two lines.
|
|
1351
|
+
if self.kernel_mode == "portable":
|
|
1352
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
1353
|
+
with self.assertRaisesRegex(
|
|
1354
|
+
RuntimeError, r"received \(3, 2\)\.; Error resizing tensor at input 0"
|
|
1355
|
+
):
|
|
1356
|
+
self.load_fn(exported_program.buffer).forward(
|
|
1357
|
+
[torch.ones(3, 2), inputs[1]]
|
|
1358
|
+
)
|
|
1359
|
+
|
|
1360
|
+
def test_numpy_float_scalar_input(self):
|
|
1361
|
+
exported_program, inputs = create_program(ModuleAddScalar())
|
|
1362
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1363
|
+
|
|
1364
|
+
output = executorch_module.forward([inputs[0], np.float64(inputs[1])])[0]
|
|
1365
|
+
|
|
1366
|
+
self.assertTrue(torch.equal(output, inputs[0] + inputs[1]))
|
|
1367
|
+
|
|
1368
|
+
def test_numpy_float_scalar_set_inputs(self):
|
|
1369
|
+
exported_program, inputs = create_program(ModuleAddScalar())
|
|
1370
|
+
program = self.load_prog_fn(exported_program.buffer)
|
|
1371
|
+
method = program.load_method("forward")
|
|
1372
|
+
|
|
1373
|
+
method.set_inputs([inputs[0], np.float64(inputs[1])])
|
|
1374
|
+
method.execute()
|
|
1375
|
+
|
|
1376
|
+
self.assertTrue(torch.equal(method.get_outputs()[0], inputs[0] + inputs[1]))
|
|
1377
|
+
|
|
1378
|
+
def test_method_rejects_tensor_for_scalar_input(self):
|
|
1379
|
+
exported_program, inputs = create_program(ModuleAddScalar())
|
|
1380
|
+
module = self.load_fn(exported_program.buffer)
|
|
1381
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1382
|
+
|
|
1383
|
+
for run in (module.forward, method.set_inputs):
|
|
1384
|
+
with self.subTest(run=run):
|
|
1385
|
+
with self.assertRaisesRegex(
|
|
1386
|
+
RuntimeError,
|
|
1387
|
+
r"^Input 1 of method 'forward': the method expects Double, "
|
|
1388
|
+
r"but got <class 'torch\.Tensor'>$",
|
|
1389
|
+
):
|
|
1390
|
+
run([inputs[0], torch.ones(1)])
|
|
1391
|
+
|
|
1392
|
+
def test_method_rejects_aliased_input_whose_storage_changed(self):
|
|
1393
|
+
# An output that is the input itself is returned as a view of the
|
|
1394
|
+
# caller's tensor, which must still be the storage the method read.
|
|
1395
|
+
if self.kernel_mode != "portable":
|
|
1396
|
+
self.skipTest("only portable bindings return a view of the input")
|
|
1397
|
+
from executorch.extension.pybindings import _C
|
|
1398
|
+
|
|
1399
|
+
if _C._tensor_output != "torch":
|
|
1400
|
+
self.skipTest("only torch output mode returns a view of the input")
|
|
1401
|
+
|
|
1402
|
+
class Identity(torch.nn.Module):
|
|
1403
|
+
def forward(self, x):
|
|
1404
|
+
return x
|
|
1405
|
+
|
|
1406
|
+
value = torch.ones(2, 2)
|
|
1407
|
+
program = to_edge(export(Identity(), (value,))).to_executorch(
|
|
1408
|
+
ExecutorchBackendConfig(
|
|
1409
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
1410
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
1411
|
+
)
|
|
1412
|
+
)
|
|
1413
|
+
)
|
|
1414
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
1415
|
+
method.set_inputs([value])
|
|
1416
|
+
method.execute()
|
|
1417
|
+
value.set_(torch.zeros(2, 2))
|
|
1418
|
+
with self.assertRaisesRegex(
|
|
1419
|
+
ValueError,
|
|
1420
|
+
r"^Input 0 of method 'forward': its storage changed before the output "
|
|
1421
|
+
r"was read; pass it again$",
|
|
1422
|
+
):
|
|
1423
|
+
method.get_outputs(clone_outputs=False)
|
|
1424
|
+
|
|
1425
|
+
def test_dlpack_inputs(self):
|
|
1426
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
1427
|
+
module = self.load_fn(exported_program.buffer)
|
|
1428
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1429
|
+
for executor in (module, method):
|
|
1430
|
+
with self.subTest(executor=type(executor)):
|
|
1431
|
+
output = executor([DLPackOnly(value.numpy()) for value in inputs])[0]
|
|
1432
|
+
torch.testing.assert_close(output, inputs[0] + inputs[1])
|
|
1433
|
+
|
|
1434
|
+
def test_dlpack_input_in_another_layout_is_converted(self):
|
|
1435
|
+
if self.kernel_mode != "portable":
|
|
1436
|
+
self.skipTest("portable input layout compatibility")
|
|
1437
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
1438
|
+
module = self.load_fn(exported_program.buffer)
|
|
1439
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1440
|
+
# Distinct values, so reading the transposed data in the exported
|
|
1441
|
+
# layout would permute them.
|
|
1442
|
+
values = np.arange(4, dtype=np.float32).reshape(2, 2).T
|
|
1443
|
+
for executor in (module, method):
|
|
1444
|
+
with self.subTest(executor=type(executor)):
|
|
1445
|
+
output = executor(DLPackOnly(values))[0]
|
|
1446
|
+
torch.testing.assert_close(output, torch.from_numpy(values * 2))
|
|
1447
|
+
|
|
1448
|
+
def test_borrowed_result_feedback_has_bounded_ownership(self):
|
|
1449
|
+
if self.kernel_mode != "portable":
|
|
1450
|
+
self.skipTest("only portable bindings implement ExecuTorchResult outputs")
|
|
1451
|
+
|
|
1452
|
+
class Identity(torch.nn.Module):
|
|
1453
|
+
def forward(self, value):
|
|
1454
|
+
return value
|
|
1455
|
+
|
|
1456
|
+
class ToChannelsLast(torch.nn.Module):
|
|
1457
|
+
def forward(self, value):
|
|
1458
|
+
return value.to(memory_format=torch.channels_last)
|
|
1459
|
+
|
|
1460
|
+
config = ExecutorchBackendConfig(
|
|
1461
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
1462
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
1463
|
+
)
|
|
1464
|
+
)
|
|
1465
|
+
program = to_edge(export(Identity(), (torch.ones(2, 2),))).to_executorch(config)
|
|
1466
|
+
# A channels-last result, read by a contiguous identity method, is
|
|
1467
|
+
# copied into the contiguous layout first.
|
|
1468
|
+
channels_last_program = to_edge(
|
|
1469
|
+
export(ToChannelsLast(), (torch.ones(1, 2, 2, 2),))
|
|
1470
|
+
).to_executorch(config)
|
|
1471
|
+
contiguous_program = to_edge(
|
|
1472
|
+
export(Identity(), (torch.ones(1, 2, 2, 2),))
|
|
1473
|
+
).to_executorch(config)
|
|
1474
|
+
script = """
|
|
1475
|
+
import gc
|
|
1476
|
+
import importlib
|
|
1477
|
+
import sys
|
|
1478
|
+
import weakref
|
|
1479
|
+
import numpy as np
|
|
1480
|
+
|
|
1481
|
+
runtime = importlib.import_module(sys.argv[4])
|
|
1482
|
+
|
|
1483
|
+
native = sys.modules[sys.argv[3]]
|
|
1484
|
+
assert native.__spec__.origin == sys.argv[2]
|
|
1485
|
+
|
|
1486
|
+
class DLPackOnly:
|
|
1487
|
+
def __init__(self, value):
|
|
1488
|
+
self.value = value
|
|
1489
|
+
def __dlpack__(self, stream=None):
|
|
1490
|
+
return self.value.__dlpack__(stream=stream)
|
|
1491
|
+
def __dlpack_device__(self):
|
|
1492
|
+
return self.value.__dlpack_device__()
|
|
1493
|
+
|
|
1494
|
+
assert not runtime._uses_aten
|
|
1495
|
+
assert native._tensor_output == "executorch"
|
|
1496
|
+
with open(sys.argv[1], "rb") as source:
|
|
1497
|
+
data = source.read()
|
|
1498
|
+
with open(sys.argv[5], "rb") as source:
|
|
1499
|
+
channels_last_data = source.read()
|
|
1500
|
+
with open(sys.argv[6], "rb") as source:
|
|
1501
|
+
contiguous_data = source.read()
|
|
1502
|
+
|
|
1503
|
+
def live_lists():
|
|
1504
|
+
gc.collect()
|
|
1505
|
+
return sum(isinstance(value, list) for value in gc.get_objects())
|
|
1506
|
+
|
|
1507
|
+
def check_feedback(executor):
|
|
1508
|
+
source = np.arange(4, dtype=np.float32).reshape(2, 2)
|
|
1509
|
+
source_ref = weakref.ref(source)
|
|
1510
|
+
executor_ref = weakref.ref(executor)
|
|
1511
|
+
pointer = source.ctypes.data
|
|
1512
|
+
result = executor(source, clone_outputs=False)[0]
|
|
1513
|
+
def advance(result, count):
|
|
1514
|
+
for index in range(count):
|
|
1515
|
+
producer = result if index % 2 == 0 else DLPackOnly(result)
|
|
1516
|
+
result = executor(producer, clone_outputs=False)[0]
|
|
1517
|
+
del producer
|
|
1518
|
+
view = np.from_dlpack(result)
|
|
1519
|
+
assert view.ctypes.data == pointer
|
|
1520
|
+
np.testing.assert_array_equal(view, source)
|
|
1521
|
+
del view
|
|
1522
|
+
return result
|
|
1523
|
+
result = advance(result, 16)
|
|
1524
|
+
before = live_lists()
|
|
1525
|
+
result = advance(result, 128)
|
|
1526
|
+
after = live_lists()
|
|
1527
|
+
# Repeated feedback must release old ownership containers, even while
|
|
1528
|
+
# the current result still shares the original allocation.
|
|
1529
|
+
assert after < before + 32, (type(executor), before, after)
|
|
1530
|
+
del executor, source
|
|
1531
|
+
gc.collect()
|
|
1532
|
+
np.testing.assert_array_equal(np.from_dlpack(result), np.arange(4).reshape(2, 2))
|
|
1533
|
+
del result, advance
|
|
1534
|
+
gc.collect()
|
|
1535
|
+
assert executor_ref() is None
|
|
1536
|
+
assert source_ref() is None
|
|
1537
|
+
|
|
1538
|
+
check_feedback(runtime._load_for_executorch_from_buffer(data))
|
|
1539
|
+
check_feedback(runtime._load_program_from_buffer(data).load_method("forward"))
|
|
1540
|
+
|
|
1541
|
+
# A result in another layout is copied into the exported one, and a borrowed
|
|
1542
|
+
# result over it reads that copy. It must keep the copy alive, not the
|
|
1543
|
+
# producer's result, whose memory holds the other layout.
|
|
1544
|
+
method = runtime._load_program_from_buffer(contiguous_data).load_method("forward")
|
|
1545
|
+
converter = runtime._load_program_from_buffer(channels_last_data).load_method(
|
|
1546
|
+
"forward"
|
|
1547
|
+
)
|
|
1548
|
+
values = np.arange(8, dtype=np.float32).reshape(1, 2, 2, 2)
|
|
1549
|
+
source = converter(values)[0]
|
|
1550
|
+
assert np.from_dlpack(source).strides != values.strides
|
|
1551
|
+
method.set_inputs([DLPackOnly(source)])
|
|
1552
|
+
method.execute()
|
|
1553
|
+
borrowed = method.get_outputs(clone_outputs=False)[0]
|
|
1554
|
+
method.set_inputs([np.full((1, 2, 2, 2), -7.0, dtype=np.float32)])
|
|
1555
|
+
gc.collect()
|
|
1556
|
+
np.testing.assert_array_equal(np.from_dlpack(borrowed), values)
|
|
1557
|
+
print("Borrowed result feedback retained bounded ownership")
|
|
1558
|
+
"""
|
|
1559
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
1560
|
+
path = os.path.join(directory, "identity.pte")
|
|
1561
|
+
with open(path, "wb") as source:
|
|
1562
|
+
source.write(program.buffer)
|
|
1563
|
+
channels_last_path = os.path.join(directory, "channels_last.pte")
|
|
1564
|
+
with open(channels_last_path, "wb") as source:
|
|
1565
|
+
source.write(channels_last_program.buffer)
|
|
1566
|
+
contiguous_path = os.path.join(directory, "contiguous.pte")
|
|
1567
|
+
with open(contiguous_path, "wb") as source:
|
|
1568
|
+
source.write(contiguous_program.buffer)
|
|
1569
|
+
environment = os.environ.copy()
|
|
1570
|
+
environment["EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT"] = "executorch"
|
|
1571
|
+
native_name = self.runtime.ExecuTorchResult.__module__
|
|
1572
|
+
completed = subprocess.run(
|
|
1573
|
+
[
|
|
1574
|
+
sys.executable,
|
|
1575
|
+
"-c",
|
|
1576
|
+
script,
|
|
1577
|
+
path,
|
|
1578
|
+
sys.modules[native_name].__spec__.origin,
|
|
1579
|
+
native_name,
|
|
1580
|
+
self.runtime.__name__,
|
|
1581
|
+
channels_last_path,
|
|
1582
|
+
contiguous_path,
|
|
1583
|
+
],
|
|
1584
|
+
env=environment,
|
|
1585
|
+
capture_output=True,
|
|
1586
|
+
text=True,
|
|
1587
|
+
timeout=60,
|
|
1588
|
+
)
|
|
1589
|
+
self.assertEqual(
|
|
1590
|
+
completed.returncode,
|
|
1591
|
+
0,
|
|
1592
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
1593
|
+
)
|
|
1594
|
+
self.assertIn(
|
|
1595
|
+
"Borrowed result feedback retained bounded ownership", completed.stdout
|
|
1596
|
+
)
|
|
1597
|
+
|
|
1598
|
+
def test_module_retains_dlpack_inputs_for_reexecution(self):
|
|
1599
|
+
if self.kernel_mode != "portable":
|
|
1600
|
+
self.skipTest("only portable bindings implement generic DLPack inputs")
|
|
1601
|
+
program, _ = create_program(
|
|
1602
|
+
ModuleAddSingleInput(),
|
|
1603
|
+
et_config=ExecutorchBackendConfig(
|
|
1604
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
1605
|
+
),
|
|
1606
|
+
)
|
|
1607
|
+
module = self.load_fn(program.buffer)
|
|
1608
|
+
source = np.ones((2, 2), dtype=np.float32)
|
|
1609
|
+
producer = DLPackOnly(source)
|
|
1610
|
+
producer_ref = weakref.ref(producer)
|
|
1611
|
+
source_ref = weakref.ref(source)
|
|
1612
|
+
output = module(producer, clone_outputs=False)[0]
|
|
1613
|
+
del producer, source
|
|
1614
|
+
gc.collect()
|
|
1615
|
+
self.assertIsNotNone(producer_ref())
|
|
1616
|
+
self.assertIsNotNone(source_ref())
|
|
1617
|
+
|
|
1618
|
+
source_ref().fill(3.0)
|
|
1619
|
+
repeated = module()[0]
|
|
1620
|
+
planned = module.plan_execute("forward", clone_outputs=False)[0]
|
|
1621
|
+
torch.testing.assert_close(repeated, torch.full((2, 2), 6.0))
|
|
1622
|
+
torch.testing.assert_close(planned, torch.full((2, 2), 6.0))
|
|
1623
|
+
del output, repeated, planned
|
|
1624
|
+
|
|
1625
|
+
replacement = DLPackOnly(np.full((2, 2), 5.0, dtype=np.float32))
|
|
1626
|
+
replacement_ref = weakref.ref(replacement)
|
|
1627
|
+
module(replacement)
|
|
1628
|
+
del replacement
|
|
1629
|
+
gc.collect()
|
|
1630
|
+
self.assertIsNone(producer_ref())
|
|
1631
|
+
self.assertIsNone(source_ref())
|
|
1632
|
+
self.assertIsNotNone(replacement_ref())
|
|
1633
|
+
output = module.plan_execute("forward", clone_outputs=False)[0]
|
|
1634
|
+
del module
|
|
1635
|
+
gc.collect()
|
|
1636
|
+
self.assertIsNone(replacement_ref())
|
|
1637
|
+
torch.testing.assert_close(output, torch.full((2, 2), 10.0))
|
|
1638
|
+
del output
|
|
1639
|
+
gc.collect()
|
|
1640
|
+
self.assertIsNone(replacement_ref())
|
|
1641
|
+
|
|
1642
|
+
def test_cuda_dlpack_producer_and_executorch_result(self):
|
|
1643
|
+
if self.kernel_mode != "portable":
|
|
1644
|
+
self.skipTest("only portable bindings implement ExecuTorchResult outputs")
|
|
1645
|
+
if not torch.cuda.is_available():
|
|
1646
|
+
self.skipTest("needs a visible CUDA device")
|
|
1647
|
+
|
|
1648
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
1649
|
+
from executorch.exir.schema import ExtraTensorInfo, Tensor
|
|
1650
|
+
|
|
1651
|
+
class Identity(torch.nn.Module):
|
|
1652
|
+
def forward(self, x):
|
|
1653
|
+
return x
|
|
1654
|
+
|
|
1655
|
+
value = torch.ones(2, 3, 4, 5).to(memory_format=torch.channels_last)
|
|
1656
|
+
program = to_edge(export(Identity(), (value,))).to_executorch(
|
|
1657
|
+
ExecutorchBackendConfig(
|
|
1658
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
1659
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
1660
|
+
)
|
|
1661
|
+
)
|
|
1662
|
+
)
|
|
1663
|
+
schema = program.executorch_program
|
|
1664
|
+
device_index = torch.cuda.device_count() - 1
|
|
1665
|
+
for entry in schema.execution_plan[0].values:
|
|
1666
|
+
if isinstance(entry.val, Tensor):
|
|
1667
|
+
entry.val.extra_tensor_info = ExtraTensorInfo(
|
|
1668
|
+
device_type=DeviceType.CUDA, device_index=device_index
|
|
1669
|
+
)
|
|
1670
|
+
data = bytes(serialize_pte_binary(PTEFile(schema)))
|
|
1671
|
+
|
|
1672
|
+
# No delegate or device arena is needed for this identity. Both APIs
|
|
1673
|
+
# must consume the generic producer rather than the Torch input path.
|
|
1674
|
+
value = value.to(f"cuda:{device_index}")
|
|
1675
|
+
module = self.load_fn(data)
|
|
1676
|
+
method = self.load_prog_fn(data).load_method("forward")
|
|
1677
|
+
for executor in (module, method):
|
|
1678
|
+
for clone_outputs in (False, True):
|
|
1679
|
+
with self.subTest(executor=type(executor), clone=clone_outputs):
|
|
1680
|
+
output = executor(DLPackOnly(value), clone_outputs=clone_outputs)[0]
|
|
1681
|
+
self.assertEqual(output.device, value.device)
|
|
1682
|
+
self.assertEqual(output.dtype, value.dtype)
|
|
1683
|
+
self.assertEqual(output.stride(), value.stride())
|
|
1684
|
+
torch.testing.assert_close(output, value)
|
|
1685
|
+
if clone_outputs:
|
|
1686
|
+
self.assertNotEqual(output.data_ptr(), value.data_ptr())
|
|
1687
|
+
else:
|
|
1688
|
+
self.assertEqual(output.data_ptr(), value.data_ptr())
|
|
1689
|
+
|
|
1690
|
+
script = """
|
|
1691
|
+
import sys
|
|
1692
|
+
import torch
|
|
1693
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
1694
|
+
|
|
1695
|
+
class DLPackOnly:
|
|
1696
|
+
def __init__(self, tensor):
|
|
1697
|
+
self.tensor = tensor
|
|
1698
|
+
def __dlpack__(self, stream=None):
|
|
1699
|
+
return self.tensor.__dlpack__(stream=stream)
|
|
1700
|
+
def __dlpack_device__(self):
|
|
1701
|
+
return self.tensor.__dlpack_device__()
|
|
1702
|
+
|
|
1703
|
+
assert not runtime._uses_aten
|
|
1704
|
+
with open(sys.argv[1], "rb") as source:
|
|
1705
|
+
data = source.read()
|
|
1706
|
+
device_index = int(sys.argv[2])
|
|
1707
|
+
value = torch.ones(2, 3, 4, 5, device=f"cuda:{device_index}").to(
|
|
1708
|
+
memory_format=torch.channels_last
|
|
1709
|
+
)
|
|
1710
|
+
module = runtime._load_for_executorch_from_buffer(data)
|
|
1711
|
+
method = runtime._load_program_from_buffer(data).load_method("forward")
|
|
1712
|
+
for executor in (module, method):
|
|
1713
|
+
output = executor(DLPackOnly(value), clone_outputs=False)[0]
|
|
1714
|
+
assert isinstance(output, runtime.ExecuTorchResult)
|
|
1715
|
+
assert output.__dlpack_device__() == (2, device_index)
|
|
1716
|
+
tensor = torch.from_dlpack(output)
|
|
1717
|
+
assert tensor.data_ptr() == value.data_ptr()
|
|
1718
|
+
assert tensor.stride() == value.stride()
|
|
1719
|
+
torch.testing.assert_close(tensor, value)
|
|
1720
|
+
roundtrip = executor(output, clone_outputs=False)[0]
|
|
1721
|
+
assert isinstance(roundtrip, runtime.ExecuTorchResult)
|
|
1722
|
+
assert roundtrip.__dlpack_device__() == (2, device_index)
|
|
1723
|
+
torch.testing.assert_close(torch.from_dlpack(roundtrip), value)
|
|
1724
|
+
print("CUDA DLPack roundtrip preserved device storage")
|
|
1725
|
+
"""
|
|
1726
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
1727
|
+
path = os.path.join(directory, "cuda_identity.pte")
|
|
1728
|
+
with open(path, "wb") as source:
|
|
1729
|
+
source.write(data)
|
|
1730
|
+
environment = os.environ.copy()
|
|
1731
|
+
environment["EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT"] = "executorch"
|
|
1732
|
+
completed = subprocess.run(
|
|
1733
|
+
[sys.executable, "-c", script, path, str(device_index)],
|
|
1734
|
+
env=environment,
|
|
1735
|
+
capture_output=True,
|
|
1736
|
+
text=True,
|
|
1737
|
+
timeout=60,
|
|
1738
|
+
)
|
|
1739
|
+
self.assertEqual(
|
|
1740
|
+
completed.returncode,
|
|
1741
|
+
0,
|
|
1742
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
1743
|
+
)
|
|
1744
|
+
self.assertIn(
|
|
1745
|
+
"CUDA DLPack roundtrip preserved device storage", completed.stdout
|
|
1746
|
+
)
|
|
1747
|
+
|
|
1748
|
+
def test_bfloat16_raw_buffer_inputs(self):
|
|
1749
|
+
exported_program, inputs = create_program(ModuleAddBFloat16())
|
|
1750
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1751
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1752
|
+
raw_inputs = [value.view(torch.uint8).numpy().tobytes() for value in inputs]
|
|
1753
|
+
|
|
1754
|
+
for executor in (executorch_module, method):
|
|
1755
|
+
with self.subTest(executor=type(executor)):
|
|
1756
|
+
output = executor(raw_inputs)[0]
|
|
1757
|
+
self.assertTrue(torch.equal(output, inputs[0] + inputs[1]))
|
|
1758
|
+
for noncontiguous in (
|
|
1759
|
+
np.arange(16, dtype=np.uint8)[::2],
|
|
1760
|
+
np.arange(8, dtype=np.uint8)[::-1],
|
|
1761
|
+
):
|
|
1762
|
+
with self.assertRaisesRegex(BufferError, "contiguous byte buffers"):
|
|
1763
|
+
executor([noncontiguous, raw_inputs[1]])
|
|
1764
|
+
with self.assertRaisesRegex(
|
|
1765
|
+
ValueError,
|
|
1766
|
+
"^Input 0 of method 'forward': raw bfloat16 input has "
|
|
1767
|
+
f"{len(raw_inputs[0]) - 2} bytes, but the method expects "
|
|
1768
|
+
f"{len(raw_inputs[0])}$",
|
|
1769
|
+
):
|
|
1770
|
+
executor([raw_inputs[0][:-2], raw_inputs[1]])
|
|
1771
|
+
|
|
1772
|
+
def test_numpy_array_is_a_single_input(self):
|
|
1773
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
1774
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1775
|
+
|
|
1776
|
+
output = executorch_module(inputs[0].numpy())[0]
|
|
1777
|
+
|
|
1778
|
+
self.assertTrue(torch.allclose(output, inputs[0] + inputs[0]))
|
|
1779
|
+
|
|
1780
|
+
def test_mixed_tensor_protocols(self):
|
|
1781
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
1782
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1783
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1784
|
+
|
|
1785
|
+
for executor in (executorch_module, method):
|
|
1786
|
+
for mixed_inputs in (
|
|
1787
|
+
[inputs[0], inputs[1].numpy()],
|
|
1788
|
+
[inputs[0], DLPackOnly(inputs[1].numpy())],
|
|
1789
|
+
[inputs[0].numpy(), DLPackOnly(inputs[1].numpy())],
|
|
1790
|
+
):
|
|
1791
|
+
with self.subTest(
|
|
1792
|
+
executor=type(executor),
|
|
1793
|
+
protocols=[type(value) for value in mixed_inputs],
|
|
1794
|
+
):
|
|
1795
|
+
output = executor(mixed_inputs)[0]
|
|
1796
|
+
self.assertTrue(torch.allclose(output, inputs[0] + inputs[1]))
|
|
1797
|
+
|
|
1798
|
+
def test_raw_dlpack_capsule_is_a_single_input(self):
|
|
1799
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
1800
|
+
module = self.load_fn(exported_program.buffer)
|
|
1801
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
1802
|
+
for executor in (module, method):
|
|
1803
|
+
with self.subTest(executor=type(executor)):
|
|
1804
|
+
output = executor(inputs[0].numpy().__dlpack__())[0]
|
|
1805
|
+
torch.testing.assert_close(
|
|
1806
|
+
torch.from_dlpack(output), inputs[0] + inputs[0]
|
|
1807
|
+
)
|
|
1808
|
+
|
|
1809
|
+
def test_non_dense_numpy_input_is_rejected(self):
|
|
1810
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
1811
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1812
|
+
non_dense = np.zeros((4, 4), dtype=np.float32)[::2, ::2]
|
|
1813
|
+
|
|
1814
|
+
with self.assertRaisesRegex(BufferError, "dense, non-overlapping"):
|
|
1815
|
+
executorch_module(non_dense)
|
|
1816
|
+
|
|
1817
|
+
def test_complex_numpy_input(self):
|
|
1818
|
+
class Identity(torch.nn.Module):
|
|
1819
|
+
def forward(self, x):
|
|
1820
|
+
return x.clone()
|
|
1821
|
+
|
|
1822
|
+
exported_program = to_edge(
|
|
1823
|
+
export(Identity(), (torch.ones(4, dtype=torch.complex64),), strict=True)
|
|
1824
|
+
).to_executorch()
|
|
1825
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1826
|
+
values = np.array([1 + 2j, 3 - 4j, 0, 1j], dtype=np.complex64)
|
|
1827
|
+
|
|
1828
|
+
output = executorch_module(values)[0]
|
|
1829
|
+
|
|
1830
|
+
np.testing.assert_array_equal(np.asarray(output), values)
|
|
1831
|
+
|
|
1832
|
+
def test_complex_half_dlpack_input(self):
|
|
1833
|
+
if self.kernel_mode != "portable":
|
|
1834
|
+
self.skipTest("only portable bindings read DLPack inputs themselves")
|
|
1835
|
+
|
|
1836
|
+
class Identity(torch.nn.Module):
|
|
1837
|
+
def forward(self, x):
|
|
1838
|
+
return x
|
|
1839
|
+
|
|
1840
|
+
value = torch.tensor([1 + 2j, 3 - 4j], dtype=torch.complex32)
|
|
1841
|
+
program = to_edge(export(Identity(), (value,))).to_executorch(
|
|
1842
|
+
ExecutorchBackendConfig(
|
|
1843
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
1844
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
1845
|
+
)
|
|
1846
|
+
)
|
|
1847
|
+
)
|
|
1848
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
1849
|
+
output = torch.from_dlpack(method(DLPackOnly(value))[0])
|
|
1850
|
+
self.assertEqual(output.dtype, torch.complex32)
|
|
1851
|
+
self.assertTrue(
|
|
1852
|
+
torch.equal(output.view(torch.float16), value.view(torch.float16))
|
|
1853
|
+
)
|
|
1854
|
+
|
|
1855
|
+
def test_unsupported_buffer_format_is_rejected(self):
|
|
1856
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
1857
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1858
|
+
|
|
1859
|
+
for value in (
|
|
1860
|
+
np.zeros((2, 2), dtype=[("a", np.float32)]),
|
|
1861
|
+
memoryview(b"\x00" * 4).cast("c"),
|
|
1862
|
+
):
|
|
1863
|
+
with self.subTest(format=memoryview(value).format):
|
|
1864
|
+
with self.assertRaisesRegex(
|
|
1865
|
+
BufferError,
|
|
1866
|
+
"Input 0 of method 'forward': Unsupported buffer format",
|
|
1867
|
+
):
|
|
1868
|
+
executorch_module(value)
|
|
1869
|
+
|
|
1870
|
+
def test_readonly_buffer_input_is_copied(self):
|
|
1871
|
+
exported_program, inputs = create_program(
|
|
1872
|
+
ModuleAddSingleInput(),
|
|
1873
|
+
et_config=ExecutorchBackendConfig(
|
|
1874
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
1875
|
+
),
|
|
1876
|
+
)
|
|
1877
|
+
program = self.load_prog_fn(exported_program.buffer)
|
|
1878
|
+
method = program.load_method("forward")
|
|
1879
|
+
array = inputs[0].numpy()
|
|
1880
|
+
method.set_inputs(memoryview(array).toreadonly())
|
|
1881
|
+
array.fill(3)
|
|
1882
|
+
|
|
1883
|
+
method.execute()
|
|
1884
|
+
|
|
1885
|
+
self.assertTrue(torch.equal(method.get_outputs()[0], torch.full((2, 2), 2.0)))
|
|
1886
|
+
|
|
1887
|
+
def test_numpy_input_in_another_layout_is_converted(self):
|
|
1888
|
+
model = ModuleChannelsLast()
|
|
1889
|
+
exported_program, inputs = create_program(model)
|
|
1890
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1891
|
+
values = torch.arange(inputs[0].numel(), dtype=torch.float32).reshape(
|
|
1892
|
+
inputs[0].shape
|
|
1893
|
+
)
|
|
1894
|
+
|
|
1895
|
+
output = executorch_module(values.numpy())[0]
|
|
1896
|
+
torch.testing.assert_close(output, model(values))
|
|
1897
|
+
|
|
1898
|
+
def test_transposed_inputs_of_every_item_size_are_converted(self):
|
|
1899
|
+
if self.kernel_mode != "portable":
|
|
1900
|
+
self.skipTest("portable input layout compatibility")
|
|
1901
|
+
|
|
1902
|
+
class Double(torch.nn.Module):
|
|
1903
|
+
def forward(self, x):
|
|
1904
|
+
return x + x
|
|
1905
|
+
|
|
1906
|
+
for dtype in (np.int8, np.int16, np.float32, np.int64, np.float64):
|
|
1907
|
+
with self.subTest(dtype=np.dtype(dtype).name):
|
|
1908
|
+
example = torch.from_numpy(np.ones((2, 3), dtype=dtype))
|
|
1909
|
+
exported_program = to_edge(
|
|
1910
|
+
export(Double(), (example,), strict=True)
|
|
1911
|
+
).to_executorch()
|
|
1912
|
+
method = self.load_prog_fn(exported_program.buffer).load_method(
|
|
1913
|
+
"forward"
|
|
1914
|
+
)
|
|
1915
|
+
values = np.arange(6, dtype=dtype).reshape(3, 2).T
|
|
1916
|
+
output = method([values])[0]
|
|
1917
|
+
np.testing.assert_array_equal(np.asarray(output), values + values)
|
|
1918
|
+
|
|
1919
|
+
def test_tensor_subclass_without_storage_is_rejected(self):
|
|
1920
|
+
class Wrapper(torch.Tensor):
|
|
1921
|
+
@staticmethod
|
|
1922
|
+
def __new__(cls, elem):
|
|
1923
|
+
return torch.Tensor._make_wrapper_subclass(
|
|
1924
|
+
cls, elem.shape, dtype=elem.dtype
|
|
1925
|
+
)
|
|
1926
|
+
|
|
1927
|
+
@classmethod
|
|
1928
|
+
def __torch_dispatch__(cls, func, types, args=(), kwargs=None):
|
|
1929
|
+
raise NotImplementedError(func)
|
|
1930
|
+
|
|
1931
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
1932
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1933
|
+
|
|
1934
|
+
with self.assertRaisesRegex(ValueError, "data is not allocated"):
|
|
1935
|
+
executorch_module(Wrapper(inputs[0]))
|
|
1936
|
+
|
|
1937
|
+
def test_multiple_entry(self):
|
|
1938
|
+
program, inputs = create_program(ModuleMulti())
|
|
1939
|
+
executorch_module = self.load_fn(program.buffer)
|
|
1940
|
+
|
|
1941
|
+
executorch_output = executorch_module.forward(inputs)[0]
|
|
1942
|
+
self.assertTrue(torch.allclose(executorch_output, torch.ones(2, 2) * 2))
|
|
1943
|
+
|
|
1944
|
+
executorch_output2 = executorch_module.run_method("forward2", inputs)[0]
|
|
1945
|
+
self.assertTrue(torch.allclose(executorch_output2, torch.ones(2, 2) * 3))
|
|
1946
|
+
|
|
1947
|
+
def test_output_lifespan(self):
|
|
1948
|
+
def lower_function_call():
|
|
1949
|
+
program, inputs = create_program(ModuleMulti())
|
|
1950
|
+
executorch_module = self.load_fn(program.buffer)
|
|
1951
|
+
return executorch_module.forward(inputs)
|
|
1952
|
+
|
|
1953
|
+
outputs = lower_function_call()
|
|
1954
|
+
self.assertTrue(torch.allclose(outputs[0], torch.ones(2, 2) * 2))
|
|
1955
|
+
|
|
1956
|
+
def test_module_callable(self):
|
|
1957
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
1958
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1959
|
+
executorch_output = executorch_module(inputs)[0]
|
|
1960
|
+
expected = inputs[0] + inputs[1]
|
|
1961
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
1962
|
+
|
|
1963
|
+
def test_clone_outputs_false_returns_a_view(self):
|
|
1964
|
+
eager_module = ModuleAddWithAttributes()
|
|
1965
|
+
inputs = eager_module.get_inputs()
|
|
1966
|
+
exported_program = export(eager_module, inputs, strict=True)
|
|
1967
|
+
exec_prog = to_edge(exported_program).to_executorch(
|
|
1968
|
+
config=ExecutorchBackendConfig(emit_mutable_buffer_names=True)
|
|
1969
|
+
)
|
|
1970
|
+
executorch_module = self.load_fn(exec_prog.buffer)
|
|
1971
|
+
|
|
1972
|
+
output = executorch_module(inputs, clone_outputs=False)[0]
|
|
1973
|
+
snapshot = output.clone()
|
|
1974
|
+
executorch_module(inputs)
|
|
1975
|
+
|
|
1976
|
+
self.assertFalse(torch.equal(output, snapshot))
|
|
1977
|
+
|
|
1978
|
+
def test_module_single_input(self):
|
|
1979
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
1980
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
1981
|
+
executorch_output = executorch_module(inputs[0])[0]
|
|
1982
|
+
expected = inputs[0] + inputs[0]
|
|
1983
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
1984
|
+
|
|
1985
|
+
def test_stderr_redirect(self):
|
|
1986
|
+
class RedirectedStderr:
|
|
1987
|
+
def __init__(self):
|
|
1988
|
+
self._stderr = None
|
|
1989
|
+
self._string_io = None
|
|
1990
|
+
|
|
1991
|
+
def __enter__(self):
|
|
1992
|
+
self._stderr = sys.stderr
|
|
1993
|
+
sys.stderr = self._string_io = StringIO()
|
|
1994
|
+
return self
|
|
1995
|
+
|
|
1996
|
+
def __exit__(self, type, value, traceback):
|
|
1997
|
+
sys.stderr = self._stderr
|
|
1998
|
+
|
|
1999
|
+
def __str__(self):
|
|
2000
|
+
return self._string_io.getvalue()
|
|
2001
|
+
|
|
2002
|
+
with RedirectedStderr() as out:
|
|
2003
|
+
try:
|
|
2004
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2005
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2006
|
+
executorch_module.run_method("missing", inputs)
|
|
2007
|
+
self.assertFalse(True) # should be unreachable
|
|
2008
|
+
except Exception:
|
|
2009
|
+
# The runtime's own log, routed to Python's stderr.
|
|
2010
|
+
self.assertIn("No method named 'missing' in program", str(out))
|
|
2011
|
+
|
|
2012
|
+
def test_quantized_ops(self):
|
|
2013
|
+
eager_module = ModuleAdd()
|
|
2014
|
+
|
|
2015
|
+
from executorch.exir import EdgeCompileConfig
|
|
2016
|
+
from executorch.exir.passes.quant_fusion_pass import QuantFusionPass
|
|
2017
|
+
from torch.ao.quantization import get_default_qconfig_mapping
|
|
2018
|
+
from torch.ao.quantization.backend_config.executorch import (
|
|
2019
|
+
get_executorch_backend_config,
|
|
2020
|
+
)
|
|
2021
|
+
from torch.ao.quantization.quantize_fx import (
|
|
2022
|
+
_convert_to_reference_decomposed_fx,
|
|
2023
|
+
prepare_fx,
|
|
2024
|
+
)
|
|
2025
|
+
|
|
2026
|
+
qconfig_mapping = get_default_qconfig_mapping("qnnpack")
|
|
2027
|
+
example_inputs = (
|
|
2028
|
+
torch.ones(1, 5, dtype=torch.float32),
|
|
2029
|
+
torch.ones(1, 5, dtype=torch.float32),
|
|
2030
|
+
)
|
|
2031
|
+
m = prepare_fx(
|
|
2032
|
+
eager_module,
|
|
2033
|
+
qconfig_mapping,
|
|
2034
|
+
example_inputs,
|
|
2035
|
+
backend_config=get_executorch_backend_config(),
|
|
2036
|
+
)
|
|
2037
|
+
m = _convert_to_reference_decomposed_fx(m)
|
|
2038
|
+
config = EdgeCompileConfig(_check_ir_validity=False)
|
|
2039
|
+
m = to_edge(export(m, example_inputs, strict=True), compile_config=config)
|
|
2040
|
+
m = m.transform([QuantFusionPass(_fix_node_meta_val=True)])
|
|
2041
|
+
|
|
2042
|
+
exec_prog = m.to_executorch()
|
|
2043
|
+
|
|
2044
|
+
executorch_module = self.load_fn(exec_prog.buffer)
|
|
2045
|
+
executorch_output = executorch_module.forward(example_inputs)[0]
|
|
2046
|
+
|
|
2047
|
+
expected = example_inputs[0] + example_inputs[1]
|
|
2048
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2049
|
+
|
|
2050
|
+
def test_constant_output_not_memory_planned(self):
|
|
2051
|
+
exported_program, inputs = create_program(
|
|
2052
|
+
ModuleAddConstReturn(),
|
|
2053
|
+
et_config=ExecutorchBackendConfig(
|
|
2054
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_output=False)
|
|
2055
|
+
),
|
|
2056
|
+
)
|
|
2057
|
+
|
|
2058
|
+
exported_program.dump_executorch_program(verbose=True)
|
|
2059
|
+
|
|
2060
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2061
|
+
executorch_output = executorch_module((torch.ones(2, 2),))
|
|
2062
|
+
|
|
2063
|
+
expected = torch.ones(2, 2) + torch.ones(2, 2)
|
|
2064
|
+
self.assertTrue(torch.allclose(expected, executorch_output[0]))
|
|
2065
|
+
self.assertEqual(str(torch.ones(2, 2)), str(executorch_output[1]))
|
|
2066
|
+
|
|
2067
|
+
def test_channels_last(self) -> None:
|
|
2068
|
+
model = ModuleChannelsLast()
|
|
2069
|
+
exported_program, inputs = create_program(model)
|
|
2070
|
+
|
|
2071
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2072
|
+
executorch_output = executorch_module(inputs[0])[0]
|
|
2073
|
+
|
|
2074
|
+
expected = model(inputs[0])
|
|
2075
|
+
self.assertTrue(torch.allclose(expected, executorch_output))
|
|
2076
|
+
|
|
2077
|
+
def test_torch_input_layout_matches_exported_dim_order(self):
|
|
2078
|
+
if self.kernel_mode != "portable":
|
|
2079
|
+
self.skipTest("ATen nonstandard input layouts are deferred to a follow-up")
|
|
2080
|
+
|
|
2081
|
+
class AddInput(ModuleAddSingleInput):
|
|
2082
|
+
def __init__(self, input_tensor):
|
|
2083
|
+
super().__init__()
|
|
2084
|
+
self.input_tensor = input_tensor
|
|
2085
|
+
|
|
2086
|
+
def get_inputs(self):
|
|
2087
|
+
return (self.input_tensor,)
|
|
2088
|
+
|
|
2089
|
+
cases = (
|
|
2090
|
+
((2, 3, 4, 5), torch.channels_last),
|
|
2091
|
+
((2, 1, 3, 4), torch.channels_last),
|
|
2092
|
+
((2, 3, 1, 1), torch.channels_last),
|
|
2093
|
+
((2, 3, 4, 5, 6), torch.channels_last_3d),
|
|
2094
|
+
)
|
|
2095
|
+
for shape, memory_format in cases:
|
|
2096
|
+
input_tensor = torch.arange(torch.Size(shape).numel(), dtype=torch.float32)
|
|
2097
|
+
input_tensor = input_tensor.reshape(shape).to(memory_format=memory_format)
|
|
2098
|
+
# Singleton dimensions can make channels last storage compatible
|
|
2099
|
+
# with a model exported using the default dimension order.
|
|
2100
|
+
export_input = (
|
|
2101
|
+
input_tensor.clone(memory_format=torch.contiguous_format)
|
|
2102
|
+
if input_tensor.is_contiguous()
|
|
2103
|
+
else input_tensor
|
|
2104
|
+
)
|
|
2105
|
+
for planned in (True, False):
|
|
2106
|
+
with self.subTest(shape=shape, planned=planned):
|
|
2107
|
+
program, _ = create_program(
|
|
2108
|
+
AddInput(export_input),
|
|
2109
|
+
et_config=ExecutorchBackendConfig(
|
|
2110
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
2111
|
+
alloc_graph_input=planned
|
|
2112
|
+
)
|
|
2113
|
+
),
|
|
2114
|
+
)
|
|
2115
|
+
expected = input_tensor * 2
|
|
2116
|
+
module = self.load_fn(program.buffer)
|
|
2117
|
+
torch.testing.assert_close(module(input_tensor)[0], expected)
|
|
2118
|
+
|
|
2119
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
2120
|
+
method.set_inputs(input_tensor)
|
|
2121
|
+
method.execute()
|
|
2122
|
+
torch.testing.assert_close(method.get_outputs()[0], expected)
|
|
2123
|
+
|
|
2124
|
+
if shape == (2, 1, 3, 4):
|
|
2125
|
+
strides = list(input_tensor.stride())
|
|
2126
|
+
strides[1] = 77
|
|
2127
|
+
equivalent = input_tensor.as_strided(shape, strides)
|
|
2128
|
+
torch.testing.assert_close(module(equivalent)[0], expected)
|
|
2129
|
+
method.set_inputs(equivalent)
|
|
2130
|
+
method.execute()
|
|
2131
|
+
torch.testing.assert_close(method.get_outputs()[0], expected)
|
|
2132
|
+
|
|
2133
|
+
def test_torch_input_in_another_layout_is_converted(self):
|
|
2134
|
+
if self.kernel_mode != "portable":
|
|
2135
|
+
self.skipTest("portable input layout compatibility")
|
|
2136
|
+
program, inputs = create_program(ModuleChannelsLast())
|
|
2137
|
+
input_tensor = torch.arange(inputs[0].numel(), dtype=torch.float32).reshape(
|
|
2138
|
+
inputs[0].shape
|
|
2139
|
+
)
|
|
2140
|
+
expected = ModuleChannelsLast()(input_tensor)
|
|
2141
|
+
module = self.load_fn(program.buffer)
|
|
2142
|
+
torch.testing.assert_close(module(input_tensor)[0], expected)
|
|
2143
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
2144
|
+
method.set_inputs(input_tensor)
|
|
2145
|
+
method.execute()
|
|
2146
|
+
torch.testing.assert_close(method.get_outputs()[0], expected)
|
|
2147
|
+
|
|
2148
|
+
def test_channels_last_input_into_a_contiguous_method_is_converted(self):
|
|
2149
|
+
if self.kernel_mode != "portable":
|
|
2150
|
+
self.skipTest("portable input layout compatibility")
|
|
2151
|
+
values = torch.arange(2 * 3 * 4 * 4, dtype=torch.float32).reshape(2, 3, 4, 4)
|
|
2152
|
+
method_program = to_edge(
|
|
2153
|
+
export(ModuleAddSingleInput(), (values,), strict=True)
|
|
2154
|
+
).to_executorch()
|
|
2155
|
+
executorch_module = self.load_fn(method_program.buffer)
|
|
2156
|
+
|
|
2157
|
+
channels_last = values.to(memory_format=torch.channels_last)
|
|
2158
|
+
for value in (channels_last, channels_last.numpy(), DLPackOnly(channels_last)):
|
|
2159
|
+
with self.subTest(kind=type(value).__name__):
|
|
2160
|
+
output = executorch_module(value)[0]
|
|
2161
|
+
torch.testing.assert_close(
|
|
2162
|
+
torch.as_tensor(np.asarray(output)), values * 2
|
|
2163
|
+
)
|
|
2164
|
+
|
|
2165
|
+
def test_converted_input_is_a_copy_made_when_passed(self):
|
|
2166
|
+
if self.kernel_mode != "portable":
|
|
2167
|
+
self.skipTest("portable input layout compatibility")
|
|
2168
|
+
exported_program, _ = create_program(
|
|
2169
|
+
ModuleAddSingleInput(),
|
|
2170
|
+
et_config=ExecutorchBackendConfig(
|
|
2171
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
2172
|
+
),
|
|
2173
|
+
)
|
|
2174
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
2175
|
+
transposed = torch.arange(4, dtype=torch.float32).reshape(2, 2).t()
|
|
2176
|
+
expected = transposed * 2
|
|
2177
|
+
method.set_inputs([transposed])
|
|
2178
|
+
# The method reads the converted copy, so the caller can reuse or
|
|
2179
|
+
# resize its own tensor without invalidating the inputs.
|
|
2180
|
+
transposed.resize_(64, 64).fill_(9.0)
|
|
2181
|
+
method.execute()
|
|
2182
|
+
torch.testing.assert_close(method.get_outputs()[0], expected)
|
|
2183
|
+
|
|
2184
|
+
def test_unsupported_dim_order(self) -> None:
|
|
2185
|
+
model = ModuleChannelsLast()
|
|
2186
|
+
exported_program, inputs = create_program(model)
|
|
2187
|
+
inputs = (torch.randn(1, 2, 3, 4, 5).to(memory_format=torch.channels_last_3d),)
|
|
2188
|
+
|
|
2189
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2190
|
+
self.assertRaisesRegex(
|
|
2191
|
+
ValueError, "rank 5.*expects rank 4", executorch_module, inputs[0]
|
|
2192
|
+
)
|
|
2193
|
+
|
|
2194
|
+
def test_channels_last_in_default_out(self) -> None:
|
|
2195
|
+
model = ModuleChannelsLastInDefaultOut()
|
|
2196
|
+
exported_program, inputs = create_program(model)
|
|
2197
|
+
|
|
2198
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2199
|
+
executorch_output = executorch_module(inputs[0])[0]
|
|
2200
|
+
|
|
2201
|
+
expected = model(inputs[0])
|
|
2202
|
+
self.assertTrue(torch.allclose(expected, executorch_output))
|
|
2203
|
+
|
|
2204
|
+
def test_method_meta(self) -> None:
|
|
2205
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2206
|
+
|
|
2207
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2208
|
+
meta = executorch_module.method_meta("forward")
|
|
2209
|
+
|
|
2210
|
+
del executorch_module
|
|
2211
|
+
self.assertEqual(meta.name(), "forward")
|
|
2212
|
+
self.assertEqual(meta.num_inputs(), 2)
|
|
2213
|
+
self.assertEqual(meta.num_outputs(), 1)
|
|
2214
|
+
|
|
2215
|
+
tensor_info = "TensorInfo(sizes=[2, 2], dtype=float32, is_memory_planned=True, nbytes=16, device=cpu)"
|
|
2216
|
+
float_dtype = 6
|
|
2217
|
+
self.assertEqual(
|
|
2218
|
+
str(meta),
|
|
2219
|
+
"MethodMeta(name='forward', num_inputs=2, "
|
|
2220
|
+
f"input_tensor_meta=['{tensor_info}', '{tensor_info}'], "
|
|
2221
|
+
f"num_outputs=1, output_tensor_meta=['{tensor_info}'])",
|
|
2222
|
+
)
|
|
2223
|
+
|
|
2224
|
+
input_tensors = [meta.input_tensor_meta(i) for i in range(2)]
|
|
2225
|
+
output_tensor = meta.output_tensor_meta(0)
|
|
2226
|
+
|
|
2227
|
+
with self.assertRaises(IndexError):
|
|
2228
|
+
meta.input_tensor_meta(2)
|
|
2229
|
+
|
|
2230
|
+
del meta
|
|
2231
|
+
self.assertEqual([t.sizes() for t in input_tensors], [(2, 2), (2, 2)])
|
|
2232
|
+
self.assertEqual([t.dtype() for t in input_tensors], [float_dtype, float_dtype])
|
|
2233
|
+
self.assertEqual(
|
|
2234
|
+
[t.dtype_name() for t in input_tensors], ["float32", "float32"]
|
|
2235
|
+
)
|
|
2236
|
+
self.assertEqual([t.is_memory_planned() for t in input_tensors], [True, True])
|
|
2237
|
+
self.assertEqual([t.nbytes() for t in input_tensors], [16, 16])
|
|
2238
|
+
self.assertEqual(str(input_tensors), f"[{tensor_info}, {tensor_info}]")
|
|
2239
|
+
|
|
2240
|
+
self.assertEqual(output_tensor.sizes(), (2, 2))
|
|
2241
|
+
self.assertEqual(output_tensor.dtype(), float_dtype)
|
|
2242
|
+
self.assertEqual(output_tensor.is_memory_planned(), True)
|
|
2243
|
+
self.assertEqual(output_tensor.nbytes(), 16)
|
|
2244
|
+
self.assertEqual(str(output_tensor), tensor_info)
|
|
2245
|
+
|
|
2246
|
+
def test_bad_name(self) -> None:
|
|
2247
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2248
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2249
|
+
|
|
2250
|
+
with self.assertRaises(RuntimeError):
|
|
2251
|
+
executorch_module.run_method("not_a_real_method", inputs)
|
|
2252
|
+
|
|
2253
|
+
def test_verification_config(self) -> None:
|
|
2254
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2255
|
+
Verification = self.runtime.Verification
|
|
2256
|
+
|
|
2257
|
+
for config in [Verification.Minimal, Verification.InternalConsistency]:
|
|
2258
|
+
executorch_module = self.load_fn(
|
|
2259
|
+
exported_program.buffer,
|
|
2260
|
+
enable_etdump=False,
|
|
2261
|
+
debug_buffer_size=0,
|
|
2262
|
+
program_verification=config,
|
|
2263
|
+
)
|
|
2264
|
+
|
|
2265
|
+
executorch_output = executorch_module.forward(inputs)[0]
|
|
2266
|
+
expected = inputs[0] + inputs[1]
|
|
2267
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2268
|
+
|
|
2269
|
+
def test_unsupported_input_type(self):
|
|
2270
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2271
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
2272
|
+
inputs = ([*inputs],)
|
|
2273
|
+
self.assertRaises(RuntimeError, executorch_module, inputs)
|
|
2274
|
+
|
|
2275
|
+
def test_program_methods_one(self):
|
|
2276
|
+
exported_program, _ = create_program(ModuleAdd())
|
|
2277
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2278
|
+
|
|
2279
|
+
self.assertEqual(executorch_program.num_methods(), 1)
|
|
2280
|
+
self.assertEqual(executorch_program.get_method_name(0), "forward")
|
|
2281
|
+
|
|
2282
|
+
def test_program_methods_multi(self):
|
|
2283
|
+
exported_program, _ = create_program(ModuleMulti())
|
|
2284
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2285
|
+
|
|
2286
|
+
self.assertEqual(executorch_program.num_methods(), 2)
|
|
2287
|
+
self.assertEqual(executorch_program.get_method_name(0), "forward")
|
|
2288
|
+
self.assertEqual(executorch_program.get_method_name(1), "forward2")
|
|
2289
|
+
|
|
2290
|
+
def test_program_method_index_out_of_bounds(self):
|
|
2291
|
+
exported_program, _ = create_program(ModuleMulti())
|
|
2292
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2293
|
+
self.assertRaises(RuntimeError, executorch_program.get_method_name, 2)
|
|
2294
|
+
|
|
2295
|
+
def test_method_e2e(self):
|
|
2296
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2297
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2298
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2299
|
+
executorch_output = executorch_method.call(inputs)[0]
|
|
2300
|
+
expected = inputs[0] + inputs[1]
|
|
2301
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2302
|
+
|
|
2303
|
+
def test_method_output_lifespan(self):
|
|
2304
|
+
def lower_function_call():
|
|
2305
|
+
program, inputs = create_program(ModuleMulti())
|
|
2306
|
+
executorch_program = self.load_prog_fn(program.buffer)
|
|
2307
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2308
|
+
return executorch_method.call(inputs)
|
|
2309
|
+
|
|
2310
|
+
outputs = lower_function_call()
|
|
2311
|
+
self.assertTrue(torch.allclose(outputs[0], torch.ones(2, 2) * 2))
|
|
2312
|
+
|
|
2313
|
+
def test_method_multiple_entry(self):
|
|
2314
|
+
program, inputs = create_program(ModuleMulti())
|
|
2315
|
+
executorch_program = self.load_prog_fn(program.buffer)
|
|
2316
|
+
|
|
2317
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2318
|
+
executorch_output = executorch_method.call(inputs)[0]
|
|
2319
|
+
self.assertTrue(torch.allclose(executorch_output, torch.ones(2, 2) * 2))
|
|
2320
|
+
|
|
2321
|
+
executorch_method2 = executorch_program.load_method("forward2")
|
|
2322
|
+
executorch_output2 = executorch_method2.call(inputs)[0]
|
|
2323
|
+
self.assertTrue(torch.allclose(executorch_output2, torch.ones(2, 2) * 3))
|
|
2324
|
+
|
|
2325
|
+
def test_method_by_parts(self):
|
|
2326
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2327
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2328
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2329
|
+
|
|
2330
|
+
executorch_method.set_inputs(inputs)
|
|
2331
|
+
executorch_method.execute()
|
|
2332
|
+
executorch_output = executorch_method.get_outputs()[0]
|
|
2333
|
+
|
|
2334
|
+
expected = inputs[0] + inputs[1]
|
|
2335
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2336
|
+
|
|
2337
|
+
def test_program_keeps_buffer_alive(self):
|
|
2338
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2339
|
+
program_data = bytes(exported_program.buffer)
|
|
2340
|
+
initial_refcount = sys.getrefcount(program_data)
|
|
2341
|
+
|
|
2342
|
+
program = self.load_prog_fn(program_data)
|
|
2343
|
+
|
|
2344
|
+
self.assertGreater(sys.getrefcount(program_data), initial_refcount)
|
|
2345
|
+
del program_data
|
|
2346
|
+
output = program.load_method("forward")(inputs)[0]
|
|
2347
|
+
self.assertTrue(torch.equal(output, inputs[0] + inputs[1]))
|
|
2348
|
+
|
|
2349
|
+
def test_method_preserves_unplanned_input_that_is_also_an_output(self):
|
|
2350
|
+
class ReturnInputAndSum(torch.nn.Module):
|
|
2351
|
+
def forward(self, x, y):
|
|
2352
|
+
return x, x + y
|
|
2353
|
+
|
|
2354
|
+
def get_methods_to_export(self):
|
|
2355
|
+
return ("forward",)
|
|
2356
|
+
|
|
2357
|
+
def get_inputs(self):
|
|
2358
|
+
return (torch.ones(2, 2), torch.full((2, 2), 2.0))
|
|
2359
|
+
|
|
2360
|
+
exported_program, inputs = create_program(
|
|
2361
|
+
ReturnInputAndSum(),
|
|
2362
|
+
et_config=ExecutorchBackendConfig(
|
|
2363
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
2364
|
+
),
|
|
2365
|
+
)
|
|
2366
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
2367
|
+
|
|
2368
|
+
outputs = method(inputs)
|
|
2369
|
+
|
|
2370
|
+
self.assertTrue(torch.equal(outputs[0], inputs[0]))
|
|
2371
|
+
self.assertTrue(torch.equal(outputs[1], inputs[0] + inputs[1]))
|
|
2372
|
+
|
|
2373
|
+
def test_borrowed_output_does_not_create_method_cycle(self):
|
|
2374
|
+
if self.kernel_mode != "portable":
|
|
2375
|
+
self.skipTest("only portable bindings retain Python tensor owners")
|
|
2376
|
+
for planned_input in (True, False):
|
|
2377
|
+
for planned_output in (True, False):
|
|
2378
|
+
with self.subTest(input=planned_input, output=planned_output):
|
|
2379
|
+
program, inputs = create_program(
|
|
2380
|
+
ModuleAddSingleInput(),
|
|
2381
|
+
et_config=ExecutorchBackendConfig(
|
|
2382
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
2383
|
+
alloc_graph_input=planned_input,
|
|
2384
|
+
alloc_graph_output=planned_output,
|
|
2385
|
+
)
|
|
2386
|
+
),
|
|
2387
|
+
)
|
|
2388
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
2389
|
+
output = method(inputs, clone_outputs=False)[0]
|
|
2390
|
+
method.set_inputs(output)
|
|
2391
|
+
expected = inputs[0] * 2
|
|
2392
|
+
if planned_output:
|
|
2393
|
+
previous_ref = weakref.ref(output)
|
|
2394
|
+
next_output = method(output, clone_outputs=False)[0]
|
|
2395
|
+
method.set_inputs(next_output)
|
|
2396
|
+
del output
|
|
2397
|
+
gc.collect()
|
|
2398
|
+
self.assertIsNone(previous_ref())
|
|
2399
|
+
output = next_output
|
|
2400
|
+
expected *= 2
|
|
2401
|
+
method_ref = weakref.ref(method)
|
|
2402
|
+
del method
|
|
2403
|
+
gc.collect()
|
|
2404
|
+
self.assertIsNone(method_ref())
|
|
2405
|
+
torch.testing.assert_close(output, expected)
|
|
2406
|
+
|
|
2407
|
+
def test_borrowed_output_preserves_replaced_input_storage(self):
|
|
2408
|
+
if self.kernel_mode != "portable":
|
|
2409
|
+
self.skipTest("only portable bindings retain Python tensor owners")
|
|
2410
|
+
|
|
2411
|
+
class Identity(torch.nn.Module):
|
|
2412
|
+
def forward(self, x):
|
|
2413
|
+
return x
|
|
2414
|
+
|
|
2415
|
+
program = to_edge(export(Identity(), (torch.ones(2, 2),))).to_executorch(
|
|
2416
|
+
ExecutorchBackendConfig(
|
|
2417
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
2418
|
+
)
|
|
2419
|
+
)
|
|
2420
|
+
for buffer_input in (True, False):
|
|
2421
|
+
with self.subTest(buffer_input=buffer_input):
|
|
2422
|
+
value = (
|
|
2423
|
+
np.full((2, 2), 3.0, dtype=np.float32)
|
|
2424
|
+
if buffer_input
|
|
2425
|
+
else torch.full((2, 2), 3.0)
|
|
2426
|
+
)
|
|
2427
|
+
value_ref = weakref.ref(value)
|
|
2428
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
2429
|
+
output = method(value, clone_outputs=False)[0]
|
|
2430
|
+
method.set_inputs(np.zeros((2, 2), dtype=np.float32))
|
|
2431
|
+
method_ref = weakref.ref(method)
|
|
2432
|
+
del value, method
|
|
2433
|
+
gc.collect()
|
|
2434
|
+
self.assertIsNone(method_ref())
|
|
2435
|
+
if buffer_input:
|
|
2436
|
+
self.assertIsNotNone(value_ref())
|
|
2437
|
+
torch.testing.assert_close(output, torch.full((2, 2), 3.0))
|
|
2438
|
+
del output
|
|
2439
|
+
gc.collect()
|
|
2440
|
+
self.assertIsNone(value_ref())
|
|
2441
|
+
|
|
2442
|
+
def test_borrowed_external_output_does_not_retain_previous_outputs(self):
|
|
2443
|
+
if self.kernel_mode != "portable":
|
|
2444
|
+
self.skipTest("only portable bindings retain Python tensor owners")
|
|
2445
|
+
|
|
2446
|
+
class Identity(torch.nn.Module):
|
|
2447
|
+
def forward(self, x):
|
|
2448
|
+
return x
|
|
2449
|
+
|
|
2450
|
+
for channels_last in (False, True):
|
|
2451
|
+
with self.subTest(channels_last=channels_last):
|
|
2452
|
+
shape = (2, 3, 4, 5) if channels_last else (2, 2)
|
|
2453
|
+
value = torch.arange(torch.Size(shape).numel() + 4, dtype=torch.float32)
|
|
2454
|
+
value = value[4:].reshape(shape)
|
|
2455
|
+
if channels_last:
|
|
2456
|
+
value = value.to(memory_format=torch.channels_last)
|
|
2457
|
+
value.requires_grad_()
|
|
2458
|
+
expected = value.detach().clone()
|
|
2459
|
+
program = to_edge(export(Identity(), (value,))).to_executorch(
|
|
2460
|
+
ExecutorchBackendConfig(
|
|
2461
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
2462
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
2463
|
+
)
|
|
2464
|
+
)
|
|
2465
|
+
)
|
|
2466
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
2467
|
+
output = method(value, clone_outputs=False)[0]
|
|
2468
|
+
address = value.data_ptr()
|
|
2469
|
+
strides = value.stride()
|
|
2470
|
+
offset = value.storage_offset()
|
|
2471
|
+
for _ in range(32):
|
|
2472
|
+
previous = weakref.ref(output)
|
|
2473
|
+
output = method(output, clone_outputs=False)[0]
|
|
2474
|
+
method.set_inputs(output)
|
|
2475
|
+
gc.collect()
|
|
2476
|
+
self.assertIsNone(previous())
|
|
2477
|
+
self.assertEqual(output.data_ptr(), address)
|
|
2478
|
+
self.assertEqual(output.stride(), strides)
|
|
2479
|
+
self.assertEqual(output.storage_offset(), offset)
|
|
2480
|
+
self.assertFalse(output.requires_grad)
|
|
2481
|
+
del value, method
|
|
2482
|
+
torch.testing.assert_close(output, expected)
|
|
2483
|
+
|
|
2484
|
+
def test_borrowed_result_reuses_backing_owner_through_buffer_views(self):
|
|
2485
|
+
if self.kernel_mode != "portable":
|
|
2486
|
+
self.skipTest("only portable bindings retain Python buffer owners")
|
|
2487
|
+
|
|
2488
|
+
class Identity(torch.nn.Module):
|
|
2489
|
+
def forward(self, x):
|
|
2490
|
+
return x
|
|
2491
|
+
|
|
2492
|
+
program = to_edge(export(Identity(), (torch.ones(2, 2),))).to_executorch(
|
|
2493
|
+
ExecutorchBackendConfig(
|
|
2494
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
2495
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
2496
|
+
)
|
|
2497
|
+
)
|
|
2498
|
+
)
|
|
2499
|
+
script = """
|
|
2500
|
+
import gc
|
|
2501
|
+
import sys
|
|
2502
|
+
import weakref
|
|
2503
|
+
import numpy as np
|
|
2504
|
+
|
|
2505
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
2506
|
+
|
|
2507
|
+
with open(sys.argv[1], "rb") as program_file:
|
|
2508
|
+
data = program_file.read()
|
|
2509
|
+
def readonly_array(value):
|
|
2510
|
+
array = np.asarray(value)
|
|
2511
|
+
array.setflags(write=False)
|
|
2512
|
+
return array
|
|
2513
|
+
for copied_root in (False, True):
|
|
2514
|
+
for wrap in (lambda value: value, np.asarray, memoryview,
|
|
2515
|
+
readonly_array, lambda value: memoryview(value).toreadonly()):
|
|
2516
|
+
method = runtime._load_program_from_buffer(data).load_method("forward")
|
|
2517
|
+
output = method(np.full((2, 2), 3.0, dtype=np.float32),
|
|
2518
|
+
clone_outputs=copied_root)[0]
|
|
2519
|
+
output = method(wrap(output), clone_outputs=False)[0]
|
|
2520
|
+
for _ in range(32):
|
|
2521
|
+
previous = weakref.ref(output)
|
|
2522
|
+
output = method(wrap(output), clone_outputs=False)[0]
|
|
2523
|
+
method.set_inputs(wrap(output))
|
|
2524
|
+
gc.collect()
|
|
2525
|
+
assert previous() is None
|
|
2526
|
+
del method
|
|
2527
|
+
gc.collect()
|
|
2528
|
+
np.testing.assert_array_equal(np.asarray(output), np.full((2, 2), 3.0))
|
|
2529
|
+
"""
|
|
2530
|
+
generic_buffer_script = """
|
|
2531
|
+
import array
|
|
2532
|
+
import gc
|
|
2533
|
+
import importlib.abc
|
|
2534
|
+
import sys
|
|
2535
|
+
import weakref
|
|
2536
|
+
|
|
2537
|
+
class BlockTensorPackages(importlib.abc.MetaPathFinder):
|
|
2538
|
+
def find_spec(self, fullname, path, target=None):
|
|
2539
|
+
if fullname.split(".")[0] in ("numpy", "torch"):
|
|
2540
|
+
raise ModuleNotFoundError(fullname, name=fullname)
|
|
2541
|
+
sys.meta_path.insert(0, BlockTensorPackages())
|
|
2542
|
+
|
|
2543
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
2544
|
+
|
|
2545
|
+
with open(sys.argv[1], "rb") as program_file:
|
|
2546
|
+
data = program_file.read()
|
|
2547
|
+
method = runtime._load_program_from_buffer(data).load_method("forward")
|
|
2548
|
+
value = memoryview(array.array("f", [3.0] * 4)).cast("B").cast("f", (2, 2))
|
|
2549
|
+
output = method(value, clone_outputs=False)[0]
|
|
2550
|
+
for _ in range(32):
|
|
2551
|
+
previous = weakref.ref(output)
|
|
2552
|
+
output = method(output, clone_outputs=False)[0]
|
|
2553
|
+
method.set_inputs(output)
|
|
2554
|
+
gc.collect()
|
|
2555
|
+
assert previous() is None
|
|
2556
|
+
del method, value
|
|
2557
|
+
assert memoryview(output).tolist() == [[3.0, 3.0], [3.0, 3.0]]
|
|
2558
|
+
assert "numpy" not in sys.modules and "torch" not in sys.modules
|
|
2559
|
+
"""
|
|
2560
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
2561
|
+
path = os.path.join(directory, "identity.pte")
|
|
2562
|
+
with open(path, "wb") as program_file:
|
|
2563
|
+
program_file.write(program.buffer)
|
|
2564
|
+
for code in (script, generic_buffer_script):
|
|
2565
|
+
completed = subprocess.run(
|
|
2566
|
+
[
|
|
2567
|
+
sys.executable,
|
|
2568
|
+
"-c",
|
|
2569
|
+
code,
|
|
2570
|
+
path,
|
|
2571
|
+
],
|
|
2572
|
+
env={
|
|
2573
|
+
**os.environ,
|
|
2574
|
+
"EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT": "executorch",
|
|
2575
|
+
},
|
|
2576
|
+
capture_output=True,
|
|
2577
|
+
text=True,
|
|
2578
|
+
timeout=60,
|
|
2579
|
+
)
|
|
2580
|
+
self.assertEqual(completed.returncode, 0, completed.stderr)
|
|
2581
|
+
|
|
2582
|
+
def test_failed_set_inputs_keeps_buffer_storage_alive(self):
|
|
2583
|
+
exported_program, inputs = create_program(
|
|
2584
|
+
ModuleAdd(),
|
|
2585
|
+
et_config=ExecutorchBackendConfig(
|
|
2586
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
2587
|
+
),
|
|
2588
|
+
)
|
|
2589
|
+
program = self.load_prog_fn(exported_program.buffer)
|
|
2590
|
+
method = program.load_method("forward")
|
|
2591
|
+
method.set_inputs([value.numpy() for value in inputs])
|
|
2592
|
+
|
|
2593
|
+
with self.assertRaises(ValueError):
|
|
2594
|
+
method.set_inputs([inputs[0].numpy(), inputs[1].to(torch.int32).numpy()])
|
|
2595
|
+
|
|
2596
|
+
method.execute()
|
|
2597
|
+
output = method.get_outputs()[0]
|
|
2598
|
+
self.assertTrue(torch.allclose(output, inputs[0] + inputs[1]))
|
|
2599
|
+
|
|
2600
|
+
def test_method_rejects_resized_borrowed_input(self):
|
|
2601
|
+
exported_program, inputs = create_program(
|
|
2602
|
+
ModuleAdd(),
|
|
2603
|
+
et_config=ExecutorchBackendConfig(
|
|
2604
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
2605
|
+
),
|
|
2606
|
+
)
|
|
2607
|
+
protocol_inputs = {
|
|
2608
|
+
"torch": [value.clone() for value in inputs],
|
|
2609
|
+
"numpy": [value.numpy().copy() for value in inputs],
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
for protocol, values in protocol_inputs.items():
|
|
2613
|
+
with self.subTest(protocol=protocol):
|
|
2614
|
+
method = self.load_prog_fn(exported_program.buffer).load_method(
|
|
2615
|
+
"forward"
|
|
2616
|
+
)
|
|
2617
|
+
method.set_inputs(values)
|
|
2618
|
+
if protocol == "torch":
|
|
2619
|
+
values[0].resize_(64, 64)
|
|
2620
|
+
else:
|
|
2621
|
+
values[0].resize((64, 64), refcheck=False)
|
|
2622
|
+
|
|
2623
|
+
with self.assertRaisesRegex(
|
|
2624
|
+
ValueError,
|
|
2625
|
+
"Input 0 of method 'forward': its storage changed.*pass it again",
|
|
2626
|
+
):
|
|
2627
|
+
method.execute()
|
|
2628
|
+
|
|
2629
|
+
def test_method_callable(self):
|
|
2630
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2631
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2632
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2633
|
+
executorch_output = executorch_method(inputs)[0]
|
|
2634
|
+
expected = inputs[0] + inputs[1]
|
|
2635
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2636
|
+
|
|
2637
|
+
def test_method_single_input(self):
|
|
2638
|
+
exported_program, inputs = create_program(ModuleAddSingleInput())
|
|
2639
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2640
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2641
|
+
executorch_output = executorch_method(inputs[0])[0]
|
|
2642
|
+
expected = inputs[0] + inputs[0]
|
|
2643
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2644
|
+
|
|
2645
|
+
def test_method_stderr_redirect(self):
|
|
2646
|
+
class RedirectedStderr:
|
|
2647
|
+
def __init__(self):
|
|
2648
|
+
self._stderr = None
|
|
2649
|
+
self._string_io = None
|
|
2650
|
+
|
|
2651
|
+
def __enter__(self):
|
|
2652
|
+
self._stderr = sys.stderr
|
|
2653
|
+
sys.stderr = self._string_io = StringIO()
|
|
2654
|
+
return self
|
|
2655
|
+
|
|
2656
|
+
def __exit__(self, type, value, traceback):
|
|
2657
|
+
sys.stderr = self._stderr
|
|
2658
|
+
|
|
2659
|
+
def __str__(self):
|
|
2660
|
+
return self._string_io.getvalue()
|
|
2661
|
+
|
|
2662
|
+
with RedirectedStderr() as out:
|
|
2663
|
+
try:
|
|
2664
|
+
program, _ = create_program(ModuleAdd())
|
|
2665
|
+
executorch_program = self.load_prog_fn(program.buffer)
|
|
2666
|
+
executorch_program.load_method("missing")
|
|
2667
|
+
self.assertFalse(True) # should be unreachable
|
|
2668
|
+
except Exception:
|
|
2669
|
+
self.assertIn("No method named 'missing' in program", str(out))
|
|
2670
|
+
|
|
2671
|
+
def test_method_quantized_ops(self):
|
|
2672
|
+
eager_module = ModuleAdd()
|
|
2673
|
+
|
|
2674
|
+
from executorch.exir import EdgeCompileConfig
|
|
2675
|
+
from executorch.exir.passes.quant_fusion_pass import QuantFusionPass
|
|
2676
|
+
from torch.ao.quantization import get_default_qconfig_mapping
|
|
2677
|
+
from torch.ao.quantization.backend_config.executorch import (
|
|
2678
|
+
get_executorch_backend_config,
|
|
2679
|
+
)
|
|
2680
|
+
from torch.ao.quantization.quantize_fx import (
|
|
2681
|
+
_convert_to_reference_decomposed_fx,
|
|
2682
|
+
prepare_fx,
|
|
2683
|
+
)
|
|
2684
|
+
|
|
2685
|
+
qconfig_mapping = get_default_qconfig_mapping("qnnpack")
|
|
2686
|
+
example_inputs = (
|
|
2687
|
+
torch.ones(1, 5, dtype=torch.float32),
|
|
2688
|
+
torch.ones(1, 5, dtype=torch.float32),
|
|
2689
|
+
)
|
|
2690
|
+
m = prepare_fx(
|
|
2691
|
+
eager_module,
|
|
2692
|
+
qconfig_mapping,
|
|
2693
|
+
example_inputs,
|
|
2694
|
+
backend_config=get_executorch_backend_config(),
|
|
2695
|
+
)
|
|
2696
|
+
m = _convert_to_reference_decomposed_fx(m)
|
|
2697
|
+
config = EdgeCompileConfig(_check_ir_validity=False)
|
|
2698
|
+
m = to_edge(export(m, example_inputs, strict=True), compile_config=config)
|
|
2699
|
+
m = m.transform([QuantFusionPass(_fix_node_meta_val=True)])
|
|
2700
|
+
|
|
2701
|
+
exec_prog = m.to_executorch()
|
|
2702
|
+
|
|
2703
|
+
executorch_program = self.load_prog_fn(exec_prog.buffer)
|
|
2704
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2705
|
+
executorch_output = executorch_method(example_inputs)[0]
|
|
2706
|
+
|
|
2707
|
+
expected = example_inputs[0] + example_inputs[1]
|
|
2708
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2709
|
+
|
|
2710
|
+
def test_method_constant_output_not_memory_planned(self):
|
|
2711
|
+
exported_program, _ = create_program(
|
|
2712
|
+
ModuleAddConstReturn(),
|
|
2713
|
+
et_config=ExecutorchBackendConfig(
|
|
2714
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_output=False)
|
|
2715
|
+
),
|
|
2716
|
+
)
|
|
2717
|
+
|
|
2718
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2719
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2720
|
+
executorch_output = executorch_method((torch.ones(2, 2),))
|
|
2721
|
+
|
|
2722
|
+
expected = torch.ones(2, 2) + torch.ones(2, 2)
|
|
2723
|
+
self.assertTrue(torch.allclose(expected, executorch_output[0]))
|
|
2724
|
+
self.assertEqual(str(torch.ones(2, 2)), str(executorch_output[1]))
|
|
2725
|
+
|
|
2726
|
+
def test_method_channels_last(self) -> None:
|
|
2727
|
+
model = ModuleChannelsLast()
|
|
2728
|
+
exported_program, inputs = create_program(model)
|
|
2729
|
+
|
|
2730
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2731
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2732
|
+
executorch_output = executorch_method(inputs[0])[0]
|
|
2733
|
+
|
|
2734
|
+
expected = model(inputs[0])
|
|
2735
|
+
self.assertTrue(torch.allclose(expected, executorch_output))
|
|
2736
|
+
|
|
2737
|
+
def test_method_unsupported_dim_order(self) -> None:
|
|
2738
|
+
model = ModuleChannelsLast()
|
|
2739
|
+
exported_program, inputs = create_program(model)
|
|
2740
|
+
inputs = (torch.randn(1, 2, 3, 4, 5).to(memory_format=torch.channels_last_3d),)
|
|
2741
|
+
|
|
2742
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2743
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2744
|
+
self.assertRaisesRegex(
|
|
2745
|
+
ValueError, "rank 5.*expects rank 4", executorch_method, inputs[0]
|
|
2746
|
+
)
|
|
2747
|
+
|
|
2748
|
+
def test_method_channels_last_in_default_out(self) -> None:
|
|
2749
|
+
model = ModuleChannelsLastInDefaultOut()
|
|
2750
|
+
exported_program, inputs = create_program(model)
|
|
2751
|
+
|
|
2752
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2753
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2754
|
+
executorch_output = executorch_method(inputs[0])[0]
|
|
2755
|
+
|
|
2756
|
+
expected = model(inputs[0])
|
|
2757
|
+
self.assertTrue(torch.allclose(expected, executorch_output))
|
|
2758
|
+
|
|
2759
|
+
def test_method_bad_name(self) -> None:
|
|
2760
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2761
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2762
|
+
|
|
2763
|
+
with self.assertRaises(RuntimeError):
|
|
2764
|
+
executorch_program.load_method("not_a_real_method")
|
|
2765
|
+
|
|
2766
|
+
def test_program_verification_config(self) -> None:
|
|
2767
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2768
|
+
Verification = self.runtime.Verification
|
|
2769
|
+
|
|
2770
|
+
for config in [Verification.Minimal, Verification.InternalConsistency]:
|
|
2771
|
+
executorch_program = self.load_prog_fn(
|
|
2772
|
+
exported_program.buffer,
|
|
2773
|
+
enable_etdump=False,
|
|
2774
|
+
debug_buffer_size=0,
|
|
2775
|
+
program_verification=config,
|
|
2776
|
+
)
|
|
2777
|
+
|
|
2778
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2779
|
+
executorch_output = executorch_method(inputs)[0]
|
|
2780
|
+
|
|
2781
|
+
expected = inputs[0] + inputs[1]
|
|
2782
|
+
self.assertEqual(str(expected), str(executorch_output))
|
|
2783
|
+
|
|
2784
|
+
def test_method_unsupported_input_type(self):
|
|
2785
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2786
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2787
|
+
inputs = ([*inputs],)
|
|
2788
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2789
|
+
self.assertRaises(RuntimeError, executorch_method, inputs)
|
|
2790
|
+
|
|
2791
|
+
def test_method_attribute(self):
|
|
2792
|
+
eager_module = ModuleAddWithAttributes()
|
|
2793
|
+
inputs = eager_module.get_inputs()
|
|
2794
|
+
|
|
2795
|
+
exported_program = export(eager_module, inputs, strict=True)
|
|
2796
|
+
exec_prog = to_edge(exported_program).to_executorch(
|
|
2797
|
+
config=ExecutorchBackendConfig(
|
|
2798
|
+
emit_mutable_buffer_names=True,
|
|
2799
|
+
)
|
|
2800
|
+
)
|
|
2801
|
+
|
|
2802
|
+
exec_prog.dump_executorch_program(verbose=True)
|
|
2803
|
+
|
|
2804
|
+
executorch_program = self.load_prog_fn(exec_prog.buffer)
|
|
2805
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2806
|
+
executorch_method(inputs)
|
|
2807
|
+
self.assertEqual(
|
|
2808
|
+
str(executorch_method.get_attribute("state")), str(torch.ones(2, 2))
|
|
2809
|
+
)
|
|
2810
|
+
|
|
2811
|
+
def test_method_attribute_is_a_view(self):
|
|
2812
|
+
eager_module = ModuleAddWithAttributes()
|
|
2813
|
+
inputs = eager_module.get_inputs()
|
|
2814
|
+
exported_program = export(eager_module, inputs, strict=True)
|
|
2815
|
+
exec_prog = to_edge(exported_program).to_executorch(
|
|
2816
|
+
config=ExecutorchBackendConfig(emit_mutable_buffer_names=True)
|
|
2817
|
+
)
|
|
2818
|
+
executorch_method = self.load_prog_fn(exec_prog.buffer).load_method("forward")
|
|
2819
|
+
|
|
2820
|
+
state = executorch_method.get_attribute("state")
|
|
2821
|
+
executorch_method(inputs)
|
|
2822
|
+
|
|
2823
|
+
self.assertTrue(torch.equal(state, torch.ones(2, 2)))
|
|
2824
|
+
|
|
2825
|
+
def test_program_method_meta(self) -> None:
|
|
2826
|
+
eager_module = ModuleAddWithAttributes()
|
|
2827
|
+
inputs = eager_module.get_inputs()
|
|
2828
|
+
|
|
2829
|
+
exported_program = export(eager_module, inputs, strict=True)
|
|
2830
|
+
exec_prog = to_edge(exported_program).to_executorch(
|
|
2831
|
+
config=ExecutorchBackendConfig(
|
|
2832
|
+
emit_mutable_buffer_names=True,
|
|
2833
|
+
)
|
|
2834
|
+
)
|
|
2835
|
+
|
|
2836
|
+
exec_prog.dump_executorch_program(verbose=True)
|
|
2837
|
+
|
|
2838
|
+
executorch_program = self.load_prog_fn(exec_prog.buffer)
|
|
2839
|
+
|
|
2840
|
+
meta = executorch_program.method_meta("forward")
|
|
2841
|
+
|
|
2842
|
+
del executorch_program
|
|
2843
|
+
self.assertEqual(meta.name(), "forward")
|
|
2844
|
+
self.assertEqual(meta.num_inputs(), 2)
|
|
2845
|
+
self.assertEqual(meta.num_outputs(), 1)
|
|
2846
|
+
self.assertEqual(meta.num_attributes(), 1)
|
|
2847
|
+
|
|
2848
|
+
tensor_info = "TensorInfo(sizes=[2, 2], dtype=float32, is_memory_planned=True, nbytes=16, device=cpu)"
|
|
2849
|
+
|
|
2850
|
+
float_dtype = 6
|
|
2851
|
+
self.assertEqual(
|
|
2852
|
+
str(meta),
|
|
2853
|
+
"MethodMeta(name='forward', num_inputs=2, "
|
|
2854
|
+
f"input_tensor_meta=['{tensor_info}', '{tensor_info}'], "
|
|
2855
|
+
f"num_outputs=1, output_tensor_meta=['{tensor_info}'])",
|
|
2856
|
+
)
|
|
2857
|
+
|
|
2858
|
+
input_tensors = [meta.input_tensor_meta(i) for i in range(2)]
|
|
2859
|
+
output_tensor = meta.output_tensor_meta(0)
|
|
2860
|
+
attribute_tensor = meta.attribute_tensor_meta(0)
|
|
2861
|
+
|
|
2862
|
+
with self.assertRaises(IndexError):
|
|
2863
|
+
meta.input_tensor_meta(2)
|
|
2864
|
+
|
|
2865
|
+
with self.assertRaises(IndexError):
|
|
2866
|
+
meta.attribute_tensor_meta(1)
|
|
2867
|
+
|
|
2868
|
+
del meta
|
|
2869
|
+
self.assertEqual([t.sizes() for t in input_tensors], [(2, 2), (2, 2)])
|
|
2870
|
+
self.assertEqual([t.dtype() for t in input_tensors], [float_dtype, float_dtype])
|
|
2871
|
+
self.assertEqual([t.is_memory_planned() for t in input_tensors], [True, True])
|
|
2872
|
+
self.assertEqual([t.nbytes() for t in input_tensors], [16, 16])
|
|
2873
|
+
self.assertEqual(str(input_tensors), f"[{tensor_info}, {tensor_info}]")
|
|
2874
|
+
|
|
2875
|
+
self.assertEqual(output_tensor.sizes(), (2, 2))
|
|
2876
|
+
self.assertEqual(output_tensor.dtype(), float_dtype)
|
|
2877
|
+
self.assertEqual(output_tensor.is_memory_planned(), True)
|
|
2878
|
+
self.assertEqual(output_tensor.nbytes(), 16)
|
|
2879
|
+
self.assertEqual(str(output_tensor), tensor_info)
|
|
2880
|
+
|
|
2881
|
+
self.assertEqual(attribute_tensor.sizes(), (2, 2))
|
|
2882
|
+
self.assertEqual(attribute_tensor.dtype(), float_dtype)
|
|
2883
|
+
self.assertEqual(attribute_tensor.is_memory_planned(), True)
|
|
2884
|
+
self.assertEqual(attribute_tensor.nbytes(), 16)
|
|
2885
|
+
self.assertEqual(str(attribute_tensor), tensor_info)
|
|
2886
|
+
|
|
2887
|
+
def test_method_method_meta(self) -> None:
|
|
2888
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
2889
|
+
|
|
2890
|
+
executorch_program = self.load_prog_fn(exported_program.buffer)
|
|
2891
|
+
executorch_method = executorch_program.load_method("forward")
|
|
2892
|
+
meta = executorch_method.method_meta()
|
|
2893
|
+
|
|
2894
|
+
del executorch_program
|
|
2895
|
+
del executorch_method
|
|
2896
|
+
self.assertEqual(meta.name(), "forward")
|
|
2897
|
+
self.assertEqual(meta.num_inputs(), 2)
|
|
2898
|
+
self.assertEqual(meta.num_outputs(), 1)
|
|
2899
|
+
|
|
2900
|
+
tensor_info = "TensorInfo(sizes=[2, 2], dtype=float32, is_memory_planned=True, nbytes=16, device=cpu)"
|
|
2901
|
+
float_dtype = 6
|
|
2902
|
+
self.assertEqual(
|
|
2903
|
+
str(meta),
|
|
2904
|
+
"MethodMeta(name='forward', num_inputs=2, "
|
|
2905
|
+
f"input_tensor_meta=['{tensor_info}', '{tensor_info}'], "
|
|
2906
|
+
f"num_outputs=1, output_tensor_meta=['{tensor_info}'])",
|
|
2907
|
+
)
|
|
2908
|
+
|
|
2909
|
+
input_tensors = [meta.input_tensor_meta(i) for i in range(2)]
|
|
2910
|
+
output_tensor = meta.output_tensor_meta(0)
|
|
2911
|
+
|
|
2912
|
+
with self.assertRaises(IndexError):
|
|
2913
|
+
meta.input_tensor_meta(2)
|
|
2914
|
+
|
|
2915
|
+
del meta
|
|
2916
|
+
self.assertEqual([t.sizes() for t in input_tensors], [(2, 2), (2, 2)])
|
|
2917
|
+
self.assertEqual([t.dtype() for t in input_tensors], [float_dtype, float_dtype])
|
|
2918
|
+
self.assertEqual([t.is_memory_planned() for t in input_tensors], [True, True])
|
|
2919
|
+
self.assertEqual([t.nbytes() for t in input_tensors], [16, 16])
|
|
2920
|
+
self.assertEqual(str(input_tensors), f"[{tensor_info}, {tensor_info}]")
|
|
2921
|
+
|
|
2922
|
+
self.assertEqual(output_tensor.sizes(), (2, 2))
|
|
2923
|
+
self.assertEqual(output_tensor.dtype(), float_dtype)
|
|
2924
|
+
self.assertEqual(output_tensor.is_memory_planned(), True)
|
|
2925
|
+
self.assertEqual(output_tensor.nbytes(), 16)
|
|
2926
|
+
self.assertEqual(str(output_tensor), tensor_info)
|
|
2927
|
+
|
|
2928
|
+
def test_constant_attribute_is_never_writable(self):
|
|
2929
|
+
# A constant from the data file can sit in read-only pages, so a write
|
|
2930
|
+
# through a borrowed view would crash the process.
|
|
2931
|
+
if self.kernel_mode != "portable":
|
|
2932
|
+
self.skipTest("only portable bindings return borrowed attributes")
|
|
2933
|
+
eager_module = ModuleLinear()
|
|
2934
|
+
program = to_edge(
|
|
2935
|
+
export(eager_module, eager_module.get_inputs(), strict=True)
|
|
2936
|
+
).to_executorch(ExecutorchBackendConfig(external_constants=True))
|
|
2937
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
2938
|
+
pte_path = os.path.join(directory, "linear.pte")
|
|
2939
|
+
ptd_path = os.path.join(directory, "linear.ptd")
|
|
2940
|
+
with open(pte_path, "wb") as file:
|
|
2941
|
+
file.write(program.buffer)
|
|
2942
|
+
with open(ptd_path, "wb") as file:
|
|
2943
|
+
file.write(bytes(program._tensor_data["_default_external_constant"]))
|
|
2944
|
+
method = self.runtime._load_program(
|
|
2945
|
+
pte_path, data_path=ptd_path
|
|
2946
|
+
).load_method("forward")
|
|
2947
|
+
weight = method.get_attribute("linear.weight")
|
|
2948
|
+
expected = eager_module.linear.weight.detach()
|
|
2949
|
+
if isinstance(weight, torch.Tensor):
|
|
2950
|
+
# A torch tensor cannot be read-only, so it is a copy.
|
|
2951
|
+
self.assertNotEqual(
|
|
2952
|
+
weight.data_ptr(), method.get_attribute("linear.weight").data_ptr()
|
|
2953
|
+
)
|
|
2954
|
+
torch.testing.assert_close(weight, expected)
|
|
2955
|
+
else:
|
|
2956
|
+
self.assertTrue(memoryview(weight).readonly)
|
|
2957
|
+
self.assertFalse(np.asarray(weight).flags.writeable)
|
|
2958
|
+
np.testing.assert_array_equal(np.asarray(weight), expected.numpy())
|
|
2959
|
+
# The method maps the data file, and Windows cannot delete a mapped
|
|
2960
|
+
# file, so drop it before the directory goes away.
|
|
2961
|
+
del weight, method
|
|
2962
|
+
gc.collect()
|
|
2963
|
+
# torch ignores the DLPack read-only flag, so a DLPack export must be
|
|
2964
|
+
# a copy that it can write. Checked in ExecuTorchResult output mode.
|
|
2965
|
+
script = """
|
|
2966
|
+
import sys
|
|
2967
|
+
|
|
2968
|
+
import numpy as np
|
|
2969
|
+
import torch
|
|
2970
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
2971
|
+
|
|
2972
|
+
method = runtime._load_program(sys.argv[1], data_path=sys.argv[2]).load_method(
|
|
2973
|
+
"forward"
|
|
2974
|
+
)
|
|
2975
|
+
weight = method.get_attribute("linear.weight")
|
|
2976
|
+
assert isinstance(weight, runtime.ExecuTorchResult)
|
|
2977
|
+
before = np.asarray(weight).copy()
|
|
2978
|
+
torch.from_dlpack(weight).add_(1)
|
|
2979
|
+
assert (np.asarray(weight) == before).all()
|
|
2980
|
+
print("the constant was not written")
|
|
2981
|
+
"""
|
|
2982
|
+
completed = subprocess.run(
|
|
2983
|
+
[sys.executable, "-c", script, pte_path, ptd_path],
|
|
2984
|
+
env=dict(os.environ, EXECUTORCH_PYBINDINGS_TENSOR_OUTPUT="executorch"),
|
|
2985
|
+
capture_output=True,
|
|
2986
|
+
text=True,
|
|
2987
|
+
timeout=120,
|
|
2988
|
+
)
|
|
2989
|
+
self.assertEqual(
|
|
2990
|
+
completed.returncode,
|
|
2991
|
+
0,
|
|
2992
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
2993
|
+
)
|
|
2994
|
+
self.assertIn("the constant was not written", completed.stdout)
|
|
2995
|
+
|
|
2996
|
+
def test_method_keeps_its_event_tracer_alive(self):
|
|
2997
|
+
# The program is dropped right away, while its method keeps running.
|
|
2998
|
+
# glibc's MALLOC_PERTURB_ overwrites freed memory, so a method still
|
|
2999
|
+
# pointing at a freed tracer crashes instead of passing by luck.
|
|
3000
|
+
if self.kernel_mode != "portable" or not sys.platform.startswith("linux"):
|
|
3001
|
+
self.skipTest("needs the portable bindings and glibc")
|
|
3002
|
+
script = """
|
|
3003
|
+
import gc
|
|
3004
|
+
import sys
|
|
3005
|
+
|
|
3006
|
+
import torch
|
|
3007
|
+
from executorch.extension.pybindings import portable_lib as runtime
|
|
3008
|
+
|
|
3009
|
+
with open(sys.argv[1], "rb") as source:
|
|
3010
|
+
data = source.read()
|
|
3011
|
+
method = runtime._load_program_from_buffer(
|
|
3012
|
+
data, enable_etdump=True, debug_buffer_size=1 << 16
|
|
3013
|
+
).load_method("forward")
|
|
3014
|
+
gc.collect()
|
|
3015
|
+
junk = [bytearray(256) for _ in range(20000)]
|
|
3016
|
+
for _ in range(5):
|
|
3017
|
+
method([torch.ones(2, 2), torch.ones(2, 2)])
|
|
3018
|
+
print("ran after its program was dropped")
|
|
3019
|
+
"""
|
|
3020
|
+
exported_program, _ = create_program(ModuleAdd())
|
|
3021
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
3022
|
+
path = os.path.join(directory, "add.pte")
|
|
3023
|
+
with open(path, "wb") as file:
|
|
3024
|
+
file.write(exported_program.buffer)
|
|
3025
|
+
completed = subprocess.run(
|
|
3026
|
+
[sys.executable, "-c", script, path],
|
|
3027
|
+
env=dict(os.environ, MALLOC_PERTURB_="165"),
|
|
3028
|
+
capture_output=True,
|
|
3029
|
+
text=True,
|
|
3030
|
+
timeout=120,
|
|
3031
|
+
)
|
|
3032
|
+
self.assertEqual(
|
|
3033
|
+
completed.returncode,
|
|
3034
|
+
0,
|
|
3035
|
+
f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}",
|
|
3036
|
+
)
|
|
3037
|
+
self.assertIn("ran after its program was dropped", completed.stdout)
|
|
3038
|
+
|
|
3039
|
+
def test_program_data_separation(self) -> None:
|
|
3040
|
+
eager_module = ModuleLinear()
|
|
3041
|
+
inputs = eager_module.get_inputs()
|
|
3042
|
+
exported_program = export(eager_module, inputs, strict=True)
|
|
3043
|
+
exec_program = to_edge(exported_program).to_executorch(
|
|
3044
|
+
config=ExecutorchBackendConfig(
|
|
3045
|
+
# Move all tensor data to '_default_external_constant' file.
|
|
3046
|
+
external_constants=True,
|
|
3047
|
+
)
|
|
3048
|
+
)
|
|
3049
|
+
program_buffer = exec_program.buffer
|
|
3050
|
+
assert len(exec_program._tensor_data) == 1
|
|
3051
|
+
data_buffer = bytes(exec_program._tensor_data.pop("_default_external_constant"))
|
|
3052
|
+
|
|
3053
|
+
import os
|
|
3054
|
+
import tempfile
|
|
3055
|
+
|
|
3056
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
3057
|
+
pte_file = os.path.join(tmpdir, "linear.pte")
|
|
3058
|
+
with open(pte_file, "wb") as f:
|
|
3059
|
+
f.write(program_buffer)
|
|
3060
|
+
ptd_file = os.path.join(tmpdir, "linear.ptd")
|
|
3061
|
+
with open(ptd_file, "wb") as ptd:
|
|
3062
|
+
ptd.write(data_buffer)
|
|
3063
|
+
expected = eager_module(inputs[0])
|
|
3064
|
+
# Test 1: File-based loading with external data file
|
|
3065
|
+
executorch_module_file = self.runtime._load_for_executorch(
|
|
3066
|
+
pte_file, ptd_file
|
|
3067
|
+
)
|
|
3068
|
+
executorch_output_file = executorch_module_file.forward(inputs)[0]
|
|
3069
|
+
self.assertTrue(torch.allclose(expected, executorch_output_file))
|
|
3070
|
+
|
|
3071
|
+
# Test 2: Buffer-based loading with external data buffer
|
|
3072
|
+
executorch_module_buffer = self.load_fn(program_buffer, data_buffer)
|
|
3073
|
+
executorch_output_buffer = executorch_module_buffer.forward(inputs)[0]
|
|
3074
|
+
self.assertTrue(torch.allclose(expected, executorch_output_buffer))
|
|
3075
|
+
|
|
3076
|
+
# Test 3: Buffer-based loading without external data file (should fail or work differently)
|
|
3077
|
+
# This should fail because the program expects external data
|
|
3078
|
+
executorch_module_no_data = self.load_fn(program_buffer)
|
|
3079
|
+
with self.assertRaises(RuntimeError):
|
|
3080
|
+
executorch_module_no_data.forward(inputs)
|
|
3081
|
+
|
|
3082
|
+
# Test 4: Test with invalid data buffer (should fail)
|
|
3083
|
+
invalid_bytes = b"invalid bytes"
|
|
3084
|
+
executorch_module_invalid_data = self.load_fn(program_buffer, invalid_bytes)
|
|
3085
|
+
with self.assertRaises(RuntimeError):
|
|
3086
|
+
executorch_module_invalid_data.forward(inputs)
|
|
3087
|
+
|
|
3088
|
+
# Test 5: Test bundled program loading with external data
|
|
3089
|
+
# First create a bundled program with external constants
|
|
3090
|
+
from executorch.devtools.bundled_program.config import (
|
|
3091
|
+
MethodTestCase,
|
|
3092
|
+
MethodTestSuite,
|
|
3093
|
+
)
|
|
3094
|
+
from executorch.devtools.bundled_program.core import BundledProgram
|
|
3095
|
+
from executorch.devtools.bundled_program.serialize import (
|
|
3096
|
+
serialize_from_bundled_program_to_flatbuffer,
|
|
3097
|
+
)
|
|
3098
|
+
|
|
3099
|
+
method_test_suites = [
|
|
3100
|
+
MethodTestSuite(
|
|
3101
|
+
method_name="forward",
|
|
3102
|
+
test_cases=[
|
|
3103
|
+
MethodTestCase(
|
|
3104
|
+
inputs=input,
|
|
3105
|
+
expected_outputs=expected,
|
|
3106
|
+
)
|
|
3107
|
+
for input in inputs
|
|
3108
|
+
],
|
|
3109
|
+
),
|
|
3110
|
+
]
|
|
3111
|
+
bundled_program = BundledProgram(exec_program, method_test_suites)
|
|
3112
|
+
bundled_buffer = serialize_from_bundled_program_to_flatbuffer(bundled_program)
|
|
3113
|
+
bundled_module = self.runtime._load_bundled_program_from_buffer(bundled_buffer)
|
|
3114
|
+
|
|
3115
|
+
# Load module from bundled program with external data buffer
|
|
3116
|
+
executorch_module_bundled = (
|
|
3117
|
+
self.runtime._load_for_executorch_from_bundled_program(
|
|
3118
|
+
bundled_module, data_buffer
|
|
3119
|
+
)
|
|
3120
|
+
)
|
|
3121
|
+
executorch_output_bundled = executorch_module_bundled.forward(inputs)[0]
|
|
3122
|
+
self.assertTrue(torch.allclose(expected, executorch_output_bundled))
|
|
3123
|
+
|
|
3124
|
+
# Load module from bundled program with external data file
|
|
3125
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
3126
|
+
ptd_file = os.path.join(tmpdir, "linear.ptd")
|
|
3127
|
+
with open(ptd_file, "wb") as ptd:
|
|
3128
|
+
ptd.write(data_buffer)
|
|
3129
|
+
executorch_module_bundled_data_file = (
|
|
3130
|
+
self.runtime._load_for_executorch_from_bundled_program(
|
|
3131
|
+
bundled_module, ptd_file
|
|
3132
|
+
)
|
|
3133
|
+
)
|
|
3134
|
+
executorch_output_bundled_data_file = (
|
|
3135
|
+
executorch_module_bundled_data_file.forward(inputs)[0]
|
|
3136
|
+
)
|
|
3137
|
+
self.assertTrue(
|
|
3138
|
+
torch.allclose(expected, executorch_output_bundled_data_file)
|
|
3139
|
+
)
|
|
3140
|
+
|
|
3141
|
+
# Test 6: Bundled program without external data should fail
|
|
3142
|
+
executorch_module_bundled_no_data = (
|
|
3143
|
+
self.runtime._load_for_executorch_from_bundled_program(bundled_module)
|
|
3144
|
+
)
|
|
3145
|
+
with self.assertRaises(RuntimeError):
|
|
3146
|
+
executorch_module_bundled_no_data.forward(inputs)
|
|
3147
|
+
|
|
3148
|
+
def test_method_rejects_input_on_unrepresentable_device(self):
|
|
3149
|
+
# The conversion used to label every input CPU, so an input whose memory
|
|
3150
|
+
# the host cannot read was described as host memory, and the failure
|
|
3151
|
+
# surfaced later as a crash instead of an error naming the input.
|
|
3152
|
+
if self.kernel_mode != "portable":
|
|
3153
|
+
self.skipTest("only the portable build converts the input tensor")
|
|
3154
|
+
|
|
3155
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3156
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3157
|
+
|
|
3158
|
+
with self.assertRaises(RuntimeError) as caught:
|
|
3159
|
+
executorch_module.forward([inputs[0].to("meta"), inputs[1]])
|
|
3160
|
+
message = str(caught.exception)
|
|
3161
|
+
self.assertIn("Input 0 of method 'forward'", message)
|
|
3162
|
+
# Asserts the device is named as Python spells it, since an uppercased or
|
|
3163
|
+
# index-less name would not match what the caller passed.
|
|
3164
|
+
self.assertIn("is on device meta", message)
|
|
3165
|
+
self.assertIn("only CPU and CUDA tensors", message)
|
|
3166
|
+
|
|
3167
|
+
def test_rejects_unexpected_empty_shape(self):
|
|
3168
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3169
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3170
|
+
empty_view = torch.empty(5, 7)[0:0, 0:2]
|
|
3171
|
+
|
|
3172
|
+
with self.assertRaises(RuntimeError):
|
|
3173
|
+
executorch_module.forward([empty_view, inputs[1]])
|
|
3174
|
+
|
|
3175
|
+
def test_empty_input_does_not_require_device_memory(self):
|
|
3176
|
+
if self.kernel_mode != "portable":
|
|
3177
|
+
self.skipTest("only the portable build converts the input tensor")
|
|
3178
|
+
|
|
3179
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3180
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3181
|
+
|
|
3182
|
+
with self.assertRaises(RuntimeError) as caught:
|
|
3183
|
+
executorch_module.forward([torch.empty(0, 2, device="meta"), inputs[1]])
|
|
3184
|
+
|
|
3185
|
+
self.assertNotIn("is on device meta", str(caught.exception))
|
|
3186
|
+
|
|
3187
|
+
def test_method_accepts_a_cpu_input_after_the_device_check(self):
|
|
3188
|
+
# The rejection tests above pass for a change that throws on every input, so this
|
|
3189
|
+
# asserts the other half: an ordinary CPU input still converts and runs. Without it
|
|
3190
|
+
# the pair does not distinguish "rejects what it cannot represent" from "rejects
|
|
3191
|
+
# everything".
|
|
3192
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3193
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3194
|
+
|
|
3195
|
+
executorch_output = executorch_module.forward(inputs)[0]
|
|
3196
|
+
|
|
3197
|
+
self.assertTrue(
|
|
3198
|
+
torch.allclose(executorch_output, inputs[0] + inputs[1]),
|
|
3199
|
+
"a CPU input must still reach the method and produce the same result",
|
|
3200
|
+
)
|
|
3201
|
+
|
|
3202
|
+
def test_method_refuses_inputs_left_by_a_failed_set_inputs(self):
|
|
3203
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3204
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3205
|
+
method.set_inputs(inputs)
|
|
3206
|
+
method.execute()
|
|
3207
|
+
# Input 0 installs, then a number where input 1 takes a tensor fails,
|
|
3208
|
+
# leaving a mix of two calls.
|
|
3209
|
+
with self.assertRaises(RuntimeError):
|
|
3210
|
+
method.set_inputs([torch.full((2, 2), 5.0), 1.0])
|
|
3211
|
+
|
|
3212
|
+
with self.assertRaisesRegex(RuntimeError, "set_inputs.*again"):
|
|
3213
|
+
method.execute()
|
|
3214
|
+
# Outputs can alias inputs, so the last results are no longer readable.
|
|
3215
|
+
with self.assertRaisesRegex(RuntimeError, "no outputs"):
|
|
3216
|
+
method.get_outputs()
|
|
3217
|
+
|
|
3218
|
+
method.set_inputs([torch.full((2, 2), 5.0), torch.full((2, 2), 5.0)])
|
|
3219
|
+
method.execute()
|
|
3220
|
+
torch.testing.assert_close(method.get_outputs()[0], torch.full((2, 2), 10.0))
|
|
3221
|
+
|
|
3222
|
+
def test_failed_calls_keep_none_of_their_inputs(self):
|
|
3223
|
+
exported_program, inputs = create_program(
|
|
3224
|
+
ModuleAdd(),
|
|
3225
|
+
et_config=ExecutorchBackendConfig(
|
|
3226
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
3227
|
+
),
|
|
3228
|
+
)
|
|
3229
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3230
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3231
|
+
method.set_inputs(inputs)
|
|
3232
|
+
executorch_module.forward(inputs)
|
|
3233
|
+
|
|
3234
|
+
# A failed call may leave its first input installed, but nothing reads
|
|
3235
|
+
# it before every input is passed again, so none of it is kept.
|
|
3236
|
+
for name, call in (
|
|
3237
|
+
("method", lambda values: method.set_inputs(values)),
|
|
3238
|
+
("module", lambda values: executorch_module.forward(values)),
|
|
3239
|
+
):
|
|
3240
|
+
with self.subTest(executor=name):
|
|
3241
|
+
references = []
|
|
3242
|
+
for _ in range(10):
|
|
3243
|
+
installed = torch.full((2, 2), 5.0)
|
|
3244
|
+
references.append(weakref.ref(installed))
|
|
3245
|
+
with self.assertRaises(RuntimeError):
|
|
3246
|
+
call([installed, 1.0])
|
|
3247
|
+
del installed
|
|
3248
|
+
gc.collect()
|
|
3249
|
+
self.assertEqual(
|
|
3250
|
+
sum(reference() is not None for reference in references), 0
|
|
3251
|
+
)
|
|
3252
|
+
|
|
3253
|
+
def test_method_keeps_its_inputs_after_a_wrong_input_count(self):
|
|
3254
|
+
exported_program, inputs = create_program(
|
|
3255
|
+
ModuleAdd(),
|
|
3256
|
+
et_config=ExecutorchBackendConfig(
|
|
3257
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
3258
|
+
),
|
|
3259
|
+
)
|
|
3260
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3261
|
+
method.set_inputs(inputs)
|
|
3262
|
+
rejected = torch.full((2, 2), 5.0)
|
|
3263
|
+
rejected_ref = weakref.ref(rejected)
|
|
3264
|
+
with self.assertRaisesRegex(RuntimeError, "takes 2 inputs"):
|
|
3265
|
+
method.set_inputs([rejected])
|
|
3266
|
+
# A rejected call installs nothing, so it must not keep its tensor or
|
|
3267
|
+
# tie the method to that tensor's storage.
|
|
3268
|
+
rejected.resize_(1 << 16)
|
|
3269
|
+
del rejected
|
|
3270
|
+
gc.collect()
|
|
3271
|
+
self.assertIsNone(rejected_ref())
|
|
3272
|
+
|
|
3273
|
+
method.execute()
|
|
3274
|
+
torch.testing.assert_close(method.get_outputs()[0], inputs[0] + inputs[1])
|
|
3275
|
+
|
|
3276
|
+
def test_method_has_no_outputs_without_a_successful_execute(self):
|
|
3277
|
+
exported_program, inputs = create_program(
|
|
3278
|
+
ModuleAdd(),
|
|
3279
|
+
et_config=ExecutorchBackendConfig(
|
|
3280
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
3281
|
+
),
|
|
3282
|
+
)
|
|
3283
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3284
|
+
with self.assertRaisesRegex(RuntimeError, "no outputs"):
|
|
3285
|
+
method.get_outputs()
|
|
3286
|
+
|
|
3287
|
+
method.set_inputs(inputs)
|
|
3288
|
+
method.execute()
|
|
3289
|
+
torch.testing.assert_close(method.get_outputs()[0], inputs[0] + inputs[1])
|
|
3290
|
+
|
|
3291
|
+
moved = inputs[0].clone()
|
|
3292
|
+
method.set_inputs([moved, inputs[1]])
|
|
3293
|
+
moved.resize_(64, 64)
|
|
3294
|
+
with self.assertRaises(ValueError):
|
|
3295
|
+
method.execute()
|
|
3296
|
+
with self.assertRaisesRegex(RuntimeError, "no outputs"):
|
|
3297
|
+
method.get_outputs()
|
|
3298
|
+
|
|
3299
|
+
def test_execute_before_any_inputs_is_refused(self):
|
|
3300
|
+
exported_program, inputs = create_program(
|
|
3301
|
+
ModuleAdd(),
|
|
3302
|
+
et_config=ExecutorchBackendConfig(
|
|
3303
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
3304
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
3305
|
+
)
|
|
3306
|
+
),
|
|
3307
|
+
)
|
|
3308
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3309
|
+
# Without the check this reads inputs that were never set.
|
|
3310
|
+
with self.assertRaisesRegex(RuntimeError, "no inputs yet"):
|
|
3311
|
+
method.execute()
|
|
3312
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3313
|
+
with self.assertRaisesRegex(RuntimeError, "Pass every input"):
|
|
3314
|
+
executorch_module.plan_execute("forward")
|
|
3315
|
+
with self.assertRaisesRegex(RuntimeError, "Pass every input"):
|
|
3316
|
+
executorch_module.forward([inputs[0]])
|
|
3317
|
+
|
|
3318
|
+
method.set_inputs(inputs)
|
|
3319
|
+
method.execute()
|
|
3320
|
+
torch.testing.assert_close(method.get_outputs()[0], inputs[0] + inputs[1])
|
|
3321
|
+
|
|
3322
|
+
def test_method_without_inputs_executes_without_set_inputs(self):
|
|
3323
|
+
class Constant(torch.nn.Module):
|
|
3324
|
+
def __init__(self):
|
|
3325
|
+
super().__init__()
|
|
3326
|
+
self.register_buffer("value", torch.full((2,), 3.0))
|
|
3327
|
+
|
|
3328
|
+
def forward(self):
|
|
3329
|
+
return self.value + 1
|
|
3330
|
+
|
|
3331
|
+
exported_program = to_edge(export(Constant(), (), strict=True)).to_executorch()
|
|
3332
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3333
|
+
method.execute()
|
|
3334
|
+
torch.testing.assert_close(
|
|
3335
|
+
torch.as_tensor(np.asarray(method.get_outputs()[0])),
|
|
3336
|
+
torch.full((2,), 4.0),
|
|
3337
|
+
)
|
|
3338
|
+
|
|
3339
|
+
def test_new_inputs_hide_outputs_that_alias_an_input(self):
|
|
3340
|
+
class Identity(torch.nn.Module):
|
|
3341
|
+
def forward(self, x):
|
|
3342
|
+
return x
|
|
3343
|
+
|
|
3344
|
+
exported_program = to_edge(
|
|
3345
|
+
export(Identity(), (torch.ones(2, 2),), strict=True)
|
|
3346
|
+
).to_executorch(
|
|
3347
|
+
config=ExecutorchBackendConfig(
|
|
3348
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
3349
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
3350
|
+
)
|
|
3351
|
+
)
|
|
3352
|
+
)
|
|
3353
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3354
|
+
method.set_inputs([torch.full((2, 2), 3.0)])
|
|
3355
|
+
method.execute()
|
|
3356
|
+
torch.testing.assert_close(method.get_outputs()[0], torch.full((2, 2), 3.0))
|
|
3357
|
+
|
|
3358
|
+
# The output is the input itself, so it would now show 9 without any
|
|
3359
|
+
# execute().
|
|
3360
|
+
method.set_inputs([torch.full((2, 2), 9.0)])
|
|
3361
|
+
with self.assertRaisesRegex(RuntimeError, "no outputs"):
|
|
3362
|
+
method.get_outputs()
|
|
3363
|
+
|
|
3364
|
+
def test_new_inputs_hide_outputs_planned_over_an_input(self):
|
|
3365
|
+
class ReluTwice(torch.nn.Module):
|
|
3366
|
+
def forward(self, x):
|
|
3367
|
+
return x.relu() * 2
|
|
3368
|
+
|
|
3369
|
+
# Default memory planning puts this output in the input's bytes.
|
|
3370
|
+
exported_program = to_edge(
|
|
3371
|
+
export(ReluTwice(), (torch.ones(4),), strict=True)
|
|
3372
|
+
).to_executorch()
|
|
3373
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3374
|
+
method.set_inputs([torch.ones(4)])
|
|
3375
|
+
method.execute()
|
|
3376
|
+
torch.testing.assert_close(method.get_outputs()[0], torch.full((4,), 2.0))
|
|
3377
|
+
|
|
3378
|
+
method.set_inputs([torch.full((4,), 5.0)])
|
|
3379
|
+
with self.assertRaisesRegex(RuntimeError, "no outputs"):
|
|
3380
|
+
method.get_outputs()
|
|
3381
|
+
|
|
3382
|
+
def test_module_refuses_inputs_left_by_a_failed_call(self):
|
|
3383
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3384
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3385
|
+
executorch_module.forward(inputs)
|
|
3386
|
+
with self.assertRaises(RuntimeError):
|
|
3387
|
+
executorch_module.forward([torch.full((2, 2), 5.0), 1.0])
|
|
3388
|
+
|
|
3389
|
+
with self.assertRaisesRegex(RuntimeError, "Pass every input"):
|
|
3390
|
+
executorch_module.plan_execute("forward")
|
|
3391
|
+
|
|
3392
|
+
executorch_module.forward([torch.full((2, 2), 5.0), torch.full((2, 2), 5.0)])
|
|
3393
|
+
torch.testing.assert_close(
|
|
3394
|
+
executorch_module.plan_execute("forward")[0], torch.full((2, 2), 10.0)
|
|
3395
|
+
)
|
|
3396
|
+
|
|
3397
|
+
def test_module_refuses_extra_inputs_before_installing_any(self):
|
|
3398
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3399
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3400
|
+
executorch_module.forward(inputs)
|
|
3401
|
+
fives = torch.full((2, 2), 5.0)
|
|
3402
|
+
with self.assertRaisesRegex(RuntimeError, "takes 2 inputs, but got 3"):
|
|
3403
|
+
executorch_module.forward([fives, fives, 1.0])
|
|
3404
|
+
|
|
3405
|
+
# Nothing was installed, so the previous inputs are still whole.
|
|
3406
|
+
torch.testing.assert_close(
|
|
3407
|
+
executorch_module.plan_execute("forward")[0], inputs[0] + inputs[1]
|
|
3408
|
+
)
|
|
3409
|
+
|
|
3410
|
+
def test_module_reuses_inputs_after_a_failure_while_running(self):
|
|
3411
|
+
class Take(torch.nn.Module):
|
|
3412
|
+
def forward(self, x, index):
|
|
3413
|
+
return x.index_select(0, index)
|
|
3414
|
+
|
|
3415
|
+
exported_program = to_edge(
|
|
3416
|
+
export(Take(), (torch.ones(4, 2), torch.tensor([1])), strict=True)
|
|
3417
|
+
).to_executorch()
|
|
3418
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3419
|
+
values = torch.arange(8, dtype=torch.float32).reshape(4, 2)
|
|
3420
|
+
# Every input installs, then the out-of-range index fails the run. The
|
|
3421
|
+
# installed inputs are one call's, so reusing them is not refused.
|
|
3422
|
+
with self.assertRaisesRegex(RuntimeError, "Failed to execute"):
|
|
3423
|
+
executorch_module.forward([values, torch.tensor([9])])
|
|
3424
|
+
with self.assertRaisesRegex(RuntimeError, "Failed to execute"):
|
|
3425
|
+
executorch_module.plan_execute("forward")
|
|
3426
|
+
output = executorch_module.forward([values, torch.tensor([3])])
|
|
3427
|
+
torch.testing.assert_close(torch.as_tensor(np.asarray(output[0])), values[3:4])
|
|
3428
|
+
|
|
3429
|
+
def test_planned_inputs_are_installed_again_at_each_run(self):
|
|
3430
|
+
class Accumulate(torch.nn.Module):
|
|
3431
|
+
def forward(self, x, state):
|
|
3432
|
+
state.add_(x)
|
|
3433
|
+
return state * 1
|
|
3434
|
+
|
|
3435
|
+
x = torch.arange(4, dtype=torch.float32) + 1
|
|
3436
|
+
state = torch.zeros(4)
|
|
3437
|
+
# Each run writes the planned copy of state, so the next run has to
|
|
3438
|
+
# install the caller's tensor again.
|
|
3439
|
+
program = to_edge(export(Accumulate(), (x, state), strict=True)).to_executorch()
|
|
3440
|
+
|
|
3441
|
+
method = self.load_prog_fn(program.buffer).load_method("forward")
|
|
3442
|
+
method.set_inputs([x, state])
|
|
3443
|
+
for _ in range(2):
|
|
3444
|
+
method.execute()
|
|
3445
|
+
torch.testing.assert_close(method.get_outputs()[0], x)
|
|
3446
|
+
|
|
3447
|
+
module = self.load_fn(program.buffer)
|
|
3448
|
+
torch.testing.assert_close(module.forward([x, state])[0], x)
|
|
3449
|
+
torch.testing.assert_close(module.forward([x])[0], x)
|
|
3450
|
+
|
|
3451
|
+
# The inputs are read again, so a change to their storage is refused.
|
|
3452
|
+
state.resize_(64, 64)
|
|
3453
|
+
with self.assertRaisesRegex(ValueError, "storage changed"):
|
|
3454
|
+
method.execute()
|
|
3455
|
+
with self.assertRaisesRegex(ValueError, "storage changed"):
|
|
3456
|
+
module.forward([x])
|
|
3457
|
+
|
|
3458
|
+
def test_module_keeps_a_temporary_program_buffer_alive(self):
|
|
3459
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3460
|
+
data = bytes(bytearray(exported_program.buffer))
|
|
3461
|
+
references = sys.getrefcount(data)
|
|
3462
|
+
|
|
3463
|
+
executorch_module = self.load_fn(data)
|
|
3464
|
+
|
|
3465
|
+
# The loader reads the program lazily from these bytes, so the module
|
|
3466
|
+
# must own them rather than rely on the caller keeping them alive.
|
|
3467
|
+
self.assertGreater(sys.getrefcount(data), references)
|
|
3468
|
+
del data
|
|
3469
|
+
gc.collect()
|
|
3470
|
+
executorch_output = executorch_module.forward(inputs)[0]
|
|
3471
|
+
torch.testing.assert_close(executorch_output, inputs[0] + inputs[1])
|
|
3472
|
+
|
|
3473
|
+
def test_bundled_program_module_keeps_its_bytes_alive(self):
|
|
3474
|
+
from executorch.devtools.bundled_program.config import (
|
|
3475
|
+
MethodTestCase,
|
|
3476
|
+
MethodTestSuite,
|
|
3477
|
+
)
|
|
3478
|
+
from executorch.devtools.bundled_program.core import BundledProgram
|
|
3479
|
+
from executorch.devtools.bundled_program.serialize import (
|
|
3480
|
+
serialize_from_bundled_program_to_flatbuffer,
|
|
3481
|
+
)
|
|
3482
|
+
|
|
3483
|
+
model = ModuleLinear()
|
|
3484
|
+
inputs = (torch.ones(2, 3),)
|
|
3485
|
+
program = to_edge(export(model, inputs, strict=True)).to_executorch(
|
|
3486
|
+
config=ExecutorchBackendConfig(external_constants=True)
|
|
3487
|
+
)
|
|
3488
|
+
data = bytes(program._tensor_data.pop("_default_external_constant"))
|
|
3489
|
+
suite = MethodTestSuite(
|
|
3490
|
+
method_name="forward",
|
|
3491
|
+
test_cases=[
|
|
3492
|
+
MethodTestCase(inputs=inputs, expected_outputs=(model(*inputs),))
|
|
3493
|
+
],
|
|
3494
|
+
)
|
|
3495
|
+
bundle = serialize_from_bundled_program_to_flatbuffer(
|
|
3496
|
+
BundledProgram(program, [suite])
|
|
3497
|
+
)
|
|
3498
|
+
bundle_bytes = bytes(bytearray(bundle))
|
|
3499
|
+
bundle_references = sys.getrefcount(bundle_bytes)
|
|
3500
|
+
bundled_module = self.runtime._load_bundled_program_from_buffer(bundle_bytes)
|
|
3501
|
+
data_copy = bytes(bytearray(data))
|
|
3502
|
+
references = sys.getrefcount(data_copy)
|
|
3503
|
+
bundle_references_with_module = sys.getrefcount(bundle_bytes)
|
|
3504
|
+
|
|
3505
|
+
executorch_module = self.runtime._load_for_executorch_from_bundled_program(
|
|
3506
|
+
bundled_module, data_copy
|
|
3507
|
+
)
|
|
3508
|
+
|
|
3509
|
+
# Both the program, inside the bundle, and the data map are read
|
|
3510
|
+
# lazily, so the module must own them.
|
|
3511
|
+
self.assertGreater(sys.getrefcount(data_copy), references)
|
|
3512
|
+
self.assertGreater(sys.getrefcount(bundle_bytes), bundle_references_with_module)
|
|
3513
|
+
self.assertGreater(bundle_references_with_module, bundle_references)
|
|
3514
|
+
del bundled_module, data_copy, bundle_bytes
|
|
3515
|
+
gc.collect()
|
|
3516
|
+
torch.testing.assert_close(executorch_module.forward(inputs)[0], model(*inputs))
|
|
3517
|
+
|
|
3518
|
+
# The overload that reads the data map from a file owns the bundle too.
|
|
3519
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
3520
|
+
data_path = os.path.join(directory, "model.ptd")
|
|
3521
|
+
with open(data_path, "wb") as file:
|
|
3522
|
+
file.write(data)
|
|
3523
|
+
bundle_bytes = bytes(bytearray(bundle))
|
|
3524
|
+
bundled_module = self.runtime._load_bundled_program_from_buffer(
|
|
3525
|
+
bundle_bytes
|
|
3526
|
+
)
|
|
3527
|
+
references = sys.getrefcount(bundle_bytes)
|
|
3528
|
+
executorch_module = self.runtime._load_for_executorch_from_bundled_program(
|
|
3529
|
+
bundled_module, data_path
|
|
3530
|
+
)
|
|
3531
|
+
self.assertGreater(sys.getrefcount(bundle_bytes), references)
|
|
3532
|
+
del bundled_module, bundle_bytes
|
|
3533
|
+
gc.collect()
|
|
3534
|
+
torch.testing.assert_close(
|
|
3535
|
+
executorch_module.forward(inputs)[0], model(*inputs)
|
|
3536
|
+
)
|
|
3537
|
+
# Windows cannot delete the data file while the module maps it.
|
|
3538
|
+
del executorch_module
|
|
3539
|
+
gc.collect()
|
|
3540
|
+
|
|
3541
|
+
def test_numbers_for_number_inputs(self):
|
|
3542
|
+
class AddInt(torch.nn.Module):
|
|
3543
|
+
def forward(self, x, n: int):
|
|
3544
|
+
return x + n
|
|
3545
|
+
|
|
3546
|
+
class Choose(torch.nn.Module):
|
|
3547
|
+
def forward(self, x, flag: bool):
|
|
3548
|
+
return x + 1 if flag else x - 1
|
|
3549
|
+
|
|
3550
|
+
class NotNumpy:
|
|
3551
|
+
ndim = 0
|
|
3552
|
+
|
|
3553
|
+
def item(self):
|
|
3554
|
+
return 1.0
|
|
3555
|
+
|
|
3556
|
+
# Each case: model, example, accepted values, expected, wrong kinds.
|
|
3557
|
+
cases = (
|
|
3558
|
+
(
|
|
3559
|
+
ModuleAddScalar(),
|
|
3560
|
+
1.0,
|
|
3561
|
+
(1, np.int64(1), np.float32(1.0), np.array(1.0)),
|
|
3562
|
+
2.0,
|
|
3563
|
+
(True, np.bool_(True)),
|
|
3564
|
+
),
|
|
3565
|
+
(
|
|
3566
|
+
AddInt(),
|
|
3567
|
+
1,
|
|
3568
|
+
(np.int64(1), np.array(1)),
|
|
3569
|
+
2.0,
|
|
3570
|
+
(True, np.bool_(True), 1.5, np.float32(1.0)),
|
|
3571
|
+
),
|
|
3572
|
+
(Choose(), True, (np.bool_(True), np.array(True)), 2.0, (1, 1.0)),
|
|
3573
|
+
)
|
|
3574
|
+
for model, example, values, expected, wrong_kinds in cases:
|
|
3575
|
+
exported_program = to_edge(
|
|
3576
|
+
export(model, (torch.ones(2), example), strict=True)
|
|
3577
|
+
).to_executorch()
|
|
3578
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3579
|
+
method = self.load_prog_fn(exported_program.buffer).load_method("forward")
|
|
3580
|
+
for executor in (executorch_module, method):
|
|
3581
|
+
for value in values:
|
|
3582
|
+
with self.subTest(
|
|
3583
|
+
model=type(model).__name__,
|
|
3584
|
+
executor=type(executor).__name__,
|
|
3585
|
+
value=repr(value),
|
|
3586
|
+
):
|
|
3587
|
+
output = executor([torch.ones(2), value])[0]
|
|
3588
|
+
torch.testing.assert_close(
|
|
3589
|
+
torch.as_tensor(np.asarray(output)),
|
|
3590
|
+
torch.full((2,), expected),
|
|
3591
|
+
)
|
|
3592
|
+
for wrong in (
|
|
3593
|
+
np.array([1.0, 2.0]),
|
|
3594
|
+
NotNumpy(),
|
|
3595
|
+
torch.tensor(1.0),
|
|
3596
|
+
*wrong_kinds,
|
|
3597
|
+
):
|
|
3598
|
+
with self.subTest(
|
|
3599
|
+
model=type(model).__name__,
|
|
3600
|
+
executor=type(executor).__name__,
|
|
3601
|
+
wrong=repr(wrong),
|
|
3602
|
+
):
|
|
3603
|
+
with self.assertRaisesRegex(
|
|
3604
|
+
RuntimeError, "of method 'forward'"
|
|
3605
|
+
):
|
|
3606
|
+
executor([torch.ones(2), wrong])
|
|
3607
|
+
|
|
3608
|
+
def test_buffer_formats_with_native_byte_order_prefix(self):
|
|
3609
|
+
exported_program, _ = create_program(ModuleAddSingleInput())
|
|
3610
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3611
|
+
values = np.arange(4, dtype=np.float32)
|
|
3612
|
+
foreign = ">" if sys.byteorder == "little" else "<"
|
|
3613
|
+
|
|
3614
|
+
# Pass each object itself: converting through NumPy would drop the
|
|
3615
|
+
# explicit prefix under test.
|
|
3616
|
+
for value in (
|
|
3617
|
+
(ctypes.c_float * 2 * 2)((0.0, 1.0), (2.0, 3.0)),
|
|
3618
|
+
memoryview(values.tobytes()).cast("B").cast("@f", (2, 2)),
|
|
3619
|
+
):
|
|
3620
|
+
with self.subTest(format=memoryview(value).format):
|
|
3621
|
+
output = executorch_module(value)[0]
|
|
3622
|
+
np.testing.assert_array_equal(
|
|
3623
|
+
np.asarray(output).reshape(-1), values * 2
|
|
3624
|
+
)
|
|
3625
|
+
|
|
3626
|
+
with self.assertRaisesRegex(
|
|
3627
|
+
BufferError, "Input 0 of method 'forward': .*byte order"
|
|
3628
|
+
):
|
|
3629
|
+
executorch_module(np.ones((2, 2), dtype=f"{foreign}f4"))
|
|
3630
|
+
|
|
3631
|
+
def test_ctypes_integer_buffers(self):
|
|
3632
|
+
class Double(torch.nn.Module):
|
|
3633
|
+
def forward(self, x):
|
|
3634
|
+
return x * 2
|
|
3635
|
+
|
|
3636
|
+
exported_program = to_edge(
|
|
3637
|
+
export(Double(), (torch.ones(4, dtype=torch.int64),), strict=True)
|
|
3638
|
+
).to_executorch()
|
|
3639
|
+
executorch_module = self.load_fn(exported_program.buffer)
|
|
3640
|
+
|
|
3641
|
+
# ctypes spells the byte order out, for example "<q".
|
|
3642
|
+
output = executorch_module((ctypes.c_int64 * 4)(1, 2, 3, 4))[0]
|
|
3643
|
+
|
|
3644
|
+
np.testing.assert_array_equal(np.asarray(output), np.array([2, 4, 6, 8]))
|
|
3645
|
+
|
|
3646
|
+
def test_program_method_rejects_input_on_unrepresentable_device(self):
|
|
3647
|
+
# The other conversion site, reached through a loaded program rather than a
|
|
3648
|
+
# module. It got the same treatment, and without this it had no test: before
|
|
3649
|
+
# the change this path aborted the process rather than raising.
|
|
3650
|
+
if self.kernel_mode != "portable":
|
|
3651
|
+
self.skipTest("only the portable build converts the input tensor")
|
|
3652
|
+
|
|
3653
|
+
exported_program, inputs = create_program(ModuleAdd())
|
|
3654
|
+
program = self.load_prog_fn(exported_program.buffer)
|
|
3655
|
+
method = program.load_method("forward")
|
|
3656
|
+
|
|
3657
|
+
with self.assertRaises(RuntimeError) as caught:
|
|
3658
|
+
method.set_inputs([inputs[0].to("meta"), inputs[1]])
|
|
3659
|
+
message = str(caught.exception)
|
|
3660
|
+
self.assertIn("Input 0 of method 'forward'", message)
|
|
3661
|
+
self.assertIn("is on device meta", message)
|
|
3662
|
+
self.assertIn("only CPU and CUDA tensors", message)
|
|
3663
|
+
|
|
3664
|
+
def test_program_loads_when_one_method_is_device_planned(self):
|
|
3665
|
+
# Linking the CUDA backend registers a CUDA allocator at static init, and the
|
|
3666
|
+
# registry has no way to drop one, so there the device load would succeed with
|
|
3667
|
+
# or without the fix and this test could not tell them apart.
|
|
3668
|
+
if "CudaBackend" in self.runtime._get_registered_backend_names():
|
|
3669
|
+
self.skipTest("a registered CUDA allocator satisfies the device load")
|
|
3670
|
+
|
|
3671
|
+
exported_program, inputs = create_program(
|
|
3672
|
+
ModuleMulti(),
|
|
3673
|
+
et_config=ExecutorchBackendConfig(enable_non_cpu_memory_planning=True),
|
|
3674
|
+
partitioner={"forward2": DeviceAwarePartitioner()},
|
|
3675
|
+
)
|
|
3676
|
+
|
|
3677
|
+
# Without this the test would quietly become a second copy of
|
|
3678
|
+
# test_method_multiple_entry if the planner stopped tagging devices.
|
|
3679
|
+
planned_devices = {
|
|
3680
|
+
plan.name: [
|
|
3681
|
+
buffer.device_type for buffer in (plan.non_const_buffer_device or [])
|
|
3682
|
+
]
|
|
3683
|
+
for plan in exported_program.executorch_program.execution_plan
|
|
3684
|
+
}
|
|
3685
|
+
self.assertIn(DeviceType.CUDA, planned_devices["forward2"])
|
|
3686
|
+
self.assertNotIn(DeviceType.CUDA, planned_devices["forward"])
|
|
3687
|
+
|
|
3688
|
+
program = self.load_prog_fn(exported_program.buffer)
|
|
3689
|
+
self.assertEqual(program.num_methods(), 2)
|
|
3690
|
+
|
|
3691
|
+
method = program.load_method("forward")
|
|
3692
|
+
self.assertTrue(torch.allclose(method.call(inputs)[0], torch.ones(2, 2) * 2))
|
|
3693
|
+
|
|
3694
|
+
# Asking for device memory at all is what this asserts. Before the fix the
|
|
3695
|
+
# loader put every planned buffer in host memory, so the device-planned method
|
|
3696
|
+
# never asked and simply loaded. Now it asks, and with no device allocator
|
|
3697
|
+
# registered the request is refused.
|
|
3698
|
+
with self.assertRaises(RuntimeError) as caught:
|
|
3699
|
+
program.load_method("forward2")
|
|
3700
|
+
self.assertIn("on device", str(caught.exception))
|
|
3701
|
+
|
|
3702
|
+
# A failed load must leave the method that already loaded usable.
|
|
3703
|
+
self.assertTrue(torch.allclose(method.call(inputs)[0], torch.ones(2, 2) * 2))
|
|
3704
|
+
|
|
3705
|
+
def test_unplanned_device_output_is_device_memory(self):
|
|
3706
|
+
# A program exported with alloc_graph_output=False leaves its outputs to the caller, and a
|
|
3707
|
+
# device-resident one tags them for the device, so the bindings supply that memory. They
|
|
3708
|
+
# used to supply host memory, which the CUDA backend rejects (InvalidArgument) and which a
|
|
3709
|
+
# delegate without that check writes into, failing later wherever the GPU cannot read
|
|
3710
|
+
# pageable host memory. This checks that the output buffer is real device memory.
|
|
3711
|
+
if "CudaBackend" not in self.runtime._get_registered_backend_names():
|
|
3712
|
+
self.skipTest("needs a build with the CUDA backend linked in")
|
|
3713
|
+
if not torch.cuda.is_available():
|
|
3714
|
+
self.skipTest("needs a visible CUDA device")
|
|
3715
|
+
|
|
3716
|
+
from executorch.backends.cuda.cuda_partitioner import CudaPartitioner
|
|
3717
|
+
from executorch.exir import to_edge_transform_and_lower
|
|
3718
|
+
from executorch.exir.backend.compile_spec_schema import CompileSpec
|
|
3719
|
+
from executorch.exir.passes.memory_planning_pass import MemoryPlanningPass
|
|
3720
|
+
from executorch.exir.passes.propagate_device_pass import PropagateDeviceConfig
|
|
3721
|
+
from executorch.runtime import Runtime
|
|
3722
|
+
|
|
3723
|
+
class Delegated(torch.nn.Module):
|
|
3724
|
+
def forward(self, x, y):
|
|
3725
|
+
return (x + y) * 2.0
|
|
3726
|
+
|
|
3727
|
+
inputs = (torch.ones(4, 4), torch.ones(4, 4))
|
|
3728
|
+
edge = to_edge_transform_and_lower(
|
|
3729
|
+
{"forward": export(Delegated(), inputs, strict=True)},
|
|
3730
|
+
partitioner={
|
|
3731
|
+
"forward": [CudaPartitioner([CompileSpec("method_name", b"forward")])]
|
|
3732
|
+
},
|
|
3733
|
+
)
|
|
3734
|
+
exported_program = edge.to_executorch(
|
|
3735
|
+
config=ExecutorchBackendConfig(
|
|
3736
|
+
propagate_device_config=PropagateDeviceConfig(
|
|
3737
|
+
skip_h2d_for_method_inputs=True, skip_d2h_for_method_outputs=True
|
|
3738
|
+
),
|
|
3739
|
+
enable_non_cpu_memory_planning=True,
|
|
3740
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
3741
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
3742
|
+
),
|
|
3743
|
+
)
|
|
3744
|
+
)
|
|
3745
|
+
# Without this the test would quietly stop covering the unplanned path if the planner
|
|
3746
|
+
# started placing these outputs: a planned device arena is device memory too, so the
|
|
3747
|
+
# pointer check below would still pass.
|
|
3748
|
+
plan = exported_program.executorch_program.execution_plan[0]
|
|
3749
|
+
for index in plan.outputs:
|
|
3750
|
+
output_tensor = plan.values[index].val
|
|
3751
|
+
self.assertIsNone(output_tensor.allocation_info)
|
|
3752
|
+
self.assertEqual(
|
|
3753
|
+
output_tensor.extra_tensor_info.device_type, DeviceType.CUDA
|
|
3754
|
+
)
|
|
3755
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
3756
|
+
pte_path = os.path.join(directory, "program.pte")
|
|
3757
|
+
with open(pte_path, "wb") as pte_file:
|
|
3758
|
+
exported_program.write_to_file(pte_file)
|
|
3759
|
+
data_names = sorted(exported_program._tensor_data or {})
|
|
3760
|
+
exported_program.write_tensor_data_to_file(directory)
|
|
3761
|
+
data_path = (
|
|
3762
|
+
os.path.join(directory, data_names[0] + ".ptd") if data_names else None
|
|
3763
|
+
)
|
|
3764
|
+
method = (
|
|
3765
|
+
Runtime.get()
|
|
3766
|
+
.load_program(pte_path, data_path=data_path)
|
|
3767
|
+
.load_method("forward")
|
|
3768
|
+
)
|
|
3769
|
+
cuda_inputs = [tensor.cuda() for tensor in inputs]
|
|
3770
|
+
output = method._method(cuda_inputs, clone_outputs=False)[0]
|
|
3771
|
+
# Ask the driver what the uncloned output points at, not the tensor's device tag,
|
|
3772
|
+
# which says cuda either way. CU_POINTER_ATTRIBUTE_MEMORY_TYPE is 2 and
|
|
3773
|
+
# CU_MEMORYTYPE_DEVICE is 2. The driver does not know a pageable host pointer at
|
|
3774
|
+
# all, and returns an error for it.
|
|
3775
|
+
memory_type = ctypes.c_uint(0)
|
|
3776
|
+
status = ctypes.CDLL("libcuda.so.1").cuPointerGetAttribute(
|
|
3777
|
+
ctypes.byref(memory_type), 2, ctypes.c_uint64(output.data_ptr())
|
|
3778
|
+
)
|
|
3779
|
+
self.assertEqual((status, memory_type.value), (0, 2))
|
|
3780
|
+
torch.testing.assert_close(
|
|
3781
|
+
method.execute(cuda_inputs)[0].cpu(), torch.full((4, 4), 4.0)
|
|
3782
|
+
)
|
|
3783
|
+
|
|
3784
|
+
def test_cuda_torch_tensor_interchange_without_aten(self):
|
|
3785
|
+
if self.kernel_mode != "portable":
|
|
3786
|
+
self.skipTest("only portable bindings use the Python Torch adapter")
|
|
3787
|
+
if not torch.cuda.is_available():
|
|
3788
|
+
self.skipTest("needs a visible CUDA device")
|
|
3789
|
+
|
|
3790
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
3791
|
+
from executorch.exir.schema import ExtraTensorInfo, Tensor
|
|
3792
|
+
|
|
3793
|
+
class Identity(torch.nn.Module):
|
|
3794
|
+
def forward(self, x):
|
|
3795
|
+
return x
|
|
3796
|
+
|
|
3797
|
+
device_indices = sorted({0, torch.cuda.device_count() - 1})
|
|
3798
|
+
for device_index in device_indices:
|
|
3799
|
+
for dtype in (torch.float32, torch.float16, torch.bfloat16):
|
|
3800
|
+
for empty in (True, False):
|
|
3801
|
+
shape = (0, 2, 3, 4) if empty else (2, 3, 4, 5)
|
|
3802
|
+
input_tensor = torch.arange(
|
|
3803
|
+
torch.Size(shape).numel() + 5,
|
|
3804
|
+
device=f"cuda:{device_index}",
|
|
3805
|
+
dtype=dtype,
|
|
3806
|
+
)[5:].reshape(shape)
|
|
3807
|
+
for memory_format in (torch.contiguous_format, torch.channels_last):
|
|
3808
|
+
with self.subTest(
|
|
3809
|
+
device=device_index,
|
|
3810
|
+
dtype=dtype,
|
|
3811
|
+
empty=empty,
|
|
3812
|
+
memory_format=memory_format,
|
|
3813
|
+
):
|
|
3814
|
+
value = (
|
|
3815
|
+
input_tensor
|
|
3816
|
+
if memory_format == torch.contiguous_format
|
|
3817
|
+
else input_tensor.to(memory_format=memory_format)
|
|
3818
|
+
)
|
|
3819
|
+
program = to_edge(
|
|
3820
|
+
export(Identity(), (value.cpu(),))
|
|
3821
|
+
).to_executorch(
|
|
3822
|
+
ExecutorchBackendConfig(
|
|
3823
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
3824
|
+
alloc_graph_input=False,
|
|
3825
|
+
alloc_graph_output=False,
|
|
3826
|
+
)
|
|
3827
|
+
)
|
|
3828
|
+
)
|
|
3829
|
+
# This identity has no kernels or device arenas, so
|
|
3830
|
+
# interchange does not require a linked CUDA backend.
|
|
3831
|
+
schema = program.executorch_program
|
|
3832
|
+
for entry in schema.execution_plan[0].values:
|
|
3833
|
+
if isinstance(entry.val, Tensor):
|
|
3834
|
+
entry.val.extra_tensor_info = ExtraTensorInfo(
|
|
3835
|
+
device_type=DeviceType.CUDA,
|
|
3836
|
+
device_index=device_index,
|
|
3837
|
+
)
|
|
3838
|
+
data = bytes(serialize_pte_binary(PTEFile(schema)))
|
|
3839
|
+
module = self.load_fn(data)
|
|
3840
|
+
method = self.load_prog_fn(data).load_method("forward")
|
|
3841
|
+
for executor in (module, method):
|
|
3842
|
+
borrowed = executor(value, clone_outputs=False)[0]
|
|
3843
|
+
self.assertEqual(borrowed.device, value.device)
|
|
3844
|
+
self.assertEqual(borrowed.dtype, value.dtype)
|
|
3845
|
+
self.assertEqual(borrowed.stride(), value.stride())
|
|
3846
|
+
self.assertEqual(borrowed.data_ptr(), value.data_ptr())
|
|
3847
|
+
cloned = executor(value)[0]
|
|
3848
|
+
self.assertEqual(cloned.device, value.device)
|
|
3849
|
+
self.assertEqual(cloned.stride(), value.stride())
|
|
3850
|
+
torch.testing.assert_close(cloned.cpu(), value.cpu())
|
|
3851
|
+
if not empty:
|
|
3852
|
+
self.assertNotEqual(
|
|
3853
|
+
cloned.data_ptr(), value.data_ptr()
|
|
3854
|
+
)
|
|
3855
|
+
|
|
3856
|
+
def test_method_meta_reports_tensor_devices(self):
|
|
3857
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
3858
|
+
from executorch.exir.schema import ExtraTensorInfo, Tensor
|
|
3859
|
+
|
|
3860
|
+
class Identity(torch.nn.Module):
|
|
3861
|
+
def forward(self, x):
|
|
3862
|
+
return x
|
|
3863
|
+
|
|
3864
|
+
program = to_edge(export(Identity(), (torch.ones(2, 2),))).to_executorch(
|
|
3865
|
+
ExecutorchBackendConfig(
|
|
3866
|
+
memory_planning_pass=MemoryPlanningPass(
|
|
3867
|
+
alloc_graph_input=False, alloc_graph_output=False
|
|
3868
|
+
)
|
|
3869
|
+
)
|
|
3870
|
+
)
|
|
3871
|
+
host_meta = self.load_prog_fn(program.buffer).method_meta("forward")
|
|
3872
|
+
self.assertEqual(host_meta.input_tensor_meta(0).device(), "cpu")
|
|
3873
|
+
self.assertEqual(host_meta.output_tensor_meta(0).device(), "cpu")
|
|
3874
|
+
schema = program.executorch_program
|
|
3875
|
+
for entry in schema.execution_plan[0].values:
|
|
3876
|
+
if isinstance(entry.val, Tensor):
|
|
3877
|
+
entry.val.extra_tensor_info = ExtraTensorInfo(
|
|
3878
|
+
device_type=DeviceType.CUDA, device_index=3
|
|
3879
|
+
)
|
|
3880
|
+
data = bytes(serialize_pte_binary(PTEFile(schema)))
|
|
3881
|
+
for meta in (
|
|
3882
|
+
self.load_prog_fn(data).method_meta("forward"),
|
|
3883
|
+
self.load_fn(data).method_meta("forward"),
|
|
3884
|
+
):
|
|
3885
|
+
self.assertEqual(meta.input_tensor_meta(0).device(), "cuda:3")
|
|
3886
|
+
self.assertEqual(meta.output_tensor_meta(0).device(), "cuda:3")
|
|
3887
|
+
self.assertIn("device=cuda:3", repr(meta.input_tensor_meta(0)))
|
|
3888
|
+
|
|
3889
|
+
# A named buffer reports its device too.
|
|
3890
|
+
eager_module = ModuleAddWithAttributes()
|
|
3891
|
+
program = to_edge(
|
|
3892
|
+
export(eager_module, eager_module.get_inputs(), strict=True)
|
|
3893
|
+
).to_executorch(ExecutorchBackendConfig(emit_mutable_buffer_names=True))
|
|
3894
|
+
schema = program.executorch_program
|
|
3895
|
+
for entry in schema.execution_plan[0].values:
|
|
3896
|
+
if isinstance(entry.val, Tensor):
|
|
3897
|
+
entry.val.extra_tensor_info = ExtraTensorInfo(
|
|
3898
|
+
device_type=DeviceType.CUDA,
|
|
3899
|
+
device_index=3,
|
|
3900
|
+
fully_qualified_name=(
|
|
3901
|
+
entry.val.extra_tensor_info.fully_qualified_name
|
|
3902
|
+
if entry.val.extra_tensor_info
|
|
3903
|
+
else None
|
|
3904
|
+
),
|
|
3905
|
+
)
|
|
3906
|
+
meta = self.load_prog_fn(
|
|
3907
|
+
bytes(serialize_pte_binary(PTEFile(schema)))
|
|
3908
|
+
).method_meta("forward")
|
|
3909
|
+
self.assertEqual(meta.num_attributes(), 1)
|
|
3910
|
+
self.assertEqual(meta.attribute_tensor_meta(0).device(), "cuda:3")
|
|
3911
|
+
|
|
3912
|
+
def test_input_device_must_match_method(self):
|
|
3913
|
+
if self.kernel_mode != "portable":
|
|
3914
|
+
self.skipTest("only portable bindings inspect input device metadata")
|
|
3915
|
+
|
|
3916
|
+
from executorch.exir._serialize._program import PTEFile, serialize_pte_binary
|
|
3917
|
+
from executorch.exir.schema import ExtraTensorInfo, Tensor
|
|
3918
|
+
|
|
3919
|
+
class Identity(torch.nn.Module):
|
|
3920
|
+
def forward(self, x):
|
|
3921
|
+
return x
|
|
3922
|
+
|
|
3923
|
+
value = torch.ones(2, 2)
|
|
3924
|
+
program = to_edge(export(Identity(), (value,))).to_executorch(
|
|
3925
|
+
ExecutorchBackendConfig(
|
|
3926
|
+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
|
|
3927
|
+
)
|
|
3928
|
+
)
|
|
3929
|
+
schema = program.executorch_program
|
|
3930
|
+
for entry in schema.execution_plan[0].values:
|
|
3931
|
+
if isinstance(entry.val, Tensor):
|
|
3932
|
+
entry.val.extra_tensor_info = ExtraTensorInfo(
|
|
3933
|
+
device_type=DeviceType.CUDA, device_index=3
|
|
3934
|
+
)
|
|
3935
|
+
data = bytes(serialize_pte_binary(PTEFile(schema)))
|
|
3936
|
+
module = self.load_fn(data)
|
|
3937
|
+
method = self.load_prog_fn(data).load_method("forward")
|
|
3938
|
+
# A host buffer would otherwise be read as device memory.
|
|
3939
|
+
for executor in (module, method):
|
|
3940
|
+
for host_input in (
|
|
3941
|
+
value,
|
|
3942
|
+
DLPackOnly(value),
|
|
3943
|
+
value.numpy(),
|
|
3944
|
+
memoryview(value.numpy()),
|
|
3945
|
+
):
|
|
3946
|
+
with self.subTest(executor=type(executor), input=type(host_input)):
|
|
3947
|
+
with self.assertRaisesRegex(
|
|
3948
|
+
ValueError,
|
|
3949
|
+
r"^Input 0 of method 'forward' is on device cpu, but the "
|
|
3950
|
+
r"method expects cuda:3\. Pass device memory instead, such "
|
|
3951
|
+
r"as ExecuTorchResult\.from_host\(\.\.\.\) or a CUDA tensor$",
|
|
3952
|
+
):
|
|
3953
|
+
executor(host_input)
|
|
3954
|
+
|
|
3955
|
+
def test_device_planned_method_allocates_on_the_device(self):
|
|
3956
|
+
# The other device test covers the refusal. This one covers what the
|
|
3957
|
+
# refusal is protecting: on a build that does have a device allocator,
|
|
3958
|
+
# the arena has to come off the device, not out of host memory. It needs
|
|
3959
|
+
# a real accelerator, so it only runs where one is present.
|
|
3960
|
+
if "CudaBackend" not in self.runtime._get_registered_backend_names():
|
|
3961
|
+
self.skipTest("needs a build with the CUDA backend linked in")
|
|
3962
|
+
if not torch.cuda.is_available():
|
|
3963
|
+
self.skipTest("needs a visible CUDA device")
|
|
3964
|
+
|
|
3965
|
+
from executorch.backends.cuda.cuda_partitioner import CudaPartitioner
|
|
3966
|
+
from executorch.exir import to_edge_transform_and_lower
|
|
3967
|
+
from executorch.exir.backend.compile_spec_schema import CompileSpec
|
|
3968
|
+
|
|
3969
|
+
# Large enough that the arena is far bigger than the noise in
|
|
3970
|
+
# mem_get_info, which moves by a few MiB as contexts are created.
|
|
3971
|
+
side = 2048
|
|
3972
|
+
inputs = (torch.ones(side, side), torch.ones(side, side))
|
|
3973
|
+
|
|
3974
|
+
class HostOnly(torch.nn.Module):
|
|
3975
|
+
def forward(self, x, y):
|
|
3976
|
+
return x + y
|
|
3977
|
+
|
|
3978
|
+
class Delegated(torch.nn.Module):
|
|
3979
|
+
def forward(self, x, y):
|
|
3980
|
+
return (x + y) * 2.0
|
|
3981
|
+
|
|
3982
|
+
edge = to_edge_transform_and_lower(
|
|
3983
|
+
{
|
|
3984
|
+
"forward": export(HostOnly(), inputs, strict=True),
|
|
3985
|
+
"forward2": export(Delegated(), inputs, strict=True),
|
|
3986
|
+
},
|
|
3987
|
+
partitioner={
|
|
3988
|
+
"forward2": [CudaPartitioner([CompileSpec("method_name", b"forward2")])]
|
|
3989
|
+
},
|
|
3990
|
+
)
|
|
3991
|
+
exported_program = edge.to_executorch(
|
|
3992
|
+
config=ExecutorchBackendConfig(enable_non_cpu_memory_planning=True)
|
|
3993
|
+
)
|
|
3994
|
+
|
|
3995
|
+
plans = {
|
|
3996
|
+
plan.name: plan
|
|
3997
|
+
for plan in exported_program.executorch_program.execution_plan
|
|
3998
|
+
}
|
|
3999
|
+
device_buffers = {
|
|
4000
|
+
buffer.buffer_idx
|
|
4001
|
+
for buffer in (plans["forward2"].non_const_buffer_device or [])
|
|
4002
|
+
}
|
|
4003
|
+
self.assertTrue(device_buffers, "the planner tagged nothing for the device")
|
|
4004
|
+
self.assertFalse(plans["forward"].non_const_buffer_device or [])
|
|
4005
|
+
device_bytes = sum(
|
|
4006
|
+
size
|
|
4007
|
+
for index, size in enumerate(plans["forward2"].non_const_buffer_sizes)
|
|
4008
|
+
if index in device_buffers
|
|
4009
|
+
)
|
|
4010
|
+
|
|
4011
|
+
# The CUDA backend keeps its weights in a separate file, so the program
|
|
4012
|
+
# has to be loaded from disk with that file alongside it.
|
|
4013
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
4014
|
+
pte_path = os.path.join(directory, "program.pte")
|
|
4015
|
+
with open(pte_path, "wb") as pte_file:
|
|
4016
|
+
exported_program.write_to_file(pte_file)
|
|
4017
|
+
data_names = sorted(exported_program._tensor_data or {})
|
|
4018
|
+
exported_program.write_tensor_data_to_file(directory)
|
|
4019
|
+
data_path = (
|
|
4020
|
+
os.path.join(directory, data_names[0] + ".ptd") if data_names else None
|
|
4021
|
+
)
|
|
4022
|
+
|
|
4023
|
+
torch.cuda.init()
|
|
4024
|
+
program = self.runtime._load_program(pte_path, data_path=data_path)
|
|
4025
|
+
|
|
4026
|
+
torch.cuda.synchronize()
|
|
4027
|
+
free_before, _ = torch.cuda.mem_get_info()
|
|
4028
|
+
|
|
4029
|
+
# The host-only method must not touch the device at all.
|
|
4030
|
+
host_method = program.load_method("forward")
|
|
4031
|
+
torch.cuda.synchronize()
|
|
4032
|
+
free_after_host, _ = torch.cuda.mem_get_info()
|
|
4033
|
+
self.assertLess(free_before - free_after_host, device_bytes // 2)
|
|
4034
|
+
|
|
4035
|
+
device_method = program.load_method("forward2")
|
|
4036
|
+
torch.cuda.synchronize()
|
|
4037
|
+
free_after_device, _ = torch.cuda.mem_get_info()
|
|
4038
|
+
self.assertGreaterEqual(
|
|
4039
|
+
free_after_host - free_after_device, device_bytes * 0.9
|
|
4040
|
+
)
|
|
4041
|
+
|
|
4042
|
+
# Before the fix this ran on a host pointer and the backend rejected
|
|
4043
|
+
# it, so getting the right answer back is itself part of the check.
|
|
4044
|
+
expected = (inputs[0] + inputs[1]) * 2.0
|
|
4045
|
+
self.assertTrue(
|
|
4046
|
+
torch.allclose(device_method.call(inputs)[0].cpu(), expected)
|
|
4047
|
+
)
|
|
4048
|
+
self.assertTrue(
|
|
4049
|
+
torch.allclose(host_method.call(inputs)[0].cpu(), inputs[0] + inputs[1])
|
|
4050
|
+
)
|
|
4051
|
+
# The device arenas are private, so running the host method in
|
|
4052
|
+
# between must not disturb them.
|
|
4053
|
+
self.assertTrue(
|
|
4054
|
+
torch.allclose(device_method.call(inputs)[0].cpu(), expected)
|
|
4055
|
+
)
|
|
4056
|
+
|
|
4057
|
+
del device_method
|
|
4058
|
+
del host_method
|
|
4059
|
+
del program
|
|
4060
|
+
torch.cuda.synchronize()
|
|
4061
|
+
free_at_end, _ = torch.cuda.mem_get_info()
|
|
4062
|
+
self.assertGreaterEqual(free_at_end - free_after_device, device_bytes * 0.9)
|