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,3126 @@
|
|
|
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-strict
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Callable, Optional, Protocol, TypeVar
|
|
11
|
+
|
|
12
|
+
import torch
|
|
13
|
+
import torch.nn as nn
|
|
14
|
+
import torch.nn.functional as F
|
|
15
|
+
from executorch.backends.cadence.aot.utils import is_depthwise_conv
|
|
16
|
+
from executorch.backends.cadence.aot.weight_packing import unpack_rows
|
|
17
|
+
from executorch.exir.scalar_type import ScalarType
|
|
18
|
+
from torch.library import impl, Library
|
|
19
|
+
|
|
20
|
+
m = Library("cadence", "IMPL", "CompositeExplicitAutograd")
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
torch.ops.load_library("//executorch/kernels/quantized:custom_ops_generated_lib")
|
|
24
|
+
except (OSError, RuntimeError):
|
|
25
|
+
|
|
26
|
+
custom_libs: list[Path] = list(
|
|
27
|
+
Path(__file__)
|
|
28
|
+
.parent.parent.parent.resolve()
|
|
29
|
+
.glob("**/kernels/quantized/**/*custom_ops_generated_lib.*")
|
|
30
|
+
)
|
|
31
|
+
if custom_libs:
|
|
32
|
+
torch.ops.load_library(str(custom_libs[0]))
|
|
33
|
+
|
|
34
|
+
# Registry to track all ops with reference implementations
|
|
35
|
+
_REGISTERED_REF_IMPLEMENTATIONS: set[str] = set()
|
|
36
|
+
|
|
37
|
+
T = TypeVar("T", bound=Callable[..., torch.Tensor | tuple[torch.Tensor, ...]])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class MyDecorator(Protocol):
|
|
41
|
+
def __call__(self, __f: T) -> T: ...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# Custom impl wrapper that tracks registrations
|
|
45
|
+
def impl_tracked(lib: Library, op_name: str) -> MyDecorator:
|
|
46
|
+
"""Wrapper around impl that tracks registered ops."""
|
|
47
|
+
_REGISTERED_REF_IMPLEMENTATIONS.add(op_name)
|
|
48
|
+
return impl(lib, op_name)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_registered_ref_implementations() -> set[str]:
|
|
52
|
+
"""Get all ops that have reference implementations."""
|
|
53
|
+
return _REGISTERED_REF_IMPLEMENTATIONS.copy()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
qdtype_map: dict[ScalarType, torch.dtype] = {
|
|
57
|
+
ScalarType.QINT8: torch.qint8,
|
|
58
|
+
ScalarType.QUINT8: torch.quint8,
|
|
59
|
+
ScalarType.QINT32: torch.qint32,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def quantize_per_tensor_common(
|
|
64
|
+
input_tensor: torch.Tensor,
|
|
65
|
+
scale: float,
|
|
66
|
+
zero_point: int,
|
|
67
|
+
quant_min: int,
|
|
68
|
+
quant_max: int,
|
|
69
|
+
dtype: torch.dtype,
|
|
70
|
+
) -> torch.Tensor:
|
|
71
|
+
"""
|
|
72
|
+
Quantizes a floating-point tensor to an integral tensor.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
- input_tensor (Tensor): input tensor
|
|
76
|
+
- scale (float): Quantization scale. Derived from the ratio
|
|
77
|
+
between the min/max of the floating-point tensor and the
|
|
78
|
+
min/max of the quantized range, and then inverted.
|
|
79
|
+
- zero_point (int): The point which represents 0 in the quantized
|
|
80
|
+
range. For example, consider the floating point range [-1., 2.] and
|
|
81
|
+
quantized integer range [-7, 7]. In this case, 0 is 1/3 of way from
|
|
82
|
+
-1. to 2. So, the point that represents 0 in the quantized range should
|
|
83
|
+
be 1/3 of the way from [-7, 7]. This ends up being -2 in the integer space.
|
|
84
|
+
- quant_min (int): The smallest value in the quantized domain. Unused since scale
|
|
85
|
+
is already provided.
|
|
86
|
+
- quant_max (int): The largest value in the quantized domain. Unused since scale
|
|
87
|
+
is already provided.
|
|
88
|
+
- dtype (torch.dtype): The type of the output tensor
|
|
89
|
+
"""
|
|
90
|
+
supported_quant_types = [
|
|
91
|
+
torch.int8,
|
|
92
|
+
torch.int16,
|
|
93
|
+
torch.int32,
|
|
94
|
+
torch.uint8,
|
|
95
|
+
torch.uint16,
|
|
96
|
+
]
|
|
97
|
+
if dtype not in supported_quant_types:
|
|
98
|
+
raise ValueError(
|
|
99
|
+
f"Unsupported dtype to quantize to {dtype}. Supported dtypes must be one of {supported_quant_types}"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return torch.ops.quantized_decomposed.quantize_per_tensor(
|
|
103
|
+
input_tensor,
|
|
104
|
+
scale,
|
|
105
|
+
zero_point,
|
|
106
|
+
quant_min,
|
|
107
|
+
quant_max,
|
|
108
|
+
dtype,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def quantize_per_tensor_variant(
|
|
113
|
+
dtype: torch.dtype | None = None,
|
|
114
|
+
) -> Callable[[Callable[..., torch.Tensor]], Callable[..., torch.Tensor]]:
|
|
115
|
+
"""Create a quantize_per_tensor variant with type checking."""
|
|
116
|
+
|
|
117
|
+
def decorator(_: Callable[..., torch.Tensor]) -> Callable[..., torch.Tensor]:
|
|
118
|
+
def variant(
|
|
119
|
+
input_tensor: torch.Tensor,
|
|
120
|
+
scale: float,
|
|
121
|
+
zero_point: int,
|
|
122
|
+
quant_min: int,
|
|
123
|
+
quant_max: int,
|
|
124
|
+
out_dtype: torch.dtype,
|
|
125
|
+
) -> torch.Tensor:
|
|
126
|
+
if dtype and out_dtype != dtype:
|
|
127
|
+
raise ValueError(f"dtype must be {dtype}. Got {out_dtype}")
|
|
128
|
+
|
|
129
|
+
return quantize_per_tensor_common(
|
|
130
|
+
input_tensor,
|
|
131
|
+
scale,
|
|
132
|
+
zero_point,
|
|
133
|
+
quant_min,
|
|
134
|
+
quant_max,
|
|
135
|
+
out_dtype,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
return variant
|
|
139
|
+
|
|
140
|
+
return decorator
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@impl_tracked(m, "quantize_per_tensor")
|
|
144
|
+
@quantize_per_tensor_variant()
|
|
145
|
+
def quantize_per_tensor() -> torch.Tensor: ...
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@impl_tracked(m, "quantize_per_tensor_asym8u")
|
|
149
|
+
@quantize_per_tensor_variant(torch.uint8)
|
|
150
|
+
def quantize_per_tensor_asym8u() -> torch.Tensor: ...
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@impl_tracked(m, "quantize_per_tensor_asym8s")
|
|
154
|
+
@quantize_per_tensor_variant(torch.int8)
|
|
155
|
+
def quantize_per_tensor_asym8s() -> torch.Tensor: ...
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@impl_tracked(m, "quantize_per_tensor_asym16u")
|
|
159
|
+
@quantize_per_tensor_variant(torch.uint16)
|
|
160
|
+
def quantize_per_tensor_asym16u() -> torch.Tensor: ...
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@impl_tracked(m, "quantize_per_tensor_asym16s")
|
|
164
|
+
@quantize_per_tensor_variant(torch.int16)
|
|
165
|
+
def quantize_per_tensor_asym16s() -> torch.Tensor: ...
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@impl_tracked(m, "quantize_per_tensor_asym32s")
|
|
169
|
+
@quantize_per_tensor_variant(torch.int32)
|
|
170
|
+
def quantize_per_tensor_asym32s() -> torch.Tensor: ...
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def dequantize_per_tensor_common(
|
|
174
|
+
input_tensor: torch.Tensor,
|
|
175
|
+
scale: float,
|
|
176
|
+
zero_point: int,
|
|
177
|
+
quant_min: int,
|
|
178
|
+
quant_max: int,
|
|
179
|
+
dtype: torch.dtype,
|
|
180
|
+
) -> torch.Tensor:
|
|
181
|
+
"""
|
|
182
|
+
Dequantizes an integral tensor to a floating-point tensor.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
- input (Tensor): input tensor
|
|
186
|
+
- scale (float): Quantization scale. Derived from the ratio
|
|
187
|
+
between the min/max of the floating-point tensor and the
|
|
188
|
+
min/max of the quantized range.
|
|
189
|
+
- zero_point (int): The point which represents 0 in the quantized
|
|
190
|
+
range. For example, consider the floating point range [-1., 2.] and
|
|
191
|
+
quantized integer range [-7, 7]. In this case, 0 is 1/3 of way from
|
|
192
|
+
-1. to 2. So, the point that represents 0 in the quantized range should
|
|
193
|
+
be 1/3 of the way from [-7, 7]. This ends up being -2 in the integer space.
|
|
194
|
+
- quant_min (int): The smallest value in the quantized domain. Unused since scale
|
|
195
|
+
is already provided.
|
|
196
|
+
- quant_max (int): The largest value in the quantized domain. Unused since scale
|
|
197
|
+
is already provided.
|
|
198
|
+
- dtype (torch.dtype): The type of the input tensor.
|
|
199
|
+
"""
|
|
200
|
+
supported_quant_types = [
|
|
201
|
+
torch.int8,
|
|
202
|
+
torch.int16,
|
|
203
|
+
torch.int32,
|
|
204
|
+
torch.uint8,
|
|
205
|
+
torch.uint16,
|
|
206
|
+
]
|
|
207
|
+
if input_tensor.dtype not in supported_quant_types:
|
|
208
|
+
raise ValueError(f"Input dtype must be one of {supported_quant_types}")
|
|
209
|
+
if input_tensor.dtype != dtype:
|
|
210
|
+
raise ValueError("Input dtype must match dtype")
|
|
211
|
+
|
|
212
|
+
return torch.ops.quantized_decomposed.dequantize_per_tensor(
|
|
213
|
+
input_tensor, scale, zero_point, quant_min, quant_max, dtype
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def dequantize_per_tensor_variant(
|
|
218
|
+
dtype: torch.dtype | None = None,
|
|
219
|
+
) -> Callable[[Callable[..., torch.Tensor]], Callable[..., torch.Tensor]]:
|
|
220
|
+
"""Create a dequantize_per_tensor variant with type checking."""
|
|
221
|
+
|
|
222
|
+
def decorator(_: Callable[..., torch.Tensor]) -> Callable[..., torch.Tensor]:
|
|
223
|
+
def variant(
|
|
224
|
+
input_tensor: torch.Tensor,
|
|
225
|
+
scale: float,
|
|
226
|
+
zero_point: int,
|
|
227
|
+
quant_min: int,
|
|
228
|
+
quant_max: int,
|
|
229
|
+
in_dtype: torch.dtype,
|
|
230
|
+
) -> torch.Tensor:
|
|
231
|
+
if dtype and in_dtype != dtype:
|
|
232
|
+
raise ValueError(f"dtype must be {dtype}. Got {in_dtype}")
|
|
233
|
+
|
|
234
|
+
return dequantize_per_tensor_common(
|
|
235
|
+
input_tensor,
|
|
236
|
+
scale,
|
|
237
|
+
zero_point,
|
|
238
|
+
quant_min,
|
|
239
|
+
quant_max,
|
|
240
|
+
in_dtype,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
return variant
|
|
244
|
+
|
|
245
|
+
return decorator
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@impl_tracked(m, "dequantize_per_tensor")
|
|
249
|
+
@dequantize_per_tensor_variant()
|
|
250
|
+
def dequantize_per_tensor() -> torch.Tensor: ...
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
@impl_tracked(m, "dequantize_per_tensor_asym8u")
|
|
254
|
+
@dequantize_per_tensor_variant(torch.uint8)
|
|
255
|
+
def dequantize_per_tensor_asym8u() -> torch.Tensor: ...
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@impl_tracked(m, "dequantize_per_tensor_asym32s")
|
|
259
|
+
@dequantize_per_tensor_variant(torch.int32)
|
|
260
|
+
def dequantize_per_tensor_asym32s() -> torch.Tensor: ...
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@impl_tracked(m, "dequantize_per_tensor_asym16u")
|
|
264
|
+
@dequantize_per_tensor_variant(torch.uint16)
|
|
265
|
+
def dequantize_per_tensor_asym16u() -> torch.Tensor: ...
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@impl_tracked(m, "dequantize_per_tensor_asym8s")
|
|
269
|
+
@dequantize_per_tensor_variant(torch.int8)
|
|
270
|
+
def dequantize_per_tensor_asym8s() -> torch.Tensor: ...
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
@impl_tracked(m, "dequantize_per_tensor_asym16s")
|
|
274
|
+
@dequantize_per_tensor_variant(torch.int16)
|
|
275
|
+
def dequantize_per_tensor_asym16s() -> torch.Tensor: ...
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@impl_tracked(m, "quantized_add.per_tensor")
|
|
279
|
+
def quantized_add_per_tensor(
|
|
280
|
+
X: torch.Tensor,
|
|
281
|
+
X_scale: float,
|
|
282
|
+
X_zero_point: int,
|
|
283
|
+
Y: torch.Tensor,
|
|
284
|
+
Y_scale: float,
|
|
285
|
+
Y_zero_point: int,
|
|
286
|
+
out_scale: float,
|
|
287
|
+
out_zero_point: int,
|
|
288
|
+
) -> torch.Tensor:
|
|
289
|
+
"""
|
|
290
|
+
Sums up two quantized tensors and returns another quantized tensor. The intuition
|
|
291
|
+
is that we want dequant(out) ~= dequant(X) + dequant(Y)
|
|
292
|
+
|
|
293
|
+
If we do that math, we get
|
|
294
|
+
out_scale(out - out_zero_point) = X_scale(X - X_zero_point) + Y_scale(Y - Y_zero_point)
|
|
295
|
+
|
|
296
|
+
Rearranging, we get
|
|
297
|
+
out = (X_scale(X - X_zero_point) + Y_scale(Y - Y_zero_point)) / out_scale + out_zero_point
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
- X: The first operand
|
|
301
|
+
- X_scale: The ratio between the sizes of X's floating point and quantized
|
|
302
|
+
ranges
|
|
303
|
+
- X_zero_point: The quantized mapping of zero for X
|
|
304
|
+
- Y: The second operand
|
|
305
|
+
- Y_scale: The ratio between the sizes of Y's floating point and quantized
|
|
306
|
+
ranges
|
|
307
|
+
- Y_zero_point: The quantized mapping of zero for Y
|
|
308
|
+
- out_scale: The ratio between the sizes of the output's floating point and
|
|
309
|
+
quantized ranges
|
|
310
|
+
- out_zero_point: The quantized mapping of zero for the output
|
|
311
|
+
"""
|
|
312
|
+
supported_dtypes = [torch.int8, torch.int16, torch.uint8]
|
|
313
|
+
if X.dtype != Y.dtype:
|
|
314
|
+
raise ValueError("X and Y dtypes need to match")
|
|
315
|
+
|
|
316
|
+
dtype = X.dtype
|
|
317
|
+
if dtype not in supported_dtypes:
|
|
318
|
+
raise ValueError(
|
|
319
|
+
f"X and Y dtypes need to be in {supported_dtypes}. Got {dtype}"
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
qmin = torch.iinfo(dtype).min
|
|
323
|
+
qmax = torch.iinfo(dtype).max
|
|
324
|
+
|
|
325
|
+
dequant_X = dequantize_per_tensor(X, X_scale, X_zero_point, qmin, qmax, dtype)
|
|
326
|
+
dequant_Y = dequantize_per_tensor(Y, Y_scale, Y_zero_point, qmin, qmax, dtype)
|
|
327
|
+
|
|
328
|
+
# q_min/q_max are unused args
|
|
329
|
+
return quantize_per_tensor(
|
|
330
|
+
dequant_X + dequant_Y,
|
|
331
|
+
out_scale,
|
|
332
|
+
out_zero_point,
|
|
333
|
+
qmin,
|
|
334
|
+
qmax,
|
|
335
|
+
dtype,
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
@impl_tracked(m, "quantized_add")
|
|
340
|
+
def quantized_add(
|
|
341
|
+
X: torch.Tensor,
|
|
342
|
+
X_scale: torch.Tensor,
|
|
343
|
+
X_zero_point: torch.Tensor,
|
|
344
|
+
Y: torch.Tensor,
|
|
345
|
+
Y_scale: torch.Tensor,
|
|
346
|
+
Y_zero_point: torch.Tensor,
|
|
347
|
+
out_scale: float,
|
|
348
|
+
out_zero_point: int,
|
|
349
|
+
) -> torch.Tensor:
|
|
350
|
+
return quantized_add_per_tensor(
|
|
351
|
+
X,
|
|
352
|
+
float(X_scale.item()),
|
|
353
|
+
int(X_zero_point.item()),
|
|
354
|
+
Y,
|
|
355
|
+
float(Y_scale.item()),
|
|
356
|
+
int(Y_zero_point.item()),
|
|
357
|
+
out_scale,
|
|
358
|
+
out_zero_point,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
@impl_tracked(m, "quantized_add_asym8sxasym8s_asym8s.per_tensor")
|
|
363
|
+
def quantized_add_asym8sxasym8s_asym8s_per_tensor(
|
|
364
|
+
X: torch.Tensor,
|
|
365
|
+
X_scale: float,
|
|
366
|
+
X_zero_point: int,
|
|
367
|
+
Y: torch.Tensor,
|
|
368
|
+
Y_scale: float,
|
|
369
|
+
Y_zero_point: int,
|
|
370
|
+
out_scale: float,
|
|
371
|
+
out_zero_point: int,
|
|
372
|
+
) -> torch.Tensor:
|
|
373
|
+
if X.dtype != torch.int8:
|
|
374
|
+
raise ValueError("X dtype must be torch.int8")
|
|
375
|
+
if Y.dtype != torch.int8:
|
|
376
|
+
raise ValueError("Y dtype must be torch.int8")
|
|
377
|
+
|
|
378
|
+
return quantized_add_per_tensor(
|
|
379
|
+
X, X_scale, X_zero_point, Y, Y_scale, Y_zero_point, out_scale, out_zero_point
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
@impl_tracked(m, "quantized_add_asym8uxasym8u_asym8u.per_tensor")
|
|
384
|
+
def quantized_add_asym8uxasym8u_asym8u_per_tensor(
|
|
385
|
+
X: torch.Tensor,
|
|
386
|
+
X_scale: float,
|
|
387
|
+
X_zero_point: int,
|
|
388
|
+
Y: torch.Tensor,
|
|
389
|
+
Y_scale: float,
|
|
390
|
+
Y_zero_point: int,
|
|
391
|
+
out_scale: float,
|
|
392
|
+
out_zero_point: int,
|
|
393
|
+
) -> torch.Tensor:
|
|
394
|
+
if X.dtype != torch.uint8:
|
|
395
|
+
raise ValueError("X dtype must be torch.uint8")
|
|
396
|
+
if Y.dtype != torch.uint8:
|
|
397
|
+
raise ValueError("Y dtype must be torch.uint8")
|
|
398
|
+
|
|
399
|
+
return quantized_add_per_tensor(
|
|
400
|
+
X, X_scale, X_zero_point, Y, Y_scale, Y_zero_point, out_scale, out_zero_point
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@impl_tracked(m, "quantized_mul.per_tensor")
|
|
405
|
+
def quantized_mul_per_tensor(
|
|
406
|
+
X: torch.Tensor,
|
|
407
|
+
X_scale: float,
|
|
408
|
+
X_zero_point: int,
|
|
409
|
+
Y: torch.Tensor,
|
|
410
|
+
Y_scale: float,
|
|
411
|
+
Y_zero_point: int,
|
|
412
|
+
out_scale: float,
|
|
413
|
+
out_zero_point: int,
|
|
414
|
+
) -> torch.Tensor:
|
|
415
|
+
"""
|
|
416
|
+
Multiplies two quantized tensors and returns another quantized tensor. The intuition
|
|
417
|
+
is that we want dequant(out) ~= dequant(X) * dequant(Y)
|
|
418
|
+
|
|
419
|
+
If we do that math, we get
|
|
420
|
+
out_scale(out - out_zero_point) = X_scale(X - X_zero_point) * Y_scale(Y - Y_zero_point)
|
|
421
|
+
|
|
422
|
+
Rearranging, we get
|
|
423
|
+
out = (X_scale(X - X_zero_point) * Y_scale(Y - Y_zero_point)) / out_scale + out_zero_point
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
- X: The first operand
|
|
427
|
+
- X_scale: The ratio between the sizes of X's floating point and quantized
|
|
428
|
+
ranges
|
|
429
|
+
- X_zero_point: The quantized mapping of zero for X
|
|
430
|
+
- Y: The second operand
|
|
431
|
+
- Y_scale: The ratio between the sizes of Y's floating point and quantized
|
|
432
|
+
ranges
|
|
433
|
+
- Y_zero_point: The quantized mapping of zero for Y
|
|
434
|
+
- out_scale: The ratio between the sizes of the output's floating point and
|
|
435
|
+
quantized ranges
|
|
436
|
+
- out_zero_point: The quantized mapping of zero for the output
|
|
437
|
+
"""
|
|
438
|
+
supported_dtypes = [torch.int8, torch.int16, torch.uint8]
|
|
439
|
+
if X.dtype != Y.dtype:
|
|
440
|
+
raise ValueError("X and Y dtypes need to match")
|
|
441
|
+
|
|
442
|
+
dtype = X.dtype
|
|
443
|
+
if dtype not in supported_dtypes:
|
|
444
|
+
raise ValueError(
|
|
445
|
+
f"X and Y dtypes need to be in {supported_dtypes}. Got {dtype}"
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
qmin = torch.iinfo(dtype).min
|
|
449
|
+
qmax = torch.iinfo(dtype).max
|
|
450
|
+
|
|
451
|
+
dequant_X = dequantize_per_tensor(X, X_scale, X_zero_point, qmin, qmax, dtype)
|
|
452
|
+
dequant_Y = dequantize_per_tensor(Y, Y_scale, Y_zero_point, qmin, qmax, dtype)
|
|
453
|
+
|
|
454
|
+
return quantize_per_tensor(
|
|
455
|
+
dequant_X * dequant_Y,
|
|
456
|
+
out_scale,
|
|
457
|
+
out_zero_point,
|
|
458
|
+
qmin,
|
|
459
|
+
qmax,
|
|
460
|
+
dtype,
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def quantized_linear_common(
|
|
465
|
+
src: torch.Tensor,
|
|
466
|
+
weight: torch.Tensor,
|
|
467
|
+
bias: torch.Tensor,
|
|
468
|
+
in_zero_point: int,
|
|
469
|
+
weight_zero_point: torch.Tensor | int | None,
|
|
470
|
+
out_multiplier: int | torch.Tensor,
|
|
471
|
+
out_shift: int | torch.Tensor,
|
|
472
|
+
out_zero_point: int,
|
|
473
|
+
) -> torch.Tensor:
|
|
474
|
+
"""
|
|
475
|
+
Quantized linear (transposed matmul) operation.
|
|
476
|
+
|
|
477
|
+
Args:
|
|
478
|
+
- src (Tensor): The activations tensor
|
|
479
|
+
- weight (Tensor): The weight tensor
|
|
480
|
+
- bias (Tensor): The bias tensor
|
|
481
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
482
|
+
- weight_zero_point (Tensor): The quantized mapping of zero for the weight
|
|
483
|
+
- out_multiplier (int | Tensor): The multiplier used to scale the output.
|
|
484
|
+
A 1-D tensor of length out_dim selects per-channel requantization.
|
|
485
|
+
- out_shift (int | Tensor): The shift used to scale the output
|
|
486
|
+
- out_zero_point (int): The quantized mapping of zero for the output
|
|
487
|
+
- offset (Tensor): Unused
|
|
488
|
+
"""
|
|
489
|
+
N, K = weight.shape
|
|
490
|
+
|
|
491
|
+
leading_dims = src.shape[:-1]
|
|
492
|
+
src = src.view(-1, K)
|
|
493
|
+
|
|
494
|
+
dtype = src.dtype
|
|
495
|
+
supported_dtypes = [torch.int8, torch.uint8, torch.int16, torch.int32]
|
|
496
|
+
if dtype not in supported_dtypes:
|
|
497
|
+
raise ValueError(
|
|
498
|
+
f"Unsupported dtype to quantize to {dtype}. Supported dtypes must be one of {supported_dtypes}"
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
per_channel = isinstance(out_multiplier, torch.Tensor) and (
|
|
502
|
+
out_multiplier.numel() > 1
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
# Absent means a symmetric weight, whose zero point is zero by definition;
|
|
506
|
+
# the AoT side omits the argument rather than emitting a constant of zeros.
|
|
507
|
+
if weight_zero_point is None:
|
|
508
|
+
weight_zero_point = 0
|
|
509
|
+
|
|
510
|
+
if (
|
|
511
|
+
per_channel
|
|
512
|
+
and isinstance(weight_zero_point, torch.Tensor)
|
|
513
|
+
and weight_zero_point.numel() == N
|
|
514
|
+
):
|
|
515
|
+
# per-channel zero point indexes output channels, i.e. weight rows.
|
|
516
|
+
# Only reshape under per-channel requant: elsewhere a multi-element
|
|
517
|
+
# zero point is expected to broadcast along the input axis.
|
|
518
|
+
weight_zero_point = weight_zero_point.reshape(N, 1)
|
|
519
|
+
|
|
520
|
+
out = torch.nn.functional.linear(
|
|
521
|
+
src.float() - in_zero_point,
|
|
522
|
+
weight.float() - weight_zero_point,
|
|
523
|
+
bias.float(),
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
if not per_channel:
|
|
527
|
+
_multiplier = (
|
|
528
|
+
int(out_multiplier.flatten()[0].item())
|
|
529
|
+
if isinstance(out_multiplier, torch.Tensor)
|
|
530
|
+
else out_multiplier
|
|
531
|
+
)
|
|
532
|
+
_shift = (
|
|
533
|
+
int(out_shift.flatten()[0].item())
|
|
534
|
+
if isinstance(out_shift, torch.Tensor)
|
|
535
|
+
else out_shift
|
|
536
|
+
)
|
|
537
|
+
out_scale = 1.0 / (-_multiplier * (1 / (1 << 31)) * (2**_shift))
|
|
538
|
+
return quantize_per_tensor(
|
|
539
|
+
out,
|
|
540
|
+
out_scale,
|
|
541
|
+
out_zero_point,
|
|
542
|
+
torch.iinfo(dtype).min,
|
|
543
|
+
torch.iinfo(dtype).max,
|
|
544
|
+
dtype,
|
|
545
|
+
).reshape(*leading_dims, N)
|
|
546
|
+
|
|
547
|
+
# Per-channel: one requant scale per output channel. Mirrors the generic
|
|
548
|
+
# kernel, which reconstructs a float scale from (multiplier, shift) per
|
|
549
|
+
# channel rather than doing integer fixed-point requantization.
|
|
550
|
+
assert isinstance(out_shift, torch.Tensor)
|
|
551
|
+
if out_multiplier.numel() != N or out_shift.numel() != N:
|
|
552
|
+
raise ValueError(
|
|
553
|
+
f"per-channel out_multiplier/out_shift must have {N} elements, got "
|
|
554
|
+
f"{out_multiplier.numel()}/{out_shift.numel()}"
|
|
555
|
+
)
|
|
556
|
+
requant_scale = (
|
|
557
|
+
-out_multiplier.to(torch.float64).flatten()
|
|
558
|
+
* (1 / (1 << 31))
|
|
559
|
+
* torch.pow(2.0, out_shift.to(torch.float64).flatten())
|
|
560
|
+
)
|
|
561
|
+
quantized = torch.round(out.to(torch.float64) * requant_scale) + out_zero_point
|
|
562
|
+
return (
|
|
563
|
+
quantized.clamp(torch.iinfo(dtype).min, torch.iinfo(dtype).max)
|
|
564
|
+
.to(dtype)
|
|
565
|
+
.reshape(*leading_dims, N)
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def quantized_linear_variant(
|
|
570
|
+
per_tensor: bool,
|
|
571
|
+
fully_connected: bool,
|
|
572
|
+
src_dtype: torch.dtype | None = None,
|
|
573
|
+
weight_dtype: torch.dtype | None = None,
|
|
574
|
+
) -> Callable[[Callable[..., torch.Tensor]], Callable[..., torch.Tensor]]:
|
|
575
|
+
|
|
576
|
+
def decorator(_: Callable[..., torch.Tensor]) -> Callable[..., torch.Tensor]:
|
|
577
|
+
def variant(
|
|
578
|
+
src: torch.Tensor,
|
|
579
|
+
weight: torch.Tensor,
|
|
580
|
+
bias: torch.Tensor,
|
|
581
|
+
in_zero_point: int,
|
|
582
|
+
weight_zero_point: torch.Tensor | int | None,
|
|
583
|
+
out_multiplier: torch.Tensor | int,
|
|
584
|
+
out_shift: torch.Tensor | int,
|
|
585
|
+
out_zero_point: int,
|
|
586
|
+
offset: torch.Tensor | None = None,
|
|
587
|
+
) -> torch.Tensor:
|
|
588
|
+
if fully_connected and src.shape[0] != 1:
|
|
589
|
+
raise ValueError(
|
|
590
|
+
"Fully connected quantized linear only supports batch size of 1"
|
|
591
|
+
)
|
|
592
|
+
if src_dtype and src.dtype != src_dtype:
|
|
593
|
+
raise ValueError(
|
|
594
|
+
f"src dtype must be {src_dtype}. Got {src.dtype} instead"
|
|
595
|
+
)
|
|
596
|
+
if weight_dtype and weight.dtype != weight_dtype:
|
|
597
|
+
raise ValueError(
|
|
598
|
+
f"weight dtype must be {weight_dtype}. Got {weight.dtype} instead"
|
|
599
|
+
)
|
|
600
|
+
if bias.dtype != torch.int32:
|
|
601
|
+
raise ValueError(
|
|
602
|
+
f"bias dtype must be torch.int32. Got {bias.dtype} instead"
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
if per_tensor:
|
|
606
|
+
assert isinstance(weight_zero_point, int)
|
|
607
|
+
assert isinstance(out_multiplier, int)
|
|
608
|
+
assert isinstance(out_shift, int)
|
|
609
|
+
_out_shift = out_shift
|
|
610
|
+
_out_multiplier = out_multiplier
|
|
611
|
+
else:
|
|
612
|
+
assert isinstance(out_shift, torch.Tensor)
|
|
613
|
+
assert isinstance(out_multiplier, torch.Tensor)
|
|
614
|
+
if out_shift.dtype != torch.int32:
|
|
615
|
+
raise ValueError(
|
|
616
|
+
f"out_shift must be an int32. Got {out_shift.dtype} instead"
|
|
617
|
+
)
|
|
618
|
+
if out_shift.numel() != out_multiplier.numel():
|
|
619
|
+
raise ValueError(
|
|
620
|
+
"out_shift and out_multiplier must have the same length, got "
|
|
621
|
+
f"{out_shift.numel()} and {out_multiplier.numel()}"
|
|
622
|
+
)
|
|
623
|
+
if out_multiplier.numel() == 1:
|
|
624
|
+
_out_shift = int(out_shift.item())
|
|
625
|
+
_out_multiplier = int(out_multiplier[0].item())
|
|
626
|
+
else:
|
|
627
|
+
# per-channel: pass the vectors through
|
|
628
|
+
_out_shift = out_shift
|
|
629
|
+
_out_multiplier = out_multiplier
|
|
630
|
+
|
|
631
|
+
return quantized_linear_common(
|
|
632
|
+
src,
|
|
633
|
+
weight,
|
|
634
|
+
bias,
|
|
635
|
+
in_zero_point,
|
|
636
|
+
weight_zero_point,
|
|
637
|
+
_out_multiplier,
|
|
638
|
+
_out_shift,
|
|
639
|
+
out_zero_point,
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
return variant
|
|
643
|
+
|
|
644
|
+
return decorator
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
@impl_tracked(m, "quantized_linear")
|
|
648
|
+
@quantized_linear_variant(False, False)
|
|
649
|
+
def quantized_linear() -> torch.Tensor: ...
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
@impl_tracked(m, "quantized_linear.per_tensor")
|
|
653
|
+
@quantized_linear_variant(True, False)
|
|
654
|
+
def quantized_linear_per_tensor() -> torch.Tensor: ...
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
@impl_tracked(m, "quantized_linear_asym8sxasym8s_asym8s.per_tensor")
|
|
658
|
+
@quantized_linear_variant(True, False, torch.int8, torch.int8)
|
|
659
|
+
def quantized_linear_asym8sxasym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
@impl_tracked(m, "quantized_linear_asym8uxasym8u_asym8u.per_tensor")
|
|
663
|
+
@quantized_linear_variant(True, False, torch.uint8, torch.uint8)
|
|
664
|
+
def quantized_linear_asym8uxasym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
@impl_tracked(m, "quantized_fully_connected")
|
|
668
|
+
@quantized_linear_variant(False, True)
|
|
669
|
+
def quantized_fully_connected() -> torch.Tensor: ...
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
@impl_tracked(m, "quantized_fully_connected.per_tensor")
|
|
673
|
+
@quantized_linear_variant(True, True)
|
|
674
|
+
def quantized_fully_connected_per_tensor() -> torch.Tensor: ...
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
@impl_tracked(m, "quantized_fully_connected_asym8sxasym8s_asym8s.per_tensor")
|
|
678
|
+
@quantized_linear_variant(True, True, torch.int8, torch.int8)
|
|
679
|
+
def quantized_fully_connected_asym8sxasym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
@impl_tracked(m, "quantized_fully_connected_asym8uxasym8u_asym8u.per_tensor")
|
|
683
|
+
@quantized_linear_variant(True, True, torch.uint8, torch.uint8)
|
|
684
|
+
def quantized_fully_connected_asym8uxasym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
@impl_tracked(m, "quantized_fully_connected_packed")
|
|
688
|
+
def quantized_fully_connected_packed(
|
|
689
|
+
src: torch.Tensor,
|
|
690
|
+
weight: torch.Tensor,
|
|
691
|
+
bias: torch.Tensor,
|
|
692
|
+
in_dim: int,
|
|
693
|
+
weight_bits: int,
|
|
694
|
+
in_zero_point: int,
|
|
695
|
+
weight_zero_point: Optional[torch.Tensor],
|
|
696
|
+
out_multiplier: torch.Tensor,
|
|
697
|
+
out_shift: torch.Tensor,
|
|
698
|
+
out_zero_point: int,
|
|
699
|
+
offset: Optional[torch.Tensor] = None,
|
|
700
|
+
) -> torch.Tensor:
|
|
701
|
+
"""Sub-byte weights: unpack, then reuse the ordinary quantized path.
|
|
702
|
+
|
|
703
|
+
Keeping the arithmetic in `quantized_linear_common` means packing cannot
|
|
704
|
+
drift from the unpacked operator, which is exactly what the tests assert.
|
|
705
|
+
"""
|
|
706
|
+
return quantized_linear_common(
|
|
707
|
+
src,
|
|
708
|
+
unpack_rows(weight, in_dim, weight_bits),
|
|
709
|
+
bias,
|
|
710
|
+
in_zero_point,
|
|
711
|
+
weight_zero_point,
|
|
712
|
+
out_multiplier,
|
|
713
|
+
out_shift,
|
|
714
|
+
out_zero_point,
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
@impl_tracked(m, "fully_connected")
|
|
719
|
+
def fully_connected(
|
|
720
|
+
input_tensor: torch.Tensor,
|
|
721
|
+
weight: torch.Tensor,
|
|
722
|
+
bias: Optional[torch.Tensor] = None,
|
|
723
|
+
) -> torch.Tensor:
|
|
724
|
+
return F.linear(input_tensor, weight, bias)
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
@impl_tracked(m, "quantized_matmul")
|
|
728
|
+
def quantized_matmul(
|
|
729
|
+
X: torch.Tensor,
|
|
730
|
+
X_zero_point: int,
|
|
731
|
+
Y: torch.Tensor,
|
|
732
|
+
Y_zero_point: int,
|
|
733
|
+
bias: torch.Tensor | None,
|
|
734
|
+
out_multiplier: int,
|
|
735
|
+
out_shift: int,
|
|
736
|
+
out_zero_point: int,
|
|
737
|
+
transposed: bool = False,
|
|
738
|
+
) -> torch.Tensor:
|
|
739
|
+
"""
|
|
740
|
+
Quantized matmul operation.
|
|
741
|
+
|
|
742
|
+
Args:
|
|
743
|
+
- X (Tensor): The activations tensor
|
|
744
|
+
- X_zero_point (int): The quantized mapping of zero for the input
|
|
745
|
+
- Y (Tensor): The weight tensor
|
|
746
|
+
- Y_zero_point (int): The quantized mapping of zero for the weight
|
|
747
|
+
- bias (Tensor): The bias tensor
|
|
748
|
+
- out_multiplier (int): The multiplier used to scale the output
|
|
749
|
+
- out_shift (int): The shift used to scale the output
|
|
750
|
+
- out_zero_point (int): The quantized mapping of zero for the output
|
|
751
|
+
- transposed (bool): Whether Y is transposed.
|
|
752
|
+
"""
|
|
753
|
+
if bias is not None and not torch.all(bias == 0):
|
|
754
|
+
raise ValueError("bias must be None or all zeros since unused in out variant")
|
|
755
|
+
|
|
756
|
+
if transposed:
|
|
757
|
+
Y = Y.transpose(-1, -2)
|
|
758
|
+
|
|
759
|
+
out_scale = 1.0 / (-out_multiplier * (1 / (1 << 31)) * (2**out_shift))
|
|
760
|
+
|
|
761
|
+
out = torch.matmul(
|
|
762
|
+
X.float() - X_zero_point,
|
|
763
|
+
Y.float() - Y_zero_point,
|
|
764
|
+
)
|
|
765
|
+
return quantize_per_tensor(
|
|
766
|
+
out,
|
|
767
|
+
out_scale,
|
|
768
|
+
out_zero_point,
|
|
769
|
+
torch.iinfo(X.dtype).min,
|
|
770
|
+
torch.iinfo(X.dtype).max,
|
|
771
|
+
X.dtype,
|
|
772
|
+
)
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
@impl_tracked(m, "quantized_matmul_asym8sxasym8s_asym8s")
|
|
776
|
+
def quantized_matmul_asym8sxasym8s_asym8s(
|
|
777
|
+
X: torch.Tensor,
|
|
778
|
+
X_zero_point: int,
|
|
779
|
+
Y: torch.Tensor,
|
|
780
|
+
Y_zero_point: int,
|
|
781
|
+
bias: torch.Tensor | None,
|
|
782
|
+
out_multiplier: int,
|
|
783
|
+
out_shift: int,
|
|
784
|
+
out_zero_point: int,
|
|
785
|
+
transposed: bool = False,
|
|
786
|
+
) -> torch.Tensor:
|
|
787
|
+
if X.dtype != torch.int8:
|
|
788
|
+
raise ValueError("X dtype must be torch.int8")
|
|
789
|
+
if Y.dtype != torch.int8:
|
|
790
|
+
raise ValueError("Y dtype must be torch.int8")
|
|
791
|
+
|
|
792
|
+
return quantized_matmul(
|
|
793
|
+
X,
|
|
794
|
+
X_zero_point,
|
|
795
|
+
Y,
|
|
796
|
+
Y_zero_point,
|
|
797
|
+
bias,
|
|
798
|
+
out_multiplier,
|
|
799
|
+
out_shift,
|
|
800
|
+
out_zero_point,
|
|
801
|
+
transposed,
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
@impl_tracked(m, "quantized_matmul_asym8uxasym8u_asym8u")
|
|
806
|
+
def quantized_matmul_asym8uxasym8u_asym8u(
|
|
807
|
+
X: torch.Tensor,
|
|
808
|
+
X_zero_point: int,
|
|
809
|
+
Y: torch.Tensor,
|
|
810
|
+
Y_zero_point: int,
|
|
811
|
+
bias: torch.Tensor | None,
|
|
812
|
+
out_multiplier: int,
|
|
813
|
+
out_shift: int,
|
|
814
|
+
out_zero_point: int,
|
|
815
|
+
transposed: bool = False,
|
|
816
|
+
) -> torch.Tensor:
|
|
817
|
+
if X.dtype != torch.uint8:
|
|
818
|
+
raise ValueError("X dtype must be torch.uint8")
|
|
819
|
+
if Y.dtype != torch.uint8:
|
|
820
|
+
raise ValueError("Y dtype must be torch.uint8")
|
|
821
|
+
|
|
822
|
+
return quantized_matmul(
|
|
823
|
+
X,
|
|
824
|
+
X_zero_point,
|
|
825
|
+
Y,
|
|
826
|
+
Y_zero_point,
|
|
827
|
+
bias,
|
|
828
|
+
out_multiplier,
|
|
829
|
+
out_shift,
|
|
830
|
+
out_zero_point,
|
|
831
|
+
transposed,
|
|
832
|
+
)
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
@impl_tracked(m, "quantized_layer_norm.per_tensor")
|
|
836
|
+
def quantized_layer_norm_per_tensor(
|
|
837
|
+
input_tensor: torch.Tensor,
|
|
838
|
+
X_scale: float,
|
|
839
|
+
X_zero_point: int,
|
|
840
|
+
normalized_shape: list[int],
|
|
841
|
+
weight: torch.Tensor,
|
|
842
|
+
bias: torch.Tensor,
|
|
843
|
+
eps: float,
|
|
844
|
+
output_scale: float,
|
|
845
|
+
output_zero_point: int,
|
|
846
|
+
) -> torch.Tensor:
|
|
847
|
+
"""
|
|
848
|
+
Quantized layer norm operation.
|
|
849
|
+
|
|
850
|
+
Args:
|
|
851
|
+
- input_tensor (Tensor): The activations tensor
|
|
852
|
+
- X_scale (float): The scale of the input
|
|
853
|
+
- X_zero_point (int): The zero point of the input
|
|
854
|
+
- normalized_shape (int): The shape of the input
|
|
855
|
+
- weight (Tensor): The weight tensor
|
|
856
|
+
- bias (Tensor): The bias tensor
|
|
857
|
+
- eps (float): The epsilon value
|
|
858
|
+
- output_scale (float): The scale of the output
|
|
859
|
+
- output_zero_point (int): The zero point of the output
|
|
860
|
+
"""
|
|
861
|
+
supported_dtypes = [torch.int8, torch.uint8, torch.int16]
|
|
862
|
+
if input_tensor.dtype not in supported_dtypes:
|
|
863
|
+
raise ValueError(
|
|
864
|
+
f"Input dtype must be one of {supported_dtypes}. Got {input_tensor.dtype}"
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
quant_min = torch.iinfo(input_tensor.dtype).min
|
|
868
|
+
quant_max = torch.iinfo(input_tensor.dtype).max
|
|
869
|
+
float_input_tensor = dequantize_per_tensor(
|
|
870
|
+
input_tensor,
|
|
871
|
+
X_scale,
|
|
872
|
+
X_zero_point,
|
|
873
|
+
quant_min,
|
|
874
|
+
quant_max,
|
|
875
|
+
input_tensor.dtype,
|
|
876
|
+
)
|
|
877
|
+
assert isinstance(float_input_tensor, torch.Tensor)
|
|
878
|
+
out = torch.nn.functional.layer_norm(
|
|
879
|
+
float_input_tensor, normalized_shape, weight, bias, eps=eps
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
return quantize_per_tensor(
|
|
883
|
+
out,
|
|
884
|
+
output_scale,
|
|
885
|
+
output_zero_point,
|
|
886
|
+
quant_min,
|
|
887
|
+
quant_max,
|
|
888
|
+
input_tensor.dtype,
|
|
889
|
+
)
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
@impl_tracked(m, "quantized_layer_norm")
|
|
893
|
+
def quantized_layer_norm(
|
|
894
|
+
input_tensor: torch.Tensor,
|
|
895
|
+
X_scale: torch.Tensor,
|
|
896
|
+
X_zero_point: torch.Tensor,
|
|
897
|
+
normalized_shape: list[int],
|
|
898
|
+
weight: torch.Tensor,
|
|
899
|
+
bias: torch.Tensor,
|
|
900
|
+
eps: float,
|
|
901
|
+
output_scale: float,
|
|
902
|
+
output_zero_point: int,
|
|
903
|
+
) -> torch.Tensor:
|
|
904
|
+
return quantized_layer_norm_per_tensor(
|
|
905
|
+
input_tensor,
|
|
906
|
+
float(X_scale.item()),
|
|
907
|
+
int(X_zero_point.item()),
|
|
908
|
+
normalized_shape,
|
|
909
|
+
weight,
|
|
910
|
+
bias,
|
|
911
|
+
eps,
|
|
912
|
+
output_scale,
|
|
913
|
+
output_zero_point,
|
|
914
|
+
)
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
def _broadcast_over_channels(
|
|
918
|
+
value: float | int | torch.Tensor,
|
|
919
|
+
ndim: int,
|
|
920
|
+
channel_dim: int,
|
|
921
|
+
out_channels: int,
|
|
922
|
+
) -> float | int | torch.Tensor:
|
|
923
|
+
"""Shape a scalar or per-output-channel qparam for broadcasting."""
|
|
924
|
+
if not isinstance(value, torch.Tensor):
|
|
925
|
+
return value
|
|
926
|
+
if value.numel() == 1:
|
|
927
|
+
return value.reshape(())
|
|
928
|
+
if value.numel() != out_channels:
|
|
929
|
+
raise ValueError(
|
|
930
|
+
f"per-channel qparam has {value.numel()} entries, "
|
|
931
|
+
f"expected 1 or {out_channels}"
|
|
932
|
+
)
|
|
933
|
+
shape = [1] * ndim
|
|
934
|
+
shape[channel_dim] = -1
|
|
935
|
+
return value.reshape(shape)
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
def quantized_conv_common(
|
|
939
|
+
input_tensor: torch.Tensor,
|
|
940
|
+
weight: torch.Tensor,
|
|
941
|
+
bias: torch.Tensor,
|
|
942
|
+
stride: tuple[int, ...],
|
|
943
|
+
padding: tuple[int, ...],
|
|
944
|
+
dilation: tuple[int, ...],
|
|
945
|
+
groups: int,
|
|
946
|
+
in_zero_point: int,
|
|
947
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
948
|
+
bias_scale: float | torch.Tensor,
|
|
949
|
+
output_scale: float,
|
|
950
|
+
output_zero_point: int,
|
|
951
|
+
out_multiplier: int | torch.Tensor,
|
|
952
|
+
out_shift: int | torch.Tensor,
|
|
953
|
+
) -> torch.Tensor:
|
|
954
|
+
"""
|
|
955
|
+
Quantized convolution operation.
|
|
956
|
+
|
|
957
|
+
Args:
|
|
958
|
+
- input_tensor (Tensor): The activations tensor
|
|
959
|
+
- weight (Tensor): The weight tensor
|
|
960
|
+
- bias (Tensor): The bias tensor
|
|
961
|
+
- stride (Tuple[int]): The stride of the convolution
|
|
962
|
+
- padding (Tuple[int]): The padding of the convolution
|
|
963
|
+
- dilation (Tuple[int]): The dilation of the convolution
|
|
964
|
+
- groups (int): The number of groups
|
|
965
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
966
|
+
- weight_zero_point (int | Tensor): The quantized mapping of zero for the
|
|
967
|
+
weight, either a scalar or one entry per output channel
|
|
968
|
+
- bias_scale (float | Tensor): The quantized bias scale, either a scalar
|
|
969
|
+
or one entry per output channel
|
|
970
|
+
- output_scale (float): The scale of the output
|
|
971
|
+
- output_zero_point (int): The zero point of the output
|
|
972
|
+
- out_multiplier (int | Tensor): Unused
|
|
973
|
+
- out_shift (int | Tensor): Unused
|
|
974
|
+
"""
|
|
975
|
+
out_channels = weight.shape[0]
|
|
976
|
+
# Absent means a symmetric weight, whose zero point is zero by definition;
|
|
977
|
+
# the AoT side omits the argument rather than emitting a constant of zeros.
|
|
978
|
+
wzp = _broadcast_over_channels(
|
|
979
|
+
0 if weight_zero_point is None else weight_zero_point,
|
|
980
|
+
weight.dim(),
|
|
981
|
+
0,
|
|
982
|
+
out_channels,
|
|
983
|
+
)
|
|
984
|
+
|
|
985
|
+
if len(input_tensor.shape) == 3:
|
|
986
|
+
acc = torch.nn.functional.conv1d(
|
|
987
|
+
input_tensor.float() - in_zero_point,
|
|
988
|
+
weight.float() - wzp,
|
|
989
|
+
bias.float(),
|
|
990
|
+
stride[-1],
|
|
991
|
+
padding[-1],
|
|
992
|
+
dilation[-1],
|
|
993
|
+
groups,
|
|
994
|
+
)
|
|
995
|
+
|
|
996
|
+
elif len(input_tensor.shape) == 4:
|
|
997
|
+
acc = torch.nn.functional.conv2d(
|
|
998
|
+
input_tensor.float() - in_zero_point,
|
|
999
|
+
weight.float() - wzp,
|
|
1000
|
+
bias.float(),
|
|
1001
|
+
stride,
|
|
1002
|
+
padding,
|
|
1003
|
+
dilation,
|
|
1004
|
+
groups,
|
|
1005
|
+
)
|
|
1006
|
+
else:
|
|
1007
|
+
raise ValueError("Input tensor must be 3D or 4D")
|
|
1008
|
+
|
|
1009
|
+
# conv accumulates in the integer domain (scale = in_scale * weight_scale =
|
|
1010
|
+
# bias_scale) with the integer bias added pre-scale; dequantize the whole
|
|
1011
|
+
# accumulation by bias_scale to get the floating-point result.
|
|
1012
|
+
float_out = acc * _broadcast_over_channels(bias_scale, acc.dim(), 1, out_channels)
|
|
1013
|
+
|
|
1014
|
+
return quantize_per_tensor(
|
|
1015
|
+
float_out,
|
|
1016
|
+
output_scale,
|
|
1017
|
+
output_zero_point,
|
|
1018
|
+
torch.iinfo(input_tensor.dtype).min,
|
|
1019
|
+
torch.iinfo(input_tensor.dtype).max,
|
|
1020
|
+
input_tensor.dtype,
|
|
1021
|
+
)
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
@impl_tracked(m, "quantized_conv2d_nchw.per_tensor")
|
|
1025
|
+
def quantized_conv2d_nchw_per_tensor(
|
|
1026
|
+
input_tensor: torch.Tensor,
|
|
1027
|
+
weight: torch.Tensor,
|
|
1028
|
+
bias: torch.Tensor,
|
|
1029
|
+
stride: tuple[int, int],
|
|
1030
|
+
padding: tuple[int, int],
|
|
1031
|
+
dilation: tuple[int, int],
|
|
1032
|
+
groups: int,
|
|
1033
|
+
in_zero_point: int,
|
|
1034
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1035
|
+
bias_scale: float | torch.Tensor,
|
|
1036
|
+
output_scale: float,
|
|
1037
|
+
output_zero_point: int,
|
|
1038
|
+
out_multiplier: int | torch.Tensor,
|
|
1039
|
+
out_shift: int | torch.Tensor,
|
|
1040
|
+
) -> torch.Tensor:
|
|
1041
|
+
"""
|
|
1042
|
+
Quantized convolution operation.
|
|
1043
|
+
|
|
1044
|
+
Args:
|
|
1045
|
+
- input_tensor (Tensor): The activations tensor
|
|
1046
|
+
- weight (Tensor): The weight tensor
|
|
1047
|
+
- bias (Tensor): The bias tensor
|
|
1048
|
+
- stride (Tuple[int]): The stride of the convolution
|
|
1049
|
+
- padding (Tuple[int]): The padding of the convolution
|
|
1050
|
+
- dilation (Tuple[int]): The dilation of the convolution
|
|
1051
|
+
- groups (int): The number of groups
|
|
1052
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
1053
|
+
- weight_zero_point (int): The quantized mapping of zero for the weight
|
|
1054
|
+
- bias_scale (float): The quantized bias scale
|
|
1055
|
+
- output_scale (float): The scale of the output
|
|
1056
|
+
- output_zero_point (int): The zero point of the output
|
|
1057
|
+
- out_multiplier (int): Unused
|
|
1058
|
+
- out_shift (int): Unused
|
|
1059
|
+
"""
|
|
1060
|
+
if not input_tensor.is_contiguous(memory_format=torch.contiguous_format):
|
|
1061
|
+
raise ValueError("Input tensor must be in NCHW format")
|
|
1062
|
+
return quantized_conv_common(
|
|
1063
|
+
input_tensor,
|
|
1064
|
+
weight,
|
|
1065
|
+
bias,
|
|
1066
|
+
stride,
|
|
1067
|
+
padding,
|
|
1068
|
+
dilation,
|
|
1069
|
+
groups,
|
|
1070
|
+
in_zero_point,
|
|
1071
|
+
weight_zero_point,
|
|
1072
|
+
bias_scale,
|
|
1073
|
+
output_scale,
|
|
1074
|
+
output_zero_point,
|
|
1075
|
+
out_multiplier,
|
|
1076
|
+
out_shift,
|
|
1077
|
+
)
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
@impl_tracked(m, "quantized_conv1d_ncl.per_tensor")
|
|
1081
|
+
def quantized_conv1d_ncl_per_tensor(
|
|
1082
|
+
input_tensor: torch.Tensor,
|
|
1083
|
+
weight: torch.Tensor,
|
|
1084
|
+
bias: torch.Tensor,
|
|
1085
|
+
stride: tuple[int],
|
|
1086
|
+
padding: tuple[int],
|
|
1087
|
+
dilation: tuple[int],
|
|
1088
|
+
groups: int,
|
|
1089
|
+
in_zero_point: int,
|
|
1090
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1091
|
+
bias_scale: float | torch.Tensor,
|
|
1092
|
+
output_scale: float,
|
|
1093
|
+
output_zero_point: int,
|
|
1094
|
+
out_multiplier: int | torch.Tensor,
|
|
1095
|
+
out_shift: int | torch.Tensor,
|
|
1096
|
+
) -> torch.Tensor:
|
|
1097
|
+
"""
|
|
1098
|
+
Quantized 1D convolution operation in NCL (channels-first) format.
|
|
1099
|
+
|
|
1100
|
+
Args:
|
|
1101
|
+
- input_tensor (Tensor): The activations tensor in [N, C, L] format
|
|
1102
|
+
- weight (Tensor): The weight tensor in [OC, IC/groups, K] format
|
|
1103
|
+
- bias (Tensor): The bias tensor
|
|
1104
|
+
- stride (Tuple[int]): The stride of the convolution
|
|
1105
|
+
- padding (Tuple[int]): The padding of the convolution
|
|
1106
|
+
- dilation (Tuple[int]): The dilation of the convolution
|
|
1107
|
+
- groups (int): The number of groups
|
|
1108
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
1109
|
+
- weight_zero_point (int): The quantized mapping of zero for the weight
|
|
1110
|
+
- bias_scale (float): The quantized bias scale
|
|
1111
|
+
- output_scale (float): The scale of the output
|
|
1112
|
+
- output_zero_point (int): The zero point of the output
|
|
1113
|
+
- out_multiplier (int): Unused
|
|
1114
|
+
- out_shift (int): Unused
|
|
1115
|
+
"""
|
|
1116
|
+
if not input_tensor.is_contiguous(memory_format=torch.contiguous_format):
|
|
1117
|
+
raise ValueError("Input tensor must be in NCL format")
|
|
1118
|
+
return quantized_conv_common(
|
|
1119
|
+
input_tensor,
|
|
1120
|
+
weight,
|
|
1121
|
+
bias,
|
|
1122
|
+
stride,
|
|
1123
|
+
padding,
|
|
1124
|
+
dilation,
|
|
1125
|
+
groups,
|
|
1126
|
+
in_zero_point,
|
|
1127
|
+
weight_zero_point,
|
|
1128
|
+
bias_scale,
|
|
1129
|
+
output_scale,
|
|
1130
|
+
output_zero_point,
|
|
1131
|
+
out_multiplier,
|
|
1132
|
+
out_shift,
|
|
1133
|
+
)
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
@impl_tracked(m, "quantized_conv1d_ncl")
|
|
1137
|
+
def quantized_conv1d_ncl(
|
|
1138
|
+
input_tensor: torch.Tensor,
|
|
1139
|
+
weight: torch.Tensor,
|
|
1140
|
+
bias: torch.Tensor,
|
|
1141
|
+
stride: tuple[int],
|
|
1142
|
+
padding: tuple[int],
|
|
1143
|
+
dilation: tuple[int],
|
|
1144
|
+
groups: int,
|
|
1145
|
+
in_zero_point: int,
|
|
1146
|
+
weight_zero_point: torch.Tensor,
|
|
1147
|
+
bias_scale: torch.Tensor,
|
|
1148
|
+
output_scale: float,
|
|
1149
|
+
output_zero_point: int,
|
|
1150
|
+
out_multiplier: torch.Tensor,
|
|
1151
|
+
out_shift: torch.Tensor,
|
|
1152
|
+
) -> torch.Tensor:
|
|
1153
|
+
return quantized_conv1d_ncl_per_tensor(
|
|
1154
|
+
input_tensor,
|
|
1155
|
+
weight,
|
|
1156
|
+
bias,
|
|
1157
|
+
stride,
|
|
1158
|
+
padding,
|
|
1159
|
+
dilation,
|
|
1160
|
+
groups,
|
|
1161
|
+
in_zero_point,
|
|
1162
|
+
weight_zero_point,
|
|
1163
|
+
bias_scale,
|
|
1164
|
+
output_scale,
|
|
1165
|
+
output_zero_point,
|
|
1166
|
+
out_multiplier,
|
|
1167
|
+
out_shift,
|
|
1168
|
+
)
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
@impl_tracked(m, "quantized_conv1d_nlc.per_tensor")
|
|
1172
|
+
def quantized_conv1d_nlc_per_tensor(
|
|
1173
|
+
input_tensor: torch.Tensor,
|
|
1174
|
+
weight: torch.Tensor,
|
|
1175
|
+
bias: torch.Tensor,
|
|
1176
|
+
stride: tuple[int],
|
|
1177
|
+
padding: tuple[int],
|
|
1178
|
+
dilation: tuple[int],
|
|
1179
|
+
groups: int,
|
|
1180
|
+
in_zero_point: int,
|
|
1181
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1182
|
+
bias_scale: float | torch.Tensor,
|
|
1183
|
+
output_scale: float,
|
|
1184
|
+
output_zero_point: int,
|
|
1185
|
+
out_multiplier: int | torch.Tensor,
|
|
1186
|
+
out_shift: int | torch.Tensor,
|
|
1187
|
+
) -> torch.Tensor:
|
|
1188
|
+
"""
|
|
1189
|
+
Quantized 1D convolution operation in NLC (channels-last) format.
|
|
1190
|
+
|
|
1191
|
+
Args:
|
|
1192
|
+
- input_tensor (Tensor): The activations tensor in [N, L, C] format
|
|
1193
|
+
- weight (Tensor): The weight tensor in [OC, K, IC/groups] format
|
|
1194
|
+
- bias (Tensor): The bias tensor
|
|
1195
|
+
- stride (Tuple[int]): The stride of the convolution
|
|
1196
|
+
- padding (Tuple[int]): The padding of the convolution
|
|
1197
|
+
- dilation (Tuple[int]): The dilation of the convolution
|
|
1198
|
+
- groups (int): The number of groups
|
|
1199
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
1200
|
+
- weight_zero_point (int): The quantized mapping of zero for the weight
|
|
1201
|
+
- bias_scale (float): The quantized bias scale
|
|
1202
|
+
- output_scale (float): The scale of the output
|
|
1203
|
+
- output_zero_point (int): The zero point of the output
|
|
1204
|
+
- out_multiplier (int): Unused
|
|
1205
|
+
- out_shift (int): Unused
|
|
1206
|
+
"""
|
|
1207
|
+
# Convert NLC to NCL for processing
|
|
1208
|
+
input_ncl = input_tensor.permute(0, 2, 1).contiguous()
|
|
1209
|
+
# Convert weight from [OC, K, IC/groups] to [OC, IC/groups, K]
|
|
1210
|
+
weight_ncl = weight.permute(0, 2, 1).contiguous()
|
|
1211
|
+
|
|
1212
|
+
result_ncl = quantized_conv_common(
|
|
1213
|
+
input_ncl,
|
|
1214
|
+
weight_ncl,
|
|
1215
|
+
bias,
|
|
1216
|
+
stride,
|
|
1217
|
+
padding,
|
|
1218
|
+
dilation,
|
|
1219
|
+
groups,
|
|
1220
|
+
in_zero_point,
|
|
1221
|
+
weight_zero_point,
|
|
1222
|
+
bias_scale,
|
|
1223
|
+
output_scale,
|
|
1224
|
+
output_zero_point,
|
|
1225
|
+
out_multiplier,
|
|
1226
|
+
out_shift,
|
|
1227
|
+
)
|
|
1228
|
+
|
|
1229
|
+
# Convert result back to NLC format
|
|
1230
|
+
return result_ncl.permute(0, 2, 1).contiguous()
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
@impl_tracked(m, "quantized_conv1d_nlc")
|
|
1234
|
+
def quantized_conv1d_nlc(
|
|
1235
|
+
input_tensor: torch.Tensor,
|
|
1236
|
+
weight: torch.Tensor,
|
|
1237
|
+
bias: torch.Tensor,
|
|
1238
|
+
stride: tuple[int],
|
|
1239
|
+
padding: tuple[int],
|
|
1240
|
+
dilation: tuple[int],
|
|
1241
|
+
groups: int,
|
|
1242
|
+
in_zero_point: int,
|
|
1243
|
+
weight_zero_point: torch.Tensor,
|
|
1244
|
+
bias_scale: torch.Tensor,
|
|
1245
|
+
output_scale: float,
|
|
1246
|
+
output_zero_point: int,
|
|
1247
|
+
out_multiplier: torch.Tensor,
|
|
1248
|
+
out_shift: torch.Tensor,
|
|
1249
|
+
) -> torch.Tensor:
|
|
1250
|
+
return quantized_conv1d_nlc_per_tensor(
|
|
1251
|
+
input_tensor,
|
|
1252
|
+
weight,
|
|
1253
|
+
bias,
|
|
1254
|
+
stride,
|
|
1255
|
+
padding,
|
|
1256
|
+
dilation,
|
|
1257
|
+
groups,
|
|
1258
|
+
in_zero_point,
|
|
1259
|
+
weight_zero_point,
|
|
1260
|
+
bias_scale,
|
|
1261
|
+
output_scale,
|
|
1262
|
+
output_zero_point,
|
|
1263
|
+
out_multiplier,
|
|
1264
|
+
out_shift,
|
|
1265
|
+
)
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
@impl_tracked(m, "quantized_depthwise_conv1d_ncl.per_tensor")
|
|
1269
|
+
def quantized_depthwise_conv1d_ncl_per_tensor(
|
|
1270
|
+
input_tensor: torch.Tensor,
|
|
1271
|
+
weight: torch.Tensor,
|
|
1272
|
+
bias: torch.Tensor,
|
|
1273
|
+
stride: tuple[int],
|
|
1274
|
+
padding: tuple[int],
|
|
1275
|
+
dilation: tuple[int],
|
|
1276
|
+
groups: int,
|
|
1277
|
+
in_zero_point: int,
|
|
1278
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1279
|
+
bias_scale: float | torch.Tensor,
|
|
1280
|
+
output_scale: float,
|
|
1281
|
+
output_zero_point: int,
|
|
1282
|
+
out_multiplier: int | torch.Tensor,
|
|
1283
|
+
out_shift: int | torch.Tensor,
|
|
1284
|
+
) -> torch.Tensor:
|
|
1285
|
+
"""
|
|
1286
|
+
Quantized depthwise 1D convolution in NCL (channels-first) format.
|
|
1287
|
+
|
|
1288
|
+
This op only handles depthwise convolutions (groups == in_channels, groups > 1).
|
|
1289
|
+
Regular convolutions must use quantized_conv1d_ncl instead.
|
|
1290
|
+
|
|
1291
|
+
Args:
|
|
1292
|
+
- input_tensor (Tensor): [N, C, L] format
|
|
1293
|
+
- weight (Tensor): [OC, 1, K] format (IC/groups == 1 for depthwise)
|
|
1294
|
+
- bias (Tensor): [OC]
|
|
1295
|
+
- stride, padding, dilation, groups: convolution parameters
|
|
1296
|
+
- in_zero_point, weight_zero_point, bias_scale: quantization params
|
|
1297
|
+
- output_scale, output_zero_point: output quantization params
|
|
1298
|
+
- out_multiplier, out_shift: unused
|
|
1299
|
+
"""
|
|
1300
|
+
assert is_depthwise_conv(
|
|
1301
|
+
groups, input_tensor.shape[1]
|
|
1302
|
+
), f"quantized_depthwise_conv1d_ncl requires depthwise conv (groups == in_channels), got groups={groups}, in_channels={input_tensor.shape[1]}"
|
|
1303
|
+
|
|
1304
|
+
return quantized_conv_common(
|
|
1305
|
+
input_tensor,
|
|
1306
|
+
weight,
|
|
1307
|
+
bias,
|
|
1308
|
+
stride,
|
|
1309
|
+
padding,
|
|
1310
|
+
dilation,
|
|
1311
|
+
groups,
|
|
1312
|
+
in_zero_point,
|
|
1313
|
+
weight_zero_point,
|
|
1314
|
+
bias_scale,
|
|
1315
|
+
output_scale,
|
|
1316
|
+
output_zero_point,
|
|
1317
|
+
out_multiplier,
|
|
1318
|
+
out_shift,
|
|
1319
|
+
)
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
@impl_tracked(m, "quantized_depthwise_conv1d_nlc.per_tensor")
|
|
1323
|
+
def quantized_depthwise_conv1d_nlc_per_tensor(
|
|
1324
|
+
input_tensor: torch.Tensor,
|
|
1325
|
+
weight: torch.Tensor,
|
|
1326
|
+
bias: torch.Tensor,
|
|
1327
|
+
stride: tuple[int],
|
|
1328
|
+
padding: tuple[int],
|
|
1329
|
+
dilation: tuple[int],
|
|
1330
|
+
groups: int,
|
|
1331
|
+
in_zero_point: int,
|
|
1332
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1333
|
+
bias_scale: float | torch.Tensor,
|
|
1334
|
+
output_scale: float,
|
|
1335
|
+
output_zero_point: int,
|
|
1336
|
+
out_multiplier: int | torch.Tensor,
|
|
1337
|
+
out_shift: int | torch.Tensor,
|
|
1338
|
+
) -> torch.Tensor:
|
|
1339
|
+
"""
|
|
1340
|
+
Quantized depthwise 1D convolution in NLC (channels-last) format.
|
|
1341
|
+
|
|
1342
|
+
This op only handles depthwise convolutions (groups == in_channels, groups > 1).
|
|
1343
|
+
Regular convolutions must use quantized_conv1d_nlc instead.
|
|
1344
|
+
|
|
1345
|
+
Args:
|
|
1346
|
+
- input_tensor (Tensor): [N, L, C] format
|
|
1347
|
+
- weight (Tensor): [OC, K, 1] format (IC/groups == 1 for depthwise)
|
|
1348
|
+
- bias (Tensor): [OC]
|
|
1349
|
+
- stride, padding, dilation, groups: convolution parameters
|
|
1350
|
+
- in_zero_point, weight_zero_point, bias_scale: quantization params
|
|
1351
|
+
- output_scale, output_zero_point: output quantization params
|
|
1352
|
+
- out_multiplier, out_shift: unused
|
|
1353
|
+
"""
|
|
1354
|
+
assert is_depthwise_conv(
|
|
1355
|
+
groups, input_tensor.shape[-1]
|
|
1356
|
+
), f"quantized_depthwise_conv1d_nlc requires depthwise conv (groups == in_channels), got groups={groups}, in_channels={input_tensor.shape[-1]}"
|
|
1357
|
+
|
|
1358
|
+
# Convert NLC to NCL for processing
|
|
1359
|
+
input_ncl = input_tensor.permute(0, 2, 1).contiguous()
|
|
1360
|
+
# Convert weight from [OC, K, IC/groups] to [OC, IC/groups, K]
|
|
1361
|
+
weight_ncl = weight.permute(0, 2, 1).contiguous()
|
|
1362
|
+
|
|
1363
|
+
result_ncl = quantized_conv_common(
|
|
1364
|
+
input_ncl,
|
|
1365
|
+
weight_ncl,
|
|
1366
|
+
bias,
|
|
1367
|
+
stride,
|
|
1368
|
+
padding,
|
|
1369
|
+
dilation,
|
|
1370
|
+
groups,
|
|
1371
|
+
in_zero_point,
|
|
1372
|
+
weight_zero_point,
|
|
1373
|
+
bias_scale,
|
|
1374
|
+
output_scale,
|
|
1375
|
+
output_zero_point,
|
|
1376
|
+
out_multiplier,
|
|
1377
|
+
out_shift,
|
|
1378
|
+
)
|
|
1379
|
+
|
|
1380
|
+
# Convert result back to NLC format
|
|
1381
|
+
return result_ncl.permute(0, 2, 1).contiguous()
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
@impl_tracked(m, "quantized_depthwise_conv1d_ncl")
|
|
1385
|
+
def quantized_depthwise_conv1d_ncl(
|
|
1386
|
+
input_tensor: torch.Tensor,
|
|
1387
|
+
weight: torch.Tensor,
|
|
1388
|
+
bias: torch.Tensor,
|
|
1389
|
+
stride: tuple[int],
|
|
1390
|
+
padding: tuple[int],
|
|
1391
|
+
dilation: tuple[int],
|
|
1392
|
+
groups: int,
|
|
1393
|
+
in_zero_point: int,
|
|
1394
|
+
weight_zero_point: torch.Tensor,
|
|
1395
|
+
bias_scale: torch.Tensor,
|
|
1396
|
+
output_scale: float,
|
|
1397
|
+
output_zero_point: int,
|
|
1398
|
+
out_multiplier: torch.Tensor,
|
|
1399
|
+
out_shift: torch.Tensor,
|
|
1400
|
+
) -> torch.Tensor:
|
|
1401
|
+
return quantized_depthwise_conv1d_ncl_per_tensor(
|
|
1402
|
+
input_tensor,
|
|
1403
|
+
weight,
|
|
1404
|
+
bias,
|
|
1405
|
+
stride,
|
|
1406
|
+
padding,
|
|
1407
|
+
dilation,
|
|
1408
|
+
groups,
|
|
1409
|
+
in_zero_point,
|
|
1410
|
+
weight_zero_point,
|
|
1411
|
+
bias_scale,
|
|
1412
|
+
output_scale,
|
|
1413
|
+
output_zero_point,
|
|
1414
|
+
out_multiplier,
|
|
1415
|
+
out_shift,
|
|
1416
|
+
)
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
@impl_tracked(m, "quantized_depthwise_conv1d_nlc")
|
|
1420
|
+
def quantized_depthwise_conv1d_nlc(
|
|
1421
|
+
input_tensor: torch.Tensor,
|
|
1422
|
+
weight: torch.Tensor,
|
|
1423
|
+
bias: torch.Tensor,
|
|
1424
|
+
stride: tuple[int],
|
|
1425
|
+
padding: tuple[int],
|
|
1426
|
+
dilation: tuple[int],
|
|
1427
|
+
groups: int,
|
|
1428
|
+
in_zero_point: int,
|
|
1429
|
+
weight_zero_point: torch.Tensor,
|
|
1430
|
+
bias_scale: torch.Tensor,
|
|
1431
|
+
output_scale: float,
|
|
1432
|
+
output_zero_point: int,
|
|
1433
|
+
out_multiplier: torch.Tensor,
|
|
1434
|
+
out_shift: torch.Tensor,
|
|
1435
|
+
) -> torch.Tensor:
|
|
1436
|
+
return quantized_depthwise_conv1d_nlc_per_tensor(
|
|
1437
|
+
input_tensor,
|
|
1438
|
+
weight,
|
|
1439
|
+
bias,
|
|
1440
|
+
stride,
|
|
1441
|
+
padding,
|
|
1442
|
+
dilation,
|
|
1443
|
+
groups,
|
|
1444
|
+
in_zero_point,
|
|
1445
|
+
weight_zero_point,
|
|
1446
|
+
bias_scale,
|
|
1447
|
+
output_scale,
|
|
1448
|
+
output_zero_point,
|
|
1449
|
+
out_multiplier,
|
|
1450
|
+
out_shift,
|
|
1451
|
+
)
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
@impl_tracked(m, "quantized_conv2d_nchw")
|
|
1455
|
+
def quantized_conv2d_nchw(
|
|
1456
|
+
input_tensor: torch.Tensor,
|
|
1457
|
+
weight: torch.Tensor,
|
|
1458
|
+
bias: torch.Tensor,
|
|
1459
|
+
stride: tuple[int, int],
|
|
1460
|
+
padding: tuple[int, int],
|
|
1461
|
+
dilation: tuple[int, int],
|
|
1462
|
+
groups: int,
|
|
1463
|
+
in_zero_point: int,
|
|
1464
|
+
weight_zero_point: torch.Tensor,
|
|
1465
|
+
bias_scale: torch.Tensor,
|
|
1466
|
+
output_scale: float,
|
|
1467
|
+
output_zero_point: int,
|
|
1468
|
+
out_multiplier: torch.Tensor,
|
|
1469
|
+
out_shift: torch.Tensor,
|
|
1470
|
+
) -> torch.Tensor:
|
|
1471
|
+
return quantized_conv2d_nchw_per_tensor(
|
|
1472
|
+
input_tensor,
|
|
1473
|
+
weight,
|
|
1474
|
+
bias,
|
|
1475
|
+
stride,
|
|
1476
|
+
padding,
|
|
1477
|
+
dilation,
|
|
1478
|
+
groups,
|
|
1479
|
+
in_zero_point,
|
|
1480
|
+
weight_zero_point,
|
|
1481
|
+
bias_scale,
|
|
1482
|
+
output_scale,
|
|
1483
|
+
output_zero_point,
|
|
1484
|
+
out_multiplier,
|
|
1485
|
+
out_shift,
|
|
1486
|
+
)
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
@impl_tracked(m, "quantized_w8a32_conv")
|
|
1490
|
+
def quantized_w8a32_conv(
|
|
1491
|
+
src: torch.Tensor,
|
|
1492
|
+
weight: torch.Tensor,
|
|
1493
|
+
w_scale: float,
|
|
1494
|
+
bias: torch.Tensor,
|
|
1495
|
+
b_scale: float,
|
|
1496
|
+
) -> torch.Tensor:
|
|
1497
|
+
|
|
1498
|
+
if len(weight.shape) != 3:
|
|
1499
|
+
raise ValueError("Weight tensor must be 3D")
|
|
1500
|
+
|
|
1501
|
+
kernel_size, out_channels, in_channels = weight.shape
|
|
1502
|
+
if kernel_size != 3:
|
|
1503
|
+
raise ValueError("Kernel size must be 3")
|
|
1504
|
+
if (out_channels % 4) != 0:
|
|
1505
|
+
raise ValueError("Out channels must be a multiple of 4")
|
|
1506
|
+
if (in_channels % 4) != 0:
|
|
1507
|
+
raise ValueError("In channels must be a multiple of 4")
|
|
1508
|
+
|
|
1509
|
+
assert weight.dtype == torch.int8
|
|
1510
|
+
assert bias.dtype == torch.int8
|
|
1511
|
+
|
|
1512
|
+
# To make compliant with torch (LCN -> NCL format)
|
|
1513
|
+
weight = weight.permute(1, 2, 0).contiguous()
|
|
1514
|
+
|
|
1515
|
+
# channels last to channels first
|
|
1516
|
+
src = src.permute(0, 2, 1).contiguous()
|
|
1517
|
+
|
|
1518
|
+
dequant_weight = weight.float() * w_scale
|
|
1519
|
+
|
|
1520
|
+
# Dequantize bias using scale
|
|
1521
|
+
dequant_bias = bias.float() * b_scale
|
|
1522
|
+
|
|
1523
|
+
# Perform 1D convolution
|
|
1524
|
+
# src: [batch, in_channel, in_length]
|
|
1525
|
+
# weight: [out_ch, in_ch, kernel_dim]
|
|
1526
|
+
# bias: [out_ch]
|
|
1527
|
+
output = torch.nn.functional.conv1d(
|
|
1528
|
+
src.float(),
|
|
1529
|
+
dequant_weight,
|
|
1530
|
+
dequant_bias,
|
|
1531
|
+
)
|
|
1532
|
+
|
|
1533
|
+
return output
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
@impl_tracked(m, "quantized_w8a32_linear")
|
|
1537
|
+
def quantized_w8a32_linear(
|
|
1538
|
+
src: torch.Tensor,
|
|
1539
|
+
weight: torch.Tensor,
|
|
1540
|
+
w_scale: float,
|
|
1541
|
+
bias: torch.Tensor,
|
|
1542
|
+
b_scale: float,
|
|
1543
|
+
) -> torch.Tensor:
|
|
1544
|
+
# src comes in shape [leading_dims, in_dim]
|
|
1545
|
+
# weight comes in shape [in_dim, out_dim]
|
|
1546
|
+
# output comes in empty with shape [leading_dims, out_dim]
|
|
1547
|
+
assert weight.dtype == torch.int8
|
|
1548
|
+
assert bias.dtype == torch.int8
|
|
1549
|
+
if len(src.shape) >= 2:
|
|
1550
|
+
assert src.shape[-2] == 1, "Only supporting vector-matrix multiplication"
|
|
1551
|
+
|
|
1552
|
+
# need to transpose to make compliant with torch linear (in, out -> out, in)
|
|
1553
|
+
weight = weight.transpose(1, 0).contiguous()
|
|
1554
|
+
dequant_weight = weight.float() * w_scale
|
|
1555
|
+
dequant_bias = bias.float() * b_scale
|
|
1556
|
+
|
|
1557
|
+
output = torch.nn.functional.linear(
|
|
1558
|
+
src.float(),
|
|
1559
|
+
dequant_weight,
|
|
1560
|
+
dequant_bias,
|
|
1561
|
+
)
|
|
1562
|
+
|
|
1563
|
+
return output
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
@impl_tracked(m, "quantized_w8a32_gru")
|
|
1567
|
+
def quantized_w8a32_gru(
|
|
1568
|
+
inputs: torch.Tensor,
|
|
1569
|
+
hidden: torch.Tensor,
|
|
1570
|
+
weights_inputs: torch.Tensor,
|
|
1571
|
+
w_i_scale: float,
|
|
1572
|
+
weights_hidden: torch.Tensor,
|
|
1573
|
+
w_h_scale: float,
|
|
1574
|
+
bias_inputs: torch.Tensor,
|
|
1575
|
+
b_scale: float,
|
|
1576
|
+
bias_hidden: torch.Tensor,
|
|
1577
|
+
) -> torch.Tensor:
|
|
1578
|
+
assert weights_inputs.dtype == torch.int8
|
|
1579
|
+
assert weights_hidden.dtype == torch.int8
|
|
1580
|
+
assert bias_inputs.dtype == torch.int8
|
|
1581
|
+
assert bias_hidden.dtype == torch.int8
|
|
1582
|
+
assert inputs.dtype == torch.float32
|
|
1583
|
+
assert hidden.dtype == torch.float32
|
|
1584
|
+
|
|
1585
|
+
# Hidden state can be 1D, 2D (1, hidden_dim), or 3D (1, 1, hidden_dim).
|
|
1586
|
+
# All leading dimensions must be 1.
|
|
1587
|
+
for d in range(len(hidden.shape) - 1):
|
|
1588
|
+
if hidden.shape[d] != 1:
|
|
1589
|
+
raise ValueError(
|
|
1590
|
+
f"Leading dimension {d} of hidden state must be 1, got {hidden.shape[d]}"
|
|
1591
|
+
)
|
|
1592
|
+
|
|
1593
|
+
original_hidden_shape = hidden.shape
|
|
1594
|
+
hidden = hidden.view(-1)
|
|
1595
|
+
|
|
1596
|
+
hidden_dim = hidden.shape[0]
|
|
1597
|
+
if (hidden_dim % 4) != 0:
|
|
1598
|
+
raise ValueError(
|
|
1599
|
+
"Hidden dimension must be a multiple of 4 for HiFi SIMD operations"
|
|
1600
|
+
)
|
|
1601
|
+
|
|
1602
|
+
dequant_weights_inputs = weights_inputs.float() * w_i_scale
|
|
1603
|
+
dequant_weights_hidden = weights_hidden.float() * w_h_scale
|
|
1604
|
+
|
|
1605
|
+
dequant_bias_inputs = bias_inputs.float() * b_scale
|
|
1606
|
+
dequant_bias_hidden = bias_hidden.float() * b_scale
|
|
1607
|
+
|
|
1608
|
+
gi = F.linear(inputs, dequant_weights_inputs, dequant_bias_inputs)
|
|
1609
|
+
gh = F.linear(hidden, dequant_weights_hidden, dequant_bias_hidden)
|
|
1610
|
+
|
|
1611
|
+
i_r, i_z, i_n = gi.chunk(3, -1)
|
|
1612
|
+
h_r, h_z, h_n = gh.chunk(3, -1)
|
|
1613
|
+
|
|
1614
|
+
reset_gate = torch.sigmoid(i_r + h_r)
|
|
1615
|
+
update_gate = torch.sigmoid(i_z + h_z)
|
|
1616
|
+
new_gate = torch.tanh(i_n + reset_gate * h_n)
|
|
1617
|
+
|
|
1618
|
+
new_hidden = (1 - update_gate) * new_gate + update_gate * hidden
|
|
1619
|
+
|
|
1620
|
+
if new_hidden.shape[0] != 1:
|
|
1621
|
+
raise ValueError("Leading dimension of hidden state must be 1")
|
|
1622
|
+
|
|
1623
|
+
assert new_hidden.shape == original_hidden_shape
|
|
1624
|
+
|
|
1625
|
+
batch_size = inputs.shape[0]
|
|
1626
|
+
hidden_dim = hidden.shape[-1]
|
|
1627
|
+
if inputs.dim() == 3:
|
|
1628
|
+
# [batch, seq_len, input] with one step: [2, batch, 1, hidden], as the
|
|
1629
|
+
# fake kernel and the HiFi kernel produce. Batch > 1 is rejected
|
|
1630
|
+
# above (the hidden state has one row).
|
|
1631
|
+
step = new_hidden.reshape(batch_size, 1, hidden_dim)
|
|
1632
|
+
return torch.stack([step, step], dim=0)
|
|
1633
|
+
|
|
1634
|
+
input_dim = inputs.shape[1]
|
|
1635
|
+
new_hidden_expanded = new_hidden.unsqueeze(1).expand(
|
|
1636
|
+
batch_size, input_dim, hidden_dim
|
|
1637
|
+
)
|
|
1638
|
+
return torch.stack([new_hidden_expanded, new_hidden_expanded], dim=0)
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
@impl_tracked(m, "quantized_conv2d_nhwc.per_tensor")
|
|
1642
|
+
def quantized_conv2d_nhwc_per_tensor(
|
|
1643
|
+
input_tensor: torch.Tensor,
|
|
1644
|
+
weight: torch.Tensor,
|
|
1645
|
+
bias: torch.Tensor,
|
|
1646
|
+
stride: tuple[int, int],
|
|
1647
|
+
padding: tuple[int, int],
|
|
1648
|
+
dilation: tuple[int, int],
|
|
1649
|
+
groups: int,
|
|
1650
|
+
in_zero_point: int,
|
|
1651
|
+
weight_zero_point: int | torch.Tensor | None,
|
|
1652
|
+
bias_scale: float | torch.Tensor,
|
|
1653
|
+
output_scale: float,
|
|
1654
|
+
output_zero_point: int,
|
|
1655
|
+
out_multiplier: int | torch.Tensor,
|
|
1656
|
+
out_shift: int | torch.Tensor,
|
|
1657
|
+
offset: torch.Tensor | None = None,
|
|
1658
|
+
) -> torch.Tensor:
|
|
1659
|
+
"""
|
|
1660
|
+
Quantized convolution operation.
|
|
1661
|
+
|
|
1662
|
+
Args:
|
|
1663
|
+
- input_tensor (Tensor): The activations tensor
|
|
1664
|
+
- weight (Tensor): The weight tensor
|
|
1665
|
+
- bias (Tensor): The bias tensor
|
|
1666
|
+
- stride (Tuple[int]): The stride of the convolution
|
|
1667
|
+
- padding (Tuple[int]): The padding of the convolution
|
|
1668
|
+
- dilation (Tuple[int]): The dilation of the convolution
|
|
1669
|
+
- groups (int): The number of groups
|
|
1670
|
+
- in_zero_point (int): The quantized mapping of zero for the input
|
|
1671
|
+
- weight_zero_point (int): The quantized mapping of zero for the weight
|
|
1672
|
+
- bias_scale (float): The quantized bias scale
|
|
1673
|
+
- output_scale (float): The scale of the output
|
|
1674
|
+
- output_zero_point (int): The zero point of the output
|
|
1675
|
+
- out_multiplier (int): Unused
|
|
1676
|
+
- out_shift (int): Unused
|
|
1677
|
+
"""
|
|
1678
|
+
|
|
1679
|
+
# Convert to NCHW format to reuse the existing implementation
|
|
1680
|
+
in_channels = input_tensor.shape[-1]
|
|
1681
|
+
depthwise = is_depthwise_conv(groups, in_channels)
|
|
1682
|
+
|
|
1683
|
+
if len(input_tensor.shape) == 3:
|
|
1684
|
+
# 1D conv: input is [N, L, C] -> [N, C, L]
|
|
1685
|
+
input_tensor = input_tensor.movedim(-1, 1).contiguous()
|
|
1686
|
+
if len(weight.shape) == 2:
|
|
1687
|
+
assert depthwise, "1D depthwise conv requires 2D weight tensor"
|
|
1688
|
+
# 1D depthwise: weight is [K, OC] -> [OC, 1, K]
|
|
1689
|
+
weight = weight.permute(1, 0).unsqueeze(1).contiguous()
|
|
1690
|
+
else:
|
|
1691
|
+
# 1D regular: weight is [OC, K, IC] -> [OC, IC, K]
|
|
1692
|
+
weight = weight.movedim(-1, 1).contiguous()
|
|
1693
|
+
conv_is_1d = True
|
|
1694
|
+
else:
|
|
1695
|
+
# 2D conv: input is [N, H, W, C] -> [N, C, H, W]
|
|
1696
|
+
input_tensor = input_tensor.movedim(-1, -3)
|
|
1697
|
+
if len(weight.shape) == 3:
|
|
1698
|
+
assert depthwise, "2D depthwise conv requires 3D weight tensor"
|
|
1699
|
+
# 2D depthwise: weight is [KH, KW, OC] -> [OC, 1, KH, KW]
|
|
1700
|
+
weight = weight.permute(2, 0, 1).unsqueeze(1).contiguous()
|
|
1701
|
+
else:
|
|
1702
|
+
# 2D regular: weight is [OC, KH, KW, IC] -> [OC, IC, KH, KW]
|
|
1703
|
+
weight = torch.permute(weight, (0, -1, 1, 2)).contiguous()
|
|
1704
|
+
conv_is_1d = False
|
|
1705
|
+
|
|
1706
|
+
nchw_out = quantized_conv_common(
|
|
1707
|
+
input_tensor,
|
|
1708
|
+
weight,
|
|
1709
|
+
bias,
|
|
1710
|
+
stride,
|
|
1711
|
+
padding,
|
|
1712
|
+
dilation,
|
|
1713
|
+
groups,
|
|
1714
|
+
in_zero_point,
|
|
1715
|
+
weight_zero_point,
|
|
1716
|
+
bias_scale,
|
|
1717
|
+
output_scale,
|
|
1718
|
+
output_zero_point,
|
|
1719
|
+
out_multiplier,
|
|
1720
|
+
out_shift,
|
|
1721
|
+
)
|
|
1722
|
+
|
|
1723
|
+
if conv_is_1d:
|
|
1724
|
+
return nchw_out.movedim(1, -1).contiguous()
|
|
1725
|
+
else:
|
|
1726
|
+
return nchw_out.movedim(-3, -1).contiguous()
|
|
1727
|
+
|
|
1728
|
+
|
|
1729
|
+
@impl_tracked(m, "quantized_conv2d_nhwc")
|
|
1730
|
+
def quantized_conv2d_nhwc(
|
|
1731
|
+
input_tensor: torch.Tensor,
|
|
1732
|
+
weight: torch.Tensor,
|
|
1733
|
+
bias: torch.Tensor,
|
|
1734
|
+
stride: tuple[int, int],
|
|
1735
|
+
padding: tuple[int, int],
|
|
1736
|
+
dilation: tuple[int, int],
|
|
1737
|
+
groups: int,
|
|
1738
|
+
in_zero_point: int,
|
|
1739
|
+
weight_zero_point: torch.Tensor,
|
|
1740
|
+
bias_scale: torch.Tensor,
|
|
1741
|
+
output_scale: float,
|
|
1742
|
+
output_zero_point: int,
|
|
1743
|
+
out_multiplier: torch.Tensor,
|
|
1744
|
+
out_shift: torch.Tensor,
|
|
1745
|
+
) -> torch.Tensor:
|
|
1746
|
+
return quantized_conv2d_nhwc_per_tensor(
|
|
1747
|
+
input_tensor,
|
|
1748
|
+
weight,
|
|
1749
|
+
bias,
|
|
1750
|
+
stride,
|
|
1751
|
+
padding,
|
|
1752
|
+
dilation,
|
|
1753
|
+
groups,
|
|
1754
|
+
in_zero_point,
|
|
1755
|
+
weight_zero_point,
|
|
1756
|
+
bias_scale,
|
|
1757
|
+
output_scale,
|
|
1758
|
+
output_zero_point,
|
|
1759
|
+
out_multiplier,
|
|
1760
|
+
out_shift,
|
|
1761
|
+
)
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
@impl_tracked(m, "quantized_conv2d_depthwise_nhwc")
|
|
1765
|
+
def quantized_conv2d_depthwise_nhwc(
|
|
1766
|
+
input_tensor: torch.Tensor,
|
|
1767
|
+
weight: torch.Tensor,
|
|
1768
|
+
bias: torch.Tensor,
|
|
1769
|
+
stride: tuple[int, int],
|
|
1770
|
+
padding: tuple[int, int],
|
|
1771
|
+
dilation: tuple[int, int],
|
|
1772
|
+
groups: int,
|
|
1773
|
+
in_zero_point: int,
|
|
1774
|
+
weight_zero_point: int,
|
|
1775
|
+
bias_scale: float,
|
|
1776
|
+
output_scale: float,
|
|
1777
|
+
output_zero_point: int,
|
|
1778
|
+
out_multiplier: int,
|
|
1779
|
+
out_shift: int,
|
|
1780
|
+
) -> torch.Tensor:
|
|
1781
|
+
return quantized_conv2d_nhwc_per_tensor(
|
|
1782
|
+
input_tensor,
|
|
1783
|
+
weight,
|
|
1784
|
+
bias,
|
|
1785
|
+
stride,
|
|
1786
|
+
padding,
|
|
1787
|
+
dilation,
|
|
1788
|
+
groups,
|
|
1789
|
+
in_zero_point,
|
|
1790
|
+
weight_zero_point,
|
|
1791
|
+
bias_scale,
|
|
1792
|
+
output_scale,
|
|
1793
|
+
output_zero_point,
|
|
1794
|
+
out_multiplier,
|
|
1795
|
+
out_shift,
|
|
1796
|
+
)
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
def quantized_conv_variant(
|
|
1800
|
+
layout: str,
|
|
1801
|
+
input_dtype: torch.dtype,
|
|
1802
|
+
weight_dtype: torch.dtype,
|
|
1803
|
+
is_1d: bool = False,
|
|
1804
|
+
) -> Callable[[Callable[..., torch.Tensor]], Callable[..., torch.Tensor]]:
|
|
1805
|
+
"""Create a quantized conv variant with type checking."""
|
|
1806
|
+
|
|
1807
|
+
def decorator(_: Callable[..., torch.Tensor]) -> Callable[..., torch.Tensor]:
|
|
1808
|
+
def variant(
|
|
1809
|
+
input_tensor: torch.Tensor,
|
|
1810
|
+
weight: torch.Tensor,
|
|
1811
|
+
bias: torch.Tensor,
|
|
1812
|
+
stride: tuple[int, int],
|
|
1813
|
+
padding: tuple[int, int],
|
|
1814
|
+
dilation: tuple[int, int],
|
|
1815
|
+
groups: int,
|
|
1816
|
+
in_zero_point: int,
|
|
1817
|
+
weight_zero_point: int,
|
|
1818
|
+
bias_scale: float,
|
|
1819
|
+
output_scale: float,
|
|
1820
|
+
output_zero_point: int,
|
|
1821
|
+
out_multiplier: int,
|
|
1822
|
+
out_shift: int,
|
|
1823
|
+
) -> torch.Tensor:
|
|
1824
|
+
assert (
|
|
1825
|
+
input_tensor.dtype == input_dtype
|
|
1826
|
+
), f"Expected input dtype {input_dtype}, got {input_tensor.dtype}"
|
|
1827
|
+
assert (
|
|
1828
|
+
weight.dtype == weight_dtype
|
|
1829
|
+
), f"Expected weight dtype {weight_dtype}, got {weight.dtype}"
|
|
1830
|
+
|
|
1831
|
+
assert (
|
|
1832
|
+
bias.dtype == torch.int32
|
|
1833
|
+
), f"Expected bias dtype int32, got {bias.dtype}"
|
|
1834
|
+
|
|
1835
|
+
if is_1d:
|
|
1836
|
+
assert (
|
|
1837
|
+
len(input_tensor.shape) == 3
|
|
1838
|
+
), f"1D convolution requires 3D input tensor, got {len(input_tensor.shape)}D"
|
|
1839
|
+
assert (
|
|
1840
|
+
len(weight.shape) == 3
|
|
1841
|
+
), f"1D convolution requires 3D weight tensor, got {len(weight.shape)}D"
|
|
1842
|
+
|
|
1843
|
+
# Call the appropriate base function
|
|
1844
|
+
match layout:
|
|
1845
|
+
case "nchw":
|
|
1846
|
+
return quantized_conv2d_nchw_per_tensor(
|
|
1847
|
+
input_tensor,
|
|
1848
|
+
weight,
|
|
1849
|
+
bias,
|
|
1850
|
+
stride,
|
|
1851
|
+
padding,
|
|
1852
|
+
dilation,
|
|
1853
|
+
groups,
|
|
1854
|
+
in_zero_point,
|
|
1855
|
+
weight_zero_point,
|
|
1856
|
+
bias_scale,
|
|
1857
|
+
output_scale,
|
|
1858
|
+
output_zero_point,
|
|
1859
|
+
out_multiplier,
|
|
1860
|
+
out_shift,
|
|
1861
|
+
)
|
|
1862
|
+
case "nhwc":
|
|
1863
|
+
return quantized_conv2d_nhwc_per_tensor(
|
|
1864
|
+
input_tensor,
|
|
1865
|
+
weight,
|
|
1866
|
+
bias,
|
|
1867
|
+
stride,
|
|
1868
|
+
padding,
|
|
1869
|
+
dilation,
|
|
1870
|
+
groups,
|
|
1871
|
+
in_zero_point,
|
|
1872
|
+
weight_zero_point,
|
|
1873
|
+
bias_scale,
|
|
1874
|
+
output_scale,
|
|
1875
|
+
output_zero_point,
|
|
1876
|
+
out_multiplier,
|
|
1877
|
+
out_shift,
|
|
1878
|
+
)
|
|
1879
|
+
case _:
|
|
1880
|
+
raise ValueError(f"Unknown layout {layout}")
|
|
1881
|
+
|
|
1882
|
+
return variant
|
|
1883
|
+
|
|
1884
|
+
return decorator
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
@impl_tracked(m, "quantized_conv2d_nchw_asym8sxsym8s_asym8s.per_tensor")
|
|
1888
|
+
@quantized_conv_variant("nchw", torch.int8, torch.int8)
|
|
1889
|
+
def quantized_conv2d_nchw_asym8sxsym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
@impl_tracked(m, "quantized_conv2d_nchw_asym8uxsym8u_asym8u.per_tensor")
|
|
1893
|
+
@quantized_conv_variant("nchw", torch.uint8, torch.uint8)
|
|
1894
|
+
def quantized_conv2d_nchw_asym8uxsym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
1895
|
+
|
|
1896
|
+
|
|
1897
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_asym8sxsym8s_asym8s.per_tensor")
|
|
1898
|
+
@quantized_conv_variant("nhwc", torch.int8, torch.int8)
|
|
1899
|
+
def quantized_conv2d_nhwc_asym8sxsym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
1900
|
+
|
|
1901
|
+
|
|
1902
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_asym8uxsym8u_asym8u.per_tensor")
|
|
1903
|
+
@quantized_conv_variant("nhwc", torch.uint8, torch.uint8)
|
|
1904
|
+
def quantized_conv2d_nhwc_asym8uxsym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
1905
|
+
|
|
1906
|
+
|
|
1907
|
+
@impl_tracked(m, "quantized_conv2d_nchw_dilated_asym8sxsym8s_asym8s.per_tensor")
|
|
1908
|
+
@quantized_conv_variant("nchw", torch.int8, torch.int8)
|
|
1909
|
+
def quantized_conv2d_nchw_dilated_asym8sxsym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
1910
|
+
|
|
1911
|
+
|
|
1912
|
+
@impl_tracked(m, "quantized_conv2d_nchw_dilated_asym8uxsym8u_asym8u.per_tensor")
|
|
1913
|
+
@quantized_conv_variant("nchw", torch.uint8, torch.uint8)
|
|
1914
|
+
def quantized_conv2d_nchw_dilated_asym8uxsym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_dilated_asym8sxsym8s_asym8s.per_tensor")
|
|
1918
|
+
@quantized_conv_variant("nhwc", torch.int8, torch.int8)
|
|
1919
|
+
def quantized_conv2d_nhwc_dilated_asym8sxsym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_dilated_asym8uxsym8u_asym8u.per_tensor")
|
|
1923
|
+
@quantized_conv_variant("nhwc", torch.uint8, torch.uint8)
|
|
1924
|
+
def quantized_conv2d_nhwc_dilated_asym8uxsym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
1925
|
+
|
|
1926
|
+
|
|
1927
|
+
@impl_tracked(m, "quantized_conv2d_nchw_depthwise_asym8sxsym8s_asym8s.per_tensor")
|
|
1928
|
+
@quantized_conv_variant("nchw", torch.int8, torch.int8)
|
|
1929
|
+
def quantized_conv2d_nchw_depthwise_asym8sxsym8s_asym8s_per_tensor() -> (
|
|
1930
|
+
torch.Tensor
|
|
1931
|
+
): ...
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
@impl_tracked(m, "quantized_conv2d_nchw_depthwise_asym8uxsym8u_asym8u.per_tensor")
|
|
1935
|
+
@quantized_conv_variant("nchw", torch.uint8, torch.uint8)
|
|
1936
|
+
def quantized_conv2d_nchw_depthwise_asym8uxsym8u_asym8u_per_tensor() -> (
|
|
1937
|
+
torch.Tensor
|
|
1938
|
+
): ...
|
|
1939
|
+
|
|
1940
|
+
|
|
1941
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_depthwise_asym8sxsym8s_asym8s.per_tensor")
|
|
1942
|
+
@quantized_conv_variant("nhwc", torch.int8, torch.int8)
|
|
1943
|
+
def quantized_conv2d_nhwc_depthwise_asym8sxsym8s_asym8s_per_tensor() -> (
|
|
1944
|
+
torch.Tensor
|
|
1945
|
+
): ...
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
@impl_tracked(m, "quantized_conv2d_nhwc_depthwise_asym8uxsym8u_asym8u.per_tensor")
|
|
1949
|
+
@quantized_conv_variant("nhwc", torch.uint8, torch.uint8)
|
|
1950
|
+
def quantized_conv2d_nhwc_depthwise_asym8uxsym8u_asym8u_per_tensor() -> (
|
|
1951
|
+
torch.Tensor
|
|
1952
|
+
): ...
|
|
1953
|
+
|
|
1954
|
+
|
|
1955
|
+
@impl_tracked(m, "conv1d")
|
|
1956
|
+
def conv1d(
|
|
1957
|
+
input_tensor: torch.Tensor,
|
|
1958
|
+
weight: torch.Tensor,
|
|
1959
|
+
bias: torch.Tensor,
|
|
1960
|
+
stride: tuple[int],
|
|
1961
|
+
padding: tuple[int],
|
|
1962
|
+
dilation: tuple[int],
|
|
1963
|
+
groups: int,
|
|
1964
|
+
) -> torch.Tensor:
|
|
1965
|
+
conv_out = torch.nn.functional.conv1d(
|
|
1966
|
+
input_tensor, weight, bias, stride[0], padding[0], dilation[0], groups
|
|
1967
|
+
)
|
|
1968
|
+
|
|
1969
|
+
return conv_out
|
|
1970
|
+
|
|
1971
|
+
|
|
1972
|
+
@impl_tracked(m, "conv2d")
|
|
1973
|
+
def conv2d(
|
|
1974
|
+
input_tensor: torch.Tensor,
|
|
1975
|
+
weight: torch.Tensor,
|
|
1976
|
+
bias: torch.Tensor,
|
|
1977
|
+
stride: tuple[int, int],
|
|
1978
|
+
padding: tuple[int, int],
|
|
1979
|
+
dilation: tuple[int, int],
|
|
1980
|
+
groups: int,
|
|
1981
|
+
) -> torch.Tensor:
|
|
1982
|
+
conv_out = torch.nn.functional.conv2d(
|
|
1983
|
+
input_tensor, weight, bias, stride, padding, dilation, groups
|
|
1984
|
+
)
|
|
1985
|
+
|
|
1986
|
+
return conv_out
|
|
1987
|
+
|
|
1988
|
+
|
|
1989
|
+
@impl_tracked(m, "conv3d")
|
|
1990
|
+
def conv3d(
|
|
1991
|
+
input_tensor: torch.Tensor,
|
|
1992
|
+
weight: torch.Tensor,
|
|
1993
|
+
bias: torch.Tensor,
|
|
1994
|
+
stride: tuple[int, int, int],
|
|
1995
|
+
padding: tuple[int, int, int],
|
|
1996
|
+
dilation: tuple[int, int, int],
|
|
1997
|
+
groups: int,
|
|
1998
|
+
) -> torch.Tensor:
|
|
1999
|
+
conv_out = torch.nn.functional.conv3d(
|
|
2000
|
+
input_tensor, weight, bias, stride, padding, dilation, groups
|
|
2001
|
+
)
|
|
2002
|
+
|
|
2003
|
+
return conv_out
|
|
2004
|
+
|
|
2005
|
+
|
|
2006
|
+
@impl_tracked(m, "transposed_convolution")
|
|
2007
|
+
def transposed_convolution(
|
|
2008
|
+
input_tensor: torch.Tensor,
|
|
2009
|
+
weight: torch.Tensor,
|
|
2010
|
+
bias: torch.Tensor,
|
|
2011
|
+
stride: tuple[int, int],
|
|
2012
|
+
padding: tuple[int, int],
|
|
2013
|
+
dilation: tuple[int, int],
|
|
2014
|
+
output_padding: tuple[int, int],
|
|
2015
|
+
groups: int,
|
|
2016
|
+
channel_last: bool = False,
|
|
2017
|
+
) -> torch.Tensor:
|
|
2018
|
+
|
|
2019
|
+
# Cadence transposed conv receives weights that have been transformed by the pass:
|
|
2020
|
+
# 1. Transposed (dims 0 and 1 swapped): [out_channels, in_channels, *kernel]
|
|
2021
|
+
# 2. Flipped (spatial dimensions reversed)
|
|
2022
|
+
# We need to reverse both transformations to call PyTorch's conv_transpose
|
|
2023
|
+
|
|
2024
|
+
conv_is_1d = len(input_tensor.shape) == 3
|
|
2025
|
+
|
|
2026
|
+
# Determine flip dimensions based on weight dimensionality
|
|
2027
|
+
weight_dim = len(weight.shape)
|
|
2028
|
+
flip_dims = [-1] if weight_dim == 3 else [-1, -2]
|
|
2029
|
+
|
|
2030
|
+
# Reverse transformation step 1: Unflip the spatial dimensions
|
|
2031
|
+
weight = torch.flip(weight, dims=flip_dims)
|
|
2032
|
+
|
|
2033
|
+
# Reverse transformation step 2: Transpose back to PyTorch format [in, out, *kernel]
|
|
2034
|
+
weight = weight.transpose(0, 1).contiguous()
|
|
2035
|
+
if channel_last:
|
|
2036
|
+
if conv_is_1d:
|
|
2037
|
+
input_tensor = input_tensor.movedim(-1, 1).contiguous()
|
|
2038
|
+
if len(weight.shape) != 3:
|
|
2039
|
+
raise ValueError("Weight tensor must be 3D if input is 3D")
|
|
2040
|
+
weight = weight.movedim(-1, 1).contiguous()
|
|
2041
|
+
else:
|
|
2042
|
+
input_tensor = input_tensor.movedim(-1, -3)
|
|
2043
|
+
if len(weight.shape) != 4:
|
|
2044
|
+
raise ValueError("Weight tensor must be 4D if input is nd > 3")
|
|
2045
|
+
weight = torch.permute(weight, (0, -1, 1, 2)).contiguous()
|
|
2046
|
+
|
|
2047
|
+
_stride: tuple[int, int] | int = stride
|
|
2048
|
+
_padding: tuple[int, int] | int = padding
|
|
2049
|
+
_dilation: tuple[int, int] | int = dilation
|
|
2050
|
+
_output_padding: tuple[int, int] | int = output_padding
|
|
2051
|
+
if conv_is_1d:
|
|
2052
|
+
conv = torch.nn.functional.conv_transpose1d
|
|
2053
|
+
_stride = stride[0]
|
|
2054
|
+
_padding = padding[0]
|
|
2055
|
+
_dilation = dilation[0]
|
|
2056
|
+
_output_padding = output_padding[0]
|
|
2057
|
+
else:
|
|
2058
|
+
conv = torch.nn.functional.conv_transpose2d
|
|
2059
|
+
|
|
2060
|
+
conv_out = conv(
|
|
2061
|
+
input_tensor,
|
|
2062
|
+
weight,
|
|
2063
|
+
bias,
|
|
2064
|
+
_stride,
|
|
2065
|
+
_padding,
|
|
2066
|
+
_output_padding,
|
|
2067
|
+
groups,
|
|
2068
|
+
_dilation,
|
|
2069
|
+
)
|
|
2070
|
+
if channel_last:
|
|
2071
|
+
if conv_is_1d:
|
|
2072
|
+
conv_out = conv_out.movedim(1, -1).contiguous()
|
|
2073
|
+
else:
|
|
2074
|
+
conv_out = conv_out.movedim(-3, -1).contiguous()
|
|
2075
|
+
|
|
2076
|
+
return conv_out
|
|
2077
|
+
|
|
2078
|
+
|
|
2079
|
+
@impl_tracked(m, "avg_pool2d")
|
|
2080
|
+
def avg_pool2d(
|
|
2081
|
+
input_tensor: torch.Tensor,
|
|
2082
|
+
kernel_size: tuple[int, int],
|
|
2083
|
+
stride: tuple[int, int],
|
|
2084
|
+
padding: tuple[int, int],
|
|
2085
|
+
ceil_mode: bool = False,
|
|
2086
|
+
count_include_pad: bool = False,
|
|
2087
|
+
divisor_override: int | None = None,
|
|
2088
|
+
in_zero_point: torch.Tensor | None = None,
|
|
2089
|
+
channel_last: bool = False,
|
|
2090
|
+
) -> torch.Tensor:
|
|
2091
|
+
if channel_last:
|
|
2092
|
+
raise NotImplementedError("Channel last is not yet supported for avg_pool2d")
|
|
2093
|
+
|
|
2094
|
+
in_dtype = input_tensor.dtype
|
|
2095
|
+
pad_h, pad_w = padding
|
|
2096
|
+
if in_zero_point is not None:
|
|
2097
|
+
# Avg pool2d does not allow non-0 padding,
|
|
2098
|
+
# so we manually pad the input
|
|
2099
|
+
pad_value = in_zero_point.item()
|
|
2100
|
+
if not count_include_pad:
|
|
2101
|
+
# To simulate this, just pad with 0s
|
|
2102
|
+
pad_value = 0
|
|
2103
|
+
|
|
2104
|
+
input_tensor = torch.nn.functional.pad(
|
|
2105
|
+
input_tensor,
|
|
2106
|
+
(pad_w, pad_w, pad_h, pad_h),
|
|
2107
|
+
mode="constant",
|
|
2108
|
+
value=pad_value,
|
|
2109
|
+
).float()
|
|
2110
|
+
|
|
2111
|
+
padding = (0, 0)
|
|
2112
|
+
|
|
2113
|
+
out = torch.nn.functional.avg_pool2d(
|
|
2114
|
+
input_tensor,
|
|
2115
|
+
kernel_size,
|
|
2116
|
+
stride,
|
|
2117
|
+
padding,
|
|
2118
|
+
ceil_mode,
|
|
2119
|
+
count_include_pad,
|
|
2120
|
+
divisor_override,
|
|
2121
|
+
)
|
|
2122
|
+
|
|
2123
|
+
if in_zero_point is not None:
|
|
2124
|
+
min_val = torch.iinfo(in_dtype).min
|
|
2125
|
+
max_val = torch.iinfo(in_dtype).max
|
|
2126
|
+
out = torch.clamp(torch.round(out), min_val, max_val)
|
|
2127
|
+
|
|
2128
|
+
return out.to(in_dtype)
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
def quantized_relu_common(
|
|
2132
|
+
X: torch.Tensor,
|
|
2133
|
+
X_zero_point: torch.Tensor | int,
|
|
2134
|
+
out_zero_point: int,
|
|
2135
|
+
out_multiplier: int,
|
|
2136
|
+
out_shift: int,
|
|
2137
|
+
) -> torch.Tensor:
|
|
2138
|
+
"""
|
|
2139
|
+
Quantized ReLU operation followed by requantization.
|
|
2140
|
+
|
|
2141
|
+
Args:
|
|
2142
|
+
- X (Tensor): The input tensor
|
|
2143
|
+
- X_zero_point (Tensor): The quantized mapping of zero for the input
|
|
2144
|
+
- out_zero_point (int): The quantized mapping of zero for the output
|
|
2145
|
+
- out_multiplier (Tensor): The multiplier used to scale the output
|
|
2146
|
+
- out_shift (Tensor): The shift used to scale the output
|
|
2147
|
+
"""
|
|
2148
|
+
supported_dtypes = [torch.int8, torch.int16, torch.uint8, torch.uint16]
|
|
2149
|
+
if X.dtype not in supported_dtypes:
|
|
2150
|
+
raise ValueError(f"X dtype must be one of {supported_dtypes}. Got {X.dtype}")
|
|
2151
|
+
|
|
2152
|
+
out_scale = 1.0 / (-out_multiplier * (1 / (1 << 31)) * (2**out_shift))
|
|
2153
|
+
dequantized_X = torch.where(
|
|
2154
|
+
X > X_zero_point, X.float() - X_zero_point, torch.zeros_like(X)
|
|
2155
|
+
)
|
|
2156
|
+
out = quantize_per_tensor(
|
|
2157
|
+
dequantized_X,
|
|
2158
|
+
out_scale,
|
|
2159
|
+
out_zero_point,
|
|
2160
|
+
torch.iinfo(X.dtype).min,
|
|
2161
|
+
torch.iinfo(X.dtype).max,
|
|
2162
|
+
X.dtype,
|
|
2163
|
+
)
|
|
2164
|
+
assert isinstance(out, torch.Tensor)
|
|
2165
|
+
return out
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
def quantized_relu_variant(
|
|
2169
|
+
dtype: torch.dtype | None = None,
|
|
2170
|
+
) -> Callable[[Callable[..., torch.Tensor]], Callable[..., torch.Tensor]]:
|
|
2171
|
+
"""Create a quantized relu variant with type checking."""
|
|
2172
|
+
|
|
2173
|
+
def decorator(_: Callable[..., torch.Tensor]) -> Callable[..., torch.Tensor]:
|
|
2174
|
+
def variant(
|
|
2175
|
+
X: torch.Tensor,
|
|
2176
|
+
X_zero_point: int,
|
|
2177
|
+
out_zero_point: int,
|
|
2178
|
+
out_multiplier: int,
|
|
2179
|
+
out_shift: int,
|
|
2180
|
+
) -> torch.Tensor:
|
|
2181
|
+
if dtype and X.dtype != dtype:
|
|
2182
|
+
raise ValueError(f"X dtype must be {dtype}. Got {X.dtype}")
|
|
2183
|
+
|
|
2184
|
+
return quantized_relu_common(
|
|
2185
|
+
X,
|
|
2186
|
+
X_zero_point,
|
|
2187
|
+
out_zero_point,
|
|
2188
|
+
out_multiplier,
|
|
2189
|
+
out_shift,
|
|
2190
|
+
)
|
|
2191
|
+
|
|
2192
|
+
return variant
|
|
2193
|
+
|
|
2194
|
+
return decorator
|
|
2195
|
+
|
|
2196
|
+
|
|
2197
|
+
@impl_tracked(m, "quantized_relu.per_tensor")
|
|
2198
|
+
@quantized_relu_variant()
|
|
2199
|
+
def quantized_relu_per_tensor() -> torch.Tensor: ...
|
|
2200
|
+
|
|
2201
|
+
|
|
2202
|
+
@impl_tracked(m, "quantized_relu_asym8s_asym8s.per_tensor")
|
|
2203
|
+
@quantized_relu_variant(torch.int8)
|
|
2204
|
+
def quantized_relu_asym8s_asym8s_per_tensor() -> torch.Tensor: ...
|
|
2205
|
+
|
|
2206
|
+
|
|
2207
|
+
@impl_tracked(m, "quantized_relu_asym8u_asym8u.per_tensor")
|
|
2208
|
+
@quantized_relu_variant(torch.uint8)
|
|
2209
|
+
def quantized_relu_asym8u_asym8u_per_tensor() -> torch.Tensor: ...
|
|
2210
|
+
|
|
2211
|
+
|
|
2212
|
+
@impl_tracked(m, "quantized_relu")
|
|
2213
|
+
def quantized_relu(
|
|
2214
|
+
X: torch.Tensor,
|
|
2215
|
+
X_zero_point: torch.Tensor,
|
|
2216
|
+
out_zero_point: int,
|
|
2217
|
+
out_multiplier: torch.Tensor,
|
|
2218
|
+
out_shift: torch.Tensor,
|
|
2219
|
+
) -> torch.Tensor:
|
|
2220
|
+
return quantized_relu_per_tensor(
|
|
2221
|
+
X, X_zero_point.item(), out_zero_point, out_multiplier.item(), out_shift.item()
|
|
2222
|
+
)
|
|
2223
|
+
|
|
2224
|
+
|
|
2225
|
+
@impl_tracked(m, "requantize.per_tensor")
|
|
2226
|
+
def requantize_per_tensor(
|
|
2227
|
+
input: torch.Tensor,
|
|
2228
|
+
in_scale: float,
|
|
2229
|
+
in_zero_point: int,
|
|
2230
|
+
out_scale: float,
|
|
2231
|
+
out_zero_point: int,
|
|
2232
|
+
dtype: ScalarType,
|
|
2233
|
+
) -> torch.Tensor:
|
|
2234
|
+
if dtype in qdtype_map:
|
|
2235
|
+
# Old quantization mechanism
|
|
2236
|
+
return torch.quantize_per_tensor(
|
|
2237
|
+
torch.dequantize(input), out_scale, out_zero_point, qdtype_map[dtype]
|
|
2238
|
+
)
|
|
2239
|
+
|
|
2240
|
+
quant_min = torch.iinfo(input.dtype).min
|
|
2241
|
+
quant_max = torch.iinfo(input.dtype).max
|
|
2242
|
+
# pyre-fixme[6]: This dtype is actually the right one.
|
|
2243
|
+
out_quant_min = torch.iinfo(dtype).min
|
|
2244
|
+
# pyre-fixme[6]: This dtype is actually the right one.
|
|
2245
|
+
out_quant_max = torch.iinfo(dtype).max
|
|
2246
|
+
return torch.ops.quantized_decomposed.quantize_per_tensor(
|
|
2247
|
+
torch.ops.quantized_decomposed.dequantize_per_tensor(
|
|
2248
|
+
input,
|
|
2249
|
+
in_scale,
|
|
2250
|
+
in_zero_point,
|
|
2251
|
+
quant_min,
|
|
2252
|
+
quant_max,
|
|
2253
|
+
input.dtype,
|
|
2254
|
+
),
|
|
2255
|
+
out_scale,
|
|
2256
|
+
out_zero_point,
|
|
2257
|
+
out_quant_min,
|
|
2258
|
+
out_quant_max,
|
|
2259
|
+
dtype,
|
|
2260
|
+
)
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
@impl_tracked(m, "requantize")
|
|
2264
|
+
def requantize(
|
|
2265
|
+
input_tensor: torch.Tensor,
|
|
2266
|
+
in_scale: torch.Tensor,
|
|
2267
|
+
in_zero_point: torch.Tensor,
|
|
2268
|
+
out_scale: torch.Tensor,
|
|
2269
|
+
out_zero_point: torch.Tensor,
|
|
2270
|
+
dtype: ScalarType,
|
|
2271
|
+
) -> torch.Tensor:
|
|
2272
|
+
return requantize_per_tensor(
|
|
2273
|
+
input_tensor,
|
|
2274
|
+
float(in_scale.item()),
|
|
2275
|
+
int(in_zero_point.item()),
|
|
2276
|
+
float(out_scale.item()),
|
|
2277
|
+
int(out_zero_point.item()),
|
|
2278
|
+
dtype,
|
|
2279
|
+
)
|
|
2280
|
+
|
|
2281
|
+
|
|
2282
|
+
@impl_tracked(m, "rms_norm")
|
|
2283
|
+
def rms_norm(
|
|
2284
|
+
X: torch.Tensor,
|
|
2285
|
+
normalized_shape: tuple[int],
|
|
2286
|
+
W: torch.Tensor,
|
|
2287
|
+
eps: float,
|
|
2288
|
+
) -> torch.Tensor:
|
|
2289
|
+
return W * nn.RMSNorm(list(normalized_shape), eps=eps, dtype=X.dtype)(X)
|
|
2290
|
+
|
|
2291
|
+
|
|
2292
|
+
@impl_tracked(m, "quantized_max_pool2d_nchw")
|
|
2293
|
+
def quantized_max_pool2d_nchw(
|
|
2294
|
+
input: torch.Tensor,
|
|
2295
|
+
kernel_size: list[int],
|
|
2296
|
+
stride: list[int],
|
|
2297
|
+
padding: list[int],
|
|
2298
|
+
dilation: list[int],
|
|
2299
|
+
ceil_mode: bool,
|
|
2300
|
+
) -> torch.Tensor:
|
|
2301
|
+
"""
|
|
2302
|
+
Quantized max pooling operation.
|
|
2303
|
+
|
|
2304
|
+
Max pooling is order-preserving, so max(a, b) in the quantized domain gives
|
|
2305
|
+
the same result as quantizing max(dequant(a), dequant(b)) when using the same
|
|
2306
|
+
scale/zero_point. This means we can perform max pooling directly on quantized
|
|
2307
|
+
integer values without dequantization/requantization.
|
|
2308
|
+
"""
|
|
2309
|
+
# Directly apply max_pool2d on quantized values
|
|
2310
|
+
# Since max is order-preserving, the result is correct without any dequant/requant
|
|
2311
|
+
return F.max_pool2d(
|
|
2312
|
+
input,
|
|
2313
|
+
kernel_size=kernel_size,
|
|
2314
|
+
stride=stride,
|
|
2315
|
+
padding=padding,
|
|
2316
|
+
dilation=dilation,
|
|
2317
|
+
ceil_mode=ceil_mode,
|
|
2318
|
+
)
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
@impl_tracked(m, "quantized_max_pool2d_nhwc")
|
|
2322
|
+
def quantized_max_pool2d_nhwc(
|
|
2323
|
+
input: torch.Tensor,
|
|
2324
|
+
kernel_size: list[int],
|
|
2325
|
+
stride: list[int],
|
|
2326
|
+
padding: list[int],
|
|
2327
|
+
dilation: list[int],
|
|
2328
|
+
ceil_mode: bool,
|
|
2329
|
+
) -> torch.Tensor:
|
|
2330
|
+
"""
|
|
2331
|
+
Quantized max pooling in NHWC layout.
|
|
2332
|
+
|
|
2333
|
+
Converts NHWC→NCHW, performs max pooling, then converts back NCHW→NHWC.
|
|
2334
|
+
"""
|
|
2335
|
+
# Convert NHWC [N, H, W, C] to NCHW [N, C, H, W]
|
|
2336
|
+
input_nchw = input.permute(0, 3, 1, 2).contiguous()
|
|
2337
|
+
|
|
2338
|
+
# Call the NCHW version
|
|
2339
|
+
output_nchw = quantized_max_pool2d_nchw(
|
|
2340
|
+
input_nchw,
|
|
2341
|
+
kernel_size=kernel_size,
|
|
2342
|
+
stride=stride,
|
|
2343
|
+
padding=padding,
|
|
2344
|
+
dilation=dilation,
|
|
2345
|
+
ceil_mode=ceil_mode,
|
|
2346
|
+
)
|
|
2347
|
+
|
|
2348
|
+
# Convert NCHW [N, C, H_out, W_out] back to NHWC [N, H_out, W_out, C]
|
|
2349
|
+
return output_nchw.permute(0, 2, 3, 1).contiguous()
|
|
2350
|
+
|
|
2351
|
+
|
|
2352
|
+
@impl_tracked(m, "where_Scalar")
|
|
2353
|
+
def where_Scalar(
|
|
2354
|
+
condition: torch.Tensor,
|
|
2355
|
+
if_true: float,
|
|
2356
|
+
if_false: float,
|
|
2357
|
+
) -> torch.Tensor:
|
|
2358
|
+
if condition.dtype != torch.bool:
|
|
2359
|
+
raise ValueError("condition must be a bool tensor")
|
|
2360
|
+
|
|
2361
|
+
return torch.where(condition, if_true, if_false)
|
|
2362
|
+
|
|
2363
|
+
|
|
2364
|
+
@impl_tracked(m, "rope")
|
|
2365
|
+
def rope(
|
|
2366
|
+
input_tensor: torch.Tensor,
|
|
2367
|
+
sin_tensor: torch.Tensor,
|
|
2368
|
+
cos_tensor: torch.Tensor,
|
|
2369
|
+
pos: torch.Tensor | None,
|
|
2370
|
+
) -> torch.Tensor:
|
|
2371
|
+
original_shape = input_tensor.shape
|
|
2372
|
+
|
|
2373
|
+
if len(original_shape) not in [4, 5]:
|
|
2374
|
+
raise ValueError(
|
|
2375
|
+
f"Input tensor must be 4D or 5D. Got {len(original_shape)}D tensor"
|
|
2376
|
+
)
|
|
2377
|
+
if original_shape[0] != 1:
|
|
2378
|
+
raise ValueError("Input tensor must have batch size 1")
|
|
2379
|
+
if len(original_shape) == 5:
|
|
2380
|
+
input_tensor = input_tensor.view(
|
|
2381
|
+
input_tensor.shape[0], input_tensor.shape[1], input_tensor.shape[2], -1
|
|
2382
|
+
)
|
|
2383
|
+
|
|
2384
|
+
_, seq, _, hd = input_tensor.shape
|
|
2385
|
+
|
|
2386
|
+
if hd % 2:
|
|
2387
|
+
raise ValueError("Hidden dimension must be divisible by 2")
|
|
2388
|
+
|
|
2389
|
+
if (
|
|
2390
|
+
sin_tensor.size(-1) * 2 != hd
|
|
2391
|
+
or cos_tensor.size(-1) * 2 != hd
|
|
2392
|
+
or sin_tensor.size(0) < seq
|
|
2393
|
+
or cos_tensor.size(0) < seq
|
|
2394
|
+
):
|
|
2395
|
+
raise ValueError(
|
|
2396
|
+
f"sin_tensor and cos_tensor must have shape <kvseq (> {seq}) x {hd // 2}>. Got {sin_tensor.shape} and {cos_tensor.shape}"
|
|
2397
|
+
)
|
|
2398
|
+
|
|
2399
|
+
if pos is not None:
|
|
2400
|
+
if pos.shape != (seq,):
|
|
2401
|
+
raise ValueError(
|
|
2402
|
+
f"pos must have shape {input_tensor.shape[1]}. Got {pos.shape}"
|
|
2403
|
+
)
|
|
2404
|
+
sin_tensor = sin_tensor[pos]
|
|
2405
|
+
cos_tensor = cos_tensor[pos]
|
|
2406
|
+
|
|
2407
|
+
# seq x 1 x hd
|
|
2408
|
+
sin_tensor = sin_tensor.unsqueeze(1)
|
|
2409
|
+
cos_tensor = cos_tensor.unsqueeze(1)
|
|
2410
|
+
|
|
2411
|
+
# batch x seq x num_heads x head_dim_by_two
|
|
2412
|
+
x0, x1 = input_tensor[..., ::2], input_tensor[..., 1::2]
|
|
2413
|
+
o0 = x0 * cos_tensor - x1 * sin_tensor
|
|
2414
|
+
o1 = x0 * sin_tensor + x1 * cos_tensor
|
|
2415
|
+
rotated = torch.cat([o0.view(-1, 1), o1.view(-1, 1)], dim=-1)
|
|
2416
|
+
return rotated.view(original_shape)
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
@impl_tracked(m, "rope_rotate_stacked_halves")
|
|
2420
|
+
def rope_rotate_stacked_halves(
|
|
2421
|
+
input_tensor: torch.Tensor,
|
|
2422
|
+
sin_tensor: torch.Tensor,
|
|
2423
|
+
cos_tensor: torch.Tensor,
|
|
2424
|
+
pos: torch.Tensor | None,
|
|
2425
|
+
) -> torch.Tensor:
|
|
2426
|
+
original_shape = input_tensor.shape
|
|
2427
|
+
|
|
2428
|
+
if len(original_shape) not in [4, 5]:
|
|
2429
|
+
raise ValueError(
|
|
2430
|
+
f"Input tensor must be 4D or 5D. Got {len(original_shape)}D tensor"
|
|
2431
|
+
)
|
|
2432
|
+
if original_shape[0] != 1:
|
|
2433
|
+
raise ValueError("Input tensor must have batch size 1")
|
|
2434
|
+
if len(original_shape) == 5:
|
|
2435
|
+
input_tensor = input_tensor.view(
|
|
2436
|
+
input_tensor.shape[0], input_tensor.shape[1], input_tensor.shape[2], -1
|
|
2437
|
+
)
|
|
2438
|
+
|
|
2439
|
+
_, seq, _, hd = input_tensor.shape
|
|
2440
|
+
|
|
2441
|
+
if hd % 2:
|
|
2442
|
+
raise ValueError("Hidden dimension must be divisible by 2")
|
|
2443
|
+
|
|
2444
|
+
if (
|
|
2445
|
+
sin_tensor.size(-1) * 2 != hd
|
|
2446
|
+
or cos_tensor.size(-1) * 2 != hd
|
|
2447
|
+
or sin_tensor.size(0) < seq
|
|
2448
|
+
or cos_tensor.size(0) < seq
|
|
2449
|
+
):
|
|
2450
|
+
raise ValueError(
|
|
2451
|
+
f"sin_tensor and cos_tensor must have shape <kvseq (> {seq}) x {hd // 2}>. Got {sin_tensor.shape} and {cos_tensor.shape}"
|
|
2452
|
+
)
|
|
2453
|
+
|
|
2454
|
+
if pos is not None:
|
|
2455
|
+
if pos.shape != (seq,):
|
|
2456
|
+
raise ValueError(
|
|
2457
|
+
f"pos must have shape {input_tensor.shape[1]}. Got {pos.shape}"
|
|
2458
|
+
)
|
|
2459
|
+
sin_tensor = sin_tensor[pos]
|
|
2460
|
+
cos_tensor = cos_tensor[pos]
|
|
2461
|
+
|
|
2462
|
+
# seq x 1 x hd
|
|
2463
|
+
sin_tensor = sin_tensor.unsqueeze(1)
|
|
2464
|
+
cos_tensor = cos_tensor.unsqueeze(1)
|
|
2465
|
+
|
|
2466
|
+
# batch x seq x num_heads x hd -> batch x seq x num_heads x 2 x head_dim_by_two
|
|
2467
|
+
x0, x1 = input_tensor[..., 0 : hd // 2], input_tensor[..., hd // 2 :]
|
|
2468
|
+
o0 = x0 * cos_tensor - x1 * sin_tensor
|
|
2469
|
+
o1 = x1 * cos_tensor + x0 * sin_tensor
|
|
2470
|
+
rotated = torch.cat([o0.view(-1, 1), o1.view(-1, 1)], dim=-2)
|
|
2471
|
+
return rotated.view(original_shape)
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
@impl_tracked(m, "quantized_rope_rotate_stacked_halves")
|
|
2475
|
+
def quantized_rope_rotate_stacked_halves(
|
|
2476
|
+
input_tensor: torch.Tensor,
|
|
2477
|
+
sin_tensor: torch.Tensor,
|
|
2478
|
+
cos_tensor: torch.Tensor,
|
|
2479
|
+
pos: torch.Tensor | None,
|
|
2480
|
+
in_scale: float,
|
|
2481
|
+
in_zero_point: int,
|
|
2482
|
+
out_scale: float,
|
|
2483
|
+
out_zero_point: int,
|
|
2484
|
+
) -> torch.Tensor:
|
|
2485
|
+
dtype = input_tensor.dtype
|
|
2486
|
+
dtype_limits = torch.iinfo(dtype)
|
|
2487
|
+
dequantized = dequantize_per_tensor_common(
|
|
2488
|
+
input_tensor,
|
|
2489
|
+
in_scale,
|
|
2490
|
+
in_zero_point,
|
|
2491
|
+
dtype_limits.min,
|
|
2492
|
+
dtype_limits.max,
|
|
2493
|
+
dtype,
|
|
2494
|
+
)
|
|
2495
|
+
rotated = rope_rotate_stacked_halves(dequantized, sin_tensor, cos_tensor, pos)
|
|
2496
|
+
return quantize_per_tensor_common(
|
|
2497
|
+
rotated,
|
|
2498
|
+
out_scale,
|
|
2499
|
+
out_zero_point,
|
|
2500
|
+
dtype_limits.min,
|
|
2501
|
+
dtype_limits.max,
|
|
2502
|
+
dtype,
|
|
2503
|
+
)
|
|
2504
|
+
|
|
2505
|
+
|
|
2506
|
+
@impl_tracked(m, "im2row")
|
|
2507
|
+
def im2row(
|
|
2508
|
+
input_tensor: torch.Tensor,
|
|
2509
|
+
kernel_size: tuple[int, int],
|
|
2510
|
+
dilation: tuple[int, int],
|
|
2511
|
+
padding: tuple[int, int],
|
|
2512
|
+
stride: tuple[int, int],
|
|
2513
|
+
in_zero_point: torch.Tensor,
|
|
2514
|
+
channel_last: bool = False,
|
|
2515
|
+
) -> torch.Tensor:
|
|
2516
|
+
"""
|
|
2517
|
+
Converts an input tensor into a 2D matrix where each row is a flattened sliding window (patch)
|
|
2518
|
+
from the input, suitable for use in convolution as a matrix multiplication (im2row).
|
|
2519
|
+
|
|
2520
|
+
Args:
|
|
2521
|
+
- input_tensor: Input tensor of shape (N, C, H, W) or (N, H, W, C) if channel_last.
|
|
2522
|
+
- kernel_size: Size of the convolution kernel.
|
|
2523
|
+
- dilation: Dilation of the convolution kernel.
|
|
2524
|
+
- padding: Padding to apply to the input.
|
|
2525
|
+
- stride: Stride of the convolution.
|
|
2526
|
+
- in_zero_point : Zero point for input quantization (broadcastable to input).
|
|
2527
|
+
- channel_last: If True, input is in NHWC format, else NCHW.
|
|
2528
|
+
|
|
2529
|
+
Returns:
|
|
2530
|
+
- Tensor of shape (N, num_patches, patch_size)
|
|
2531
|
+
"""
|
|
2532
|
+
if len(input_tensor.shape) == 3:
|
|
2533
|
+
height_dim = 1 if channel_last else 2
|
|
2534
|
+
input_tensor = input_tensor.unsqueeze(height_dim)
|
|
2535
|
+
|
|
2536
|
+
if in_zero_point is not None:
|
|
2537
|
+
if in_zero_point.numel() != 1 and in_zero_point.shape != (
|
|
2538
|
+
input_tensor.shape[0],
|
|
2539
|
+
):
|
|
2540
|
+
raise ValueError(
|
|
2541
|
+
f"Input zero point must be a scalar or broadcastable to input shape {input_tensor.shape}"
|
|
2542
|
+
)
|
|
2543
|
+
if in_zero_point.dtype != torch.int32:
|
|
2544
|
+
raise ValueError("Input zero point must be an int32 tensor")
|
|
2545
|
+
|
|
2546
|
+
if channel_last:
|
|
2547
|
+
input_tensor = input_tensor.movedim(-1, -3).contiguous() # NHWC -> NCHW
|
|
2548
|
+
|
|
2549
|
+
N, C, H, W = input_tensor.shape
|
|
2550
|
+
kH, kW = kernel_size
|
|
2551
|
+
dH, dW = dilation
|
|
2552
|
+
pH, pW = padding
|
|
2553
|
+
sH, sW = stride
|
|
2554
|
+
|
|
2555
|
+
# Handle padding with zero point values
|
|
2556
|
+
if in_zero_point is not None and (pH > 0 or pW > 0):
|
|
2557
|
+
# Expand zero point to (N, 1, 1, 1) for broadcasting
|
|
2558
|
+
in_zero_point = in_zero_point.expand(N)
|
|
2559
|
+
|
|
2560
|
+
# Pad input with the per-batch zero point values
|
|
2561
|
+
input_tensor = torch.stack(
|
|
2562
|
+
[
|
|
2563
|
+
torch.nn.functional.pad(
|
|
2564
|
+
input_tensor[i],
|
|
2565
|
+
(pW, pW, pH, pH),
|
|
2566
|
+
mode="constant",
|
|
2567
|
+
value=in_zero_point[i].item(),
|
|
2568
|
+
)
|
|
2569
|
+
for i in range(len(input_tensor))
|
|
2570
|
+
]
|
|
2571
|
+
)
|
|
2572
|
+
|
|
2573
|
+
padding = (0, 0) # Already padded manually
|
|
2574
|
+
|
|
2575
|
+
# Use unfold to extract sliding local blocks
|
|
2576
|
+
# Unfold: (N, C, H, W) -> (N, C, L, kH, kW), where L = number of sliding windows
|
|
2577
|
+
# torch.nn.functional.unfold returns (N, C*kH*kW, L)
|
|
2578
|
+
patches = torch.nn.functional.unfold(
|
|
2579
|
+
input_tensor.float(), # unfold not implemented for int
|
|
2580
|
+
kernel_size=(kH, kW),
|
|
2581
|
+
dilation=(dH, dW),
|
|
2582
|
+
padding=padding,
|
|
2583
|
+
stride=(sH, sW),
|
|
2584
|
+
).to(
|
|
2585
|
+
input_tensor.dtype
|
|
2586
|
+
) # (N, C*kH*kW, L)
|
|
2587
|
+
|
|
2588
|
+
# Transpose to (N, L, C*kH*kW)
|
|
2589
|
+
patches = patches.transpose(1, 2).contiguous()
|
|
2590
|
+
|
|
2591
|
+
# Reshape to (N*L, C*kH*kW)
|
|
2592
|
+
patches = patches.view(N, -1, C * kH * kW)
|
|
2593
|
+
|
|
2594
|
+
# If channel_last, output should be in NHWC patch order (but im2row is always row-major)
|
|
2595
|
+
return patches
|
|
2596
|
+
|
|
2597
|
+
|
|
2598
|
+
@impl_tracked(m, "im2row.per_tensor")
|
|
2599
|
+
def im2row_per_tensor(
|
|
2600
|
+
input_tensor: torch.Tensor,
|
|
2601
|
+
kernel_size: tuple[int, int],
|
|
2602
|
+
dilation: tuple[int, int],
|
|
2603
|
+
padding: tuple[int, int],
|
|
2604
|
+
stride: tuple[int, int],
|
|
2605
|
+
in_zero_point: int,
|
|
2606
|
+
channel_last: bool = False,
|
|
2607
|
+
) -> torch.Tensor:
|
|
2608
|
+
out = im2row(
|
|
2609
|
+
input_tensor,
|
|
2610
|
+
kernel_size,
|
|
2611
|
+
dilation,
|
|
2612
|
+
padding,
|
|
2613
|
+
stride,
|
|
2614
|
+
torch.tensor(in_zero_point, dtype=torch.int32),
|
|
2615
|
+
channel_last,
|
|
2616
|
+
)
|
|
2617
|
+
assert isinstance(out, torch.Tensor)
|
|
2618
|
+
return out
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
@impl_tracked(m, "transposed_im2row")
|
|
2622
|
+
def transposed_im2row(
|
|
2623
|
+
input_tensor: torch.Tensor,
|
|
2624
|
+
kernel_size: tuple[int, int],
|
|
2625
|
+
dilation: tuple[int, int],
|
|
2626
|
+
padding: tuple[int, int],
|
|
2627
|
+
stride: tuple[int, int],
|
|
2628
|
+
output_padding: tuple[int, int],
|
|
2629
|
+
in_zero_point: torch.Tensor,
|
|
2630
|
+
channel_last: bool = False,
|
|
2631
|
+
) -> torch.Tensor:
|
|
2632
|
+
"""
|
|
2633
|
+
Converts input tensor into im2row format for transposed convolutions.
|
|
2634
|
+
For each output position, extracts the kernel-sized patch of input values that
|
|
2635
|
+
contribute to that position in a transposed convolution.
|
|
2636
|
+
|
|
2637
|
+
Args:
|
|
2638
|
+
- input_tensor: Input spatial tensor, NCHW or NHWC format (3D or 4D).
|
|
2639
|
+
- kernel_size: Size of the convolution kernel (kernel_h, kernel_w).
|
|
2640
|
+
- dilation: Dilation of the convolution kernel.
|
|
2641
|
+
- padding: Padding to apply to the input.
|
|
2642
|
+
- stride: Stride of the convolution.
|
|
2643
|
+
- output_padding: Additional output padding for transposed convolution.
|
|
2644
|
+
- in_zero_point: Zero point for input quantization (broadcastable to input).
|
|
2645
|
+
- channel_last: If True, input is in NHWC format, else NCHW.
|
|
2646
|
+
|
|
2647
|
+
Returns:
|
|
2648
|
+
- 3D tensor of shape (N, output_h * output_w, kernel_h * kernel_w * in_c)
|
|
2649
|
+
"""
|
|
2650
|
+
# Handle 1D convolution case by adding height dimension
|
|
2651
|
+
if len(input_tensor.shape) == 3:
|
|
2652
|
+
height_dim = 1 if channel_last else 2
|
|
2653
|
+
input_tensor = input_tensor.unsqueeze(height_dim)
|
|
2654
|
+
|
|
2655
|
+
if in_zero_point is not None:
|
|
2656
|
+
if in_zero_point.dtype != torch.int32:
|
|
2657
|
+
raise ValueError("Input zero point must be an int32 tensor")
|
|
2658
|
+
|
|
2659
|
+
# Move to NCHW for processing if needed
|
|
2660
|
+
if channel_last:
|
|
2661
|
+
input_tensor = input_tensor.movedim(-1, -3).contiguous() # NHWC -> NCHW
|
|
2662
|
+
|
|
2663
|
+
N, C, H_in, W_in = input_tensor.shape
|
|
2664
|
+
K_h, K_w = kernel_size
|
|
2665
|
+
device = input_tensor.device
|
|
2666
|
+
|
|
2667
|
+
# Calculate output spatial size
|
|
2668
|
+
H_out = (
|
|
2669
|
+
(H_in - 1) * stride[0]
|
|
2670
|
+
- 2 * padding[0]
|
|
2671
|
+
+ dilation[0] * (K_h - 1)
|
|
2672
|
+
+ output_padding[0]
|
|
2673
|
+
+ 1
|
|
2674
|
+
)
|
|
2675
|
+
W_out = (
|
|
2676
|
+
(W_in - 1) * stride[1]
|
|
2677
|
+
- 2 * padding[1]
|
|
2678
|
+
+ dilation[1] * (K_w - 1)
|
|
2679
|
+
+ output_padding[1]
|
|
2680
|
+
+ 1
|
|
2681
|
+
)
|
|
2682
|
+
|
|
2683
|
+
# Create meshgrids for all output positions and kernel positions
|
|
2684
|
+
h_out_grid = torch.arange(H_out, device=device).view(
|
|
2685
|
+
-1, 1, 1, 1
|
|
2686
|
+
) # [H_out, 1, 1, 1]
|
|
2687
|
+
w_out_grid = torch.arange(W_out, device=device).view(
|
|
2688
|
+
1, -1, 1, 1
|
|
2689
|
+
) # [1, W_out, 1, 1]
|
|
2690
|
+
kh_grid = torch.arange(K_h, device=device).view(1, 1, -1, 1) # [1, 1, K_h, 1]
|
|
2691
|
+
kw_grid = torch.arange(K_w, device=device).view(1, 1, 1, -1) # [1, 1, 1, K_w]
|
|
2692
|
+
|
|
2693
|
+
# Compute input positions for all (h_out, w_out, kh, kw) combinations
|
|
2694
|
+
# From C++ reference: h_im = _h - ((kernel_h - 1) * dilation_h) + _kh * dilation_h + pad_h
|
|
2695
|
+
h_im = h_out_grid - (K_h - 1) * dilation[0] + kh_grid * dilation[0] + padding[0]
|
|
2696
|
+
w_im = w_out_grid - (K_w - 1) * dilation[1] + kw_grid * dilation[1] + padding[1]
|
|
2697
|
+
|
|
2698
|
+
# Check which positions are valid (divisible by stride and within bounds)
|
|
2699
|
+
# From C++ reference: if (h_im < 0 || h_im >= stride_h * height || h_im % stride_h != 0)
|
|
2700
|
+
h_valid = (h_im % stride[0] == 0) & (h_im >= 0) & (h_im < stride[0] * H_in)
|
|
2701
|
+
w_valid = (w_im % stride[1] == 0) & (w_im >= 0) & (w_im < stride[1] * W_in)
|
|
2702
|
+
valid = h_valid & w_valid # [H_out, W_out, K_h, K_w]
|
|
2703
|
+
|
|
2704
|
+
# Actual input indices (h_im / stride_h from C++ reference)
|
|
2705
|
+
h_in = h_im // stride[0]
|
|
2706
|
+
w_in = w_im // stride[1]
|
|
2707
|
+
|
|
2708
|
+
# Clamp indices to valid range (will be masked out anyway)
|
|
2709
|
+
h_in_safe = h_in.clamp(0, H_in - 1)
|
|
2710
|
+
w_in_safe = w_in.clamp(0, W_in - 1)
|
|
2711
|
+
|
|
2712
|
+
# Initialize output patches with zero points (vectorized across batches)
|
|
2713
|
+
# Layout depends on channel_last: NHWC uses [K_h, K_w, C], NCHW uses [C, K_h, K_w]
|
|
2714
|
+
if channel_last:
|
|
2715
|
+
# NHWC: patches layout [N, H_out, W_out, K_h, K_w, C]
|
|
2716
|
+
patches = torch.zeros(
|
|
2717
|
+
(N, H_out, W_out, K_h, K_w, C),
|
|
2718
|
+
dtype=input_tensor.dtype,
|
|
2719
|
+
device=device,
|
|
2720
|
+
)
|
|
2721
|
+
else:
|
|
2722
|
+
# NCHW: patches layout [N, H_out, W_out, C, K_h, K_w]
|
|
2723
|
+
patches = torch.zeros(
|
|
2724
|
+
(N, H_out, W_out, C, K_h, K_w),
|
|
2725
|
+
dtype=input_tensor.dtype,
|
|
2726
|
+
device=device,
|
|
2727
|
+
)
|
|
2728
|
+
|
|
2729
|
+
# Initialize patches with zero points (vectorized)
|
|
2730
|
+
if in_zero_point is not None:
|
|
2731
|
+
if in_zero_point.numel() == 1:
|
|
2732
|
+
# Scalar zero point - fill all patches
|
|
2733
|
+
patches.fill_(in_zero_point.item())
|
|
2734
|
+
else:
|
|
2735
|
+
# Per-batch zero points - expand and fill
|
|
2736
|
+
# in_zero_point: [N] -> [N, 1, 1, 1, 1, 1] or [N, 1, 1, 1, 1, 1]
|
|
2737
|
+
zp_shape = [N] + [1] * (patches.ndim - 1)
|
|
2738
|
+
patches = patches + in_zero_point.view(*zp_shape)
|
|
2739
|
+
|
|
2740
|
+
# Flatten the spatial and kernel dimensions for efficient gathering
|
|
2741
|
+
# h_in_safe, w_in_safe: [H_out, W_out, K_h, K_w] (broadcast shape)
|
|
2742
|
+
h_flat = h_in_safe.expand(H_out, W_out, K_h, K_w).contiguous().view(-1)
|
|
2743
|
+
w_flat = w_in_safe.expand(H_out, W_out, K_h, K_w).contiguous().view(-1)
|
|
2744
|
+
|
|
2745
|
+
# Vectorized gathering across all batches and channels using advanced indexing
|
|
2746
|
+
# Create index tensors with appropriate broadcasting shapes
|
|
2747
|
+
num_positions = h_flat.shape[0]
|
|
2748
|
+
|
|
2749
|
+
# batch_indices: [N, 1, 1] -> broadcasts to [N, C, num_positions]
|
|
2750
|
+
batch_indices = torch.arange(N, device=device).view(N, 1, 1)
|
|
2751
|
+
|
|
2752
|
+
# channel_indices: [1, C, 1] -> broadcasts to [N, C, num_positions]
|
|
2753
|
+
channel_indices = torch.arange(C, device=device).view(1, C, 1)
|
|
2754
|
+
|
|
2755
|
+
# h_flat, w_flat: [1, 1, num_positions] -> broadcasts to [N, C, num_positions]
|
|
2756
|
+
h_indices = h_flat.view(1, 1, num_positions)
|
|
2757
|
+
w_indices = w_flat.view(1, 1, num_positions)
|
|
2758
|
+
|
|
2759
|
+
# Advanced indexing gathers all values at once: [N, C, num_positions]
|
|
2760
|
+
gathered = input_tensor[batch_indices, channel_indices, h_indices, w_indices]
|
|
2761
|
+
|
|
2762
|
+
# Reshape based on channel_last flag
|
|
2763
|
+
if channel_last:
|
|
2764
|
+
# NHWC: Reshape to [N, H_out, W_out, K_h, K_w, C]
|
|
2765
|
+
# gathered: [N, C, H_out*W_out*K_h*K_w] -> [N, H_out*W_out*K_h*K_w, C] -> [N, H_out, W_out, K_h, K_w, C]
|
|
2766
|
+
gathered = gathered.transpose(1, 2).contiguous() # [N, num_positions, C]
|
|
2767
|
+
gathered = gathered.view(N, H_out, W_out, K_h, K_w, C)
|
|
2768
|
+
else:
|
|
2769
|
+
# NCHW: Reshape to [N, H_out, W_out, C, K_h, K_w]
|
|
2770
|
+
# gathered: [N, C, H_out*W_out*K_h*K_w] -> [N, C, H_out, W_out, K_h, K_w] -> [N, H_out, W_out, C, K_h, K_w]
|
|
2771
|
+
gathered = gathered.view(N, C, H_out, W_out, K_h, K_w)
|
|
2772
|
+
gathered = gathered.permute(0, 2, 3, 1, 4, 5).contiguous()
|
|
2773
|
+
|
|
2774
|
+
# Apply validity mask (vectorized across batches)
|
|
2775
|
+
# valid: [H_out, W_out, K_h, K_w] -> expand to match gathered shape
|
|
2776
|
+
if channel_last:
|
|
2777
|
+
# gathered: [N, H_out, W_out, K_h, K_w, C]
|
|
2778
|
+
valid_exp = valid.unsqueeze(0).unsqueeze(-1) # [1, H_out, W_out, K_h, K_w, 1]
|
|
2779
|
+
else:
|
|
2780
|
+
# gathered: [N, H_out, W_out, C, K_h, K_w]
|
|
2781
|
+
valid_exp = valid.unsqueeze(0).unsqueeze(3) # [1, H_out, W_out, 1, K_h, K_w]
|
|
2782
|
+
|
|
2783
|
+
patches = torch.where(valid_exp, gathered, patches)
|
|
2784
|
+
|
|
2785
|
+
# Reshape to final output format: [N, H_out * W_out, K_h * K_w * C]
|
|
2786
|
+
# The reshaping will preserve the correct dimension ordering
|
|
2787
|
+
if channel_last:
|
|
2788
|
+
# patches: [N, H_out, W_out, K_h, K_w, C] -> [N, H_out*W_out, K_h*K_w*C]
|
|
2789
|
+
patches = patches.view(N, H_out * W_out, K_h * K_w * C)
|
|
2790
|
+
else:
|
|
2791
|
+
# patches: [N, H_out, W_out, C, K_h, K_w] -> [N, H_out*W_out, C*K_h*K_w]
|
|
2792
|
+
patches = patches.view(N, H_out * W_out, C * K_h * K_w)
|
|
2793
|
+
|
|
2794
|
+
return patches
|
|
2795
|
+
|
|
2796
|
+
|
|
2797
|
+
@impl_tracked(m, "quantized_embedding_byte")
|
|
2798
|
+
def quantized_embedding_byte(
|
|
2799
|
+
weight: torch.Tensor,
|
|
2800
|
+
weight_scales: torch.Tensor,
|
|
2801
|
+
weight_zero_points: torch.Tensor | None,
|
|
2802
|
+
indices: torch.Tensor,
|
|
2803
|
+
pruned_weights: bool = False,
|
|
2804
|
+
) -> torch.Tensor:
|
|
2805
|
+
if pruned_weights:
|
|
2806
|
+
raise NotImplementedError("Pruned weights not supported")
|
|
2807
|
+
|
|
2808
|
+
# Cannot use torch.ops.quantized_decomposed.embedding_byte.dtype because
|
|
2809
|
+
# it doesn't support num_groups == 1
|
|
2810
|
+
num_groups = 1
|
|
2811
|
+
if len(weight_scales.shape) == 2:
|
|
2812
|
+
num_groups = weight_scales.shape[1]
|
|
2813
|
+
|
|
2814
|
+
group_size = weight.shape[1] // num_groups
|
|
2815
|
+
weight = torch.ops.torchao.dequantize_affine.default(
|
|
2816
|
+
input=weight,
|
|
2817
|
+
block_size=(1, group_size),
|
|
2818
|
+
scale=weight_scales,
|
|
2819
|
+
zero_point=weight_zero_points,
|
|
2820
|
+
input_dtype=weight.dtype,
|
|
2821
|
+
quant_min=torch.iinfo(weight.dtype).min,
|
|
2822
|
+
quant_max=torch.iinfo(weight.dtype).max,
|
|
2823
|
+
)
|
|
2824
|
+
|
|
2825
|
+
return weight[indices]
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
@impl_tracked(m, "idma_copy")
|
|
2829
|
+
def idma_copy(src: torch.Tensor, task_num: int = 0, channel: int = 0) -> torch.Tensor:
|
|
2830
|
+
return src.clone()
|
|
2831
|
+
|
|
2832
|
+
|
|
2833
|
+
@impl_tracked(m, "idma_store")
|
|
2834
|
+
def idma_store(src: torch.Tensor, task_num: int = 0, channel: int = 0) -> torch.Tensor:
|
|
2835
|
+
return src.clone()
|
|
2836
|
+
|
|
2837
|
+
|
|
2838
|
+
@impl_tracked(m, "idma_load")
|
|
2839
|
+
def idma_load(src: torch.Tensor, task_num: int = 0, channel: int = 0) -> torch.Tensor:
|
|
2840
|
+
return src.clone()
|
|
2841
|
+
|
|
2842
|
+
|
|
2843
|
+
@impl_tracked(m, "idma_wait")
|
|
2844
|
+
def idma_wait(src: torch.Tensor, task_num: int = 0, channel: int = 0) -> torch.Tensor:
|
|
2845
|
+
return src.clone()
|
|
2846
|
+
|
|
2847
|
+
|
|
2848
|
+
@impl_tracked(m, "linalg_svd")
|
|
2849
|
+
def linalg_svd(
|
|
2850
|
+
A: torch.Tensor,
|
|
2851
|
+
full_matrices: bool = False,
|
|
2852
|
+
compute_uv: bool = True,
|
|
2853
|
+
driver: str | None = None,
|
|
2854
|
+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
|
2855
|
+
assert compute_uv
|
|
2856
|
+
U, S, Vh = torch.linalg.svd(A, full_matrices=full_matrices, driver=driver)
|
|
2857
|
+
return U.contiguous(), S.contiguous(), Vh.contiguous()
|
|
2858
|
+
|
|
2859
|
+
|
|
2860
|
+
@impl_tracked(m, "_softmax_f32_f32")
|
|
2861
|
+
def softmax_f32_f32(
|
|
2862
|
+
input_tensor: torch.Tensor,
|
|
2863
|
+
dim: int,
|
|
2864
|
+
half_to_float: bool | None = None,
|
|
2865
|
+
) -> torch.Tensor:
|
|
2866
|
+
assert input_tensor.dtype == torch.float32, "input_tensor must be float32"
|
|
2867
|
+
assert not half_to_float, "half_to_float is not supported"
|
|
2868
|
+
return torch.nn.functional.softmax(input_tensor, dim=dim, dtype=torch.float32)
|
|
2869
|
+
|
|
2870
|
+
|
|
2871
|
+
def quantized_softmax_per_tensor_common(
|
|
2872
|
+
input_tensor: torch.Tensor,
|
|
2873
|
+
mask: torch.Tensor | None,
|
|
2874
|
+
dim: int,
|
|
2875
|
+
mask_type: int,
|
|
2876
|
+
pos: torch.Tensor,
|
|
2877
|
+
in_scale: float,
|
|
2878
|
+
in_zero_point: int,
|
|
2879
|
+
out_scale: float,
|
|
2880
|
+
out_zero_point: int,
|
|
2881
|
+
) -> torch.Tensor:
|
|
2882
|
+
"""
|
|
2883
|
+
Quantized softmax operation.
|
|
2884
|
+
|
|
2885
|
+
Args:
|
|
2886
|
+
- input_tensor (Tensor): The quantized input tensor
|
|
2887
|
+
- mask (Tensor): Mask tensor
|
|
2888
|
+
- dim (int): The dimension along which softmax is computed
|
|
2889
|
+
- mask_type (int): Masking strategy (0=none, 1=position-based causal)
|
|
2890
|
+
- pos (Tensor): Position tensor for causal masking
|
|
2891
|
+
- in_scale (float): The scale of the input quantization
|
|
2892
|
+
- in_zero_point (int): The zero point of the input quantization
|
|
2893
|
+
- out_scale (float): The scale of the output quantization
|
|
2894
|
+
- out_zero_point (int): The zero point of the output quantization
|
|
2895
|
+
"""
|
|
2896
|
+
# TODO: T228751479 - Add support for mask parameter in softmax
|
|
2897
|
+
assert mask is None
|
|
2898
|
+
assert (
|
|
2899
|
+
mask_type == 0
|
|
2900
|
+
), f"Only mask_type=0 (no masking) is supported, got {mask_type}"
|
|
2901
|
+
supported_dtypes = [torch.int8, torch.uint8, torch.int16]
|
|
2902
|
+
if input_tensor.dtype not in supported_dtypes:
|
|
2903
|
+
raise ValueError(
|
|
2904
|
+
f"Input dtype must be one of {supported_dtypes}. Got {input_tensor.dtype}"
|
|
2905
|
+
)
|
|
2906
|
+
|
|
2907
|
+
float_input_tensor = dequantize_per_tensor(
|
|
2908
|
+
input_tensor,
|
|
2909
|
+
in_scale,
|
|
2910
|
+
in_zero_point,
|
|
2911
|
+
torch.iinfo(input_tensor.dtype).min,
|
|
2912
|
+
torch.iinfo(input_tensor.dtype).max,
|
|
2913
|
+
input_tensor.dtype,
|
|
2914
|
+
)
|
|
2915
|
+
|
|
2916
|
+
softmax_output = torch.nn.functional.softmax(float_input_tensor, dim=dim)
|
|
2917
|
+
|
|
2918
|
+
return quantize_per_tensor(
|
|
2919
|
+
softmax_output,
|
|
2920
|
+
out_scale,
|
|
2921
|
+
out_zero_point,
|
|
2922
|
+
torch.iinfo(input_tensor.dtype).min,
|
|
2923
|
+
torch.iinfo(input_tensor.dtype).max,
|
|
2924
|
+
input_tensor.dtype,
|
|
2925
|
+
)
|
|
2926
|
+
|
|
2927
|
+
|
|
2928
|
+
@impl_tracked(m, "quantized_softmax.per_tensor")
|
|
2929
|
+
def quantized_softmax_per_tensor(
|
|
2930
|
+
input_tensor: torch.Tensor,
|
|
2931
|
+
mask: torch.Tensor | None,
|
|
2932
|
+
dim: int,
|
|
2933
|
+
mask_type: int,
|
|
2934
|
+
pos: torch.Tensor,
|
|
2935
|
+
in_scale: float,
|
|
2936
|
+
in_zero_point: int,
|
|
2937
|
+
out_scale: float,
|
|
2938
|
+
out_zero_point: int,
|
|
2939
|
+
) -> torch.Tensor:
|
|
2940
|
+
return quantized_softmax_per_tensor_common(
|
|
2941
|
+
input_tensor,
|
|
2942
|
+
mask,
|
|
2943
|
+
dim,
|
|
2944
|
+
mask_type,
|
|
2945
|
+
pos,
|
|
2946
|
+
in_scale,
|
|
2947
|
+
in_zero_point,
|
|
2948
|
+
out_scale,
|
|
2949
|
+
out_zero_point,
|
|
2950
|
+
)
|
|
2951
|
+
|
|
2952
|
+
|
|
2953
|
+
@impl_tracked(m, "quantized_softmax")
|
|
2954
|
+
def quantized_softmax(
|
|
2955
|
+
input_tensor: torch.Tensor,
|
|
2956
|
+
mask: torch.Tensor | None,
|
|
2957
|
+
dim: int,
|
|
2958
|
+
mask_type: int,
|
|
2959
|
+
pos: torch.Tensor,
|
|
2960
|
+
in_scale: torch.Tensor,
|
|
2961
|
+
in_zero_point: torch.Tensor,
|
|
2962
|
+
out_scale: float,
|
|
2963
|
+
out_zero_point: int,
|
|
2964
|
+
) -> torch.Tensor:
|
|
2965
|
+
return quantized_softmax_per_tensor_common(
|
|
2966
|
+
input_tensor,
|
|
2967
|
+
mask,
|
|
2968
|
+
dim,
|
|
2969
|
+
mask_type,
|
|
2970
|
+
pos,
|
|
2971
|
+
float(in_scale.item()),
|
|
2972
|
+
int(in_zero_point.item()),
|
|
2973
|
+
out_scale,
|
|
2974
|
+
out_zero_point,
|
|
2975
|
+
)
|
|
2976
|
+
|
|
2977
|
+
|
|
2978
|
+
@impl_tracked(m, "sdpa_bitwise_mask_gen")
|
|
2979
|
+
def sdpa_bitwise_mask_gen(mask: torch.Tensor, threshold: float) -> torch.Tensor:
|
|
2980
|
+
"""
|
|
2981
|
+
Generate a bit-packed mask tensor for SDPA.
|
|
2982
|
+
|
|
2983
|
+
Notes:
|
|
2984
|
+
- The semantic of "mask" here is inverted relative to PyTorch's typical boolean masks.
|
|
2985
|
+
In PyTorch, a boolean mask generally uses True to indicate positions to keep/attend,
|
|
2986
|
+
and False to indicate positions to mask out. In this function, the convention is
|
|
2987
|
+
reversed: a value of 1 in the packed byte indicates a masked (disallowed) position,
|
|
2988
|
+
while 0 indicates an unmasked (allowed) position.
|
|
2989
|
+
Concretely:
|
|
2990
|
+
* For a bool mask input:
|
|
2991
|
+
True -> unmasked/allowed -> stored as bit 0 (we invert with ~)
|
|
2992
|
+
False -> masked/disallowed -> stored as bit 1
|
|
2993
|
+
* For a float mask input with threshold:
|
|
2994
|
+
value < threshold -> masked/disallowed (bit 1)
|
|
2995
|
+
value >= threshold -> unmasked/allowed (bit 0)
|
|
2996
|
+
|
|
2997
|
+
Behavior:
|
|
2998
|
+
- Input mask can be torch.bool or torch.float.
|
|
2999
|
+
- The last dimension must be a multiple of 8 so that each group of 8 elements
|
|
3000
|
+
packs into one byte (little-endian within the byte: the first element maps
|
|
3001
|
+
to the least significant bit).
|
|
3002
|
+
- For bool masks, bits are computed as the inverse of the boolean value to align
|
|
3003
|
+
with the "1 means masked" convention.
|
|
3004
|
+
- For float masks, a comparison against `threshold` is used to determine masked
|
|
3005
|
+
positions (value < threshold -> masked -> bit = 1).
|
|
3006
|
+
"""
|
|
3007
|
+
|
|
3008
|
+
assert len(mask.shape) >= 1, "Mask must be at least 1D"
|
|
3009
|
+
assert mask.dtype in [torch.bool, torch.float], "Mask must be bool or float"
|
|
3010
|
+
assert mask.shape[-1] % 8 == 0, "Mask last dim must be a multiple of 8"
|
|
3011
|
+
if mask.dtype == torch.bool:
|
|
3012
|
+
# Pack every 8 boolean elements into a single byte in the output tensor.
|
|
3013
|
+
# Flatten to 1D for straightforward packing
|
|
3014
|
+
original_shape = mask.shape
|
|
3015
|
+
flat = mask.contiguous().view(-1)
|
|
3016
|
+
# Convert boolean to uint8 and group into chunks of 8
|
|
3017
|
+
bits = flat.to(torch.uint8).view(-1, 8)
|
|
3018
|
+
|
|
3019
|
+
# Pack 8 bits into one byte (little-endian within a byte: first element -> LSB)
|
|
3020
|
+
packed = (
|
|
3021
|
+
(~bits[:, 0] & 1) << 0
|
|
3022
|
+
| (~bits[:, 1] & 1) << 1
|
|
3023
|
+
| (~bits[:, 2] & 1) << 2
|
|
3024
|
+
| (~bits[:, 3] & 1) << 3
|
|
3025
|
+
| (~bits[:, 4] & 1) << 4
|
|
3026
|
+
| (~bits[:, 5] & 1) << 5
|
|
3027
|
+
| (~bits[:, 6] & 1) << 6
|
|
3028
|
+
| (~bits[:, 7] & 1) << 7
|
|
3029
|
+
).to(torch.uint8)
|
|
3030
|
+
|
|
3031
|
+
# Compute packed last dim size
|
|
3032
|
+
last_dim = original_shape[-1]
|
|
3033
|
+
packed_last = last_dim // 8
|
|
3034
|
+
# Reshape packed to match mask shape, with last dim packed to bytes
|
|
3035
|
+
return packed.view(*original_shape[:-1], packed_last)
|
|
3036
|
+
else:
|
|
3037
|
+
assert mask.dtype == torch.float, "Mask must be bool or float"
|
|
3038
|
+
# Pack every 8 boolean elements into a single byte in the output tensor.
|
|
3039
|
+
# Flatten to 1D for straightforward packing
|
|
3040
|
+
original_shape = mask.shape
|
|
3041
|
+
flat = mask.contiguous().view(-1, 8)
|
|
3042
|
+
packed = (
|
|
3043
|
+
(flat[:, 0] < threshold) << 0
|
|
3044
|
+
| (flat[:, 1] < threshold) << 1
|
|
3045
|
+
| (flat[:, 2] < threshold) << 2
|
|
3046
|
+
| (flat[:, 3] < threshold) << 3
|
|
3047
|
+
| (flat[:, 4] < threshold) << 4
|
|
3048
|
+
| (flat[:, 5] < threshold) << 5
|
|
3049
|
+
| (flat[:, 6] < threshold) << 6
|
|
3050
|
+
| (flat[:, 7] < threshold) << 7
|
|
3051
|
+
).to(torch.uint8)
|
|
3052
|
+
|
|
3053
|
+
# Compute packed last dim size
|
|
3054
|
+
last_dim = original_shape[-1]
|
|
3055
|
+
packed_last = last_dim // 8
|
|
3056
|
+
# Reshape packed to match mask shape, with last dim packed to bytes
|
|
3057
|
+
return packed.view(*original_shape[:-1], packed_last)
|
|
3058
|
+
|
|
3059
|
+
|
|
3060
|
+
@impl_tracked(m, "sdpa_bitwise_causal_mask_gen")
|
|
3061
|
+
def sdpa_bitwise_causal_mask_gen(
|
|
3062
|
+
positions: torch.Tensor, key_length: int
|
|
3063
|
+
) -> torch.Tensor:
|
|
3064
|
+
"""Generate an LSB-first packed causal mask directly from token positions."""
|
|
3065
|
+
assert positions.dtype in (
|
|
3066
|
+
torch.int32,
|
|
3067
|
+
torch.int64,
|
|
3068
|
+
), "Positions must use int32 or int64"
|
|
3069
|
+
assert positions.dim() == 1, "Positions must be one-dimensional"
|
|
3070
|
+
assert (
|
|
3071
|
+
key_length > 0 and key_length % 8 == 0
|
|
3072
|
+
), "Key length must be positive and divisible by 8"
|
|
3073
|
+
assert bool(torch.all(positions >= 0)), "Positions must be nonnegative"
|
|
3074
|
+
|
|
3075
|
+
visible_lengths = (
|
|
3076
|
+
torch.clamp(positions.to(torch.int64), max=key_length - 1).unsqueeze(1) + 1
|
|
3077
|
+
)
|
|
3078
|
+
byte_starts = torch.arange(
|
|
3079
|
+
0,
|
|
3080
|
+
key_length,
|
|
3081
|
+
8,
|
|
3082
|
+
dtype=torch.int64,
|
|
3083
|
+
device=positions.device,
|
|
3084
|
+
).unsqueeze(0)
|
|
3085
|
+
visible_bits = torch.clamp(visible_lengths - byte_starts, min=0, max=8)
|
|
3086
|
+
return torch.bitwise_and(
|
|
3087
|
+
torch.bitwise_left_shift(torch.full_like(visible_bits, 0xFF), visible_bits),
|
|
3088
|
+
0xFF,
|
|
3089
|
+
).to(torch.uint8)
|
|
3090
|
+
|
|
3091
|
+
|
|
3092
|
+
@impl_tracked(m, "sdpa_bitwise_ring_mask_gen")
|
|
3093
|
+
def sdpa_bitwise_ring_mask_gen(
|
|
3094
|
+
positions: torch.Tensor, sliding_window: int, cache_length: int
|
|
3095
|
+
) -> torch.Tensor:
|
|
3096
|
+
"""Generate an LSB-first ring mask; set bits represent masked cache slots."""
|
|
3097
|
+
assert positions.dtype in (torch.int32, torch.int64)
|
|
3098
|
+
assert positions.dim() == 1
|
|
3099
|
+
assert cache_length > 0 and cache_length % 8 == 0
|
|
3100
|
+
assert 0 < sliding_window <= cache_length
|
|
3101
|
+
assert bool(torch.all(positions >= 0))
|
|
3102
|
+
absolute = positions.to(torch.int64).unsqueeze(1)
|
|
3103
|
+
slots = torch.arange(
|
|
3104
|
+
0, cache_length, 8, dtype=torch.int64, device=positions.device
|
|
3105
|
+
).unsqueeze(0)
|
|
3106
|
+
packed = positions.new_zeros(
|
|
3107
|
+
(positions.numel(), cache_length // 8), dtype=torch.uint8
|
|
3108
|
+
)
|
|
3109
|
+
for bit in range(8):
|
|
3110
|
+
distance = (absolute - (slots + bit)) % cache_length
|
|
3111
|
+
masked = (distance >= sliding_window) | (distance > absolute)
|
|
3112
|
+
packed |= masked.to(torch.uint8) << bit
|
|
3113
|
+
return packed
|
|
3114
|
+
|
|
3115
|
+
|
|
3116
|
+
@impl_tracked(m, "slice_scatter_")
|
|
3117
|
+
def slice_scatter_impl(
|
|
3118
|
+
self: torch.Tensor,
|
|
3119
|
+
src: torch.Tensor,
|
|
3120
|
+
dim: int = 0,
|
|
3121
|
+
start: Optional[int] = None,
|
|
3122
|
+
end: Optional[int] = None,
|
|
3123
|
+
step: int = 1,
|
|
3124
|
+
) -> torch.Tensor:
|
|
3125
|
+
self[:] = torch.ops.aten.slice_scatter.default(self, src, dim, start, end, step)
|
|
3126
|
+
return self
|