executorch 1.4.0__cp314-cp314-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 +360 -0
- executorch/backends/aoti/aoti_partitioner.py +141 -0
- executorch/backends/aoti/passes/replace_view_copy_with_view.py +118 -0
- executorch/backends/apple/coreml/compiler/__init__.py +9 -0
- executorch/backends/apple/coreml/compiler/coreml_preprocess.py +955 -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 +382 -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/runtime/test/export_stateful_model.py +77 -0
- executorch/backends/apple/coreml/test/test_coreml_multifunction.py +334 -0
- executorch/backends/apple/coreml/test/test_coreml_partitioner.py +536 -0
- executorch/backends/apple/coreml/test/test_coreml_quantizer.py +172 -0
- executorch/backends/apple/coreml/test/test_coreml_recipes.py +552 -0
- executorch/backends/apple/coreml/test/test_coreml_utils.py +19 -0
- executorch/backends/apple/coreml/test/test_enumerated_shapes.py +112 -0
- executorch/backends/apple/coreml/test/test_torch_ops.py +360 -0
- executorch/backends/apple/coreml/test/tester.py +121 -0
- executorch/backends/apple/metal/metal_backend.py +118 -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/apple/metal/tests/test_metal_backend.py +79 -0
- executorch/backends/apple/metal/tests/test_metal_partitioner.py +172 -0
- executorch/backends/apple/metal/tests/test_modules.py +1404 -0
- executorch/backends/apple/mps/__init__.py +19 -0
- executorch/backends/apple/mps/mps_preprocess.py +329 -0
- executorch/backends/apple/mps/operators/__init__.py +77 -0
- executorch/backends/apple/mps/operators/activation_ops.py +99 -0
- executorch/backends/apple/mps/operators/binary_ops.py +156 -0
- executorch/backends/apple/mps/operators/clamp_ops.py +60 -0
- executorch/backends/apple/mps/operators/constant_ops.py +128 -0
- executorch/backends/apple/mps/operators/convolution_ops.py +70 -0
- executorch/backends/apple/mps/operators/indexing_ops.py +225 -0
- executorch/backends/apple/mps/operators/linear_algebra_ops.py +52 -0
- executorch/backends/apple/mps/operators/node_visitor.py +473 -0
- executorch/backends/apple/mps/operators/normalization_ops.py +97 -0
- executorch/backends/apple/mps/operators/op_clone.py +54 -0
- executorch/backends/apple/mps/operators/op_getitem.py +29 -0
- executorch/backends/apple/mps/operators/op_quant_dequant.py +142 -0
- executorch/backends/apple/mps/operators/op_skip_ops.py +24 -0
- executorch/backends/apple/mps/operators/pad_ops.py +37 -0
- executorch/backends/apple/mps/operators/pooling_ops.py +142 -0
- executorch/backends/apple/mps/operators/range_ops.py +53 -0
- executorch/backends/apple/mps/operators/reduce_ops.py +39 -0
- executorch/backends/apple/mps/operators/shape_ops.py +263 -0
- executorch/backends/apple/mps/operators/unary_ops.py +130 -0
- executorch/backends/apple/mps/partition/__init__.py +20 -0
- executorch/backends/apple/mps/partition/mps_partitioner.py +159 -0
- executorch/backends/apple/mps/serialization/mps_graph_schema.py +817 -0
- executorch/backends/apple/mps/serialization/mps_graph_serialize.py +34 -0
- executorch/backends/apple/mps/serialization/schema.fbs +523 -0
- executorch/backends/apple/mps/test/test_mps.py +2507 -0
- executorch/backends/apple/mps/test/test_mps_binary_ops.py +296 -0
- executorch/backends/apple/mps/test/test_mps_deprecation.py +125 -0
- executorch/backends/apple/mps/test/test_mps_indexing_ops.py +264 -0
- executorch/backends/apple/mps/test/test_mps_linear.py +523 -0
- executorch/backends/apple/mps/test/test_mps_models.py +416 -0
- executorch/backends/apple/mps/test/test_mps_unary_ops.py +26 -0
- executorch/backends/apple/mps/test/test_mps_utils.py +326 -0
- executorch/backends/apple/mps/utils/mps_utils.py +82 -0
- executorch/backends/apple/mps/utils/quant_utils.py +41 -0
- executorch/backends/arm/__init__.py +55 -0
- executorch/backends/arm/_passes/__init__.py +213 -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 +294 -0
- executorch/backends/arm/_passes/arm_pass_manager.py +779 -0
- executorch/backends/arm/_passes/arm_pass_utils.py +427 -0
- executorch/backends/arm/_passes/aten_to_tosa_activation_functions.py +148 -0
- executorch/backends/arm/_passes/aten_to_tosa_data_layout.py +98 -0
- executorch/backends/arm/_passes/aten_to_tosa_tensor_operators.py +118 -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 +372 -0
- executorch/backends/arm/_passes/cast_int64_pass.py +99 -0
- executorch/backends/arm/_passes/cast_to_int32_pass.py +69 -0
- executorch/backends/arm/_passes/constant_folding_pass.py +81 -0
- executorch/backends/arm/_passes/control_flow_const_inline.py +78 -0
- executorch/backends/arm/_passes/conv1d_unsqueeze_pass.py +113 -0
- executorch/backends/arm/_passes/convert_elu_params.py +88 -0
- executorch/backends/arm/_passes/convert_expand_copy_to_repeat.py +80 -0
- executorch/backends/arm/_passes/convert_full_like_to_full_pass.py +49 -0
- executorch/backends/arm/_passes/convert_int64_const_ops_to_int32.py +81 -0
- executorch/backends/arm/_passes/convert_int64_output_ops_to_int32.py +199 -0
- executorch/backends/arm/_passes/convert_minmax_pass.py +166 -0
- executorch/backends/arm/_passes/convert_permute_singleton_to_view_pass.py +65 -0
- executorch/backends/arm/_passes/convert_split_to_slice.py +134 -0
- executorch/backends/arm/_passes/convert_squeezes_to_view.py +40 -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 +462 -0
- executorch/backends/arm/_passes/decompose_adaptive_max_pool2d_pass.py +203 -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 +122 -0
- executorch/backends/arm/_passes/decompose_as_strided_copy_pass.py +116 -0
- executorch/backends/arm/_passes/decompose_asin_and_acos_pass.py +223 -0
- executorch/backends/arm/_passes/decompose_asinh_pass.py +72 -0
- executorch/backends/arm/_passes/decompose_atan_pass.py +139 -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 +235 -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 +182 -0
- executorch/backends/arm/_passes/decompose_index_tensor_to_gather_pass.py +400 -0
- executorch/backends/arm/_passes/decompose_int_pow_pass.py +87 -0
- executorch/backends/arm/_passes/decompose_layernorm_pass.py +203 -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 +117 -0
- executorch/backends/arm/_passes/decompose_log1p_pass.py +96 -0
- executorch/backends/arm/_passes/decompose_logit_pass.py +119 -0
- executorch/backends/arm/_passes/decompose_lstm_pass.py +378 -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_maxpool2d_with_dilation_pass.py +242 -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_quant_nodes.py +161 -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_round_pass.py +85 -0
- executorch/backends/arm/_passes/decompose_sdpa_pass.py +41 -0
- executorch/backends/arm/_passes/decompose_select.py +80 -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 +119 -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_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 +372 -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_get_attr_pass.py +96 -0
- executorch/backends/arm/_passes/dim_maps.py +959 -0
- executorch/backends/arm/_passes/ensure_unique_output_nodes_pass.py +82 -0
- executorch/backends/arm/_passes/exir_to_tosa_pass.py +136 -0
- executorch/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py +442 -0
- executorch/backends/arm/_passes/fold_scalar_mul_into_conv_pass.py +335 -0
- executorch/backends/arm/_passes/fuse_batch_norm2d_pass.py +246 -0
- executorch/backends/arm/_passes/fuse_consecutive_concat_shapes.py +64 -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 +362 -0
- executorch/backends/arm/_passes/fuse_duplicate_users_pass.py +170 -0
- executorch/backends/arm/_passes/fuse_equal_placeholders_pass.py +125 -0
- executorch/backends/arm/_passes/fuse_identical_input_transforms_pass.py +401 -0
- executorch/backends/arm/_passes/fuse_quantized_activation_pass.py +82 -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 +101 -0
- executorch/backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py +129 -0
- executorch/backends/arm/_passes/insert_rescales_pass.py +667 -0
- executorch/backends/arm/_passes/insert_table_ops.py +345 -0
- executorch/backends/arm/_passes/match_arg_dtype_pass.py +105 -0
- executorch/backends/arm/_passes/match_arg_ranks_pass.py +116 -0
- executorch/backends/arm/_passes/mm_to_bmm_pass.py +114 -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_while_initial_args_pass.py +115 -0
- executorch/backends/arm/_passes/promote_bool_operands_pass.py +84 -0
- executorch/backends/arm/_passes/propagate_view_copy_permute_pass.py +751 -0
- executorch/backends/arm/_passes/quant_args.py +131 -0
- executorch/backends/arm/_passes/remove_getitem_pass.py +14 -0
- executorch/backends/arm/_passes/remove_graph_asserts_pass.py +18 -0
- executorch/backends/arm/_passes/remove_noop_pass.py +43 -0
- executorch/backends/arm/_passes/remove_permutes_around_elementwise_tosa_ops.py +42 -0
- executorch/backends/arm/_passes/replace_inf_and_limit_values_pass.py +81 -0
- executorch/backends/arm/_passes/replace_scalar_with_tensor_pass.py +139 -0
- executorch/backends/arm/_passes/rewrite_adaptive_avg_pool2d.py +170 -0
- executorch/backends/arm/_passes/rewrite_avg_pool2d_pass.py +108 -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_conv_pass.py +699 -0
- executorch/backends/arm/_passes/rewrite_high_rank_singleton_permute_pass.py +114 -0
- executorch/backends/arm/_passes/rewrite_index_put_pass.py +200 -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 +189 -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 +177 -0
- executorch/backends/arm/_passes/rewrite_slice.py +75 -0
- executorch/backends/arm/_passes/rewrite_upsample.py +267 -0
- executorch/backends/arm/_passes/scalars_to_attribute_pass.py +144 -0
- executorch/backends/arm/_passes/size_adjust_input_pass.py +287 -0
- executorch/backends/arm/_passes/symbolic_to_tosa_shape_pass.py +26 -0
- executorch/backends/arm/_passes/symbolic_value_range.py +189 -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 +144 -0
- executorch/backends/arm/cmsis_pack/scripts/generate_components.py +462 -0
- executorch/backends/arm/cmsis_pack/scripts/generate_register_all_kernels.py +1215 -0
- executorch/backends/arm/cmsis_pack/test/validate_pack.py +85 -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 +385 -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 +109 -0
- executorch/backends/arm/common/type.py +28 -0
- executorch/backends/arm/constants.py +52 -0
- executorch/backends/arm/debug/__init__.py +4 -0
- executorch/backends/arm/debug/schema.py +145 -0
- executorch/backends/arm/ethosu/__init__.py +11 -0
- executorch/backends/arm/ethosu/backend.py +115 -0
- executorch/backends/arm/ethosu/compile_spec.py +154 -0
- executorch/backends/arm/ethosu/partitioner.py +41 -0
- executorch/backends/arm/operator_support/__init__.py +30 -0
- executorch/backends/arm/operator_support/as_strided_copy_support.py +113 -0
- executorch/backends/arm/operator_support/bool_bitwise_support.py +39 -0
- executorch/backends/arm/operator_support/clone_dim_order_support.py +77 -0
- executorch/backends/arm/operator_support/control_flow_support.py +194 -0
- executorch/backends/arm/operator_support/convolution_support.py +321 -0
- executorch/backends/arm/operator_support/embedding_support.py +56 -0
- executorch/backends/arm/operator_support/ethos_u55_support.py +306 -0
- executorch/backends/arm/operator_support/gather_support.py +166 -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 +193 -0
- executorch/backends/arm/operator_support/minmax_support.py +59 -0
- executorch/backends/arm/operator_support/pool_2d_support.py +266 -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/slice_copy_support.py +119 -0
- executorch/backends/arm/operator_support/sym_size_int_support.py +25 -0
- executorch/backends/arm/operator_support/to_dim_order_copy_support.py +119 -0
- executorch/backends/arm/operator_support/tosa_profile_supported_op_lists.py +285 -0
- executorch/backends/arm/operator_support/tosa_supported_operators.py +1154 -0
- executorch/backends/arm/operator_support/unfold_copy_support.py +146 -0
- executorch/backends/arm/operator_support/upsample_support.py +91 -0
- executorch/backends/arm/operator_support/where_support.py +76 -0
- executorch/backends/arm/operators/__init__.py +79 -0
- executorch/backends/arm/operators/node_visitor.py +261 -0
- executorch/backends/arm/operators/op_amax.py +80 -0
- executorch/backends/arm/operators/op_amin.py +79 -0
- executorch/backends/arm/operators/op_any.py +59 -0
- executorch/backends/arm/operators/op_cond_if.py +67 -0
- executorch/backends/arm/operators/op_flip.py +77 -0
- executorch/backends/arm/operators/op_sum.py +58 -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 +63 -0
- executorch/backends/arm/operators/op_tosa_avg_pool2d.py +73 -0
- executorch/backends/arm/operators/op_tosa_avg_pool2d_adaptive.py +71 -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 +141 -0
- executorch/backends/arm/operators/op_tosa_ceil.py +30 -0
- executorch/backends/arm/operators/op_tosa_clamp.py +71 -0
- executorch/backends/arm/operators/op_tosa_clz.py +30 -0
- executorch/backends/arm/operators/op_tosa_concat.py +73 -0
- executorch/backends/arm/operators/op_tosa_conv2d.py +140 -0
- executorch/backends/arm/operators/op_tosa_conv2d_block_scaled.py +114 -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 +90 -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 +98 -0
- executorch/backends/arm/operators/op_tosa_matmul_t_block_scaled.py +100 -0
- executorch/backends/arm/operators/op_tosa_max_pool2d.py +71 -0
- executorch/backends/arm/operators/op_tosa_max_pool2d_adaptive.py +60 -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 +60 -0
- executorch/backends/arm/operators/op_tosa_neg.py +81 -0
- executorch/backends/arm/operators/op_tosa_pad.py +78 -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_rescale.py +265 -0
- executorch/backends/arm/operators/op_tosa_reshape.py +72 -0
- executorch/backends/arm/operators/op_tosa_resize.py +57 -0
- executorch/backends/arm/operators/op_tosa_reverse.py +64 -0
- executorch/backends/arm/operators/op_tosa_rshift_tensor.py +57 -0
- executorch/backends/arm/operators/op_tosa_rsqrt.py +30 -0
- executorch/backends/arm/operators/op_tosa_scatter.py +77 -0
- executorch/backends/arm/operators/op_tosa_shapes.py +257 -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 +69 -0
- executorch/backends/arm/operators/op_tosa_sub.py +26 -0
- executorch/backends/arm/operators/op_tosa_table.py +68 -0
- executorch/backends/arm/operators/op_tosa_tanh.py +30 -0
- executorch/backends/arm/operators/op_tosa_tile.py +68 -0
- executorch/backends/arm/operators/op_tosa_transpose.py +71 -0
- executorch/backends/arm/operators/op_tosa_transpose_conv2d.py +132 -0
- executorch/backends/arm/operators/op_where.py +69 -0
- executorch/backends/arm/operators/op_while.py +105 -0
- executorch/backends/arm/operators/operator_validation_utils.py +209 -0
- executorch/backends/arm/operators/ops_quant_utils.py +36 -0
- executorch/backends/arm/operators/simple_node_visitor.py +70 -0
- executorch/backends/arm/process_node.py +326 -0
- executorch/backends/arm/quantizer/__init__.py +37 -0
- executorch/backends/arm/quantizer/arm_quantizer.py +1453 -0
- executorch/backends/arm/quantizer/arm_quantizer_utils.py +768 -0
- executorch/backends/arm/quantizer/quantization_annotator.py +1084 -0
- executorch/backends/arm/quantizer/quantization_config.py +424 -0
- executorch/backends/arm/quantizer/quantizer_support.py +246 -0
- executorch/backends/arm/scripts/aot_arm_compiler.py +1194 -0
- executorch/backends/arm/scripts/docgen/docgen.py +271 -0
- executorch/backends/arm/scripts/etdump_to_chrome_trace.py +109 -0
- executorch/backends/arm/scripts/evaluate_model.py +395 -0
- executorch/backends/arm/scripts/generate_grid_sampler_spirv.py +81 -0
- executorch/backends/arm/scripts/get_ethosu_scratch_from_pte.py +77 -0
- executorch/backends/arm/scripts/public_api_manifest/__init__.py +4 -0
- executorch/backends/arm/scripts/public_api_manifest/generate_public_api_manifest.py +155 -0
- executorch/backends/arm/scripts/public_api_manifest/validate_public_api_manifest.py +358 -0
- executorch/backends/arm/test/_custom_vgf_test_utils.py +999 -0
- executorch/backends/arm/test/common.py +357 -0
- executorch/backends/arm/test/conftest.py +149 -0
- executorch/backends/arm/test/deprecation/test_arm_compile_spec_deprecation.py +46 -0
- executorch/backends/arm/test/misc/test_bn_relu_folding_qat.py +124 -0
- executorch/backends/arm/test/misc/test_call_operator_submodule.py +72 -0
- executorch/backends/arm/test/misc/test_compile_spec.py +125 -0
- executorch/backends/arm/test/misc/test_const_shape.py +58 -0
- executorch/backends/arm/test/misc/test_conv_relu_residual_add.py +108 -0
- executorch/backends/arm/test/misc/test_convolution_operator_support.py +218 -0
- executorch/backends/arm/test/misc/test_count_tosa_ops.py +41 -0
- executorch/backends/arm/test/misc/test_custom_partition.py +183 -0
- executorch/backends/arm/test/misc/test_custom_shader_payload.py +371 -0
- executorch/backends/arm/test/misc/test_custom_shader_payloads.py +178 -0
- executorch/backends/arm/test/misc/test_debug_feats.py +416 -0
- executorch/backends/arm/test/misc/test_debug_hook.py +186 -0
- executorch/backends/arm/test/misc/test_dim_order.py +122 -0
- executorch/backends/arm/test/misc/test_dw_convs_with_shared_weights.py +46 -0
- executorch/backends/arm/test/misc/test_evaluate_model.py +72 -0
- executorch/backends/arm/test/misc/test_extract_io_params_tosa.py +115 -0
- executorch/backends/arm/test/misc/test_high_rank_permute_view_invariants.py +186 -0
- executorch/backends/arm/test/misc/test_int64.py +112 -0
- executorch/backends/arm/test/misc/test_lifted_tensor.py +146 -0
- executorch/backends/arm/test/misc/test_mixed_fp_bf16_partition.py +123 -0
- executorch/backends/arm/test/misc/test_mixed_type_lowering.py +83 -0
- executorch/backends/arm/test/misc/test_model_evaluator.py +54 -0
- executorch/backends/arm/test/misc/test_multiple_delegates.py +71 -0
- executorch/backends/arm/test/misc/test_multiple_outputs.py +70 -0
- executorch/backends/arm/test/misc/test_mxfp_conv2d_ao.py +318 -0
- executorch/backends/arm/test/misc/test_mxfp_linear_ao.py +207 -0
- executorch/backends/arm/test/misc/test_non_persistent_buffers.py +45 -0
- executorch/backends/arm/test/misc/test_partition_cycle_detection.py +92 -0
- executorch/backends/arm/test/misc/test_partition_decomposed_quantized_ops.py +188 -0
- executorch/backends/arm/test/misc/test_pass_pipeline_config.py +210 -0
- executorch/backends/arm/test/misc/test_pass_required_order.py +97 -0
- executorch/backends/arm/test/misc/test_post_quant_device_switch.py +232 -0
- executorch/backends/arm/test/misc/test_process_node.py +172 -0
- executorch/backends/arm/test/misc/test_public_api_manifest.py +117 -0
- executorch/backends/arm/test/misc/test_qat_training_loop.py +104 -0
- executorch/backends/arm/test/misc/test_quant_custom_meta.py +110 -0
- executorch/backends/arm/test/misc/test_rescale_range.py +206 -0
- executorch/backends/arm/test/misc/test_reshape_permute_5d_regression.py +189 -0
- executorch/backends/arm/test/misc/test_runner_utils.py +231 -0
- executorch/backends/arm/test/misc/test_save_exported_model.py +64 -0
- executorch/backends/arm/test/misc/test_shared_qspecs.py +689 -0
- executorch/backends/arm/test/misc/test_tosa_data_layout_visitors.py +61 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_activation.py +195 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_argmax.py +43 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_fft.py +121 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_max_pool2d_adaptive.py +128 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_scatter.py +38 -0
- executorch/backends/arm/test/misc/test_tosa_dialect_unary_ops.py +394 -0
- executorch/backends/arm/test/misc/test_tosa_operator_support.py +89 -0
- executorch/backends/arm/test/misc/test_tosa_shape_node_visitors.py +583 -0
- executorch/backends/arm/test/misc/test_tosa_shape_support.py +170 -0
- executorch/backends/arm/test/misc/test_tosa_spec.py +227 -0
- executorch/backends/arm/test/misc/test_transpose_counts.py +580 -0
- executorch/backends/arm/test/misc/test_validate_public_api_manifest.py +262 -0
- executorch/backends/arm/test/misc/test_vgf_backend.py +332 -0
- executorch/backends/arm/test/misc/test_vgf_check_env.py +442 -0
- executorch/backends/arm/test/misc/test_vgf_smoke.py +61 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_data_layout_ops.py +180 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_avg_pool2d_adaptive.py +324 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_conv2d.py +220 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dialect_binary_ops.py +439 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dialect_cast_to_block_scaled.py +106 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dialect_conversion_ops.py +35 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dialect_mxfp_conv2d.py +91 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dialect_mxfp_linear.py +90 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_dw_conv2d.py +227 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_gather.py +44 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_identity.py +34 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_reduction_ops.py +134 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_rescale.py +60 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_resize.py +154 -0
- executorch/backends/arm/test/misc/tosa_dialect/test_tosa_shape_ops.py +815 -0
- executorch/backends/arm/test/models/Gemma3n/gemma3n_test_config.py +37 -0
- executorch/backends/arm/test/models/Gemma3n/test_gemma3nModel.py +811 -0
- executorch/backends/arm/test/models/Qwen3_VL/qwen3_vl_test_config.py +64 -0
- executorch/backends/arm/test/models/Qwen3_VL/test_qwen3_vl_layers.py +628 -0
- executorch/backends/arm/test/models/Qwen3_VL/test_qwen3_vl_model.py +407 -0
- executorch/backends/arm/test/models/phi3/phi3_module_test_configs.py +24 -0
- executorch/backends/arm/test/models/phi3/test_phi3_layers.py +277 -0
- executorch/backends/arm/test/models/stable_diffusion/stable_diffusion_module_test_configs.py +113 -0
- executorch/backends/arm/test/models/stable_diffusion/test_CLIPTextModelWithProjection.py +166 -0
- executorch/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py +188 -0
- executorch/backends/arm/test/models/stable_diffusion/test_T5EncoderModel.py +165 -0
- executorch/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py +121 -0
- executorch/backends/arm/test/models/test_T5ForConditionalGeneration_arm.py +170 -0
- executorch/backends/arm/test/models/test_conformer.py +144 -0
- executorch/backends/arm/test/models/test_deep_autoencoder.py +123 -0
- executorch/backends/arm/test/models/test_deit_tiny_arm.py +122 -0
- executorch/backends/arm/test/models/test_dl3_arm.py +120 -0
- executorch/backends/arm/test/models/test_ds_cnn.py +97 -0
- executorch/backends/arm/test/models/test_inception_v3_arm.py +139 -0
- executorch/backends/arm/test/models/test_llama.py +349 -0
- executorch/backends/arm/test/models/test_lstm_arm.py +198 -0
- executorch/backends/arm/test/models/test_mobilenet_v1_025.py +93 -0
- executorch/backends/arm/test/models/test_mobilenet_v2_arm.py +240 -0
- executorch/backends/arm/test/models/test_mobilenet_v3_arm.py +138 -0
- executorch/backends/arm/test/models/test_nn_functional.py +130 -0
- executorch/backends/arm/test/models/test_nn_modules.py +174 -0
- executorch/backends/arm/test/models/test_nss.py +148 -0
- executorch/backends/arm/test/models/test_residual_conv_block.py +143 -0
- executorch/backends/arm/test/models/test_resnet18.py +133 -0
- executorch/backends/arm/test/models/test_resnet8.py +91 -0
- executorch/backends/arm/test/models/test_swin2sr_arm.py +132 -0
- executorch/backends/arm/test/models/test_torch_functions.py +155 -0
- executorch/backends/arm/test/models/test_w2l_arm.py +144 -0
- executorch/backends/arm/test/modules/test_gru.py +178 -0
- executorch/backends/arm/test/modules/test_lstm.py +199 -0
- executorch/backends/arm/test/modules/test_rnn.py +242 -0
- executorch/backends/arm/test/modules/test_static_cache.py +228 -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/mxfp/test_mxfp_linear.py +437 -0
- executorch/backends/arm/test/ops/test_abs.py +117 -0
- executorch/backends/arm/test/ops/test_acos.py +121 -0
- executorch/backends/arm/test/ops/test_acosh.py +137 -0
- executorch/backends/arm/test/ops/test_adaptive_avg_pool2d.py +294 -0
- executorch/backends/arm/test/ops/test_add.py +550 -0
- executorch/backends/arm/test/ops/test_addmm.py +275 -0
- executorch/backends/arm/test/ops/test_alias_copy.py +127 -0
- executorch/backends/arm/test/ops/test_amax.py +319 -0
- executorch/backends/arm/test/ops/test_amin.py +326 -0
- executorch/backends/arm/test/ops/test_any.py +231 -0
- executorch/backends/arm/test/ops/test_arange.py +258 -0
- executorch/backends/arm/test/ops/test_argmax.py +133 -0
- executorch/backends/arm/test/ops/test_as_strided_copy.py +138 -0
- executorch/backends/arm/test/ops/test_asin.py +105 -0
- executorch/backends/arm/test/ops/test_asinh.py +104 -0
- executorch/backends/arm/test/ops/test_at.py +117 -0
- executorch/backends/arm/test/ops/test_atan.py +111 -0
- executorch/backends/arm/test/ops/test_atanh.py +116 -0
- executorch/backends/arm/test/ops/test_avg_pool2d.py +382 -0
- executorch/backends/arm/test/ops/test_batch_norm.py +397 -0
- executorch/backends/arm/test/ops/test_bitwise.py +769 -0
- executorch/backends/arm/test/ops/test_bitwise_not.py +135 -0
- executorch/backends/arm/test/ops/test_bmm.py +240 -0
- executorch/backends/arm/test/ops/test_cat.py +297 -0
- executorch/backends/arm/test/ops/test_ceil.py +152 -0
- executorch/backends/arm/test/ops/test_clamp.py +584 -0
- executorch/backends/arm/test/ops/test_clone.py +150 -0
- executorch/backends/arm/test/ops/test_cond.py +313 -0
- executorch/backends/arm/test/ops/test_constant_pad_nd.py +390 -0
- executorch/backends/arm/test/ops/test_conv1d.py +433 -0
- executorch/backends/arm/test/ops/test_conv2d.py +872 -0
- executorch/backends/arm/test/ops/test_conv3d.py +908 -0
- executorch/backends/arm/test/ops/test_conv_combos.py +667 -0
- executorch/backends/arm/test/ops/test_conv_constant_pad_nd.py +161 -0
- executorch/backends/arm/test/ops/test_copy.py +171 -0
- executorch/backends/arm/test/ops/test_cos.py +136 -0
- executorch/backends/arm/test/ops/test_cosh.py +111 -0
- executorch/backends/arm/test/ops/test_cumsum.py +120 -0
- executorch/backends/arm/test/ops/test_custom_shader_lowering.py +287 -0
- executorch/backends/arm/test/ops/test_depthwise_conv.py +589 -0
- executorch/backends/arm/test/ops/test_detach_copy.py +56 -0
- executorch/backends/arm/test/ops/test_div.py +209 -0
- executorch/backends/arm/test/ops/test_div_tensor_mode.py +235 -0
- executorch/backends/arm/test/ops/test_elu.py +241 -0
- executorch/backends/arm/test/ops/test_embedding.py +173 -0
- executorch/backends/arm/test/ops/test_eq.py +371 -0
- executorch/backends/arm/test/ops/test_erf.py +121 -0
- executorch/backends/arm/test/ops/test_erfinv.py +121 -0
- executorch/backends/arm/test/ops/test_exp.py +172 -0
- executorch/backends/arm/test/ops/test_expand.py +153 -0
- executorch/backends/arm/test/ops/test_expm1.py +113 -0
- executorch/backends/arm/test/ops/test_eye.py +156 -0
- executorch/backends/arm/test/ops/test_fft.py +62 -0
- executorch/backends/arm/test/ops/test_fill_scalar.py +108 -0
- executorch/backends/arm/test/ops/test_flip.py +226 -0
- executorch/backends/arm/test/ops/test_floor.py +148 -0
- executorch/backends/arm/test/ops/test_floor_div.py +162 -0
- executorch/backends/arm/test/ops/test_full.py +257 -0
- executorch/backends/arm/test/ops/test_gather.py +259 -0
- executorch/backends/arm/test/ops/test_ge.py +379 -0
- executorch/backends/arm/test/ops/test_gelu.py +215 -0
- executorch/backends/arm/test/ops/test_glu.py +134 -0
- executorch/backends/arm/test/ops/test_grid_sampler.py +62 -0
- executorch/backends/arm/test/ops/test_group_norm.py +175 -0
- executorch/backends/arm/test/ops/test_gt.py +383 -0
- executorch/backends/arm/test/ops/test_hardsigmoid.py +114 -0
- executorch/backends/arm/test/ops/test_hardswish.py +104 -0
- executorch/backends/arm/test/ops/test_hardtanh.py +113 -0
- executorch/backends/arm/test/ops/test_index_copy.py +216 -0
- executorch/backends/arm/test/ops/test_index_put.py +519 -0
- executorch/backends/arm/test/ops/test_index_select.py +231 -0
- executorch/backends/arm/test/ops/test_index_tensor.py +624 -0
- executorch/backends/arm/test/ops/test_layer_norm.py +213 -0
- executorch/backends/arm/test/ops/test_le.py +355 -0
- executorch/backends/arm/test/ops/test_leaky_relu.py +121 -0
- executorch/backends/arm/test/ops/test_linalg_vector_norm.py +161 -0
- executorch/backends/arm/test/ops/test_linear.py +409 -0
- executorch/backends/arm/test/ops/test_log.py +126 -0
- executorch/backends/arm/test/ops/test_log10.py +87 -0
- executorch/backends/arm/test/ops/test_log1p.py +78 -0
- executorch/backends/arm/test/ops/test_logical.py +429 -0
- executorch/backends/arm/test/ops/test_logit.py +122 -0
- executorch/backends/arm/test/ops/test_logsoftmax.py +124 -0
- executorch/backends/arm/test/ops/test_lshift.py +220 -0
- executorch/backends/arm/test/ops/test_lt.py +356 -0
- executorch/backends/arm/test/ops/test_masked_fill.py +171 -0
- executorch/backends/arm/test/ops/test_matmul.py +557 -0
- executorch/backends/arm/test/ops/test_max_pool.py +449 -0
- executorch/backends/arm/test/ops/test_max_pool1d.py +164 -0
- executorch/backends/arm/test/ops/test_maximum.py +195 -0
- executorch/backends/arm/test/ops/test_mean_dim.py +487 -0
- executorch/backends/arm/test/ops/test_minimum.py +195 -0
- executorch/backends/arm/test/ops/test_mm.py +93 -0
- executorch/backends/arm/test/ops/test_mul.py +416 -0
- executorch/backends/arm/test/ops/test_multihead_attention.py +131 -0
- executorch/backends/arm/test/ops/test_mxfp_conv2d.py +445 -0
- executorch/backends/arm/test/ops/test_ne.py +253 -0
- executorch/backends/arm/test/ops/test_neg.py +166 -0
- executorch/backends/arm/test/ops/test_ones.py +152 -0
- executorch/backends/arm/test/ops/test_permute.py +263 -0
- executorch/backends/arm/test/ops/test_pixel_shuffling.py +235 -0
- executorch/backends/arm/test/ops/test_pow.py +240 -0
- executorch/backends/arm/test/ops/test_reciprocal.py +176 -0
- executorch/backends/arm/test/ops/test_relu.py +166 -0
- executorch/backends/arm/test/ops/test_remainder.py +208 -0
- executorch/backends/arm/test/ops/test_repeat.py +271 -0
- executorch/backends/arm/test/ops/test_round.py +114 -0
- executorch/backends/arm/test/ops/test_rshift.py +226 -0
- executorch/backends/arm/test/ops/test_rsqrt.py +212 -0
- executorch/backends/arm/test/ops/test_rsub.py +121 -0
- executorch/backends/arm/test/ops/test_scalar_tensor.py +135 -0
- executorch/backends/arm/test/ops/test_scalars.py +396 -0
- executorch/backends/arm/test/ops/test_sdpa.py +154 -0
- executorch/backends/arm/test/ops/test_select.py +204 -0
- executorch/backends/arm/test/ops/test_select_scatter.py +188 -0
- executorch/backends/arm/test/ops/test_sigmoid.py +358 -0
- executorch/backends/arm/test/ops/test_sigmoid_32bit.py +219 -0
- executorch/backends/arm/test/ops/test_sign.py +111 -0
- executorch/backends/arm/test/ops/test_silu.py +193 -0
- executorch/backends/arm/test/ops/test_sin.py +130 -0
- executorch/backends/arm/test/ops/test_sinh.py +103 -0
- executorch/backends/arm/test/ops/test_slice.py +410 -0
- executorch/backends/arm/test/ops/test_slice_scatter.py +342 -0
- executorch/backends/arm/test/ops/test_softmax.py +239 -0
- executorch/backends/arm/test/ops/test_split.py +347 -0
- executorch/backends/arm/test/ops/test_sqrt.py +112 -0
- executorch/backends/arm/test/ops/test_squeeze.py +318 -0
- executorch/backends/arm/test/ops/test_stack.py +150 -0
- executorch/backends/arm/test/ops/test_sub.py +547 -0
- executorch/backends/arm/test/ops/test_sum.py +303 -0
- executorch/backends/arm/test/ops/test_t_copy.py +115 -0
- executorch/backends/arm/test/ops/test_tan.py +146 -0
- executorch/backends/arm/test/ops/test_tanh.py +198 -0
- executorch/backends/arm/test/ops/test_to_copy.py +655 -0
- executorch/backends/arm/test/ops/test_transpose_conv2d.py +670 -0
- executorch/backends/arm/test/ops/test_transpose_copy.py +114 -0
- executorch/backends/arm/test/ops/test_tril.py +177 -0
- executorch/backends/arm/test/ops/test_unary_combos.py +143 -0
- executorch/backends/arm/test/ops/test_unbind.py +82 -0
- executorch/backends/arm/test/ops/test_unflatten.py +110 -0
- executorch/backends/arm/test/ops/test_unfold_copy.py +262 -0
- executorch/backends/arm/test/ops/test_unsqueeze.py +107 -0
- executorch/backends/arm/test/ops/test_upsample_bilinear2d.py +717 -0
- executorch/backends/arm/test/ops/test_upsample_nearest2d.py +656 -0
- executorch/backends/arm/test/ops/test_var.py +441 -0
- executorch/backends/arm/test/ops/test_view.py +261 -0
- executorch/backends/arm/test/ops/test_where.py +319 -0
- executorch/backends/arm/test/ops/test_while.py +311 -0
- executorch/backends/arm/test/ops/test_zeros.py +158 -0
- executorch/backends/arm/test/passes/test_arm_op_targeted_pass.py +150 -0
- executorch/backends/arm/test/passes/test_arm_pass_manager_insertions.py +288 -0
- executorch/backends/arm/test/passes/test_broadcast_args_pass.py +57 -0
- executorch/backends/arm/test/passes/test_canonicalize_view_copy_permute_pass.py +573 -0
- executorch/backends/arm/test/passes/test_cast_int64_pass.py +81 -0
- executorch/backends/arm/test/passes/test_convert_expand_copy_to_repeat.py +49 -0
- executorch/backends/arm/test/passes/test_convert_int64_const_ops_to_int32.py +527 -0
- executorch/backends/arm/test/passes/test_convert_int64_output_ops_to_int32.py +173 -0
- executorch/backends/arm/test/passes/test_convert_permute_singleton_to_view_pass.py +100 -0
- executorch/backends/arm/test/passes/test_convert_split_to_slice.py +71 -0
- executorch/backends/arm/test/passes/test_convert_to_clamp.py +92 -0
- executorch/backends/arm/test/passes/test_custom_op_rewrite.py +257 -0
- executorch/backends/arm/test/passes/test_decompose_adaptive_avg_pool2d_pass.py +191 -0
- executorch/backends/arm/test/passes/test_decompose_adaptive_max_pool2d_pass.py +80 -0
- executorch/backends/arm/test/passes/test_decompose_avg_pool2d_pass.py +80 -0
- executorch/backends/arm/test/passes/test_decompose_cosine_similarity_pass.py +58 -0
- executorch/backends/arm/test/passes/test_decompose_div_pass.py +66 -0
- executorch/backends/arm/test/passes/test_decompose_dynamic_adaptive_avg_pool2d_pass.py +93 -0
- executorch/backends/arm/test/passes/test_decompose_dynamic_full_pass.py +176 -0
- executorch/backends/arm/test/passes/test_decompose_einsum_pass.py +73 -0
- executorch/backends/arm/test/passes/test_decompose_int_pow_pass.py +107 -0
- executorch/backends/arm/test/passes/test_decompose_layernorm_pass.py +67 -0
- executorch/backends/arm/test/passes/test_decompose_linalg_vector_norm_pass.py +109 -0
- executorch/backends/arm/test/passes/test_decompose_linear_pass.py +54 -0
- executorch/backends/arm/test/passes/test_decompose_meandim_pass.py +133 -0
- executorch/backends/arm/test/passes/test_decompose_quant_nodes.py +44 -0
- executorch/backends/arm/test/passes/test_decompose_select_pass.py +73 -0
- executorch/backends/arm/test/passes/test_decompose_softmax_pass.py +132 -0
- executorch/backends/arm/test/passes/test_decompose_tosa_unsupported_clamp_pass.py +73 -0
- executorch/backends/arm/test/passes/test_decompose_unsupported_bilinear_resize_pass.py +249 -0
- executorch/backends/arm/test/passes/test_decompose_var_pass.py +85 -0
- executorch/backends/arm/test/passes/test_decorate_fp32_to_int32_casting_pass.py +87 -0
- executorch/backends/arm/test/passes/test_deduplicate_get_attr_pass.py +37 -0
- executorch/backends/arm/test/passes/test_dim_maps.py +708 -0
- executorch/backends/arm/test/passes/test_ensure_unique_output_nodes_pass.py +64 -0
- executorch/backends/arm/test/passes/test_fold_qdq_pass.py +51 -0
- executorch/backends/arm/test/passes/test_fold_scalar_mul_into_conv_pass.py +196 -0
- executorch/backends/arm/test/passes/test_fuse_batchnorm_pass.py +192 -0
- executorch/backends/arm/test/passes/test_fuse_consecutive_concat_shapes.py +110 -0
- executorch/backends/arm/test/passes/test_fuse_consecutive_slices_pass.py +110 -0
- executorch/backends/arm/test/passes/test_fuse_constant_ops_pass.py +504 -0
- executorch/backends/arm/test/passes/test_fuse_duplicate_users_pass.py +169 -0
- executorch/backends/arm/test/passes/test_fuse_equal_placeholders_ops_pass.py +170 -0
- executorch/backends/arm/test/passes/test_fuse_identical_input_transforms_pass.py +860 -0
- executorch/backends/arm/test/passes/test_fuse_quantized_activation_pass.py +48 -0
- executorch/backends/arm/test/passes/test_fuse_view_copy.py +82 -0
- executorch/backends/arm/test/passes/test_insert_data_layout_casts_pass.py +140 -0
- executorch/backends/arm/test/passes/test_insert_dynamic_padding_pass.py +124 -0
- executorch/backends/arm/test/passes/test_insert_int32_casts_after_int64_placeholders_pass.py +109 -0
- executorch/backends/arm/test/passes/test_insert_rescale_i32_pass.py +107 -0
- executorch/backends/arm/test/passes/test_insert_table_ops_pass.py +100 -0
- executorch/backends/arm/test/passes/test_int32_cast_embedding_pass.py +46 -0
- executorch/backends/arm/test/passes/test_ioquantization_pass.py +617 -0
- executorch/backends/arm/test/passes/test_permute_view_swap.py +230 -0
- executorch/backends/arm/test/passes/test_promote_bool_operands_pass.py +101 -0
- executorch/backends/arm/test/passes/test_propagate_permutes_views_pass.py +1515 -0
- executorch/backends/arm/test/passes/test_rank_match_after_propagation.py +51 -0
- executorch/backends/arm/test/passes/test_remove_clone_pass.py +43 -0
- executorch/backends/arm/test/passes/test_remove_permutes_around_elementwise_tosa_ops.py +196 -0
- executorch/backends/arm/test/passes/test_replace_inf_values_pass.py +115 -0
- executorch/backends/arm/test/passes/test_rescale_optimization.py +244 -0
- executorch/backends/arm/test/passes/test_rescale_pass.py +95 -0
- executorch/backends/arm/test/passes/test_rewrite_adaptive_avg_pool2d_pass.py +328 -0
- executorch/backends/arm/test/passes/test_rewrite_avg_pool2d_pass.py +122 -0
- executorch/backends/arm/test/passes/test_rewrite_conv_pass.py +476 -0
- executorch/backends/arm/test/passes/test_rewrite_grid_sampler_to_tosa_custom_pass.py +455 -0
- executorch/backends/arm/test/passes/test_rewrite_le_lt_to_ge_gt_pass.py +51 -0
- executorch/backends/arm/test/passes/test_rewrite_max_pool2d_pass.py +198 -0
- executorch/backends/arm/test/passes/test_rewrite_mxfp_conv2d_pass.py +195 -0
- executorch/backends/arm/test/passes/test_rewrite_mxfp_linear_pass.py +177 -0
- executorch/backends/arm/test/passes/test_rewrite_upsample_pass.py +44 -0
- executorch/backends/arm/test/passes/test_size_adjust_input_pass.py +459 -0
- executorch/backends/arm/test/passes/test_symbolic_to_tosa_shape_pass.py +101 -0
- executorch/backends/arm/test/passes/test_symbolic_value_range.py +83 -0
- executorch/backends/arm/test/passes/test_unsqueeze_before_repeat_pass.py +59 -0
- executorch/backends/arm/test/passes/test_view_permute_swap.py +227 -0
- executorch/backends/arm/test/public_api_bc/run_public_api_bc_scenarios.py +104 -0
- executorch/backends/arm/test/public_api_bc/test_ethosu_flow.py +129 -0
- executorch/backends/arm/test/public_api_bc/test_vgf_fp_flow.py +75 -0
- executorch/backends/arm/test/public_api_bc/test_vgf_int_flow.py +113 -0
- executorch/backends/arm/test/quantizer/test_conv_relu_fusing.py +118 -0
- executorch/backends/arm/test/quantizer/test_generic_annotater.py +251 -0
- executorch/backends/arm/test/quantizer/test_partial_quantization.py +226 -0
- executorch/backends/arm/test/quantizer/test_preserve_kwargs.py +55 -0
- executorch/backends/arm/test/quantizer/test_selective_quantization.py +349 -0
- executorch/backends/arm/test/quantizer/test_set_module_name.py +158 -0
- executorch/backends/arm/test/quantizer/test_tosa_quantizer_validate.py +55 -0
- executorch/backends/arm/test/quantizer/test_uint8_io_quantization.py +177 -0
- executorch/backends/arm/test/runner_utils.py +1170 -0
- executorch/backends/arm/test/runtime/_vgf_runtime_test_utils.py +350 -0
- executorch/backends/arm/test/runtime/test_vgf_aliasing_runtime.py +133 -0
- executorch/backends/arm/test/runtime/test_vgf_combinations_runtime.py +465 -0
- executorch/backends/arm/test/runtime/test_vgf_multi_segment_runtime.py +153 -0
- executorch/backends/arm/test/runtime/test_vgf_sampler_image_runtime.py +110 -0
- executorch/backends/arm/test/runtime/test_vgf_tensor_buffer_runtime.py +165 -0
- executorch/backends/arm/test/test_memory_allocator_log.py +170 -0
- executorch/backends/arm/test/test_model.py +368 -0
- executorch/backends/arm/test/tester/__init__.py +6 -0
- executorch/backends/arm/test/tester/analyze_output_utils.py +473 -0
- executorch/backends/arm/test/tester/arm_tester.py +1408 -0
- executorch/backends/arm/test/tester/quantize.py +63 -0
- executorch/backends/arm/test/tester/serialize.py +96 -0
- executorch/backends/arm/test/tester/test_pipeline.py +1369 -0
- executorch/backends/arm/tosa/__init__.py +16 -0
- executorch/backends/arm/tosa/backend.py +491 -0
- executorch/backends/arm/tosa/cast_support.py +175 -0
- executorch/backends/arm/tosa/compile_spec.py +44 -0
- executorch/backends/arm/tosa/dialect/__init__.py +33 -0
- executorch/backends/arm/tosa/dialect/lib.py +83 -0
- executorch/backends/arm/tosa/dialect/ops/_common.py +46 -0
- executorch/backends/arm/tosa/dialect/ops/activation.py +138 -0
- executorch/backends/arm/tosa/dialect/ops/argmax.py +78 -0
- executorch/backends/arm/tosa/dialect/ops/avg_pool2d.py +173 -0
- executorch/backends/arm/tosa/dialect/ops/avg_pool2d_adaptive.py +82 -0
- executorch/backends/arm/tosa/dialect/ops/binary_elementwise.py +336 -0
- executorch/backends/arm/tosa/dialect/ops/conv2d.py +139 -0
- executorch/backends/arm/tosa/dialect/ops/conv2d_block_scaled.py +213 -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 +274 -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 +128 -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 +116 -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/transpose_conv2d.py +58 -0
- executorch/backends/arm/tosa/dialect/ops/unary_elementwise.py +224 -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 +335 -0
- executorch/backends/arm/tosa/partitioner.py +772 -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 +254 -0
- executorch/backends/arm/vgf/__init__.py +11 -0
- executorch/backends/arm/vgf/_passes/__init__.py +11 -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 +458 -0
- executorch/backends/arm/vgf/backend.py +393 -0
- executorch/backends/arm/vgf/check_env.py +678 -0
- executorch/backends/arm/vgf/compile_spec.py +108 -0
- executorch/backends/arm/vgf/model_converter.py +229 -0
- executorch/backends/arm/vgf/partitioner.py +44 -0
- executorch/backends/arm/vgf/shaders/__init__.py +4 -0
- executorch/backends/arm/vgf/shaders/grid_sampler.glsl +41 -0
- executorch/backends/arm/vgf/shaders/grid_sampler.py +340 -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 +514 -0
- executorch/backends/cadence/aot/compiler_funcs.py +739 -0
- executorch/backends/cadence/aot/compiler_utils.py +271 -0
- executorch/backends/cadence/aot/decompose_ops.py +120 -0
- executorch/backends/cadence/aot/export_example.py +123 -0
- executorch/backends/cadence/aot/functions.yaml +505 -0
- executorch/backends/cadence/aot/functions_fusion_g3.yaml +191 -0
- executorch/backends/cadence/aot/functions_hifi.yaml +590 -0
- executorch/backends/cadence/aot/functions_vision.yaml +275 -0
- executorch/backends/cadence/aot/fuse_ops.py +1111 -0
- executorch/backends/cadence/aot/graph_builder.py +13 -0
- executorch/backends/cadence/aot/memory_constraints.py +766 -0
- executorch/backends/cadence/aot/memory_planning.py +472 -0
- executorch/backends/cadence/aot/memory_planning_algo.py +341 -0
- executorch/backends/cadence/aot/ops_registrations.py +3349 -0
- executorch/backends/cadence/aot/pass_utils.py +231 -0
- executorch/backends/cadence/aot/passes.py +140 -0
- executorch/backends/cadence/aot/program_builder.py +9 -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 +207 -0
- executorch/backends/cadence/aot/quantizer/patterns.py +1570 -0
- executorch/backends/cadence/aot/quantizer/quantizer.py +490 -0
- executorch/backends/cadence/aot/quantizer/utils.py +286 -0
- executorch/backends/cadence/aot/ref_implementations.py +2832 -0
- executorch/backends/cadence/aot/remove_ops.py +986 -0
- executorch/backends/cadence/aot/reorder_ops.py +1279 -0
- executorch/backends/cadence/aot/replace_ops.py +2646 -0
- executorch/backends/cadence/aot/simplify_ops.py +221 -0
- executorch/backends/cadence/aot/tests/test_decompose_ops_passes.py +80 -0
- executorch/backends/cadence/aot/tests/test_fusion_ops_passes.py +2030 -0
- executorch/backends/cadence/aot/tests/test_graph_builder.py +101 -0
- executorch/backends/cadence/aot/tests/test_idma_ops.py +31 -0
- executorch/backends/cadence/aot/tests/test_memory_passes.py +1367 -0
- executorch/backends/cadence/aot/tests/test_pass_filter.py +170 -0
- executorch/backends/cadence/aot/tests/test_pass_utils.py +85 -0
- executorch/backends/cadence/aot/tests/test_program_builder.py +222 -0
- executorch/backends/cadence/aot/tests/test_quantizer_ops.py +975 -0
- executorch/backends/cadence/aot/tests/test_ref_implementations.py +3633 -0
- executorch/backends/cadence/aot/tests/test_remove_bn_tracking_pass.py +209 -0
- executorch/backends/cadence/aot/tests/test_remove_ops_passes.py +1390 -0
- executorch/backends/cadence/aot/tests/test_reorder_ops_passes.py +1554 -0
- executorch/backends/cadence/aot/tests/test_replace_ops_passes.py +3660 -0
- executorch/backends/cadence/aot/tests/test_simplify_ops_passes.py +160 -0
- executorch/backends/cadence/aot/tests/test_to_out_var_pass.py +98 -0
- executorch/backends/cadence/aot/tests/test_type_dispatch_passes.py +424 -0
- executorch/backends/cadence/aot/to_out_var_pass.py +24 -0
- executorch/backends/cadence/aot/type_dispatch.py +184 -0
- executorch/backends/cadence/aot/typing_stubs.py +22 -0
- executorch/backends/cadence/aot/utils.py +372 -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/calibrator/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/calibrator/runner.py +209 -0
- executorch/backends/cadence/utils/FACTO/examples/config_example.py +96 -0
- executorch/backends/cadence/utils/FACTO/examples/example.py +59 -0
- executorch/backends/cadence/utils/FACTO/examples/minimal_example.py +21 -0
- executorch/backends/cadence/utils/FACTO/examples/minimal_modelgen_example.py +23 -0
- executorch/backends/cadence/utils/FACTO/examples/random_seed.py +35 -0
- executorch/backends/cadence/utils/FACTO/facto/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/engine.py +129 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/gen.py +245 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/engine.py +303 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/gen.py +320 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/type.py +148 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/engine.py +58 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/model.py +133 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/solve.py +125 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/specs/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/specs/model.py +149 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/utils/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/utils/config.py +44 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/utils/random_manager.py +36 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/constants.py +9 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/gen.py +283 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/solve.py +154 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/space.py +450 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/type.py +105 -0
- executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/utils.py +30 -0
- executorch/backends/cadence/utils/FACTO/facto/modelgen/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/modelgen/gen.py +251 -0
- executorch/backends/cadence/utils/FACTO/facto/specdb/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/specdb/db.py +5973 -0
- executorch/backends/cadence/utils/FACTO/facto/specdb/default.py +36 -0
- executorch/backends/cadence/utils/FACTO/facto/specdb/function.py +585 -0
- executorch/backends/cadence/utils/FACTO/facto/utils/__init__.py +0 -0
- executorch/backends/cadence/utils/FACTO/facto/utils/dtypes.py +24 -0
- executorch/backends/cadence/utils/FACTO/facto/utils/ops.py +48 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_argtuple_engine.py +53 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_argtuple_generator.py +71 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_attributes.py +78 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_generator.py +98 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_types.py +28 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_attribute_engine.py +87 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_attribute_solver.py +98 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_config.py +269 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_constraints.py +27 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_meta_arg_engine.py +85 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_specs.py +48 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_structural_engine.py +32 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_generation.py +80 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_solving.py +193 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_space.py +231 -0
- executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_types.py +71 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/__init__.py +1 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/base_model_test.py +78 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/base_test.py +82 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/test_executorch_portable.py +340 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/test_model_cpu.py +70 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/test_specdb_cpu.py +67 -0
- executorch/backends/cadence/utils/FACTO/test/specdb/test_specdb_mps.py +111 -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/library/__init__.py +4 -0
- executorch/backends/cortex_m/library/_cmsis_nn/cmsis_nn.cp314-win_amd64.pyd +0 -0
- executorch/backends/cortex_m/library/cmsis_nn.py +281 -0
- executorch/backends/cortex_m/ops/operators.py +1438 -0
- executorch/backends/cortex_m/ops/operators.yaml +108 -0
- executorch/backends/cortex_m/passes/__init__.py +15 -0
- executorch/backends/cortex_m/passes/activation_fusion_pass.py +200 -0
- executorch/backends/cortex_m/passes/aten_to_cortex_m_pass.py +1156 -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 +122 -0
- executorch/backends/cortex_m/passes/decompose_hardswish_pass.py +128 -0
- executorch/backends/cortex_m/passes/decompose_mean_pass.py +45 -0
- executorch/backends/cortex_m/passes/matmul_to_bmm_pass.py +81 -0
- executorch/backends/cortex_m/passes/passes_utils.py +350 -0
- executorch/backends/cortex_m/passes/quantized_clamp_activation_pass.py +129 -0
- executorch/backends/cortex_m/passes/replace_quant_nodes_pass.py +76 -0
- executorch/backends/cortex_m/passes/scratch_buffer_sizes.py +290 -0
- executorch/backends/cortex_m/quantizer/__init__.py +19 -0
- executorch/backends/cortex_m/quantizer/node_finders.py +153 -0
- executorch/backends/cortex_m/quantizer/pattern_checkers.py +348 -0
- executorch/backends/cortex_m/quantizer/pattern_matcher.py +214 -0
- executorch/backends/cortex_m/quantizer/quantization_configs.py +205 -0
- executorch/backends/cortex_m/quantizer/quantizer.py +89 -0
- executorch/backends/cortex_m/quantizer/quantizer_support.py +172 -0
- executorch/backends/cortex_m/quantizer_reporter.py +443 -0
- executorch/backends/cortex_m/target_config.py +117 -0
- executorch/backends/cortex_m/test/conftest.py +97 -0
- executorch/backends/cortex_m/test/misc/test_cmsis_pybind.py +132 -0
- executorch/backends/cortex_m/test/misc/test_node_finders.py +186 -0
- executorch/backends/cortex_m/test/misc/test_pattern_matcher.py +254 -0
- executorch/backends/cortex_m/test/misc/test_portable_int8.py +784 -0
- executorch/backends/cortex_m/test/misc/test_quantization.py +411 -0
- executorch/backends/cortex_m/test/misc/test_quantizer_reporter.py +245 -0
- executorch/backends/cortex_m/test/misc/test_target_config.py +117 -0
- executorch/backends/cortex_m/test/models/__init__.py +4 -0
- executorch/backends/cortex_m/test/models/test_deep_autoencoder.py +44 -0
- executorch/backends/cortex_m/test/models/test_ds_cnn.py +57 -0
- executorch/backends/cortex_m/test/models/test_mobilenet_v1_025.py +54 -0
- executorch/backends/cortex_m/test/models/test_mobilenet_v2.py +91 -0
- executorch/backends/cortex_m/test/models/test_mobilenet_v3.py +102 -0
- executorch/backends/cortex_m/test/models/test_nn_functional.py +119 -0
- executorch/backends/cortex_m/test/models/test_nn_modules.py +197 -0
- executorch/backends/cortex_m/test/models/test_resnet8.py +55 -0
- executorch/backends/cortex_m/test/models/test_silero_vad.py +104 -0
- executorch/backends/cortex_m/test/models/test_torch_functions.py +154 -0
- executorch/backends/cortex_m/test/models/test_wav2letter.py +34 -0
- executorch/backends/cortex_m/test/models/test_yolo11.py +45 -0
- executorch/backends/cortex_m/test/ops/__init__.py +4 -0
- executorch/backends/cortex_m/test/ops/test_activation.py +716 -0
- executorch/backends/cortex_m/test/ops/test_activation_quant.py +156 -0
- executorch/backends/cortex_m/test/ops/test_add.py +255 -0
- executorch/backends/cortex_m/test/ops/test_avg_pool2d.py +145 -0
- executorch/backends/cortex_m/test/ops/test_batch_matmul.py +192 -0
- executorch/backends/cortex_m/test/ops/test_conv.py +345 -0
- executorch/backends/cortex_m/test/ops/test_conv_transpose.py +331 -0
- executorch/backends/cortex_m/test/ops/test_linear.py +295 -0
- executorch/backends/cortex_m/test/ops/test_lstm.py +102 -0
- executorch/backends/cortex_m/test/ops/test_max_pool2d.py +146 -0
- executorch/backends/cortex_m/test/ops/test_maximum.py +87 -0
- executorch/backends/cortex_m/test/ops/test_minimum.py +108 -0
- executorch/backends/cortex_m/test/ops/test_mul.py +160 -0
- executorch/backends/cortex_m/test/ops/test_pad.py +100 -0
- executorch/backends/cortex_m/test/ops/test_softmax.py +88 -0
- executorch/backends/cortex_m/test/ops/test_transpose.py +106 -0
- executorch/backends/cortex_m/test/test_helpers_passes_utils.py +103 -0
- executorch/backends/cortex_m/test/test_replace_quant_nodes.py +134 -0
- executorch/backends/cortex_m/test/tester.py +181 -0
- executorch/backends/cuda/__init__.py +5 -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 +684 -0
- executorch/backends/cuda/cuda_partitioner.py +53 -0
- executorch/backends/cuda/dp4a_planar_int5_tensor.py +323 -0
- executorch/backends/cuda/dp4a_planar_int6_tensor.py +307 -0
- executorch/backends/cuda/passes/__init__.py +0 -0
- executorch/backends/cuda/passes/move_cond_predicate_to_cpu.py +90 -0
- executorch/backends/cuda/passes/replace_int64_floordiv.py +152 -0
- executorch/backends/cuda/passes/tests/__init__.py +0 -0
- executorch/backends/cuda/passes/tests/test_move_cond_predicate_to_cpu.py +553 -0
- executorch/backends/cuda/passes/tests/test_replace_int64_floordiv.py +216 -0
- executorch/backends/cuda/quantize_op_dispatch/__init__.py +31 -0
- executorch/backends/cuda/quantize_op_dispatch/_library.py +17 -0
- executorch/backends/cuda/quantize_op_dispatch/int4_dispatch.py +181 -0
- executorch/backends/cuda/quantize_op_dispatch/int5_dispatch.py +168 -0
- executorch/backends/cuda/quantize_op_dispatch/int6_dispatch.py +128 -0
- executorch/backends/cuda/quantize_op_dispatch/int8_dispatch.py +132 -0
- executorch/backends/cuda/runtime/shims/tests/gen_plain_mm_test_vectors.py +460 -0
- executorch/backends/cuda/tests/__init__.py +5 -0
- executorch/backends/cuda/tests/test_chunk_gated_delta_rule.py +328 -0
- executorch/backends/cuda/tests/test_cuda_export.py +509 -0
- executorch/backends/cuda/tests/test_cuda_partitioner.py +458 -0
- executorch/backends/cuda/tests/test_fused_deltanet_decode.py +357 -0
- executorch/backends/cuda/tests/test_fused_moe.py +812 -0
- executorch/backends/cuda/tests/test_int4_dispatch.py +365 -0
- executorch/backends/cuda/tests/test_int4_matmul.py +287 -0
- executorch/backends/cuda/tests/test_int5_dispatch.py +323 -0
- executorch/backends/cuda/tests/test_int6_dispatch.py +321 -0
- executorch/backends/cuda/tests/test_output_stride_rearrange.py +177 -0
- executorch/backends/cuda/tests/test_sdpa_splitk_replacement.py +179 -0
- executorch/backends/cuda/tests/test_sort_shim.py +128 -0
- executorch/backends/cuda/tests/test_topk.py +308 -0
- executorch/backends/cuda/tests/test_tq4_sdpa.py +1232 -0
- executorch/backends/cuda/tests/test_triton_sdpa.py +522 -0
- executorch/backends/cuda/tests/test_triton_sdpa_nan.py +253 -0
- executorch/backends/cuda/tests/test_triton_sdpa_splitk.py +310 -0
- executorch/backends/cuda/triton/__init__.py +17 -0
- executorch/backends/cuda/triton/kernels/__init__.py +58 -0
- executorch/backends/cuda/triton/kernels/chunk_gated_delta_rule.py +269 -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 +529 -0
- executorch/backends/cuda/triton/kernels/sdpa.py +1551 -0
- executorch/backends/cuda/triton/kernels/topk.py +220 -0
- executorch/backends/cuda/triton/kernels/tq4_sdpa.py +1216 -0
- executorch/backends/cuda/triton/replacement_pass.py +185 -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/builder/__init__.py +16 -0
- executorch/backends/mlx/builder/op_helpers.py +810 -0
- executorch/backends/mlx/builder/op_registry.py +151 -0
- executorch/backends/mlx/builder/pattern_matcher.py +64 -0
- executorch/backends/mlx/builder/program_builder.py +1135 -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 +608 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/__init__.py +18 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/patterns.py +177 -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 +60 -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 +88 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q4k/repack_mlx.py +60 -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 +60 -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 +88 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q5k/repack_mlx.py +60 -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 +64 -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 +89 -0
- executorch/backends/mlx/custom_kernel_ops/gguf/q6k/repack_mlx.py +87 -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 +987 -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 +467 -0
- executorch/backends/mlx/examples/__init__.py +6 -0
- executorch/backends/mlx/examples/llm/__init__.py +6 -0
- executorch/backends/mlx/examples/llm/export_llm_hf.py +457 -0
- executorch/backends/mlx/examples/llm/run_llm_hf.py +249 -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 +617 -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 +556 -0
- executorch/backends/mlx/llm/et_attention.py +252 -0
- executorch/backends/mlx/llm/hf_attention.py +258 -0
- executorch/backends/mlx/llm/quantization.py +57 -0
- executorch/backends/mlx/llm/sampling.py +44 -0
- executorch/backends/mlx/llm/source_transformation.py +318 -0
- executorch/backends/mlx/llm/switch.py +330 -0
- executorch/backends/mlx/llm/turboquant_cache.py +244 -0
- executorch/backends/mlx/ops.py +4808 -0
- executorch/backends/mlx/partitioner.py +298 -0
- executorch/backends/mlx/passes.py +570 -0
- executorch/backends/mlx/pattern_utils.py +360 -0
- executorch/backends/mlx/patterns.py +1339 -0
- executorch/backends/mlx/preprocess.py +168 -0
- executorch/backends/mlx/pte_inspector.py +902 -0
- executorch/backends/mlx/serialization/__init__.py +32 -0
- executorch/backends/mlx/serialization/generate.py +1566 -0
- executorch/backends/mlx/serialization/mlx_graph_serialize.py +417 -0
- executorch/backends/mlx/serialization/schema.fbs +1273 -0
- executorch/backends/mlx/test/__init__.py +5 -0
- executorch/backends/mlx/test/export_multi_thread_test_model.py +124 -0
- executorch/backends/mlx/test/run_all_tests.py +496 -0
- executorch/backends/mlx/test/test_ops.py +7929 -0
- executorch/backends/mlx/test/test_partitioner.py +45 -0
- executorch/backends/mlx/test/test_passes.py +828 -0
- executorch/backends/mlx/test/test_pattern_utils.py +592 -0
- executorch/backends/mlx/test/test_quant_regroup.py +70 -0
- executorch/backends/mlx/test/test_sample.py +295 -0
- executorch/backends/mlx/test/test_serialization_dedup.py +84 -0
- executorch/backends/mlx/test/test_slot_recycling.py +198 -0
- executorch/backends/mlx/test/test_utils.py +1162 -0
- executorch/backends/mlx/test/tester.py +78 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/numpy/single_ops.py +39 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/numpy/time_utils.py +20 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/batch_matmul_bench.py +62 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/blas/bench_gemm.py +191 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/blas/bench_gemv.py +220 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/block_masked_mm_bench.py +193 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/comparative/bench_mlx.py +519 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/comparative/bench_torch.py +482 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/comparative/compare.py +284 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/compile_bench.py +107 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv1d_bench.py +123 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv2d_bench_cpu.py +127 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv2d_train_bench_cpu.py +143 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv2d_transpose_bench_cpu.py +129 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv3d_bench.py +152 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv3d_bench_cpu.py +110 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv3d_train_bench_cpu.py +143 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv3d_transpose_bench_cpu.py +116 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv_bench.py +135 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv_transpose_bench.py +135 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/conv_unaligned_bench.py +107 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/distributed_bench.py +66 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/einsum_bench.py +84 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/fft_bench.py +118 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/gather_bench.py +52 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/gather_mm_bench.py +74 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/gather_qmm_bench.py +84 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/hadamard_bench.py +70 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/large_gemm_bench.py +119 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/layer_norm_bench.py +82 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/masked_scatter.py +236 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/rms_norm_bench.py +63 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/rope_bench.py +35 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/scatter_bench.py +96 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/sdpa_bench.py +229 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/sdpa_vector_bench.py +95 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/segmented_mm_bench.py +209 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/single_ops.py +132 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/slice_update_bench.py +109 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/synchronize_bench.py +55 -0
- executorch/backends/mlx/third-party/mlx/benchmarks/python/time_utils.py +38 -0
- executorch/backends/mlx/third-party/mlx/docs/src/conf.py +99 -0
- executorch/backends/mlx/third-party/mlx/examples/export/eval_mlp.py +52 -0
- executorch/backends/mlx/third-party/mlx/examples/export/train_mlp.py +76 -0
- executorch/backends/mlx/third-party/mlx/examples/extensions/mlx_sample_extensions/__init__.py +5 -0
- executorch/backends/mlx/third-party/mlx/examples/extensions/setup.py +18 -0
- executorch/backends/mlx/third-party/mlx/examples/extensions/test.py +12 -0
- executorch/backends/mlx/third-party/mlx/examples/python/linear_regression.py +46 -0
- executorch/backends/mlx/third-party/mlx/examples/python/logistic_regression.py +49 -0
- executorch/backends/mlx/third-party/mlx/examples/python/qqmm.py +117 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/__main__.py +27 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/_distributed_utils/common.py +135 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/_distributed_utils/config.py +639 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/_distributed_utils/launch.py +562 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/_reprlib_fix.py +16 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/extension.py +88 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/__init__.py +9 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/init.py +451 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/__init__.py +105 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/activations.py +667 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/base.py +689 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/containers.py +24 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/convolution.py +235 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/convolution_transpose.py +245 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/distributed.py +619 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/dropout.py +137 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/embedding.py +53 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/linear.py +180 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/normalization.py +381 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/pooling.py +398 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/positional_encoding.py +174 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/quantized.py +426 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/recurrent.py +291 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/transformer.py +354 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/layers/upsample.py +277 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/losses.py +614 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/nn/utils.py +321 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/optimizers/__init__.py +4 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/optimizers/optimizers.py +974 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/optimizers/schedulers.py +158 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/py.typed +1 -0
- executorch/backends/mlx/third-party/mlx/python/mlx/utils.py +326 -0
- executorch/backends/mlx/third-party/mlx/python/tests/__main__.py +5 -0
- executorch/backends/mlx/third-party/mlx/python/tests/mlx_distributed_tests.py +324 -0
- executorch/backends/mlx/third-party/mlx/python/tests/mlx_tests.py +93 -0
- executorch/backends/mlx/third-party/mlx/python/tests/mpi_test_distributed.py +142 -0
- executorch/backends/mlx/third-party/mlx/python/tests/nccl_test_distributed.py +346 -0
- executorch/backends/mlx/third-party/mlx/python/tests/ring_test_distributed.py +130 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_array.py +2743 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_autograd.py +1421 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_bf16.py +228 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_blas.py +1432 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_compile.py +1506 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_constants.py +41 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_conv.py +1214 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_conv_transpose.py +810 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_device.py +150 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_double.py +306 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_einsum.py +363 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_eval.py +200 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_export_import.py +709 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_fast.py +1122 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_fast_sdpa.py +687 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_fft.py +413 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_graph.py +37 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_init.py +158 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_linalg.py +896 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_load.py +529 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_losses.py +476 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_memory.py +77 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_nn.py +2198 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_ops.py +3520 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_optimizers.py +615 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_quantized.py +1388 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_random.py +392 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_reduce.py +223 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_threads.py +112 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_tree.py +126 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_upsample.py +100 -0
- executorch/backends/mlx/third-party/mlx/python/tests/test_vmap.py +949 -0
- executorch/backends/mlx/third-party/mlx/setup.py +336 -0
- executorch/backends/nxp/__init__.py +0 -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/decompose_split_to_slices_pass.py +196 -0
- executorch/backends/nxp/aten_passes/fuse_batch_norm_with_conv_pass.py +146 -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 +204 -0
- executorch/backends/nxp/aten_passes/move_activation_before_concat.py +102 -0
- executorch/backends/nxp/aten_passes/neutron_aten_pass_manager.py +82 -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 +11 -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 +515 -0
- executorch/backends/nxp/backend/edge_program_converter.py +360 -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 +535 -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 +162 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/abs_converter.py +52 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/adaptive_avg_pool_2d_converter.py +107 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/add_tensor_converter.py +66 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/addmm_converter.py +140 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/amax_converter.py +81 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/amin_converter.py +81 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/avg_pool_2d_converter.py +137 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/bmm_converter.py +101 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/cat_converter.py +122 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/clamp_converter.py +250 -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 +162 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/convolution_converter.py +542 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/exp_converter.py +59 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/getitem_converter.py +56 -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 +63 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/log_converter.py +59 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/max_pool2d_with_indices_converter.py +178 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/maximum_converter.py +68 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mean_dim_converter.py +107 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/minimum_converter.py +68 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mm_converter.py +94 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mul_tensor_converter.py +63 -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/permute_copy_converter.py +434 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/prelu_converter.py +66 -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 +66 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sigmoid_converter.py +62 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/slice_tensor_converter.py +115 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/softmax_converter.py +150 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sub_tensor_converter.py +71 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sum_dim_int_list_converter.py +83 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/tanh_converter.py +60 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/upsample_bilinear2d_converter.py +152 -0
- executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/upsample_nearest2d_converter.py +136 -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 +167 -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_converter_manager.py +151 -0
- executorch/backends/nxp/backend/neutron_map.py +459 -0
- executorch/backends/nxp/backend/neutron_operator_support.py +57 -0
- executorch/backends/nxp/backend/neutron_target_spec.py +141 -0
- executorch/backends/nxp/backend/node_format_inference.py +396 -0
- executorch/backends/nxp/edge_passes/convert_reshaping_nodes_to_view.py +102 -0
- executorch/backends/nxp/edge_passes/fold_redundant_qdq_pass.py +36 -0
- executorch/backends/nxp/edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py +301 -0
- executorch/backends/nxp/edge_passes/neutron_edge_pass.py +55 -0
- executorch/backends/nxp/edge_passes/neutron_edge_pass_manager.py +37 -0
- executorch/backends/nxp/edge_passes/remove_additional_quantize_dequantize_nodes_pass.py +111 -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 +79 -0
- executorch/backends/nxp/neutron_node_extraction.py +152 -0
- executorch/backends/nxp/neutron_partitioner.py +555 -0
- executorch/backends/nxp/nxp_backend.py +476 -0
- executorch/backends/nxp/quantizer/neutron_quantizer.py +398 -0
- executorch/backends/nxp/quantizer/patterns.py +1395 -0
- executorch/backends/nxp/quantizer/utils.py +257 -0
- executorch/backends/nxp/tests/__init__.py +0 -0
- executorch/backends/nxp/tests/calibration_dataset.py +30 -0
- executorch/backends/nxp/tests/config.py +56 -0
- executorch/backends/nxp/tests/config_importer.py +17 -0
- executorch/backends/nxp/tests/conftest.py +38 -0
- executorch/backends/nxp/tests/dataset_creator.py +417 -0
- executorch/backends/nxp/tests/executorch_pipeline.py +323 -0
- executorch/backends/nxp/tests/executors.py +433 -0
- executorch/backends/nxp/tests/generic_tests/__init__.py +0 -0
- executorch/backends/nxp/tests/generic_tests/conftest.py +35 -0
- executorch/backends/nxp/tests/generic_tests/test_aot_example.py +172 -0
- executorch/backends/nxp/tests/generic_tests/test_batch_norm_fusion.py +221 -0
- executorch/backends/nxp/tests/generic_tests/test_cifarnet.py +104 -0
- executorch/backends/nxp/tests/generic_tests/test_context_sensitive_delegation.py +180 -0
- executorch/backends/nxp/tests/generic_tests/test_convert_div_to_mul.py +236 -0
- executorch/backends/nxp/tests/generic_tests/test_debug_results.py +155 -0
- executorch/backends/nxp/tests/generic_tests/test_decompose_split_to_slices.py +287 -0
- executorch/backends/nxp/tests/generic_tests/test_gru_splitting.py +267 -0
- executorch/backends/nxp/tests/generic_tests/test_integration.py +54 -0
- executorch/backends/nxp/tests/generic_tests/test_kernel_selection.py +80 -0
- executorch/backends/nxp/tests/generic_tests/test_linear_and_add_fusion.py +653 -0
- executorch/backends/nxp/tests/generic_tests/test_move_activation_before_concatenation.py +901 -0
- executorch/backends/nxp/tests/generic_tests/test_neutron_backend.py +63 -0
- executorch/backends/nxp/tests/generic_tests/test_neutron_backend_executor.py +176 -0
- executorch/backends/nxp/tests/generic_tests/test_neutron_converter_manager.py +55 -0
- executorch/backends/nxp/tests/generic_tests/test_node_format_inference.py +121 -0
- executorch/backends/nxp/tests/generic_tests/test_operator_selector.py +24 -0
- executorch/backends/nxp/tests/generic_tests/test_per_channel_conversion.py +187 -0
- executorch/backends/nxp/tests/generic_tests/test_profiling.py +466 -0
- executorch/backends/nxp/tests/generic_tests/test_qdq_clustering_conv.py +31 -0
- executorch/backends/nxp/tests/generic_tests/test_quantized_input_data.py +115 -0
- executorch/backends/nxp/tests/generic_tests/test_quantizer.py +719 -0
- executorch/backends/nxp/tests/generic_tests/test_removing_dead_code.py +65 -0
- executorch/backends/nxp/tests/generic_tests/test_removing_nodes_with_known_outputs.py +116 -0
- executorch/backends/nxp/tests/generic_tests/test_split_group_convolution.py +307 -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/converter/node_converter/test_abs_converter.py +102 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_adaptive_avg_pool2d_converter.py +142 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_add_tensor_converter.py +259 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_addmm_converter.py +190 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_amax_converter.py +432 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_amin_converter.py +432 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_avg_pool2d_converter.py +127 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_bmm_converter.py +118 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_cat_converter.py +163 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_clamp_converter.py +224 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_clone_converter.py +347 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_constant_pad_nd_converter.py +129 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_conv_converter.py +1394 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_exp_converter.py +72 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_hardtanh_converter.py +274 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_leaky_relu_converter.py +92 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_log_converter.py +76 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_max_pool_2d_converter.py +174 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_maximum_converter.py +231 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_mean_dim_converter.py +410 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_minimum_converter.py +231 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_mm_converter.py +115 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_mul_tensor_converter.py +224 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_neg_converter.py +116 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_permute_copy_converter.py +231 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_prelu_converter.py +238 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_relu_converter.py +190 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_sigmoid_converter.py +76 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_slice_tensor_converter.py +395 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_softmax_converter.py +233 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_sub_tensor_converter.py +254 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_sum_dim_int_list_converter.py +436 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_tanh_converter.py +100 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_upsample_bilinear2d.py +272 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_upsample_nearest2d.py +162 -0
- executorch/backends/nxp/tests/ir/converter/node_converter/test_view_copy_converter.py +420 -0
- executorch/backends/nxp/tests/ir/edge_passes/__init__.py +0 -0
- executorch/backends/nxp/tests/ir/edge_passes/test_convert_reshaping_nodes_to_view.py +126 -0
- executorch/backends/nxp/tests/ir/edge_passes/test_edge_passes.py +402 -0
- executorch/backends/nxp/tests/ir/edge_passes/test_linear_bn_fusing.py +316 -0
- executorch/backends/nxp/tests/ir/edge_passes/test_remove_io_quant_ops_pass.py +128 -0
- executorch/backends/nxp/tests/ir/test_model_builder.py +69 -0
- executorch/backends/nxp/tests/model_output_comparator.py +391 -0
- executorch/backends/nxp/tests/models.py +1083 -0
- executorch/backends/nxp/tests/nsys_testing.py +828 -0
- executorch/backends/nxp/tests/ops_aliases.py +66 -0
- executorch/backends/nxp/tests/outputs_dir.py +10 -0
- executorch/backends/nxp/tests/outputs_dir_importer.py +17 -0
- executorch/backends/nxp/tests/test_convert_1d_conv_to_2d.py +528 -0
- executorch/backends/nxp/tests/test_fold_redundant_qdq.py +86 -0
- executorch/backends/nxp/tests/test_fuse_batch_norm_single_user.py +112 -0
- executorch/backends/nxp/tests/use_qat.py +21 -0
- executorch/backends/nxp/tests/utils.py +66 -0
- executorch/backends/openvino/__init__.py +5 -0
- executorch/backends/openvino/_passes/__init__.py +9 -0
- executorch/backends/openvino/_passes/decompose_floor_divide_pass.py +106 -0
- executorch/backends/openvino/partitioner.py +238 -0
- executorch/backends/openvino/preprocess.py +62 -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/models/test_classification.py +38 -0
- executorch/backends/openvino/tests/ops/base_openvino_op_test.py +86 -0
- executorch/backends/openvino/tests/ops/test_add.py +22 -0
- executorch/backends/openvino/tests/ops/test_addmm.py +28 -0
- executorch/backends/openvino/tests/ops/test_arange.py +23 -0
- executorch/backends/openvino/tests/ops/test_batch_norm.py +61 -0
- executorch/backends/openvino/tests/ops/test_convolution.py +296 -0
- executorch/backends/openvino/tests/ops/test_mean.py +90 -0
- executorch/backends/openvino/tests/ops/test_permute.py +33 -0
- executorch/backends/openvino/tests/ops/test_pooling.py +91 -0
- executorch/backends/openvino/tests/ops/test_unary_ops.py +37 -0
- executorch/backends/openvino/tests/ops/test_view.py +35 -0
- executorch/backends/openvino/tests/quantizer/synthetic_test_models.py +22 -0
- executorch/backends/openvino/tests/quantizer/test_llm_compression.py +249 -0
- executorch/backends/openvino/tests/test_runner.py +73 -0
- executorch/backends/qualcomm/__init__.py +41 -0
- executorch/backends/qualcomm/_passes/__init__.py +135 -0
- executorch/backends/qualcomm/_passes/annotate_avg_pool1d.py +63 -0
- executorch/backends/qualcomm/_passes/annotate_quant_attrs.py +145 -0
- executorch/backends/qualcomm/_passes/annotate_stack.py +44 -0
- executorch/backends/qualcomm/_passes/annotate_unbind.py +42 -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 +49 -0
- executorch/backends/qualcomm/_passes/backends/htp/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/backends/htp/qnn_htp_pass_manager.py +49 -0
- executorch/backends/qualcomm/_passes/backends/lpai/__init__.py +11 -0
- executorch/backends/qualcomm/_passes/backends/lpai/qnn_lpai_pass_manager.py +95 -0
- executorch/backends/qualcomm/_passes/build_quant_io.py +53 -0
- executorch/backends/qualcomm/_passes/canonicalize_conv.py +216 -0
- executorch/backends/qualcomm/_passes/convert_bmm_to_matmul.py +83 -0
- executorch/backends/qualcomm/_passes/convert_linear_to_conv2d.py +232 -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 +64 -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 +74 -0
- executorch/backends/qualcomm/_passes/decompose_col_im.py +139 -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_expm1.py +46 -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 +133 -0
- executorch/backends/qualcomm/_passes/decompose_minmaxdim.py +109 -0
- executorch/backends/qualcomm/_passes/decompose_pad.py +57 -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 +177 -0
- executorch/backends/qualcomm/_passes/decompose_wrap_with_autocast.py +79 -0
- executorch/backends/qualcomm/_passes/expand_broadcast_tensor_shape.py +66 -0
- executorch/backends/qualcomm/_passes/fixed_linear_keep_dim.py +94 -0
- executorch/backends/qualcomm/_passes/fold_qdq.py +83 -0
- executorch/backends/qualcomm/_passes/fuse_consecutive_cast.py +115 -0
- executorch/backends/qualcomm/_passes/fuse_consecutive_transpose.py +108 -0
- executorch/backends/qualcomm/_passes/i64_to_i32.py +184 -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 +360 -0
- executorch/backends/qualcomm/_passes/lift_constant_scalar_operands.py +196 -0
- executorch/backends/qualcomm/_passes/lpai_partition_fallback_support.py +326 -0
- executorch/backends/qualcomm/_passes/qnn_pass_manager.py +522 -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 +155 -0
- executorch/backends/qualcomm/_passes/remove_0d_tensor.py +36 -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 +237 -0
- executorch/backends/qualcomm/_passes/tag_quant_io.py +45 -0
- executorch/backends/qualcomm/_passes/utils.py +371 -0
- executorch/backends/qualcomm/builders/__init__.py +235 -0
- executorch/backends/qualcomm/builders/node_visitor.py +572 -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 +155 -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 +107 -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_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 +103 -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_space_to_depth.py +78 -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_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 +704 -0
- executorch/backends/qualcomm/builders/utils.py +162 -0
- executorch/backends/qualcomm/custom_op/annotator.py +137 -0
- executorch/backends/qualcomm/custom_op/interface.py +112 -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 +435 -0
- executorch/backends/qualcomm/export_utils.py +969 -0
- executorch/backends/qualcomm/genai_pipeline/__init__.py +49 -0
- executorch/backends/qualcomm/genai_pipeline/configs/__init__.py +41 -0
- executorch/backends/qualcomm/genai_pipeline/configs/compilation_input_config.py +38 -0
- executorch/backends/qualcomm/genai_pipeline/configs/compilation_output_config.py +29 -0
- executorch/backends/qualcomm/genai_pipeline/configs/inference_input_config.py +36 -0
- executorch/backends/qualcomm/genai_pipeline/configs/inference_output_config.py +30 -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 +33 -0
- executorch/backends/qualcomm/genai_pipeline/configs/quantization_input_config.py +38 -0
- executorch/backends/qualcomm/genai_pipeline/configs/quantization_output_config.py +19 -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/pipeline_context.py +116 -0
- executorch/backends/qualcomm/genai_pipeline/pipeline_types.py +29 -0
- executorch/backends/qualcomm/genai_pipeline/tests/configs/test_compilation_input_config.py +28 -0
- executorch/backends/qualcomm/genai_pipeline/tests/configs/test_inference_input_config.py +29 -0
- executorch/backends/qualcomm/genai_pipeline/tests/configs/test_model_preparation_input_config.py +28 -0
- executorch/backends/qualcomm/genai_pipeline/tests/configs/test_quantization_input_config.py +29 -0
- executorch/backends/qualcomm/genai_pipeline/tests/test_engine_proxy.py +80 -0
- executorch/backends/qualcomm/genai_pipeline/tests/test_exceptions.py +49 -0
- executorch/backends/qualcomm/genai_pipeline/tests/test_pipeline_context.py +157 -0
- executorch/backends/qualcomm/genai_pipeline/tests/test_utils.py +27 -0
- executorch/backends/qualcomm/partition/common_defs.py +39 -0
- executorch/backends/qualcomm/partition/qnn_partitioner.py +241 -0
- executorch/backends/qualcomm/partition/utils.py +79 -0
- executorch/backends/qualcomm/qnn_preprocess.py +247 -0
- executorch/backends/qualcomm/quantizer/annotators/__init__.py +0 -0
- executorch/backends/qualcomm/quantizer/annotators/htp_rules.py +1879 -0
- executorch/backends/qualcomm/quantizer/annotators/lpai_rules.py +1134 -0
- executorch/backends/qualcomm/quantizer/backend_opinfo_adapter.py +138 -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 +1031 -0
- executorch/backends/qualcomm/quantizer/quant_recipe.py +500 -0
- executorch/backends/qualcomm/quantizer/quantizer.py +766 -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 +188 -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 +369 -0
- executorch/backends/qualcomm/serialization/qc_schema.py +305 -0
- executorch/backends/qualcomm/serialization/qc_schema_serialize.py +59 -0
- executorch/backends/qualcomm/tests/conftest.py +61 -0
- executorch/backends/qualcomm/tests/models.py +2968 -0
- executorch/backends/qualcomm/tests/rework/common/pass/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/common/utils/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/conftest.py +589 -0
- executorch/backends/qualcomm/tests/rework/gpu/conftest.py +5 -0
- executorch/backends/qualcomm/tests/rework/gpu/e2e/genai/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/gpu/e2e/oss/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/gpu/feature/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/gpu/op/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/conftest.py +102 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v68/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v69/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v73/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v75/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v79/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/genai/v81/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v68/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v69/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v73/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v75/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v79/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/e2e/oss/v81/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/conftest.py +37 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v68/test.py +112 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v69/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v73/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v75/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v79/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/feature/v81/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v68/test.py +1357 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v69/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v73/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v75/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v79/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/htp/op/v81/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/lpai/conftest.py +5 -0
- executorch/backends/qualcomm/tests/rework/lpai/e2e/oss/v6/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/lpai/feature/v6/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/lpai/op/v6/test.py +5 -0
- executorch/backends/qualcomm/tests/rework/src/feature.py +692 -0
- executorch/backends/qualcomm/tests/rework/src/op.py +5032 -0
- executorch/backends/qualcomm/tests/rework/src/pattern.py +5 -0
- executorch/backends/qualcomm/tests/test_passes.py +475 -0
- executorch/backends/qualcomm/tests/test_qnn_delegate.py +11079 -0
- executorch/backends/qualcomm/tests/test_qnn_delegate_x86.py +47 -0
- executorch/backends/qualcomm/tests/tester.py +117 -0
- executorch/backends/qualcomm/tests/utils.py +930 -0
- executorch/backends/qualcomm/utils/check_qnn_version.py +74 -0
- executorch/backends/qualcomm/utils/constants.py +64 -0
- executorch/backends/qualcomm/utils/qnn_manager_lifecycle.py +94 -0
- executorch/backends/qualcomm/utils/utils.py +1427 -0
- executorch/backends/samsung/_passes/annotate_qparams.py +201 -0
- executorch/backends/samsung/_passes/annotate_scalar_parameters.py +65 -0
- executorch/backends/samsung/_passes/conv1d_to_conv2d.py +97 -0
- executorch/backends/samsung/_passes/customized_constant_prop.py +40 -0
- executorch/backends/samsung/_passes/fold_qdq.py +36 -0
- executorch/backends/samsung/_passes/fuse_conv_act.py +77 -0
- executorch/backends/samsung/_passes/insert_qdq.py +164 -0
- executorch/backends/samsung/_passes/remove_useless_ops.py +87 -0
- executorch/backends/samsung/_passes/replace_scalar_ops.py +46 -0
- executorch/backends/samsung/_passes/utils.py +15 -0
- executorch/backends/samsung/builders/__init__.py +97 -0
- executorch/backends/samsung/builders/node_visitor.py +116 -0
- executorch/backends/samsung/builders/op_add.py +41 -0
- executorch/backends/samsung/builders/op_avg_pool2d.py +70 -0
- executorch/backends/samsung/builders/op_batch_norm.py +56 -0
- executorch/backends/samsung/builders/op_bmm.py +43 -0
- executorch/backends/samsung/builders/op_cat.py +50 -0
- executorch/backends/samsung/builders/op_clamp.py +47 -0
- executorch/backends/samsung/builders/op_constant_pad_nd.py +56 -0
- executorch/backends/samsung/builders/op_conv2d.py +89 -0
- executorch/backends/samsung/builders/op_dequantize.py +19 -0
- executorch/backends/samsung/builders/op_div.py +42 -0
- executorch/backends/samsung/builders/op_embedding.py +41 -0
- executorch/backends/samsung/builders/op_expand_copy.py +77 -0
- executorch/backends/samsung/builders/op_gelu.py +40 -0
- executorch/backends/samsung/builders/op_getitem.py +32 -0
- executorch/backends/samsung/builders/op_hardsigmoid.py +35 -0
- executorch/backends/samsung/builders/op_hardswish.py +35 -0
- executorch/backends/samsung/builders/op_hardtanh.py +42 -0
- executorch/backends/samsung/builders/op_layer_norm.py +53 -0
- executorch/backends/samsung/builders/op_leaky_relu.py +58 -0
- executorch/backends/samsung/builders/op_linear.py +51 -0
- executorch/backends/samsung/builders/op_log_softmax.py +39 -0
- executorch/backends/samsung/builders/op_max_pool2d.py +96 -0
- executorch/backends/samsung/builders/op_maximum.py +37 -0
- executorch/backends/samsung/builders/op_mean_dim.py +49 -0
- executorch/backends/samsung/builders/op_minimum.py +39 -0
- executorch/backends/samsung/builders/op_mul.py +43 -0
- executorch/backends/samsung/builders/op_permute.py +37 -0
- executorch/backends/samsung/builders/op_pixel_shuffle.py +38 -0
- executorch/backends/samsung/builders/op_quantize.py +60 -0
- executorch/backends/samsung/builders/op_relu.py +37 -0
- executorch/backends/samsung/builders/op_reshape.py +34 -0
- executorch/backends/samsung/builders/op_rsqrt.py +35 -0
- executorch/backends/samsung/builders/op_select.py +52 -0
- executorch/backends/samsung/builders/op_slice_copy.py +59 -0
- executorch/backends/samsung/builders/op_softmax.py +39 -0
- executorch/backends/samsung/builders/op_sqrt.py +35 -0
- executorch/backends/samsung/builders/op_squeeze.py +37 -0
- executorch/backends/samsung/builders/op_sub.py +39 -0
- executorch/backends/samsung/builders/op_to_copy.py +44 -0
- executorch/backends/samsung/builders/op_unsqueeze.py +35 -0
- executorch/backends/samsung/builders/op_upsample_bilinear2d.py +53 -0
- executorch/backends/samsung/builders/op_upsample_nearest2d.py +52 -0
- executorch/backends/samsung/builders/utils.py +64 -0
- executorch/backends/samsung/enn_preprocess.py +110 -0
- executorch/backends/samsung/partition/enn_partitioner.py +134 -0
- executorch/backends/samsung/quantizer/__init__.py +10 -0
- executorch/backends/samsung/quantizer/annotator.py +871 -0
- executorch/backends/samsung/quantizer/qconfig.py +174 -0
- executorch/backends/samsung/quantizer/quantizer.py +65 -0
- executorch/backends/samsung/serialization/compile_options.py +78 -0
- executorch/backends/samsung/serialization/compile_options_def.fbs +23 -0
- executorch/backends/samsung/serialization/enn_graph_schema.py +141 -0
- executorch/backends/samsung/test/models/test_deeplab_v3.py +28 -0
- executorch/backends/samsung/test/models/test_edsr.py +30 -0
- executorch/backends/samsung/test/models/test_inception_v3.py +33 -0
- executorch/backends/samsung/test/models/test_inception_v4.py +30 -0
- executorch/backends/samsung/test/models/test_mobilenet_v2.py +28 -0
- executorch/backends/samsung/test/models/test_mobilenet_v3.py +33 -0
- executorch/backends/samsung/test/models/test_resnet18.py +30 -0
- executorch/backends/samsung/test/models/test_resnet50.py +30 -0
- executorch/backends/samsung/test/models/test_torchvision_vit.py +32 -0
- executorch/backends/samsung/test/models/test_wav2letter.py +28 -0
- executorch/backends/samsung/test/ops/test_add.py +63 -0
- executorch/backends/samsung/test/ops/test_avg_pool2d.py +66 -0
- executorch/backends/samsung/test/ops/test_batch_norm.py +52 -0
- executorch/backends/samsung/test/ops/test_bmm.py +50 -0
- executorch/backends/samsung/test/ops/test_cat.py +49 -0
- executorch/backends/samsung/test/ops/test_clamp.py +50 -0
- executorch/backends/samsung/test/ops/test_constant_pad_nd.py +46 -0
- executorch/backends/samsung/test/ops/test_conv2d.py +95 -0
- executorch/backends/samsung/test/ops/test_div.py +50 -0
- executorch/backends/samsung/test/ops/test_embedding.py +46 -0
- executorch/backends/samsung/test/ops/test_expand_copy.py +46 -0
- executorch/backends/samsung/test/ops/test_gelu.py +65 -0
- executorch/backends/samsung/test/ops/test_leaky_relu.py +47 -0
- executorch/backends/samsung/test/ops/test_linear.py +48 -0
- executorch/backends/samsung/test/ops/test_log_softmax.py +46 -0
- executorch/backends/samsung/test/ops/test_max_pool2d.py +72 -0
- executorch/backends/samsung/test/ops/test_mean_dim.py +51 -0
- executorch/backends/samsung/test/ops/test_minimum.py +45 -0
- executorch/backends/samsung/test/ops/test_mul.py +63 -0
- executorch/backends/samsung/test/ops/test_permute.py +55 -0
- executorch/backends/samsung/test/ops/test_pixel_shuffle.py +49 -0
- executorch/backends/samsung/test/ops/test_relu.py +65 -0
- executorch/backends/samsung/test/ops/test_reshape.py +46 -0
- executorch/backends/samsung/test/ops/test_rsqrt.py +46 -0
- executorch/backends/samsung/test/ops/test_select.py +52 -0
- executorch/backends/samsung/test/ops/test_slice_copy.py +46 -0
- executorch/backends/samsung/test/ops/test_softmax.py +46 -0
- executorch/backends/samsung/test/ops/test_sqrt.py +46 -0
- executorch/backends/samsung/test/ops/test_squeeze.py +47 -0
- executorch/backends/samsung/test/ops/test_sub.py +63 -0
- executorch/backends/samsung/test/ops/test_to_copy.py +49 -0
- executorch/backends/samsung/test/ops/test_unsqueeze.py +47 -0
- executorch/backends/samsung/test/ops/test_upsample_bilinear2d.py +54 -0
- executorch/backends/samsung/test/ops/test_upsample_nearest2d.py +53 -0
- executorch/backends/samsung/test/tester/__init__.py +11 -0
- executorch/backends/samsung/test/tester/samsung_tester.py +125 -0
- executorch/backends/samsung/test/utils/__init__.py +11 -0
- executorch/backends/samsung/test/utils/runtime_executor.py +186 -0
- executorch/backends/samsung/utils/constants.py +45 -0
- executorch/backends/samsung/utils/export_utils.py +93 -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 +301 -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 +66 -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 +543 -0
- executorch/backends/test/harness/tests/test_error_statistics.py +67 -0
- executorch/backends/test/program_builder.py +138 -0
- executorch/backends/test/suite/__init__.py +74 -0
- executorch/backends/test/suite/conftest.py +221 -0
- executorch/backends/test/suite/context.py +34 -0
- executorch/backends/test/suite/discovery.py +100 -0
- executorch/backends/test/suite/flow.py +202 -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/mlx.py +14 -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/vulkan.py +44 -0
- executorch/backends/test/suite/flows/webgpu.py +36 -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 +350 -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/channels_last_ops.py +153 -0
- executorch/backends/transforms/convert_dtype_pass.py +103 -0
- executorch/backends/transforms/decompose_channels_last_pass.py +92 -0
- executorch/backends/transforms/decompose_sdpa.py +208 -0
- executorch/backends/transforms/duplicate_dynamic_quant_chain.py +195 -0
- executorch/backends/transforms/fuse_batch_norm_with_conv.py +161 -0
- executorch/backends/transforms/fuse_cascaded_transpose_or_permute_ops.py +181 -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_transpose_or_permute_op_pairs_pass.py +102 -0
- executorch/backends/transforms/fuse_view_copy.py +139 -0
- executorch/backends/transforms/mean_to_sum_div.py +41 -0
- executorch/backends/transforms/permute_pass_utils.py +278 -0
- executorch/backends/transforms/postpone_permute_below_squeeze_view.py +207 -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 +589 -0
- executorch/backends/transforms/replace_nop_transpose_or_permute_with_view.py +90 -0
- executorch/backends/transforms/replace_scalar_with_tensor.py +99 -0
- executorch/backends/transforms/test/common.py +69 -0
- executorch/backends/transforms/test/test_aten_to_dialect_pass.py +208 -0
- executorch/backends/transforms/test/test_channels_last_ops.py +226 -0
- executorch/backends/transforms/test/test_create_delete_constant_placeholder.py +122 -0
- executorch/backends/transforms/test/test_create_mutable_buffer.py +503 -0
- executorch/backends/transforms/test/test_decompose_channels_last_pass.py +210 -0
- executorch/backends/transforms/test/test_decompose_sdpa.py +96 -0
- executorch/backends/transforms/test/test_duplicate_dynamic_quant_chain.py +184 -0
- executorch/backends/transforms/test/test_permute_optimization_passes.py +1099 -0
- executorch/backends/transforms/test/test_quantize_fused_convbn_bias_pass.py +174 -0
- executorch/backends/transforms/test/test_rank_0_to_rank_1.py +32 -0
- executorch/backends/transforms/test/test_remove_clone_ops.py +197 -0
- executorch/backends/transforms/test/test_to_contiguous_channels_last_pass.py +700 -0
- executorch/backends/transforms/utils.py +386 -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 +41 -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 +83 -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 +1321 -0
- executorch/backends/vulkan/op_registry.py +1852 -0
- executorch/backends/vulkan/partitioner/vulkan_partitioner.py +424 -0
- executorch/backends/vulkan/patterns/__init__.py +151 -0
- executorch/backends/vulkan/patterns/pattern_registry.py +116 -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/weight_packing_utils.py +51 -0
- executorch/backends/vulkan/quantizer/vulkan_quantizer.py +183 -0
- executorch/backends/vulkan/quantizer/vulkan_quantizer_utils.py +223 -0
- executorch/backends/vulkan/runtime/gen_vulkan_spv.py +1673 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/adamw_step.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/apply_rotary_emb_interleaved.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/arange_buffer.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/arange_texture.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/avg_pool2d.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/batchnorm.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.yaml +59 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/binary_op_texture.yaml +61 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_texture.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/choose_qparams_per_row.yaml +23 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/clone.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/col2im.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/concat_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv1d.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv1d_dw.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv1d_pw.yaml +31 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_output_tile.yaml +34 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_prepack_weights.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_sned_output_tile.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_gemm.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_im2col.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_prepack_weights.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw_q8ta_q8csw_q8to_tiled.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw_s1p0.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw_tiled.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8csw_linear_tiled.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_linear_tiled.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_q8to.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_q8to_linear_tiled.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv_transpose2d.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/conv_transpose2d_prepack_weights.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/coopmat_mm.yaml +43 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_legacy.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_q4gsw.yaml +38 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/expand_texture.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/flip.yaml +14 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/full_buffer.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/full_texture.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/fused_ce.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/fused_ce_sum.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/gather_texture.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/grid_priors.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/grid_sampler_2d.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/group_norm_reduce_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/group_norm_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/im2col.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.yaml +35 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/index_select.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/index_select_channel.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/index_tensor_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/index_tensor_texture.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/int8x4_buffer_to_nchw.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_dW.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_dq8ca_q4gsw_tiled.yaml +33 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_dq8ca_qw_coopmat.yaml +40 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.yaml +72 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_tiled.yaml +28 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q8csw_tiled.yaml +28 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q8ta_q8csw_tiled.yaml +24 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.yaml +23 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.yaml +38 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.yaml +54 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qw_coopmat.yaml +40 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_scalar.yaml +39 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/linear_vec.yaml +41 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/matmul_scalar.yaml +35 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/matmul_vec.yaml +36 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/max_pool2d.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/native_layer_norm_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/native_layer_norm_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_bitw8_image_nobitw8buffer.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_image.yaml +28 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_int8x4_buffer.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/no_op.yaml +24 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_conv2d_gemm_weight.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_fp_linear_weight.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_int4_linear_weight_transposed_interleaved.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q4_linear_weight.yaml +14 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q4_linear_weight__w_4x8.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_conv2d_dw_weights.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_conv2d_weights.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_linear_weight.yaml +14 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pad_buffer.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pad_texture.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/permute_texture.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/pixel_shuffle_texture.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q4gsw_backward.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q4gsw_linear_gemm__tin__w_4x8.yaml +34 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q4gsw_linear_gemm__w_4x8.yaml +29 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q4gsw_linear_gemv_coop__w_4x8.yaml +41 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q4gsw_requant.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_binary.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_clone.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_conv2d.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_conv2d_dw.yaml +14 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_conv2d_pw.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_conv2d_transposed.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_dequantize.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_im2col.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_linear_gemv.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_pixel_shuffle.yaml +11 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_quantize.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/q8ta_unary.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4h4w.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4h4w_with_group_sums.yaml +34 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4w4c.yaml +23 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_im2col.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/reduce.yaml +29 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/reduce2d.yaml +29 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/reduce_per_row_buffer.yaml +42 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_buffer.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_channel.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_interleave.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_texture.yaml +12 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/rms_norm_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/rms_norm_texture.yaml +15 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/rotary_embedding.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/rotary_embedding_hf.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.yaml +27 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_attn_weights_softmax.yaml +35 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_attn_weights_coop.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_attn_weights_tiled.yaml +60 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_out_coop.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_out_tiled.yaml +39 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_kv_cache_update.yaml +23 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/set_zero.yaml +8 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/softmax.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/softmax_buffer.yaml +21 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/split_buffer.yaml +18 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/split_texture.yaml +17 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/tan.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/transfer_texture.yaml +22 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/transpose_cast_contig_to_vectorized.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/transpose_cast_contig_to_vectorized_4x4.yaml +25 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/unary_op.yaml +51 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/unpack_4w4c_and_dequantize.yaml +23 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/upsample_2d.yaml +19 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/var_buffer.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/var_texture3d.yaml +16 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/view_buffer.yaml +20 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/view_convert_texture.yaml +26 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/view_texture.yaml +13 -0
- executorch/backends/vulkan/runtime/graph/ops/glsl/where.yaml +12 -0
- executorch/backends/vulkan/serialization/schema.fbs +162 -0
- executorch/backends/vulkan/serialization/vulkan_graph_builder.py +490 -0
- executorch/backends/vulkan/serialization/vulkan_graph_schema.py +165 -0
- executorch/backends/vulkan/serialization/vulkan_graph_serialize.py +274 -0
- executorch/backends/vulkan/test/custom_ops/glsl/add.yaml +29 -0
- executorch/backends/vulkan/test/custom_ops/glsl/q4gsw_linear_gemv__w_4x8.yaml +40 -0
- executorch/backends/vulkan/test/glsl/all_shaders.yaml +68 -0
- executorch/backends/vulkan/test/glsl/dynamic_dispatch_test.yaml +7 -0
- executorch/backends/vulkan/test/glsl/reference_matmul_common.yaml +9 -0
- executorch/backends/vulkan/test/op_tests/cases.py +2252 -0
- executorch/backends/vulkan/test/op_tests/generate_op_benchmarks.py +88 -0
- executorch/backends/vulkan/test/op_tests/generate_op_correctness_tests.py +90 -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/test_serialization.py +135 -0
- executorch/backends/vulkan/test/test_vulkan_compile_options.py +48 -0
- executorch/backends/vulkan/test/test_vulkan_delegate.py +2716 -0
- executorch/backends/vulkan/test/test_vulkan_delegate_header.py +104 -0
- executorch/backends/vulkan/test/test_vulkan_passes.py +781 -0
- executorch/backends/vulkan/test/test_vulkan_tensor_repr.py +991 -0
- executorch/backends/vulkan/test/tester.py +91 -0
- executorch/backends/vulkan/test/utils.py +1111 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/apiconventions.py +23 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/base_generator.py +1425 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/cgenerator.py +575 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/generator.py +1478 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/parse_dependency.py +474 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/reg.py +2115 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/spec_tools/conventions.py +561 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/spec_tools/util.py +58 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/stripAPI.py +42 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/vkconventions.py +330 -0
- executorch/backends/vulkan/third-party/Vulkan-Headers/registry/vulkan_object.py +690 -0
- executorch/backends/vulkan/third-party/VulkanMemoryAllocator/tools/GpuMemDumpVis/GpuMemDumpVis.py +333 -0
- executorch/backends/vulkan/third-party/volk/generate.py +212 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/buf_bandwidth.yaml +18 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/buf_cacheline_size.yaml +12 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/reg_count.yaml +16 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/tex_bandwidth.yaml +15 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/tex_cacheline_concurr.yaml +14 -0
- executorch/backends/vulkan/tools/gpuinfo/glsl/warp_size.yaml +16 -0
- executorch/backends/vulkan/utils.py +2016 -0
- executorch/backends/vulkan/vulkan_preprocess.py +256 -0
- executorch/backends/webgpu/__init__.py +5 -0
- executorch/backends/webgpu/runtime/ops/binary_op/binary_op.yaml +11 -0
- executorch/backends/webgpu/runtime/ops/boolean_op/boolean_op.yaml +20 -0
- executorch/backends/webgpu/runtime/ops/quantized_linear/q4gsw_linear_gemm_steel.yaml +22 -0
- executorch/backends/webgpu/runtime/ops/rms_norm/rms_norm.yaml +12 -0
- executorch/backends/webgpu/runtime/ops/sdpa/sdpa_compute_attn_weights.yaml +11 -0
- executorch/backends/webgpu/runtime/ops/sdpa/sdpa_compute_out.yaml +11 -0
- executorch/backends/webgpu/runtime/ops/sdpa_fd_decode/sdpa_fd_split.yaml +11 -0
- executorch/backends/webgpu/runtime/ops/softmax/softmax.yaml +8 -0
- executorch/backends/webgpu/runtime/ops/update_cache/update_cache.yaml +11 -0
- executorch/backends/webgpu/scripts/gen_wgsl_headers.py +584 -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 +288 -0
- executorch/backends/webgpu/test/op_tests/generate_op_tests.py +198 -0
- executorch/backends/webgpu/test/op_tests/test_generator.py +111 -0
- executorch/backends/webgpu/test/op_tests/test_schema.py +84 -0
- executorch/backends/webgpu/test/op_tests/test_suite.py +98 -0
- executorch/backends/webgpu/test/ops/__init__.py +0 -0
- executorch/backends/webgpu/test/ops/dynamic_shape/test_dynamic_shape_export.py +459 -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_bmm.py +104 -0
- executorch/backends/webgpu/test/ops/test_cat.py +82 -0
- executorch/backends/webgpu/test/ops/test_compare.py +109 -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_expand_copy.py +120 -0
- executorch/backends/webgpu/test/ops/test_fill.py +91 -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_linear.py +116 -0
- executorch/backends/webgpu/test/ops/test_linear_dW.py +88 -0
- executorch/backends/webgpu/test/ops/test_log_softmax.py +97 -0
- executorch/backends/webgpu/test/ops/test_logical_not.py +116 -0
- executorch/backends/webgpu/test/ops/test_matmul.py +67 -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_prepack.py +142 -0
- executorch/backends/webgpu/test/ops/test_q4gsw_requant.py +123 -0
- executorch/backends/webgpu/test/ops/test_quantized_linear.py +193 -0
- executorch/backends/webgpu/test/ops/test_quantized_linear_backward.py +157 -0
- executorch/backends/webgpu/test/ops/test_reduce.py +127 -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_sdpa.py +533 -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_squeeze.py +75 -0
- executorch/backends/webgpu/test/ops/test_sub.py +114 -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_view_copy.py +66 -0
- executorch/backends/webgpu/test/ops/test_where.py +86 -0
- executorch/backends/webgpu/test/test_wgsl_codegen.py +473 -0
- executorch/backends/webgpu/test/tester.py +91 -0
- executorch/backends/xnnpack/__init__.py +28 -0
- executorch/backends/xnnpack/_passes/__init__.py +113 -0
- executorch/backends/xnnpack/_passes/channels_last_tagged_reshape_pass.py +570 -0
- executorch/backends/xnnpack/_passes/conv1d_unsqueeze_pass.py +203 -0
- executorch/backends/xnnpack/_passes/convert_to_linear.py +198 -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 +296 -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 +279 -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/xnnpack_pass.py +22 -0
- executorch/backends/xnnpack/operators/__init__.py +61 -0
- executorch/backends/xnnpack/operators/node_visitor.py +758 -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 +75 -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 +183 -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 +56 -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 +52 -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 +110 -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 +136 -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 +134 -0
- executorch/backends/xnnpack/partition/config/gemm_configs.py +599 -0
- executorch/backends/xnnpack/partition/config/generic_node_configs.py +783 -0
- executorch/backends/xnnpack/partition/config/node_configs.py +139 -0
- executorch/backends/xnnpack/partition/config/quant_affine_configs.py +56 -0
- executorch/backends/xnnpack/partition/config/xnnpack_config.py +252 -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 +160 -0
- executorch/backends/xnnpack/quantizer/xnnpack_quantizer.py +462 -0
- executorch/backends/xnnpack/quantizer/xnnpack_quantizer_utils.py +1172 -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 +389 -0
- executorch/backends/xnnpack/serialization/schema.fbs +381 -0
- executorch/backends/xnnpack/serialization/xnnpack_graph_schema.py +542 -0
- executorch/backends/xnnpack/serialization/xnnpack_graph_serialize.py +393 -0
- executorch/backends/xnnpack/test/__init__.py +0 -0
- executorch/backends/xnnpack/test/fragments/test_dim_order.py +40 -0
- executorch/backends/xnnpack/test/models/deeplab_v3.py +76 -0
- executorch/backends/xnnpack/test/models/edsr.py +87 -0
- executorch/backends/xnnpack/test/models/emformer_rnnt.py +146 -0
- executorch/backends/xnnpack/test/models/inception_v3.py +117 -0
- executorch/backends/xnnpack/test/models/inception_v4.py +95 -0
- executorch/backends/xnnpack/test/models/llama2_et_example.py +49 -0
- executorch/backends/xnnpack/test/models/mobilebert.py +72 -0
- executorch/backends/xnnpack/test/models/mobilenet_v2.py +103 -0
- executorch/backends/xnnpack/test/models/mobilenet_v3.py +84 -0
- executorch/backends/xnnpack/test/models/resnet.py +90 -0
- executorch/backends/xnnpack/test/models/torchvision_vit.py +105 -0
- executorch/backends/xnnpack/test/models/very_big_model.py +45 -0
- executorch/backends/xnnpack/test/models/w2l.py +60 -0
- executorch/backends/xnnpack/test/ops/test_abs.py +87 -0
- executorch/backends/xnnpack/test/ops/test_add.py +266 -0
- executorch/backends/xnnpack/test/ops/test_avgpool2d.py +92 -0
- executorch/backends/xnnpack/test/ops/test_batch_norm.py +380 -0
- executorch/backends/xnnpack/test/ops/test_bilinear2d.py +152 -0
- executorch/backends/xnnpack/test/ops/test_bmm.py +49 -0
- executorch/backends/xnnpack/test/ops/test_cat.py +297 -0
- executorch/backends/xnnpack/test/ops/test_ceil.py +63 -0
- executorch/backends/xnnpack/test/ops/test_check_quant_params.py +107 -0
- executorch/backends/xnnpack/test/ops/test_clamp.py +79 -0
- executorch/backends/xnnpack/test/ops/test_clone.py +165 -0
- executorch/backends/xnnpack/test/ops/test_conv1d.py +243 -0
- executorch/backends/xnnpack/test/ops/test_conv2d.py +1025 -0
- executorch/backends/xnnpack/test/ops/test_cos.py +87 -0
- executorch/backends/xnnpack/test/ops/test_div.py +78 -0
- executorch/backends/xnnpack/test/ops/test_elu.py +98 -0
- executorch/backends/xnnpack/test/ops/test_exp.py +70 -0
- executorch/backends/xnnpack/test/ops/test_floor.py +58 -0
- executorch/backends/xnnpack/test/ops/test_gelu.py +91 -0
- executorch/backends/xnnpack/test/ops/test_hardswish.py +70 -0
- executorch/backends/xnnpack/test/ops/test_hardtanh.py +83 -0
- executorch/backends/xnnpack/test/ops/test_leaky_relu.py +131 -0
- executorch/backends/xnnpack/test/ops/test_linear.py +1059 -0
- executorch/backends/xnnpack/test/ops/test_log.py +45 -0
- executorch/backends/xnnpack/test/ops/test_lstm.py +67 -0
- executorch/backends/xnnpack/test/ops/test_max_dim.py +66 -0
- executorch/backends/xnnpack/test/ops/test_maximum.py +66 -0
- executorch/backends/xnnpack/test/ops/test_maxpool2d.py +221 -0
- executorch/backends/xnnpack/test/ops/test_mean_dim.py +128 -0
- executorch/backends/xnnpack/test/ops/test_minimum.py +49 -0
- executorch/backends/xnnpack/test/ops/test_multiply.py +149 -0
- executorch/backends/xnnpack/test/ops/test_negate.py +58 -0
- executorch/backends/xnnpack/test/ops/test_permute.py +134 -0
- executorch/backends/xnnpack/test/ops/test_pow.py +62 -0
- executorch/backends/xnnpack/test/ops/test_prelu.py +50 -0
- executorch/backends/xnnpack/test/ops/test_quantize_per_tensor.py +70 -0
- executorch/backends/xnnpack/test/ops/test_relu.py +38 -0
- executorch/backends/xnnpack/test/ops/test_rsqrt.py +45 -0
- executorch/backends/xnnpack/test/ops/test_sigmoid.py +45 -0
- executorch/backends/xnnpack/test/ops/test_sin.py +87 -0
- executorch/backends/xnnpack/test/ops/test_slice_copy.py +170 -0
- executorch/backends/xnnpack/test/ops/test_softmax.py +73 -0
- executorch/backends/xnnpack/test/ops/test_sqrt.py +45 -0
- executorch/backends/xnnpack/test/ops/test_square.py +48 -0
- executorch/backends/xnnpack/test/ops/test_static_constant_pad.py +294 -0
- executorch/backends/xnnpack/test/ops/test_sub.py +178 -0
- executorch/backends/xnnpack/test/ops/test_tanh.py +43 -0
- executorch/backends/xnnpack/test/ops/test_to_copy.py +113 -0
- executorch/backends/xnnpack/test/passes/__init__.py +0 -0
- executorch/backends/xnnpack/test/passes/test_activation_fusion.py +301 -0
- executorch/backends/xnnpack/test/passes/test_batch_norm_fusion.py +133 -0
- executorch/backends/xnnpack/test/passes/test_channels_last_tagged_reshape.py +667 -0
- executorch/backends/xnnpack/test/passes/test_convert_to_linear.py +43 -0
- executorch/backends/xnnpack/test/passes/test_decompose_batch_norm.py +196 -0
- executorch/backends/xnnpack/test/passes/test_decompose_cat_pass.py +112 -0
- executorch/backends/xnnpack/test/passes/test_insert_pad_qdq.py +73 -0
- executorch/backends/xnnpack/test/passes/test_propagate_custom_meta_pass.py +185 -0
- executorch/backends/xnnpack/test/passes/test_remove_get_item_pass.py +99 -0
- executorch/backends/xnnpack/test/passes/test_remove_noop_expand_copy_pass.py +75 -0
- executorch/backends/xnnpack/test/passes/test_remove_redundant_copy_pass.py +182 -0
- executorch/backends/xnnpack/test/quantizer/test_pt2e_quantization.py +818 -0
- executorch/backends/xnnpack/test/quantizer/test_representation.py +308 -0
- executorch/backends/xnnpack/test/quantizer/test_xnnpack_quantizer.py +1217 -0
- executorch/backends/xnnpack/test/recipes/test_xnnpack_recipes.py +320 -0
- executorch/backends/xnnpack/test/serialization/test_serialization.py +50 -0
- executorch/backends/xnnpack/test/serialization/test_xnnheader.py +104 -0
- executorch/backends/xnnpack/test/test_xnnpack_partitioner.py +163 -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/third-party/FP16/configure.py +65 -0
- executorch/backends/xnnpack/third-party/FP16/confu.yaml +8 -0
- executorch/backends/xnnpack/third-party/FP16/include/fp16/__init__.py +0 -0
- executorch/backends/xnnpack/third-party/FP16/include/fp16/avx.py +50 -0
- executorch/backends/xnnpack/third-party/FP16/include/fp16/avx2.py +53 -0
- executorch/backends/xnnpack/third-party/FP16/test/peachpy/stubs.py +38 -0
- executorch/backends/xnnpack/third-party/FXdiv/configure.py +30 -0
- executorch/backends/xnnpack/third-party/FXdiv/confu.yaml +6 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/aarch32_template.py +361 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/aarch64_template.py +347 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/arm_template.py +78 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512bf16_template.py +81 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512f_template.py +393 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512vnni_template.py +703 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/base_architecture.py +276 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/fma3_template.py +280 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate.py +71 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_bf16_f32_gemm_microkernels.py +39 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_f32_gemm_microkernels.py +104 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_gemm_microkernels_main.py +29 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qd8_f32_qc4w_gemm_microkernels.py +81 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qd8_f32_qc8w_gemm_microkernels.py +105 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qs8_qc4w_gemm_microkernels.py +42 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qs8_qc8w_gemm_microkernels.py +43 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neondot_template.py +474 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neonfma_template.py +248 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neonmlal_aarch32_template.py +394 -0
- executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/x64_template.py +525 -0
- executorch/backends/xnnpack/third-party/XNNPACK/scripts/check_config.py +152 -0
- executorch/backends/xnnpack/third-party/XNNPACK/scripts/check_files_changed.py +53 -0
- executorch/backends/xnnpack/third-party/XNNPACK/scripts/generate-build-identifier.py +106 -0
- executorch/backends/xnnpack/third-party/XNNPACK/scripts/run-gn-tests.py +198 -0
- executorch/backends/xnnpack/third-party/XNNPACK/scripts/sort-filenames.py +134 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/bf16-f32-gemm-minmax.yaml +121 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/bf16-gemm-minmax.yaml +106 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-conv-hwc2chw.yaml +8 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-dwconv2d-chw.yaml +88 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-f32acc-gemm-minmax.yaml +42 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-f32acc-igemm-minmax.yaml +42 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-gemm-minmax.yaml +233 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-ibilinear-chw.yaml +9 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-ibilinear.yaml +12 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-igemm-minmax.yaml +179 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f16-raddstoreexpminusmax.yaml +27 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-argmaxpool.yaml +15 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-conv-hwc2chw.yaml +32 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-dwconv2d-chw.yaml +712 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm-minmax.yaml +1584 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm-relu.yaml +123 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm.yaml +127 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ibilinear-chw.yaml +22 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ibilinear.yaml +23 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm-minmax.yaml +1021 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm-relu.yaml +123 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm.yaml +123 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ppmm-minmax.yaml +122 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc4w-gemm-minmax.yaml +277 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm-minmax.yaml +757 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm-relu.yaml +67 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm.yaml +115 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-raddexpminusmax.yaml +38 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/f32-raddstoreexpminusmax.yaml +88 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/pf16-f16-igemm-minmax.yaml +24 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/pf16-gemm-minmax.yaml +34 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/pf32-gemm-minmax.yaml +34 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/pqs8-qc8w-gemm-minmax.yaml +27 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qb4w-gemm-minmax.yaml +260 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc2w-gemm-minmax.yaml +148 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc4w-gemm-minmax.yaml +678 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc8w-gemm-minmax.yaml +412 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc8w-igemm-minmax.yaml +360 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qb4w-gemm-minmax.yaml +537 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc2w-gemm-minmax.yaml +230 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc4w-gemm-minmax.yaml +2218 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc8w-gemm-minmax.yaml +1600 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc8w-igemm-minmax.yaml +1035 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qb4w-gemm-minmax.yaml +54 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qc4w-gemm-minmax.yaml +66 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qc8w-gemm-minmax.yaml +54 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc2w-gemm-minmax-fp32.yaml +204 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc4w-gemm-minmax-fp32.yaml +784 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc8w-gemm-minmax-fp32.yaml +1997 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc8w-igemm-minmax-fp32.yaml +1775 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-gemm-minmax-fp32.yaml +584 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-gemm-minmax-rndnu.yaml +148 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-igemm-minmax-fp32.yaml +581 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-igemm-minmax-rndnu.yaml +110 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/s8-ibilinear.yaml +22 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/u8-ibilinear.yaml +22 -0
- executorch/backends/xnnpack/third-party/XNNPACK/test/x8-lut.yaml +47 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-argmaxpool-test.py +692 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-conv-hwc-test.py +543 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-conv-hwc2chw-test.py +591 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-dwconv-test.py +343 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-dwconv2d-chw-test.py +463 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-gemm-test.py +1152 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-ibilinear-chw-test.py +236 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-ibilinear-test.py +237 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-lut-test.py +164 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-raddexpminusmax-test.py +159 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-raddstoreexpminusmax-test.py +210 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-reduce-discontiguous-test.py +495 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-reduce-test.py +289 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-vbinary-test.py +179 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-vunary-test.py +280 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/parse-microkernel-bench.py +189 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/primes.py +1015 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/update-microkernels.py +567 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/xngen.py +159 -0
- executorch/backends/xnnpack/third-party/XNNPACK/tools/xnncommon.py +287 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/binary/generator.py +13 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/binary/kernels.py +81 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm.py +210 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm_bf16_bf16_fp32.py +66 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm_bf16_bf16_fp32_k2.py +64 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm_fp32.py +49 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm_fp64.py +45 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/arm_int8_int8_int32.py +152 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/dot_base.py +538 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/generator.py +113 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86.py +316 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_bf16_bf16_fp32.py +144 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_bf16_bf16_fp32_k1.py +92 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_fp16_fp16_fp32.py +88 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_fp32.py +105 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_fp32_k2.py +150 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_fp32_k4.py +105 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_fp64.py +105 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_int8_int8_int32.py +138 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_int8_int8_int32_k1.py +77 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_int8_int8_int32_k16.py +88 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_uint8_int8_int32.py +47 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/dot/generator/x86_uint8_int8_int32_k16.py +85 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/arm.py +284 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/common_rules.py +89 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/compiler.py +1804 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/compiler_test.py +241 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/generator.py +54 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/elementwise/x86.py +980 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/ternary/convert.py +36 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/ternary/generator.py +14 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/ternary/kernels.py +49 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/convert.py +32 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/exp.py +121 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/generator.py +18 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/kernels.py +55 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/sigmoid.py +49 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/sine_cosine.py +86 -0
- executorch/backends/xnnpack/third-party/XNNPACK/ynnpack/kernels/unary/tanh.py +65 -0
- executorch/backends/xnnpack/third-party/cpuinfo/configure.py +110 -0
- executorch/backends/xnnpack/third-party/cpuinfo/confu.yaml +9 -0
- executorch/backends/xnnpack/third-party/cpuinfo/deps/clog/configure.py +26 -0
- executorch/backends/xnnpack/third-party/cpuinfo/deps/clog/confu.yaml +5 -0
- executorch/backends/xnnpack/third-party/cpuinfo/scripts/android-device-dump.py +400 -0
- executorch/backends/xnnpack/third-party/cpuinfo/scripts/arm-linux-filesystem-dump.py +107 -0
- executorch/backends/xnnpack/third-party/cpuinfo/scripts/parse-x86-cpuid-dump.py +47 -0
- executorch/backends/xnnpack/third-party/generate-cpuinfo-wrappers.py +93 -0
- executorch/backends/xnnpack/third-party/pthreadpool/configure.py +38 -0
- executorch/backends/xnnpack/third-party/pthreadpool/confu.yaml +8 -0
- executorch/backends/xnnpack/utils/configs.py +41 -0
- executorch/backends/xnnpack/utils/quant_utils.py +301 -0
- executorch/backends/xnnpack/utils/utils.py +214 -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 +1049 -0
- executorch/codegen/model.py +220 -0
- executorch/codegen/parse.py +158 -0
- executorch/codegen/test/test_executorch_custom_ops.py +153 -0
- executorch/codegen/test/test_executorch_gen.py +698 -0
- executorch/codegen/test/test_executorch_signatures.py +65 -0
- executorch/codegen/test/test_executorch_types.py +121 -0
- executorch/codegen/test/test_executorch_unboxing.py +165 -0
- executorch/codegen/test/test_selective_build.py +51 -0
- executorch/codegen/tools/__init__.py +0 -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 +369 -0
- executorch/codegen/tools/gen_ops_def.py +96 -0
- executorch/codegen/tools/gen_selected_op_variants.py +133 -0
- executorch/codegen/tools/gen_selected_prim_ops.py +96 -0
- executorch/codegen/tools/merge_yaml.py +125 -0
- executorch/codegen/tools/selective_build.cp314-win_amd64.pyd +0 -0
- executorch/codegen/tools/selective_build.pyi +23 -0
- executorch/codegen/tools/test/test_gen_all_oplist.py +122 -0
- executorch/codegen/tools/test/test_gen_max_kernel_num.py +226 -0
- executorch/codegen/tools/test/test_gen_oplist.py +263 -0
- executorch/codegen/tools/test/test_gen_oplist_real_model.py +50 -0
- executorch/codegen/tools/test/test_gen_selected_op_variants.py +204 -0
- executorch/codegen/tools/test/test_tools_selective_build.py +129 -0
- executorch/codegen/tools/yaml_util.py +15 -0
- executorch/data/bin/__init__.py +44 -0
- executorch/data/bin/flatc.exe +0 -0
- executorch/data/lib/aoti_cuda_shims.lib +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/backend_debug/tests/test_delegation_info.py +79 -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/serialize/test/test_serialize.py +37 -0
- executorch/devtools/bundled_program/test/test_bundle_data.py +168 -0
- executorch/devtools/bundled_program/test/test_config.py +131 -0
- executorch/devtools/bundled_program/test/test_end2end.py +64 -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 +108 -0
- executorch/devtools/etdump/tests/serialize_test.py +142 -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 +1712 -0
- executorch/devtools/inspector/_inspector_utils.py +1252 -0
- executorch/devtools/inspector/_intermediate_output_capturer.py +62 -0
- executorch/devtools/inspector/inspector_cli.py +76 -0
- executorch/devtools/inspector/numerical_comparator/__init__.py +35 -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/event_blocks_test.py +657 -0
- executorch/devtools/inspector/tests/inspector_test.py +2279 -0
- executorch/devtools/inspector/tests/inspector_test_utils.py +189 -0
- executorch/devtools/inspector/tests/inspector_utils_test.py +877 -0
- executorch/devtools/inspector/tests/intermediate_output_capturer_test.py +101 -0
- executorch/devtools/inspector/tests/l1_comparator_test.py +49 -0
- executorch/devtools/inspector/tests/mse_comparator_test.py +49 -0
- executorch/devtools/inspector/tests/snr_comparator_test.py +52 -0
- executorch/devtools/inspector/vgf_neural_statistics.py +124 -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/intermediate_output_tap/tests/test_coreml_e2e.py +284 -0
- executorch/devtools/intermediate_output_tap/tests/test_reducers.py +131 -0
- executorch/devtools/intermediate_output_tap/tests/test_selectors.py +198 -0
- executorch/devtools/intermediate_output_tap/tests/test_strip_pass.py +130 -0
- executorch/devtools/intermediate_output_tap/tests/test_tap_pass.py +239 -0
- executorch/devtools/intermediate_output_tap/tests/test_xnnpack_e2e.py +482 -0
- executorch/devtools/pte_tool/diff_pte.py +895 -0
- executorch/devtools/pte_tool/tests/test_diff_pte.py +341 -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 +305 -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/apple/mps/scripts/bench_utils.py +108 -0
- executorch/examples/apple/mps/scripts/mps_example.py +239 -0
- executorch/examples/cuda/scripts/__init__.py +0 -0
- executorch/examples/cuda/scripts/export.py +107 -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/python/__init__.py +7 -0
- executorch/examples/llm_server/python/chat_template.py +338 -0
- executorch/examples/llm_server/python/errors.py +105 -0
- executorch/examples/llm_server/python/openai_transcript.py +337 -0
- executorch/examples/llm_server/python/protocol.py +153 -0
- executorch/examples/llm_server/python/server.py +244 -0
- executorch/examples/llm_server/python/serving_chat.py +664 -0
- executorch/examples/llm_server/python/session_runtime.py +250 -0
- executorch/examples/llm_server/python/tests/conftest.py +143 -0
- executorch/examples/llm_server/python/tests/test_contract.py +457 -0
- executorch/examples/llm_server/python/tests/test_gemma_tool_parser.py +131 -0
- executorch/examples/llm_server/python/tests/test_hermes_tool_parser.py +100 -0
- executorch/examples/llm_server/python/tests/test_qwen_tool_parser.py +218 -0
- executorch/examples/llm_server/python/tests/test_sampling_params.py +269 -0
- executorch/examples/llm_server/python/tests/test_session_runtime.py +244 -0
- executorch/examples/llm_server/python/tests/test_sessions.py +426 -0
- executorch/examples/llm_server/python/tests/test_streaming_stops.py +274 -0
- executorch/examples/llm_server/python/tests/test_template.py +382 -0
- executorch/examples/llm_server/python/tests/test_tool_calls.py +221 -0
- executorch/examples/llm_server/python/tests/test_warm_resume_scaffold.py +745 -0
- executorch/examples/llm_server/python/tests/test_worker_client.py +261 -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 +275 -0
- executorch/examples/models/__init__.py +120 -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/tests/test_speech_transform.py +107 -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 +353 -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/quant/tests/test_pack_cuda.py +492 -0
- executorch/examples/models/gemma4_31b/quant/tests/test_quantize.py +230 -0
- executorch/examples/models/gemma4_31b/quant/tests/test_recipe.py +167 -0
- executorch/examples/models/gemma4_31b/quant/tests/test_safetensors_roundtrip.py +143 -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_cuda_packers.py +501 -0
- executorch/examples/models/gemma4_31b/tests/test_cuda_pipeline.py +334 -0
- executorch/examples/models/gemma4_31b/tests/test_mlx_pipeline.py +582 -0
- executorch/examples/models/gemma4_31b/tests/test_pipeline.py +504 -0
- executorch/examples/models/gemma4_31b/tests/test_recipe.py +61 -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_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 +112 -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 +882 -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 +106 -0
- executorch/examples/models/llama/convert_weights.py +61 -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 +89 -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 +1932 -0
- executorch/examples/models/llama/fairseq2.py +63 -0
- executorch/examples/models/llama/feed_forward.py +72 -0
- executorch/examples/models/llama/hf_download.py +50 -0
- executorch/examples/models/llama/install_requirement_helper.py +29 -0
- executorch/examples/models/llama/llama_transformer.py +523 -0
- executorch/examples/models/llama/lora.py +80 -0
- executorch/examples/models/llama/model.py +396 -0
- executorch/examples/models/llama/model_args.py +234 -0
- executorch/examples/models/llama/norm.py +172 -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 +378 -0
- executorch/examples/models/llama/source_transformation/custom_kv_cache.py +714 -0
- executorch/examples/models/llama/source_transformation/lora.py +153 -0
- executorch/examples/models/llama/source_transformation/pre_quantization.py +340 -0
- executorch/examples/models/llama/source_transformation/prune_vocab.py +119 -0
- executorch/examples/models/llama/source_transformation/quantize.py +904 -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 +550 -0
- executorch/examples/models/llama/source_transformation/spin_quant.py +88 -0
- executorch/examples/models/llama/source_transformation/test_attention_sink.py +462 -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 +97 -0
- executorch/examples/models/llama/static_attention.py +1601 -0
- executorch/examples/models/llama/tests/test_export_llama_lib.py +158 -0
- executorch/examples/models/llama/tests/test_pre_quantization_transforms.py +188 -0
- executorch/examples/models/llama/tests/test_qwen3_5_attention.py +128 -0
- executorch/examples/models/llama/tests/test_replace_kv_cache.py +158 -0
- executorch/examples/models/llama/tests/test_ring_attention.py +359 -0
- executorch/examples/models/llama/tests/test_ring_kv_cache.py +492 -0
- executorch/examples/models/llama/tests/test_simple_sdpa.py +66 -0
- executorch/examples/models/llama/tests/test_static_attention.py +624 -0
- executorch/examples/models/llama/tests/test_yoco_attention.py +708 -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/text_decoder/test/__init__.py +0 -0
- executorch/examples/models/llama3_2_vision/text_decoder/test/test_text_decoder.py +88 -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/llama3_2_vision/vision_encoder/test/test_vision_encoder.py +46 -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 +20 -0
- executorch/examples/models/mlperf_tiny/deep_autoencoder.py +40 -0
- executorch/examples/models/mlperf_tiny/ds_cnn.py +86 -0
- executorch/examples/models/mlperf_tiny/mobilenet_v1_025.py +94 -0
- executorch/examples/models/mlperf_tiny/resnet8.py +93 -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/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/tests/test_convert_weights.py +108 -0
- executorch/examples/models/qwen3_5_moe/__init__.py +0 -0
- executorch/examples/models/qwen3_5_moe/export.py +1383 -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/stable_diffusion/__init__.py +21 -0
- executorch/examples/models/stable_diffusion/model.py +202 -0
- executorch/examples/models/test/__init__.py +0 -0
- executorch/examples/models/test/test_export.py +161 -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 +677 -0
- executorch/examples/models/voxtral_realtime/model.py +1517 -0
- executorch/examples/models/voxtral_realtime/tests/test_ring_kv_cache.py +42 -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 +397 -0
- executorch/examples/models/yolo26/model.py +30 -0
- executorch/examples/nxp/experimental/cifar_net/cifar_net.py +301 -0
- executorch/examples/qualcomm/__init__.py +5 -0
- executorch/examples/qualcomm/custom_op/custom_ops_1.py +305 -0
- executorch/examples/qualcomm/custom_op/custom_ops_2.py +315 -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 +152 -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/hf_causal_lm.py +260 -0
- executorch/examples/qualcomm/oss_scripts/llama/__init__.py +604 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/__init__.py +53 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/builders.py +348 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/collators.py +75 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/config.py +41 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/datasets.py +41 -0
- executorch/examples/qualcomm/oss_scripts/llama/dataset/loaders.py +105 -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/decoder_constants.py +66 -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 +794 -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 +148 -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 +870 -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 +16 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/apply_rope.py +52 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/audio_encoder.py +157 -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 +1088 -0
- executorch/examples/qualcomm/oss_scripts/llama/model/vision_encoder.py +364 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/__init__.py +12 -0
- executorch/examples/qualcomm/oss_scripts/llama/quantize/ptq.py +77 -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 +738 -0
- executorch/examples/qualcomm/oss_scripts/llama/tokenizer.py +414 -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 +197 -0
- executorch/examples/qualcomm/oss_scripts/llama/wrappers/llm_wrappers.py +1344 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/decoder_model_wrapper.py +165 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/eval_decoder_model_qnn.py +299 -0
- executorch/examples/qualcomm/oss_scripts/llm_utils/qnn_decoder_model_manager.py +341 -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 +507 -0
- executorch/examples/qualcomm/qaihub_scripts/utils/utils.py +82 -0
- executorch/examples/qualcomm/scripts/deeplab_v3.py +200 -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 +681 -0
- executorch/examples/qualcomm/util_scripts/gen_etrecord.py +104 -0
- executorch/examples/qualcomm/util_scripts/qairt_visualizer_demo.py +93 -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 +148 -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 +104 -0
- executorch/exir/_serialize/__init__.py +20 -0
- executorch/exir/_serialize/_cord.py +49 -0
- executorch/exir/_serialize/_dataclass.py +145 -0
- executorch/exir/_serialize/_flatbuffer.py +426 -0
- executorch/exir/_serialize/_flatbuffer_program.py +359 -0
- executorch/exir/_serialize/_named_data_store.py +246 -0
- executorch/exir/_serialize/_program.py +827 -0
- executorch/exir/_serialize/_serialize.py +123 -0
- executorch/exir/_serialize/data_serializer.py +80 -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 +158 -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 +91 -0
- executorch/exir/_serialize/padding.py +39 -0
- executorch/exir/_serialize/program.fbs +534 -0
- executorch/exir/_serialize/scalar_type.fbs +43 -0
- executorch/exir/_serialize/test/__init__.py +0 -0
- executorch/exir/_serialize/test/test_cord.py +63 -0
- executorch/exir/_serialize/test/test_flatbuffer.py +273 -0
- executorch/exir/_serialize/test/test_flatbuffer_program.py +174 -0
- executorch/exir/_serialize/test/test_named_data_store.py +249 -0
- executorch/exir/_serialize/test/test_program.py +1369 -0
- executorch/exir/_serialize/test/test_serialize.py +289 -0
- executorch/exir/_warnings.py +44 -0
- executorch/exir/backend/backend_api.py +794 -0
- executorch/exir/backend/backend_details.py +150 -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 +151 -0
- executorch/exir/backend/canonical_partitioners/duplicate_dequant_node_pass.py +111 -0
- executorch/exir/backend/canonical_partitioners/group_partitioner.py +382 -0
- executorch/exir/backend/canonical_partitioners/pattern_op_partitioner.py +185 -0
- executorch/exir/backend/compile_spec_schema.py +17 -0
- executorch/exir/backend/operator_support.py +127 -0
- executorch/exir/backend/partitioner.py +114 -0
- executorch/exir/backend/test/backend_with_compiler_demo.py +142 -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/demos/rpc/test_rpc.py +189 -0
- executorch/exir/backend/test/demos/test_delegate_aten_mode.py +72 -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/test/test_backend_with_named_data_map.py +85 -0
- executorch/exir/backend/test/test_backends_lifted.py +1322 -0
- executorch/exir/backend/test/test_backends_nested.py +258 -0
- executorch/exir/backend/test/test_compatibility.py +118 -0
- executorch/exir/backend/test/test_debug_handle_map.py +136 -0
- executorch/exir/backend/test/test_delegate_map_builder.py +274 -0
- executorch/exir/backend/test/test_graph_partition.py +248 -0
- executorch/exir/backend/test/test_group_partitioner.py +1770 -0
- executorch/exir/backend/test/test_lowered_backend_module.py +281 -0
- executorch/exir/backend/test/test_partitioner.py +731 -0
- executorch/exir/backend/test/test_passes.py +88 -0
- executorch/exir/backend/test/test_to_backend_multi_method.py +595 -0
- executorch/exir/backend/test/test_utils.py +392 -0
- executorch/exir/backend/utils.py +724 -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/backend/test/test_backend_ops.py +88 -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/op/test/test_api.py +51 -0
- executorch/exir/dialects/edge/spec/gen.py +523 -0
- executorch/exir/dialects/edge/spec/utils.py +328 -0
- executorch/exir/dialects/edge/test/test_edge_ops.py +443 -0
- executorch/exir/dialects/edge/test/test_edge_yaml.py +225 -0
- executorch/exir/dialects/test/test_exir_dialect_ops.py +22 -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 +2117 -0
- executorch/exir/emit/test/test_emit.py +2812 -0
- executorch/exir/error.py +55 -0
- executorch/exir/graph.py +86 -0
- executorch/exir/graph_module.py +153 -0
- executorch/exir/lowered_backend_module.py +1073 -0
- executorch/exir/memory.py +50 -0
- executorch/exir/memory_planning.py +1610 -0
- executorch/exir/operator/convert.py +371 -0
- executorch/exir/operator/manip.py +89 -0
- executorch/exir/operator/test/test_operator.py +172 -0
- executorch/exir/operator/util.py +68 -0
- executorch/exir/pass_base.py +979 -0
- executorch/exir/pass_manager.py +241 -0
- executorch/exir/passes/__init__.py +545 -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 +402 -0
- executorch/exir/passes/convert_constant_dim_order_pass.py +86 -0
- executorch/exir/passes/cse_pass.py +201 -0
- executorch/exir/passes/debug_handle_generator_pass.py +81 -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/init_mutable_pass.py +32 -0
- executorch/exir/passes/insert_write_back_for_buffers_pass.py +185 -0
- executorch/exir/passes/legalize_portable_dim_order_pass.py +69 -0
- executorch/exir/passes/memory_format_ops_pass.py +139 -0
- executorch/exir/passes/memory_planning_pass.py +329 -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 +56 -0
- executorch/exir/passes/propagate_device_pass.py +458 -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 +95 -0
- executorch/exir/passes/remove_noop_pass.py +129 -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 +327 -0
- executorch/exir/passes/scalar_to_tensor_pass.py +44 -0
- executorch/exir/passes/spec_prop_pass.py +132 -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 +428 -0
- executorch/exir/program/__init__.py +32 -0
- executorch/exir/program/_fake_program.py +67 -0
- executorch/exir/program/_program.py +1998 -0
- executorch/exir/program/test/__init__.py +0 -0
- executorch/exir/program/test/test_fake_program.py +78 -0
- executorch/exir/program/test/test_program.py +952 -0
- executorch/exir/scalar_type.py +38 -0
- executorch/exir/schema.py +330 -0
- executorch/exir/serde/__init__.py +0 -0
- executorch/exir/serde/export_serialize.py +2875 -0
- executorch/exir/serde/schema.py +409 -0
- executorch/exir/serde/schema_check.py +293 -0
- executorch/exir/serde/serialize.py +838 -0
- executorch/exir/serde/union.py +77 -0
- executorch/exir/sym_util.py +105 -0
- executorch/exir/tensor.py +413 -0
- executorch/exir/tensor_layout.py +39 -0
- executorch/exir/tests/asr_joiner.py +82 -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_arg_validator.py +72 -0
- executorch/exir/tests/test_common.py +81 -0
- executorch/exir/tests/test_delegate.py +308 -0
- executorch/exir/tests/test_device_copy_ops.py +73 -0
- executorch/exir/tests/test_dim_order_utils.py +49 -0
- executorch/exir/tests/test_dynamic_shape_propagation.py +174 -0
- executorch/exir/tests/test_error.py +19 -0
- executorch/exir/tests/test_extract_io_quant_params.py +93 -0
- executorch/exir/tests/test_joint_graph.py +124 -0
- executorch/exir/tests/test_legalize_portable_dim_order_pass.py +228 -0
- executorch/exir/tests/test_memory_format_ops_pass.py +443 -0
- executorch/exir/tests/test_memory_format_ops_pass_aten.py +142 -0
- executorch/exir/tests/test_memory_format_ops_pass_utils.py +266 -0
- executorch/exir/tests/test_memory_planning.py +1767 -0
- executorch/exir/tests/test_op_convert.py +88 -0
- executorch/exir/tests/test_pass_infra.py +559 -0
- executorch/exir/tests/test_passes.py +2898 -0
- executorch/exir/tests/test_print_program.py +54 -0
- executorch/exir/tests/test_propagate_device_pass.py +1275 -0
- executorch/exir/tests/test_prune_empty_tensors_pass.py +112 -0
- executorch/exir/tests/test_quant_fusion_pass.py +548 -0
- executorch/exir/tests/test_quantization.py +120 -0
- executorch/exir/tests/test_quantize_io_pass.py +156 -0
- executorch/exir/tests/test_reinplace_pass.py +725 -0
- executorch/exir/tests/test_remove_unused_parameters_pass.py +205 -0
- executorch/exir/tests/test_remove_view_copy.py +236 -0
- executorch/exir/tests/test_serde.py +352 -0
- executorch/exir/tests/test_tensor.py +416 -0
- executorch/exir/tests/test_verification.py +326 -0
- executorch/exir/tests/test_warnings.py +169 -0
- executorch/exir/tests/transformer.py +122 -0
- executorch/exir/tracer.py +803 -0
- executorch/exir/types.py +18 -0
- executorch/exir/verification/arg_validator.py +140 -0
- executorch/exir/verification/dev_html.py +68 -0
- executorch/exir/verification/interpreter.py +425 -0
- executorch/exir/verification/test/test_verifier.py +137 -0
- executorch/exir/verification/verifier.py +346 -0
- executorch/exir/version.py +9 -0
- executorch/exir/wrap.py +32 -0
- executorch/export/__init__.py +40 -0
- executorch/export/export.py +696 -0
- executorch/export/recipe.py +328 -0
- executorch/export/recipe_provider.py +60 -0
- executorch/export/recipe_registry.py +86 -0
- executorch/export/stages.py +686 -0
- executorch/export/target_recipes.py +185 -0
- executorch/export/tests/test_executorch_export.py +34 -0
- executorch/export/tests/test_export_recipe.py +131 -0
- executorch/export/tests/test_export_session.py +973 -0
- executorch/export/tests/test_export_stages.py +534 -0
- executorch/export/tests/test_recipe_provider.py +98 -0
- executorch/export/tests/test_recipe_registry.py +139 -0
- executorch/export/tests/test_target_recipes.py +539 -0
- executorch/export/types.py +22 -0
- executorch/export/utils.py +51 -0
- executorch/extension/apple/ExecuTorch/__tests__/resources/generate_coreml_test_models.py +81 -0
- executorch/extension/audio/mel_spectrogram.py +332 -0
- executorch/extension/export_util/__init__.py +13 -0
- executorch/extension/export_util/utils.py +147 -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 +446 -0
- executorch/extension/flat_tensor/test/test_serialize.py +326 -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/custom_ops/__init__.py +0 -0
- executorch/extension/llm/custom_ops/custom_ops.py +581 -0
- executorch/extension/llm/custom_ops/custom_ops_aot_lib.dll +0 -0
- executorch/extension/llm/custom_ops/model_sharding.py +102 -0
- executorch/extension/llm/custom_ops/op_fallback.py +29 -0
- executorch/extension/llm/custom_ops/op_tile_crop_aot.py +38 -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/spinquant/third-party/FFHT/example.py +20 -0
- executorch/extension/llm/custom_ops/spinquant/third-party/FFHT/gen.py +869 -0
- executorch/extension/llm/custom_ops/test_preprocess_custom_ops.py +34 -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 +754 -0
- executorch/extension/llm/custom_ops/test_update_cross_attn_cache.py +286 -0
- executorch/extension/llm/export/__init__.py +11 -0
- executorch/extension/llm/export/builder.py +592 -0
- executorch/extension/llm/export/config/llm_config.py +912 -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 +315 -0
- executorch/extension/llm/export/nvfp4.py +191 -0
- executorch/extension/llm/export/partitioner_lib.py +278 -0
- executorch/extension/llm/export/quant/__init__.py +20 -0
- executorch/extension/llm/export/quant/convert.py +216 -0
- executorch/extension/llm/export/quant/quantize.py +386 -0
- executorch/extension/llm/export/quant/recipe.py +62 -0
- executorch/extension/llm/export/quant/test/test_convert.py +362 -0
- executorch/extension/llm/export/quant/test/test_quantize.py +310 -0
- executorch/extension/llm/export/quant/test/test_recipe.py +118 -0
- executorch/extension/llm/export/quant/test/test_safetensors_roundtrip.py +143 -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_builder.py +118 -0
- executorch/extension/llm/export/test/test_export_llm.py +155 -0
- executorch/extension/llm/export/test/test_gguf.py +409 -0
- executorch/extension/llm/export/test/test_int4.py +139 -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/test/test_attention.py +353 -0
- executorch/extension/llm/modules/test/test_kv_cache.py +218 -0
- executorch/extension/llm/modules/test/test_position_embeddings.py +230 -0
- executorch/extension/llm/modules/test/test_turboquant_kv_cache.py +262 -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 +238 -0
- executorch/extension/llm/runner/_llm_runner.pyi +596 -0
- executorch/extension/llm/runner/test/test_runner_pybindings.py +266 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/__init__.py +63 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/constants.py +31 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/hf_tokenizer.py +57 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/llama2c.py +111 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/tiktoken.py +197 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/__init__.py +0 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/llama2c/__init__.py +0 -0
- executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/llama2c/convert.py +49 -0
- executorch/extension/llm/tokenizers/setup.py +200 -0
- executorch/extension/llm/tokenizers/test/test_hf_tokenizer.py +96 -0
- executorch/extension/llm/tokenizers/test/test_python_bindings.py +131 -0
- executorch/extension/llm/tokenizers/test/test_tekken_python.py +453 -0
- executorch/extension/llm/tokenizers/test/test_tiktoken.py +49 -0
- executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/abseil.podspec.gen.py +243 -0
- executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/copts/copts.py +194 -0
- executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/copts/generate_copts.py +109 -0
- executorch/extension/llm/tokenizers/third-party/abseil-cpp/conanfile.py +51 -0
- executorch/extension/llm/tokenizers/third-party/abseil-cpp/create_lts.py +139 -0
- executorch/extension/llm/tokenizers/third-party/json/docs/mkdocs/scripts/check_structure.py +179 -0
- executorch/extension/llm/tokenizers/third-party/json/tests/thirdparty/imapdl/filterbr.py +109 -0
- executorch/extension/llm/tokenizers/third-party/json/tools/amalgamate/amalgamate.py +299 -0
- executorch/extension/llm/tokenizers/third-party/json/tools/gdb_pretty_printer/nlohmann-json.py +32 -0
- executorch/extension/llm/tokenizers/third-party/json/tools/generate_natvis/generate_natvis.py +41 -0
- executorch/extension/llm/tokenizers/third-party/json/tools/serve_header/serve_header.py +410 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateCommon.py +354 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateTest.py +186 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcd.py +999 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcpHeader.py +98 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcpTables.py +203 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateCommon.py +31 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateDates.py +59 -0
- executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateRelease.py +29 -0
- executorch/extension/llm/tokenizers/third-party/re2/benchlog/benchplot.py +98 -0
- executorch/extension/llm/tokenizers/third-party/re2/python/re2.py +583 -0
- executorch/extension/llm/tokenizers/third-party/re2/python/re2_test.py +489 -0
- executorch/extension/llm/tokenizers/third-party/re2/python/setup.py +158 -0
- executorch/extension/llm/tokenizers/third-party/re2/python/toolchains/generate.py +98 -0
- executorch/extension/llm/tokenizers/third-party/re2/re2/make_unicode_casefold.py +151 -0
- executorch/extension/llm/tokenizers/third-party/re2/re2/make_unicode_groups.py +117 -0
- executorch/extension/llm/tokenizers/third-party/re2/re2/unicode.py +284 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/setup.py +225 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/__init__.py +1224 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/_version.py +1 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/sentencepiece_model_pb2.py +44 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/sentencepiece_pb2.py +30 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/test/__init__.py +0 -0
- executorch/extension/llm/tokenizers/third-party/sentencepiece/python/test/sentencepiece_test.py +937 -0
- executorch/extension/module/test/resources/gen_bundled_program.py +99 -0
- executorch/extension/pybindings/_portable_lib.cp314-win_amd64.pyd +0 -0
- executorch/extension/pybindings/data_loader.cp314-win_amd64.pyd +0 -0
- executorch/extension/pybindings/data_loader.pyi +12 -0
- executorch/extension/pybindings/portable_lib.py +108 -0
- executorch/extension/pybindings/pybindings.pyi +393 -0
- executorch/extension/pybindings/test/make_test.py +186 -0
- executorch/extension/pybindings/test/test_backend_pybinding.py +27 -0
- executorch/extension/pybindings/test/test_pybindings.py +735 -0
- executorch/extension/pytree/__init__.py +54 -0
- executorch/extension/pytree/test/test.py +331 -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/examples/XOR/test/test_export.py +19 -0
- executorch/extension/training/pybindings/_training_lib.pyi +45 -0
- executorch/extension/training/pybindings/_training_module.py +86 -0
- executorch/extension/training/pybindings/test/test.py +67 -0
- executorch/extension/wasm/test/test_model.py +34 -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/tensor/tensor.h +14 -0
- executorch/include/executorch/extension/tensor/tensor_accessor.h +218 -0
- executorch/include/executorch/extension/tensor/tensor_ptr.h +561 -0
- executorch/include/executorch/extension/tensor/tensor_ptr_maker.h +687 -0
- executorch/include/executorch/extension/threadpool/cpuinfo_utils.h +24 -0
- executorch/include/executorch/extension/threadpool/threadpool.h +130 -0
- executorch/include/executorch/extension/threadpool/threadpool_guard.h +37 -0
- executorch/include/executorch/runtime/backend/backend_execution_context.h +80 -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 +230 -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 +141 -0
- executorch/include/executorch/runtime/core/defines.h +20 -0
- executorch/include/executorch/runtime/core/device_allocator.h +198 -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 +867 -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/testing_util/tensor_factory.h +1133 -0
- executorch/include/executorch/runtime/core/exec_aten/testing_util/tensor_util.h +378 -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 +21 -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 +218 -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 +75 -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 +299 -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 +78 -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/complex_utils.h +46 -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 +123 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +905 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +100 -0
- executorch/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +114 -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 +741 -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 +148 -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 +616 -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/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 +340 -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/core/test/mock_cuda_allocator.h +146 -0
- executorch/include/executorch/runtime/core/testing_util/error_matchers.h +303 -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 +465 -0
- executorch/include/executorch/runtime/executor/method_meta.h +316 -0
- executorch/include/executorch/runtime/executor/platform_memory_allocator.h +124 -0
- executorch/include/executorch/runtime/executor/program.h +329 -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/executor/tensor_parser.h +167 -0
- executorch/include/executorch/runtime/executor/test/managed_memory_manager.h +68 -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/test/test_util.h +40 -0
- executorch/include/executorch/runtime/kernel/thread_parallel_interface.h +107 -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 +225 -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/test/pal_spy.h +86 -0
- executorch/include/executorch/runtime/platform/test/stub_platform.h +76 -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 +1071 -0
- executorch/kernels/portable/test/op_grid_sampler_2d_test.py +234 -0
- executorch/kernels/portable/test/op_upsample_bilinear2d_aa_test.py +356 -0
- executorch/kernels/portable/test/op_upsample_bilinear2d_test.py +87 -0
- executorch/kernels/portable/test/op_upsample_nearest2d_test.py +71 -0
- executorch/kernels/portable/test/supported_features_def.yaml +1 -0
- executorch/kernels/portable/test/test_grid_sampler_2d_executorch.py +458 -0
- executorch/kernels/quantized/__init__.py +21 -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/kernels/quantized/test/test_out_variants.py +100 -0
- executorch/kernels/quantized/test/test_quant_dequant_per_token.py +149 -0
- executorch/runtime/__init__.py +334 -0
- executorch/runtime/kernel/test/functions.yaml +13 -0
- executorch/runtime/test/test_runtime.py +106 -0
- executorch/runtime/test/test_runtime_etdump_gen.py +163 -0
- executorch/runtime/test/test_runtime_xnnpack.py +181 -0
- executorch/schema/program.fbs +534 -0
- executorch/schema/scalar_type.fbs +43 -0
- executorch/schema/test/test_schema.py +52 -0
- executorch/share/cmake/executorch-config.cmake +78 -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.4.0.dist-info/METADATA +109 -0
- executorch-1.4.0.dist-info/RECORD +4120 -0
- executorch-1.4.0.dist-info/WHEEL +5 -0
- executorch-1.4.0.dist-info/entry_points.txt +2 -0
- executorch-1.4.0.dist-info/licenses/LICENSE +37 -0
- executorch-1.4.0.dist-info/top_level.txt +9 -0
|
@@ -0,0 +1,3520 @@
|
|
|
1
|
+
# Copyright © 2023-2024 Apple Inc.
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import os
|
|
5
|
+
import unittest
|
|
6
|
+
from itertools import permutations, product
|
|
7
|
+
|
|
8
|
+
import mlx.core as mx
|
|
9
|
+
import mlx_tests
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def np_wrap_between(x, a):
|
|
14
|
+
"""Wraps `x` between `[-a, a]`."""
|
|
15
|
+
two_a = 2 * a
|
|
16
|
+
zero = 0
|
|
17
|
+
rem = np.remainder(np.add(x, a), two_a)
|
|
18
|
+
if isinstance(rem, np.ndarray):
|
|
19
|
+
rem = np.select(rem < zero, np.add(rem, two_a), rem)
|
|
20
|
+
else:
|
|
21
|
+
rem = np.add(rem, two_a) if rem < zero else rem
|
|
22
|
+
return np.subtract(rem, a)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def np_logaddexp(x1: np.ndarray, x2: np.ndarray):
|
|
26
|
+
amax = np.maximum(x1, x2)
|
|
27
|
+
if np.issubdtype(x1.dtype, np.floating):
|
|
28
|
+
delta = np.subtract(x1, x2)
|
|
29
|
+
if isinstance(delta, np.ndarray):
|
|
30
|
+
return np.select(
|
|
31
|
+
np.isnan(delta),
|
|
32
|
+
np.add(x1, x2),
|
|
33
|
+
np.add(amax, np.log1p(np.exp(np.negative(np.abs(delta))))),
|
|
34
|
+
)
|
|
35
|
+
else:
|
|
36
|
+
return (
|
|
37
|
+
np.add(x1, x2)
|
|
38
|
+
if np.isnan(delta)
|
|
39
|
+
else np.add(amax, np.log1p(np.exp(np.negative(np.abs(delta)))))
|
|
40
|
+
)
|
|
41
|
+
else:
|
|
42
|
+
delta = np.subtract(np.add(x1, x2), np.multiply(amax, 2))
|
|
43
|
+
out = np.add(amax, np.log1p(np.exp(delta)))
|
|
44
|
+
return np.real(out) + 1j * np_wrap_between(np.imag(out), np.pi)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def np_cumlogaddexp(x1: np.ndarray, axis: int = -1):
|
|
48
|
+
out = x1.copy()
|
|
49
|
+
for i in range(1, out.shape[axis]):
|
|
50
|
+
out[i] = np_logaddexp(out[i], out[i - 1])
|
|
51
|
+
return out
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class TestOps(mlx_tests.MLXTestCase):
|
|
55
|
+
def test_full_ones_zeros(self):
|
|
56
|
+
x = mx.full(2, 3.0)
|
|
57
|
+
self.assertEqual(x.shape, (2,))
|
|
58
|
+
self.assertEqual(x.tolist(), [3.0, 3.0])
|
|
59
|
+
|
|
60
|
+
x = mx.full((2, 3), 2.0)
|
|
61
|
+
self.assertEqual(x.dtype, mx.float32)
|
|
62
|
+
self.assertEqual(x.shape, (2, 3))
|
|
63
|
+
self.assertEqual(x.tolist(), [[2, 2, 2], [2, 2, 2]])
|
|
64
|
+
|
|
65
|
+
x = mx.full([3, 2], mx.array([False, True]))
|
|
66
|
+
self.assertEqual(x.dtype, mx.bool_)
|
|
67
|
+
self.assertEqual(x.tolist(), [[False, True], [False, True], [False, True]])
|
|
68
|
+
|
|
69
|
+
x = mx.full([3, 2], mx.array([2.0, 3.0]))
|
|
70
|
+
self.assertEqual(x.tolist(), [[2, 3], [2, 3], [2, 3]])
|
|
71
|
+
|
|
72
|
+
x = mx.zeros(2)
|
|
73
|
+
self.assertEqual(x.shape, (2,))
|
|
74
|
+
self.assertEqual(x.tolist(), [0.0, 0.0])
|
|
75
|
+
|
|
76
|
+
x = mx.ones(2)
|
|
77
|
+
self.assertEqual(x.shape, (2,))
|
|
78
|
+
self.assertEqual(x.tolist(), [1.0, 1.0])
|
|
79
|
+
|
|
80
|
+
for t in [mx.bool_, mx.int32, mx.float32]:
|
|
81
|
+
x = mx.zeros([2, 2], t)
|
|
82
|
+
self.assertEqual(x.dtype, t)
|
|
83
|
+
self.assertTrue(mx.array_equal(x, mx.array([[0, 0], [0, 0]])))
|
|
84
|
+
y = mx.zeros_like(x)
|
|
85
|
+
self.assertEqual(y.dtype, t)
|
|
86
|
+
self.assertTrue(mx.array_equal(y, x))
|
|
87
|
+
|
|
88
|
+
x = mx.ones([2, 2], t)
|
|
89
|
+
self.assertEqual(x.dtype, t)
|
|
90
|
+
self.assertTrue(mx.array_equal(x, mx.array([[1, 1], [1, 1]])))
|
|
91
|
+
y = mx.ones_like(x)
|
|
92
|
+
self.assertEqual(y.dtype, t)
|
|
93
|
+
self.assertTrue(mx.array_equal(y, x))
|
|
94
|
+
|
|
95
|
+
def test_shape_overflow_error(self):
|
|
96
|
+
# Shape dimensions that don't fit in int32 should raise a clear
|
|
97
|
+
# OverflowError that names the offending value, rather than a generic
|
|
98
|
+
# "incompatible function arguments" TypeError. The overflow check
|
|
99
|
+
# lives in the mx::Shape type caster, so it applies to every op that
|
|
100
|
+
# takes a shape. See issue #2681.
|
|
101
|
+
too_big = 2**31
|
|
102
|
+
|
|
103
|
+
# Array creation ops — also exercise the scalar shape path.
|
|
104
|
+
for ctor in (mx.zeros, mx.ones):
|
|
105
|
+
with self.assertRaises(OverflowError) as cm:
|
|
106
|
+
ctor(too_big)
|
|
107
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
108
|
+
with self.assertRaises(OverflowError) as cm:
|
|
109
|
+
ctor([too_big])
|
|
110
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
111
|
+
|
|
112
|
+
with self.assertRaises(OverflowError) as cm:
|
|
113
|
+
mx.full(too_big, 0.0)
|
|
114
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
115
|
+
with self.assertRaises(OverflowError) as cm:
|
|
116
|
+
mx.full([too_big], 0.0)
|
|
117
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
118
|
+
|
|
119
|
+
# Other shape-taking ops should surface the same clean error.
|
|
120
|
+
a = mx.zeros(4)
|
|
121
|
+
with self.assertRaises(OverflowError) as cm:
|
|
122
|
+
mx.reshape(a, [too_big])
|
|
123
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
124
|
+
|
|
125
|
+
with self.assertRaises(OverflowError) as cm:
|
|
126
|
+
mx.broadcast_to(a, [too_big, 1])
|
|
127
|
+
self.assertIn(str(too_big), str(cm.exception))
|
|
128
|
+
|
|
129
|
+
# Negative overflow (< int32 min) is caught too.
|
|
130
|
+
too_negative = -(2**31) - 1
|
|
131
|
+
with self.assertRaises(OverflowError) as cm:
|
|
132
|
+
mx.zeros([too_negative])
|
|
133
|
+
self.assertIn(str(too_negative), str(cm.exception))
|
|
134
|
+
|
|
135
|
+
# Shapes that fit in int32 still go through unchanged.
|
|
136
|
+
self.assertEqual(mx.zeros(4).shape, (4,))
|
|
137
|
+
self.assertEqual(mx.zeros((2, 3)).shape, (2, 3))
|
|
138
|
+
self.assertEqual(mx.ones([2, 3]).shape, (2, 3))
|
|
139
|
+
self.assertEqual(mx.full((2, 3), 1.5).tolist(), [[1.5] * 3] * 2)
|
|
140
|
+
|
|
141
|
+
def test_scalar_inputs(self):
|
|
142
|
+
# Check combinations of python types
|
|
143
|
+
a = mx.add(False, True)
|
|
144
|
+
self.assertEqual(a.dtype, mx.bool_)
|
|
145
|
+
self.assertEqual(a.item(), True)
|
|
146
|
+
|
|
147
|
+
a = mx.add(1, 2)
|
|
148
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
149
|
+
self.assertEqual(a.item(), 3)
|
|
150
|
+
|
|
151
|
+
a = mx.add(1.0, 2.0)
|
|
152
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
153
|
+
self.assertEqual(a.item(), 3.0)
|
|
154
|
+
|
|
155
|
+
a = mx.add(True, 2)
|
|
156
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
157
|
+
self.assertEqual(a.item(), 3)
|
|
158
|
+
|
|
159
|
+
a = mx.add(True, 2.0)
|
|
160
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
161
|
+
self.assertEqual(a.item(), 3.0)
|
|
162
|
+
|
|
163
|
+
a = mx.add(1, 2.0)
|
|
164
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
165
|
+
self.assertEqual(a.item(), 3.0)
|
|
166
|
+
|
|
167
|
+
a = mx.add(2, True)
|
|
168
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
169
|
+
self.assertEqual(a.item(), 3)
|
|
170
|
+
|
|
171
|
+
a = mx.add(2.0, True)
|
|
172
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
173
|
+
self.assertEqual(a.item(), 3.0)
|
|
174
|
+
|
|
175
|
+
a = mx.add(2.0, 1)
|
|
176
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
177
|
+
self.assertEqual(a.item(), 3.0)
|
|
178
|
+
|
|
179
|
+
# Check combinations with mlx arrays
|
|
180
|
+
a = mx.add(mx.array(True), False)
|
|
181
|
+
self.assertEqual(a.dtype, mx.bool_)
|
|
182
|
+
self.assertEqual(a.item(), True)
|
|
183
|
+
|
|
184
|
+
a = mx.add(mx.array(1), False)
|
|
185
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
186
|
+
self.assertEqual(a.item(), 1.0)
|
|
187
|
+
|
|
188
|
+
# Edge case: take the type of the scalar
|
|
189
|
+
a = mx.add(mx.array(True), 1)
|
|
190
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
191
|
+
self.assertEqual(a.item(), 2)
|
|
192
|
+
|
|
193
|
+
a = mx.add(mx.array(1.0), 1)
|
|
194
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
195
|
+
self.assertEqual(a.item(), 2.0)
|
|
196
|
+
|
|
197
|
+
a = mx.add(1, mx.array(1.0))
|
|
198
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
199
|
+
self.assertEqual(a.item(), 2.0)
|
|
200
|
+
|
|
201
|
+
binary_ops = [
|
|
202
|
+
"add",
|
|
203
|
+
"subtract",
|
|
204
|
+
"multiply",
|
|
205
|
+
"divide",
|
|
206
|
+
"floor_divide",
|
|
207
|
+
"remainder",
|
|
208
|
+
"equal",
|
|
209
|
+
"not_equal",
|
|
210
|
+
"less",
|
|
211
|
+
"greater",
|
|
212
|
+
"less_equal",
|
|
213
|
+
"greater_equal",
|
|
214
|
+
"maximum",
|
|
215
|
+
"minimum",
|
|
216
|
+
]
|
|
217
|
+
|
|
218
|
+
for op in binary_ops:
|
|
219
|
+
npop = getattr(np, op)
|
|
220
|
+
mlxop = getattr(mx, op)
|
|
221
|
+
|
|
222
|
+
# Avoid subtract from bool and divide by 0
|
|
223
|
+
for x in [-1, 0, 1, -1.0, 1.0]:
|
|
224
|
+
for y in [True, -1, 1, -1.0, 1.0]:
|
|
225
|
+
self.assertEqual(npop(x, y).item(), mlxop(x, y).item())
|
|
226
|
+
|
|
227
|
+
def test_add(self):
|
|
228
|
+
x = mx.array(1)
|
|
229
|
+
y = mx.array(1)
|
|
230
|
+
z = mx.add(x, y)
|
|
231
|
+
self.assertEqual(z.item(), 2)
|
|
232
|
+
|
|
233
|
+
x = mx.array(False, mx.bool_)
|
|
234
|
+
z = x + 1
|
|
235
|
+
self.assertEqual(z.dtype, mx.int32)
|
|
236
|
+
self.assertEqual(z.item(), 1)
|
|
237
|
+
z = 2 + x
|
|
238
|
+
self.assertEqual(z.dtype, mx.int32)
|
|
239
|
+
self.assertEqual(z.item(), 2)
|
|
240
|
+
|
|
241
|
+
x = mx.array(1, mx.uint32)
|
|
242
|
+
z = x + 3
|
|
243
|
+
self.assertEqual(z.dtype, mx.uint32)
|
|
244
|
+
self.assertEqual(z.item(), 4)
|
|
245
|
+
|
|
246
|
+
z = 3 + x
|
|
247
|
+
self.assertEqual(z.dtype, mx.uint32)
|
|
248
|
+
self.assertEqual(z.item(), 4)
|
|
249
|
+
|
|
250
|
+
z = x + 3.0
|
|
251
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
252
|
+
self.assertEqual(z.item(), 4.0)
|
|
253
|
+
|
|
254
|
+
z = 3.0 + x
|
|
255
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
256
|
+
self.assertEqual(z.item(), 4.0)
|
|
257
|
+
|
|
258
|
+
x = mx.array(1, mx.int64)
|
|
259
|
+
z = x + 3
|
|
260
|
+
self.assertEqual(z.dtype, mx.int64)
|
|
261
|
+
self.assertEqual(z.item(), 4)
|
|
262
|
+
z = 3 + x
|
|
263
|
+
self.assertEqual(z.dtype, mx.int64)
|
|
264
|
+
self.assertEqual(z.item(), 4)
|
|
265
|
+
z = x + 3.0
|
|
266
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
267
|
+
self.assertEqual(z.item(), 4.0)
|
|
268
|
+
z = 3.0 + x
|
|
269
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
270
|
+
self.assertEqual(z.item(), 4.0)
|
|
271
|
+
|
|
272
|
+
x = mx.array(1, mx.float32)
|
|
273
|
+
z = x + 3
|
|
274
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
275
|
+
self.assertEqual(z.item(), 4)
|
|
276
|
+
z = 3 + x
|
|
277
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
278
|
+
self.assertEqual(z.item(), 4)
|
|
279
|
+
|
|
280
|
+
def test_subtract(self):
|
|
281
|
+
x = mx.array(4.0)
|
|
282
|
+
y = mx.array(3.0)
|
|
283
|
+
|
|
284
|
+
z = mx.subtract(x, y)
|
|
285
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
286
|
+
self.assertEqual(z.item(), 1.0)
|
|
287
|
+
|
|
288
|
+
z = x - 3.0
|
|
289
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
290
|
+
self.assertEqual(z.item(), 1.0)
|
|
291
|
+
|
|
292
|
+
z = 5.0 - x
|
|
293
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
294
|
+
self.assertEqual(z.item(), 1.0)
|
|
295
|
+
|
|
296
|
+
def test_multiply(self):
|
|
297
|
+
x = mx.array(2.0)
|
|
298
|
+
y = mx.array(3.0)
|
|
299
|
+
|
|
300
|
+
z = mx.multiply(x, y)
|
|
301
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
302
|
+
self.assertEqual(z.item(), 6.0)
|
|
303
|
+
|
|
304
|
+
z = x * 3.0
|
|
305
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
306
|
+
self.assertEqual(z.item(), 6.0)
|
|
307
|
+
|
|
308
|
+
z = 3.0 * x
|
|
309
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
310
|
+
self.assertEqual(z.item(), 6.0)
|
|
311
|
+
|
|
312
|
+
def test_divide(self):
|
|
313
|
+
x = mx.array(2.0)
|
|
314
|
+
y = mx.array(4.0)
|
|
315
|
+
|
|
316
|
+
z = mx.divide(x, y)
|
|
317
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
318
|
+
self.assertEqual(z.item(), 0.5)
|
|
319
|
+
|
|
320
|
+
z = x / 4.0
|
|
321
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
322
|
+
self.assertEqual(z.item(), 0.5)
|
|
323
|
+
|
|
324
|
+
z = 1.0 / x
|
|
325
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
326
|
+
self.assertEqual(z.item(), 0.5)
|
|
327
|
+
|
|
328
|
+
x = x.astype(mx.float16)
|
|
329
|
+
z = x / 4.0
|
|
330
|
+
self.assertEqual(z.dtype, mx.float16)
|
|
331
|
+
|
|
332
|
+
x = x.astype(mx.float16)
|
|
333
|
+
z = 4.0 / x
|
|
334
|
+
self.assertEqual(z.dtype, mx.float16)
|
|
335
|
+
|
|
336
|
+
x = mx.array(5)
|
|
337
|
+
y = mx.array(2)
|
|
338
|
+
z = x / y
|
|
339
|
+
self.assertEqual(z.dtype, mx.float32)
|
|
340
|
+
self.assertEqual(z.item(), 2.5)
|
|
341
|
+
|
|
342
|
+
z = x // y
|
|
343
|
+
self.assertEqual(z.dtype, mx.int32)
|
|
344
|
+
self.assertEqual(z.item(), 2)
|
|
345
|
+
|
|
346
|
+
def test_remainder(self):
|
|
347
|
+
for dt in [mx.int32, mx.float32]:
|
|
348
|
+
x = mx.array(2, dtype=dt)
|
|
349
|
+
y = mx.array(4, dtype=dt)
|
|
350
|
+
|
|
351
|
+
z1 = mx.remainder(x, y)
|
|
352
|
+
z2 = mx.remainder(y, x)
|
|
353
|
+
self.assertEqual(z1.dtype, dt)
|
|
354
|
+
self.assertEqual(z1.item(), 2)
|
|
355
|
+
self.assertEqual(z2.item(), 0)
|
|
356
|
+
|
|
357
|
+
z = x % 4
|
|
358
|
+
self.assertEqual(z.dtype, dt)
|
|
359
|
+
self.assertEqual(z.item(), 2)
|
|
360
|
+
|
|
361
|
+
z = 1 % x
|
|
362
|
+
self.assertEqual(z.dtype, dt)
|
|
363
|
+
self.assertEqual(z.item(), 1)
|
|
364
|
+
|
|
365
|
+
z = -1 % x
|
|
366
|
+
self.assertEqual(z.dtype, dt)
|
|
367
|
+
self.assertEqual(z.item(), 1)
|
|
368
|
+
|
|
369
|
+
z = -1 % -x
|
|
370
|
+
self.assertEqual(z.dtype, dt)
|
|
371
|
+
self.assertEqual(z.item(), -1)
|
|
372
|
+
|
|
373
|
+
x = mx.arange(10).astype(dt) - 5
|
|
374
|
+
y = x % 5
|
|
375
|
+
z = x % -5
|
|
376
|
+
self.assertEqual(y.tolist(), [0, 1, 2, 3, 4, 0, 1, 2, 3, 4])
|
|
377
|
+
self.assertEqual(z.tolist(), [0, -4, -3, -2, -1, 0, -4, -3, -2, -1])
|
|
378
|
+
|
|
379
|
+
z = -mx.ones(64) % mx.full(64, 2)
|
|
380
|
+
self.assertTrue(mx.array_equal(z, mx.ones(64)))
|
|
381
|
+
|
|
382
|
+
def test_comparisons(self):
|
|
383
|
+
a = mx.array([0.0, 1.0, 5.0])
|
|
384
|
+
b = mx.array([-1.0, 2.0, 5.0])
|
|
385
|
+
|
|
386
|
+
self.assertEqual(mx.less(a, b).tolist(), [False, True, False])
|
|
387
|
+
self.assertEqual(mx.less_equal(a, b).tolist(), [False, True, True])
|
|
388
|
+
self.assertEqual(mx.greater(a, b).tolist(), [True, False, False])
|
|
389
|
+
self.assertEqual(mx.greater_equal(a, b).tolist(), [True, False, True])
|
|
390
|
+
|
|
391
|
+
self.assertEqual(mx.less(a, 5).tolist(), [True, True, False])
|
|
392
|
+
self.assertEqual(mx.less(5, a).tolist(), [False, False, False])
|
|
393
|
+
self.assertEqual(mx.less_equal(5, a).tolist(), [False, False, True])
|
|
394
|
+
self.assertEqual(mx.greater(a, 1).tolist(), [False, False, True])
|
|
395
|
+
self.assertEqual(mx.greater_equal(a, 1).tolist(), [False, True, True])
|
|
396
|
+
|
|
397
|
+
a = mx.array([0.0, 1.0, 5.0, -1.0])
|
|
398
|
+
b = mx.array([0.0, 2.0, 5.0, 3.0])
|
|
399
|
+
self.assertEqual(mx.equal(a, b).tolist(), [True, False, True, False])
|
|
400
|
+
self.assertEqual(mx.not_equal(a, b).tolist(), [False, True, False, True])
|
|
401
|
+
|
|
402
|
+
def test_array_equal(self):
|
|
403
|
+
x = mx.array([1, 2, 3, 4])
|
|
404
|
+
y = mx.array([1, 2, 3, 4])
|
|
405
|
+
self.assertTrue(mx.array_equal(x, y))
|
|
406
|
+
|
|
407
|
+
y = mx.array([1, 2, 4, 5])
|
|
408
|
+
self.assertFalse(mx.array_equal(x, y))
|
|
409
|
+
|
|
410
|
+
y = mx.array([1, 2, 3])
|
|
411
|
+
self.assertFalse(mx.array_equal(x, y))
|
|
412
|
+
|
|
413
|
+
# Can still be equal with different types
|
|
414
|
+
y = mx.array([1.0, 2.0, 3.0, 4.0])
|
|
415
|
+
self.assertTrue(mx.array_equal(x, y))
|
|
416
|
+
|
|
417
|
+
x = mx.array([0.0, float("nan")])
|
|
418
|
+
y = mx.array([0.0, float("nan")])
|
|
419
|
+
self.assertFalse(mx.array_equal(x, y))
|
|
420
|
+
self.assertTrue(mx.array_equal(x, y, equal_nan=True))
|
|
421
|
+
|
|
422
|
+
for t in [mx.float32, mx.float16, mx.bfloat16, mx.complex64]:
|
|
423
|
+
with self.subTest(type=t):
|
|
424
|
+
x = mx.array([0.0, float("nan")]).astype(t)
|
|
425
|
+
y = mx.array([0.0, float("nan")]).astype(t)
|
|
426
|
+
self.assertFalse(mx.array_equal(x, y))
|
|
427
|
+
self.assertTrue(mx.array_equal(x, y, equal_nan=True))
|
|
428
|
+
|
|
429
|
+
def test_isnan(self):
|
|
430
|
+
x = mx.array([0.0, float("nan")])
|
|
431
|
+
self.assertEqual(mx.isnan(x).tolist(), [False, True])
|
|
432
|
+
|
|
433
|
+
x = mx.array([0.0, float("nan")]).astype(mx.float16)
|
|
434
|
+
self.assertEqual(mx.isnan(x).tolist(), [False, True])
|
|
435
|
+
|
|
436
|
+
x = mx.array([0.0, float("nan")]).astype(mx.bfloat16)
|
|
437
|
+
self.assertEqual(mx.isnan(x).tolist(), [False, True])
|
|
438
|
+
|
|
439
|
+
x = mx.array([0.0, float("nan")]).astype(mx.complex64)
|
|
440
|
+
self.assertEqual(mx.isnan(x).tolist(), [False, True])
|
|
441
|
+
|
|
442
|
+
self.assertEqual(mx.isnan(0 * mx.array(float("inf"))).tolist(), True)
|
|
443
|
+
|
|
444
|
+
def test_isinf(self):
|
|
445
|
+
x = mx.array([0.0, float("inf")])
|
|
446
|
+
self.assertEqual(mx.isinf(x).tolist(), [False, True])
|
|
447
|
+
|
|
448
|
+
x = mx.array([0.0, float("inf")]).astype(mx.float16)
|
|
449
|
+
self.assertEqual(mx.isinf(x).tolist(), [False, True])
|
|
450
|
+
|
|
451
|
+
x = mx.array([0.0, float("inf")]).astype(mx.bfloat16)
|
|
452
|
+
self.assertEqual(mx.isinf(x).tolist(), [False, True])
|
|
453
|
+
|
|
454
|
+
x = mx.array([0.0, float("inf")]).astype(mx.complex64)
|
|
455
|
+
self.assertEqual(mx.isinf(x).tolist(), [False, True])
|
|
456
|
+
|
|
457
|
+
self.assertEqual(mx.isinf(0 * mx.array(float("inf"))).tolist(), False)
|
|
458
|
+
|
|
459
|
+
x = mx.array([-2147483648, 0, 2147483647], dtype=mx.int32)
|
|
460
|
+
result = mx.isinf(x)
|
|
461
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
462
|
+
|
|
463
|
+
x = mx.array([-32768, 0, 32767], dtype=mx.int16)
|
|
464
|
+
result = mx.isinf(x)
|
|
465
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
466
|
+
|
|
467
|
+
def test_isfinite(self):
|
|
468
|
+
x = mx.array([0.0, float("inf"), float("nan")])
|
|
469
|
+
self.assertEqual(mx.isfinite(x).tolist(), [True, False, False])
|
|
470
|
+
|
|
471
|
+
x = x.astype(mx.float16)
|
|
472
|
+
self.assertEqual(mx.isfinite(x).tolist(), [True, False, False])
|
|
473
|
+
|
|
474
|
+
x = x.astype(mx.bfloat16)
|
|
475
|
+
self.assertEqual(mx.isfinite(x).tolist(), [True, False, False])
|
|
476
|
+
|
|
477
|
+
def test_tri(self):
|
|
478
|
+
for shape in [[4], [4, 4], [2, 10]]:
|
|
479
|
+
for diag in [-1, 0, 1, -2]:
|
|
480
|
+
self.assertCmpNumpy(shape, mx.tri, np.tri, k=diag)
|
|
481
|
+
self.assertEqual(mx.tri(1, 1).dtype, mx.float32)
|
|
482
|
+
self.assertEqual(mx.tri(1, 1, dtype=mx.bfloat16).dtype, mx.bfloat16)
|
|
483
|
+
|
|
484
|
+
def test_tril(self):
|
|
485
|
+
for diag in [-1, 0, 1, -2]:
|
|
486
|
+
self.assertCmpNumpy([(10, 10)], mx.tril, np.tril, k=diag)
|
|
487
|
+
|
|
488
|
+
with self.assertRaises(Exception):
|
|
489
|
+
mx.tril(mx.zeros((1)))
|
|
490
|
+
|
|
491
|
+
def test_triu(self):
|
|
492
|
+
for diag in [-1, 0, 1, -2]:
|
|
493
|
+
self.assertCmpNumpy([(10, 10)], mx.triu, np.triu, k=diag)
|
|
494
|
+
with self.assertRaises(Exception):
|
|
495
|
+
mx.triu(mx.zeros((1)))
|
|
496
|
+
|
|
497
|
+
def test_minimum(self):
|
|
498
|
+
x = mx.array([0.0, -5, 10.0])
|
|
499
|
+
y = mx.array([1.0, -7.0, 3.0])
|
|
500
|
+
|
|
501
|
+
expected = [0, -7, 3]
|
|
502
|
+
self.assertListEqual(mx.minimum(x, y).tolist(), expected)
|
|
503
|
+
|
|
504
|
+
a = mx.array([float("nan")])
|
|
505
|
+
b = mx.array([0.0])
|
|
506
|
+
self.assertTrue(math.isnan(mx.minimum(a, b).item()))
|
|
507
|
+
self.assertTrue(math.isnan(mx.minimum(b, a).item()))
|
|
508
|
+
|
|
509
|
+
def test_maximum(self):
|
|
510
|
+
x = mx.array([0.0, -5, 10.0])
|
|
511
|
+
y = mx.array([1.0, -7.0, 3.0])
|
|
512
|
+
|
|
513
|
+
expected = [1, -5, 10]
|
|
514
|
+
self.assertListEqual(mx.maximum(x, y).tolist(), expected)
|
|
515
|
+
|
|
516
|
+
a = mx.array([float("nan")])
|
|
517
|
+
b = mx.array([0.0])
|
|
518
|
+
self.assertTrue(math.isnan(mx.maximum(a, b).item()))
|
|
519
|
+
self.assertTrue(math.isnan(mx.maximum(b, a).item()))
|
|
520
|
+
|
|
521
|
+
def test_floor(self):
|
|
522
|
+
x = mx.array([-22.03, 19.98, -27, 9, 0.0, -np.inf, np.inf])
|
|
523
|
+
expected = [-23, 19, -27, 9, 0, -np.inf, np.inf]
|
|
524
|
+
self.assertListEqual(mx.floor(x).tolist(), expected)
|
|
525
|
+
|
|
526
|
+
with self.assertRaises(ValueError):
|
|
527
|
+
mx.floor(mx.array([22 + 3j, 19 + 98j]))
|
|
528
|
+
|
|
529
|
+
def test_ceil(self):
|
|
530
|
+
x = mx.array([-22.03, 19.98, -27, 9, 0.0, -np.inf, np.inf])
|
|
531
|
+
expected = [-22, 20, -27, 9, 0, -np.inf, np.inf]
|
|
532
|
+
self.assertListEqual(mx.ceil(x).tolist(), expected)
|
|
533
|
+
|
|
534
|
+
with self.assertRaises(ValueError):
|
|
535
|
+
mx.ceil(mx.array([22 + 3j, 19 + 98j]))
|
|
536
|
+
|
|
537
|
+
def test_isposinf(self):
|
|
538
|
+
x = mx.array([0.0, float("-inf")])
|
|
539
|
+
self.assertEqual(mx.isposinf(x).tolist(), [False, False])
|
|
540
|
+
|
|
541
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.float16)
|
|
542
|
+
self.assertEqual(mx.isposinf(x).tolist(), [False, False])
|
|
543
|
+
|
|
544
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.bfloat16)
|
|
545
|
+
self.assertEqual(mx.isposinf(x).tolist(), [False, False])
|
|
546
|
+
|
|
547
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.complex64)
|
|
548
|
+
self.assertEqual(mx.isposinf(x).tolist(), [False, False])
|
|
549
|
+
|
|
550
|
+
self.assertEqual(mx.isposinf(0 * mx.array(float("inf"))).tolist(), False)
|
|
551
|
+
|
|
552
|
+
x = mx.array([-2147483648, 0, 2147483647], dtype=mx.int32)
|
|
553
|
+
result = mx.isposinf(x)
|
|
554
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
555
|
+
|
|
556
|
+
x = mx.array([-32768, 0, 32767], dtype=mx.int16)
|
|
557
|
+
result = mx.isposinf(x)
|
|
558
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
559
|
+
|
|
560
|
+
def test_isneginf(self):
|
|
561
|
+
x = mx.array([0.0, float("-inf")])
|
|
562
|
+
self.assertEqual(mx.isneginf(x).tolist(), [False, True])
|
|
563
|
+
|
|
564
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.float16)
|
|
565
|
+
self.assertEqual(mx.isneginf(x).tolist(), [False, True])
|
|
566
|
+
|
|
567
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.bfloat16)
|
|
568
|
+
self.assertEqual(mx.isneginf(x).tolist(), [False, True])
|
|
569
|
+
|
|
570
|
+
x = mx.array([0.0, float("-inf")]).astype(mx.complex64)
|
|
571
|
+
self.assertEqual(mx.isneginf(x).tolist(), [False, True])
|
|
572
|
+
|
|
573
|
+
self.assertEqual(mx.isneginf(0 * mx.array(float("inf"))).tolist(), False)
|
|
574
|
+
|
|
575
|
+
x = mx.array([-2147483648, 0, 2147483647], dtype=mx.int32)
|
|
576
|
+
result = mx.isneginf(x)
|
|
577
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
578
|
+
|
|
579
|
+
x = mx.array([-32768, 0, 32767], dtype=mx.int16)
|
|
580
|
+
result = mx.isneginf(x)
|
|
581
|
+
self.assertEqual(result.tolist(), [False, False, False])
|
|
582
|
+
|
|
583
|
+
def test_round(self):
|
|
584
|
+
# float
|
|
585
|
+
x = mx.array(
|
|
586
|
+
[0.5, -0.5, 1.5, -1.5, -21.03, 19.98, -27, 9, 0.0, -np.inf, np.inf]
|
|
587
|
+
)
|
|
588
|
+
expected = [0, -0, 2, -2, -21, 20, -27, 9, 0, -np.inf, np.inf]
|
|
589
|
+
self.assertListEqual(mx.round(x).tolist(), expected)
|
|
590
|
+
|
|
591
|
+
# complex
|
|
592
|
+
y = mx.round(mx.array([22.2 + 3.6j, 18.5 + 98.2j]))
|
|
593
|
+
self.assertListEqual(y.tolist(), [22 + 4j, 18 + 98j])
|
|
594
|
+
|
|
595
|
+
# decimals
|
|
596
|
+
y0 = mx.round(mx.array([15, 122], mx.int32), decimals=0)
|
|
597
|
+
y1 = mx.round(mx.array([15, 122], mx.int32), decimals=-1)
|
|
598
|
+
y2 = mx.round(mx.array([15, 122], mx.int32), decimals=-2)
|
|
599
|
+
self.assertEqual(y0.dtype, mx.int32)
|
|
600
|
+
self.assertEqual(y1.dtype, mx.int32)
|
|
601
|
+
self.assertEqual(y2.dtype, mx.int32)
|
|
602
|
+
self.assertListEqual(y0.tolist(), [15, 122])
|
|
603
|
+
self.assertListEqual(y1.tolist(), [20, 120])
|
|
604
|
+
self.assertListEqual(y2.tolist(), [0, 100])
|
|
605
|
+
|
|
606
|
+
y1 = mx.round(mx.array([1.537, 1.471], mx.float32), decimals=1)
|
|
607
|
+
y2 = mx.round(mx.array([1.537, 1.471], mx.float32), decimals=2)
|
|
608
|
+
self.assertTrue(mx.allclose(y1, mx.array([1.5, 1.5])))
|
|
609
|
+
self.assertTrue(mx.allclose(y2, mx.array([1.54, 1.47])))
|
|
610
|
+
|
|
611
|
+
# check round to nearest for different types
|
|
612
|
+
dtypes = [mx.bfloat16, mx.float16, mx.float32]
|
|
613
|
+
for dtype in dtypes:
|
|
614
|
+
x = mx.arange(10, dtype=dtype) - 4.5
|
|
615
|
+
x = mx.round(x)
|
|
616
|
+
self.assertEqual(
|
|
617
|
+
x.astype(mx.float32).tolist(),
|
|
618
|
+
[-4.0, -4.0, -2.0, -2.0, -0.0, 0.0, 2.0, 2.0, 4.0, 4.0],
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
def test_transpose_noargs(self):
|
|
622
|
+
x = mx.array([[0, 1, 1], [1, 0, 0]])
|
|
623
|
+
|
|
624
|
+
expected = [
|
|
625
|
+
[0, 1],
|
|
626
|
+
[1, 0],
|
|
627
|
+
[1, 0],
|
|
628
|
+
]
|
|
629
|
+
|
|
630
|
+
self.assertListEqual(mx.transpose(x).tolist(), expected)
|
|
631
|
+
|
|
632
|
+
def test_transpose_axis(self):
|
|
633
|
+
x = mx.array(
|
|
634
|
+
[
|
|
635
|
+
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]],
|
|
636
|
+
[[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]],
|
|
637
|
+
]
|
|
638
|
+
)
|
|
639
|
+
expected = [
|
|
640
|
+
[[0, 4, 8], [1, 5, 9], [2, 6, 10], [3, 7, 11]],
|
|
641
|
+
[[12, 16, 20], [13, 17, 21], [14, 18, 22], [15, 19, 23]],
|
|
642
|
+
]
|
|
643
|
+
|
|
644
|
+
self.assertListEqual(mx.transpose(x, axes=(0, 2, 1)).tolist(), expected)
|
|
645
|
+
|
|
646
|
+
def test_move_swap_axes(self):
|
|
647
|
+
x = mx.zeros((2, 3, 4))
|
|
648
|
+
self.assertEqual(mx.moveaxis(x, 0, 2).shape, (3, 4, 2))
|
|
649
|
+
self.assertEqual(x.moveaxis(0, 2).shape, (3, 4, 2))
|
|
650
|
+
self.assertEqual(mx.swapaxes(x, 0, 2).shape, (4, 3, 2))
|
|
651
|
+
self.assertEqual(x.swapaxes(0, 2).shape, (4, 3, 2))
|
|
652
|
+
|
|
653
|
+
def test_sum(self):
|
|
654
|
+
x = mx.array(
|
|
655
|
+
[
|
|
656
|
+
[1, 2],
|
|
657
|
+
[3, 3],
|
|
658
|
+
]
|
|
659
|
+
)
|
|
660
|
+
self.assertEqual(mx.sum(x).item(), 9)
|
|
661
|
+
y = mx.sum(x, keepdims=True)
|
|
662
|
+
self.assertEqual(y, mx.array(9))
|
|
663
|
+
self.assertEqual(y.shape, (1, 1))
|
|
664
|
+
|
|
665
|
+
self.assertEqual(mx.sum(x, axis=0).tolist(), [4, 5])
|
|
666
|
+
self.assertEqual(mx.sum(x, axis=1).tolist(), [3, 6])
|
|
667
|
+
|
|
668
|
+
x_npy = np.arange(3 * 5 * 4 * 7).astype(np.float32)
|
|
669
|
+
x_npy = np.reshape(x_npy, (3, 5, 4, 7))
|
|
670
|
+
x_mlx = mx.array(x_npy)
|
|
671
|
+
|
|
672
|
+
for axis in (None, 0, 1, 2, 3, (0, 1), (2, 3), (1, 2, 3)):
|
|
673
|
+
sum_npy = np.sum(x_npy, axis=axis)
|
|
674
|
+
sum_mlx = np.asarray(mx.sum(x_mlx, axis=axis))
|
|
675
|
+
self.assertListEqual(list(sum_npy.shape), list(sum_mlx.shape))
|
|
676
|
+
self.assertTrue(np.all(sum_npy == sum_mlx))
|
|
677
|
+
|
|
678
|
+
x_npy = np.array([1.0, 2.0, 3.0, 4.0]).astype(np.float32)
|
|
679
|
+
x_mlx = mx.array(x_npy)
|
|
680
|
+
|
|
681
|
+
y_npy = x_npy[0:4:2]
|
|
682
|
+
y_npy = np.broadcast_to(y_npy, (2, 2))
|
|
683
|
+
|
|
684
|
+
y_mlx = x_mlx[0:4:2]
|
|
685
|
+
y_mlx = mx.broadcast_to(y_mlx, (2, 2))
|
|
686
|
+
|
|
687
|
+
for axis in (None, 0, 1, (0, 1)):
|
|
688
|
+
sum_npy = np.sum(y_npy, axis=axis)
|
|
689
|
+
sum_mlx = np.asarray(mx.sum(y_mlx, axis=axis))
|
|
690
|
+
self.assertListEqual(list(sum_npy.shape), list(sum_mlx.shape))
|
|
691
|
+
self.assertTrue(np.all(sum_npy == sum_mlx))
|
|
692
|
+
|
|
693
|
+
x_npy = (
|
|
694
|
+
np.arange(3 * 2 * 3 * 3 * 3 * 3)
|
|
695
|
+
.reshape(3, 2, 3, 3, 3, 3)
|
|
696
|
+
.astype(np.float32)
|
|
697
|
+
)
|
|
698
|
+
x_mlx = mx.array(x_npy)
|
|
699
|
+
|
|
700
|
+
y_mlx = x_mlx.sum(axis=(0, 1, 3, 4, 5))
|
|
701
|
+
y_npy = x_npy.sum(axis=(0, 1, 3, 4, 5))
|
|
702
|
+
|
|
703
|
+
self.assertTrue(np.array_equal(y_mlx, y_npy))
|
|
704
|
+
|
|
705
|
+
def test_count_nonzero(self):
|
|
706
|
+
c = mx.array([[0, 1, 0], [2, 3, 0]])
|
|
707
|
+
self.assertEqual(mx.count_nonzero(c).item(), 3)
|
|
708
|
+
self.assertEqual(mx.count_nonzero(c, axis=0).tolist(), [1, 2, 0])
|
|
709
|
+
self.assertEqual(mx.count_nonzero(c, axis=1).tolist(), [1, 2])
|
|
710
|
+
self.assertEqual(mx.count_nonzero(c).dtype, mx.int32)
|
|
711
|
+
|
|
712
|
+
def test_prod(self):
|
|
713
|
+
x = mx.array(
|
|
714
|
+
[
|
|
715
|
+
[1, 2],
|
|
716
|
+
[3, 3],
|
|
717
|
+
]
|
|
718
|
+
)
|
|
719
|
+
self.assertEqual(mx.prod(x).item(), 18)
|
|
720
|
+
y = mx.prod(x, keepdims=True)
|
|
721
|
+
self.assertEqual(y, mx.array(18))
|
|
722
|
+
self.assertEqual(y.shape, (1, 1))
|
|
723
|
+
|
|
724
|
+
self.assertEqual(mx.prod(x, axis=0).tolist(), [3, 6])
|
|
725
|
+
self.assertEqual(mx.prod(x, axis=1).tolist(), [2, 9])
|
|
726
|
+
|
|
727
|
+
def test_min_and_max(self):
|
|
728
|
+
x = mx.array(
|
|
729
|
+
[
|
|
730
|
+
[1, 2],
|
|
731
|
+
[3, 4],
|
|
732
|
+
]
|
|
733
|
+
)
|
|
734
|
+
self.assertEqual(mx.min(x).item(), 1)
|
|
735
|
+
self.assertEqual(mx.max(x).item(), 4)
|
|
736
|
+
y = mx.min(x, keepdims=True)
|
|
737
|
+
self.assertEqual(y.shape, (1, 1))
|
|
738
|
+
self.assertEqual(y, mx.array(1))
|
|
739
|
+
|
|
740
|
+
y = mx.max(x, keepdims=True)
|
|
741
|
+
self.assertEqual(y.shape, (1, 1))
|
|
742
|
+
self.assertEqual(y, mx.array(4))
|
|
743
|
+
|
|
744
|
+
self.assertEqual(mx.min(x, axis=0).tolist(), [1, 2])
|
|
745
|
+
self.assertEqual(mx.min(x, axis=1).tolist(), [1, 3])
|
|
746
|
+
self.assertEqual(mx.max(x, axis=0).tolist(), [3, 4])
|
|
747
|
+
self.assertEqual(mx.max(x, axis=1).tolist(), [2, 4])
|
|
748
|
+
|
|
749
|
+
def test_argmin_argmax(self):
|
|
750
|
+
data = np.random.rand(10, 12, 13)
|
|
751
|
+
x = mx.array(data)
|
|
752
|
+
for op in ["argmin", "argmax"]:
|
|
753
|
+
for axis in range(3):
|
|
754
|
+
for kd in [True, False]:
|
|
755
|
+
a = getattr(mx, op)(x, axis, kd)
|
|
756
|
+
b = getattr(np, op)(data, axis, keepdims=kd)
|
|
757
|
+
self.assertEqual(a.tolist(), b.tolist())
|
|
758
|
+
|
|
759
|
+
for op in ["argmin", "argmax"]:
|
|
760
|
+
a = getattr(mx, op)(x, keepdims=True)
|
|
761
|
+
b = getattr(np, op)(data, keepdims=True)
|
|
762
|
+
self.assertEqual(a.tolist(), b.tolist())
|
|
763
|
+
a = getattr(mx, op)(x)
|
|
764
|
+
b = getattr(np, op)(data)
|
|
765
|
+
self.assertEqual(a.item(), b)
|
|
766
|
+
|
|
767
|
+
def test_broadcast(self):
|
|
768
|
+
a_npy = np.reshape(np.arange(200), (10, 20))
|
|
769
|
+
a_mlx = mx.array(a_npy)
|
|
770
|
+
|
|
771
|
+
b_npy = np.broadcast_to(a_npy, (30, 10, 20))
|
|
772
|
+
b_mlx = mx.broadcast_to(a_mlx, (30, 10, 20))
|
|
773
|
+
self.assertListEqual(list(b_npy.shape), list(b_mlx.shape))
|
|
774
|
+
self.assertTrue(np.array_equal(b_npy, b_mlx))
|
|
775
|
+
|
|
776
|
+
b_npy = np.broadcast_to(a_npy, (1, 10, 20))
|
|
777
|
+
b_mlx = mx.broadcast_to(a_mlx, (1, 10, 20))
|
|
778
|
+
self.assertListEqual(list(b_npy.shape), list(b_mlx.shape))
|
|
779
|
+
self.assertTrue(np.array_equal(b_npy, b_mlx))
|
|
780
|
+
|
|
781
|
+
b_npy = np.broadcast_to(1, (10, 20))
|
|
782
|
+
b_mlx = mx.broadcast_to(1, (10, 20))
|
|
783
|
+
self.assertListEqual(list(b_npy.shape), list(b_mlx.shape))
|
|
784
|
+
self.assertTrue(np.array_equal(b_npy, b_mlx))
|
|
785
|
+
|
|
786
|
+
def test_logsumexp(self):
|
|
787
|
+
def logsumexp(x, axes=None):
|
|
788
|
+
maxs = mx.max(x, axis=axes, keepdims=True)
|
|
789
|
+
return mx.log(mx.sum(mx.exp(x - maxs), axis=axes, keepdims=True)) + maxs
|
|
790
|
+
|
|
791
|
+
x = mx.array(
|
|
792
|
+
[
|
|
793
|
+
[1.0, 2.0],
|
|
794
|
+
[3.0, 4.0],
|
|
795
|
+
]
|
|
796
|
+
)
|
|
797
|
+
self.assertTrue(math.isclose(mx.logsumexp(x).item(), logsumexp(x).item()))
|
|
798
|
+
|
|
799
|
+
x = mx.random.uniform(shape=(1025,))
|
|
800
|
+
self.assertTrue(mx.allclose(mx.logsumexp(x), logsumexp(x)))
|
|
801
|
+
|
|
802
|
+
# Transposed
|
|
803
|
+
x = mx.random.uniform(shape=(2, 2, 8))
|
|
804
|
+
x = x.swapaxes(0, 1)
|
|
805
|
+
self.assertTrue(mx.allclose(mx.logsumexp(x), logsumexp(x)))
|
|
806
|
+
|
|
807
|
+
# Broadcast
|
|
808
|
+
x = mx.broadcast_to(mx.random.uniform(shape=(2, 1, 8)), (2, 2, 8))
|
|
809
|
+
self.assertTrue(mx.allclose(mx.logsumexp(x), logsumexp(x)))
|
|
810
|
+
|
|
811
|
+
# Large
|
|
812
|
+
x = mx.random.uniform(shape=(1025,))
|
|
813
|
+
x = mx.broadcast_to(mx.random.uniform(shape=(2, 1, 8)), (2, 2, 8))
|
|
814
|
+
self.assertTrue(mx.allclose(mx.logsumexp(x), logsumexp(x)))
|
|
815
|
+
|
|
816
|
+
def test_mean(self):
|
|
817
|
+
x = mx.array(
|
|
818
|
+
[
|
|
819
|
+
[1, 2],
|
|
820
|
+
[3, 4],
|
|
821
|
+
]
|
|
822
|
+
)
|
|
823
|
+
self.assertEqual(mx.mean(x).item(), 2.5)
|
|
824
|
+
y = mx.mean(x, keepdims=True)
|
|
825
|
+
self.assertEqual(y, mx.array(2.5))
|
|
826
|
+
self.assertEqual(y.shape, (1, 1))
|
|
827
|
+
|
|
828
|
+
self.assertEqual(mx.mean(x, axis=0).tolist(), [2, 3])
|
|
829
|
+
self.assertEqual(mx.mean(x, axis=1).tolist(), [1.5, 3.5])
|
|
830
|
+
|
|
831
|
+
def test_median(self):
|
|
832
|
+
x = mx.array([])
|
|
833
|
+
with self.assertRaises(ValueError):
|
|
834
|
+
mx.median(x, axis=0)
|
|
835
|
+
x = mx.array([0, 1, 2, 3, 4])
|
|
836
|
+
with self.assertRaises(ValueError):
|
|
837
|
+
mx.median(x, axis=(0, 1))
|
|
838
|
+
with self.assertRaises(ValueError):
|
|
839
|
+
mx.median(x, axis=(0, 0))
|
|
840
|
+
|
|
841
|
+
out = mx.median(x)
|
|
842
|
+
self.assertEqual(out.shape, ())
|
|
843
|
+
self.assertEqual(out.item(), 2)
|
|
844
|
+
out = mx.median(x, keepdims=True)
|
|
845
|
+
self.assertEqual(out.shape, (1,))
|
|
846
|
+
|
|
847
|
+
x = mx.array([0, 1, 2, 3, 4, 5])
|
|
848
|
+
out = mx.median(x)
|
|
849
|
+
self.assertEqual(out.item(), 2.5)
|
|
850
|
+
|
|
851
|
+
x = mx.random.normal((5, 5, 5, 5))
|
|
852
|
+
out = mx.median(x, axis=(0, 2), keepdims=True)
|
|
853
|
+
out_np = np.median(x, axis=(0, 2), keepdims=True)
|
|
854
|
+
self.assertTrue(np.allclose(out, out_np))
|
|
855
|
+
|
|
856
|
+
out = mx.median(x, axis=(1, 3), keepdims=True)
|
|
857
|
+
out_np = np.median(x, axis=(1, 3), keepdims=True)
|
|
858
|
+
self.assertTrue(np.allclose(out, out_np))
|
|
859
|
+
|
|
860
|
+
out = mx.median(x, axis=(0, 1, 3), keepdims=True)
|
|
861
|
+
out_np = np.median(x, axis=(0, 1, 3), keepdims=True)
|
|
862
|
+
self.assertTrue(np.allclose(out, out_np))
|
|
863
|
+
|
|
864
|
+
def test_var(self):
|
|
865
|
+
x = mx.array(
|
|
866
|
+
[
|
|
867
|
+
[1, 2],
|
|
868
|
+
[3, 4],
|
|
869
|
+
]
|
|
870
|
+
)
|
|
871
|
+
self.assertEqual(mx.var(x).item(), 1.25)
|
|
872
|
+
y = mx.var(x, keepdims=True)
|
|
873
|
+
self.assertEqual(y, mx.array(1.25))
|
|
874
|
+
self.assertEqual(y.shape, (1, 1))
|
|
875
|
+
|
|
876
|
+
self.assertEqual(mx.var(x, axis=0).tolist(), [1.0, 1.0])
|
|
877
|
+
self.assertEqual(mx.var(x, axis=1).tolist(), [0.25, 0.25])
|
|
878
|
+
|
|
879
|
+
x = mx.array([1.0, 2.0])
|
|
880
|
+
out = mx.var(x, ddof=2)
|
|
881
|
+
self.assertEqual(out.item(), float("inf"))
|
|
882
|
+
|
|
883
|
+
x = mx.array([1.0, 2.0])
|
|
884
|
+
out = mx.var(x, ddof=3)
|
|
885
|
+
self.assertEqual(out.item(), float("inf"))
|
|
886
|
+
|
|
887
|
+
def test_std(self):
|
|
888
|
+
x = mx.random.uniform(shape=(5, 5))
|
|
889
|
+
x_np = np.array(x)
|
|
890
|
+
self.assertAlmostEqual(mx.std(x).item(), x_np.std().item(), places=6)
|
|
891
|
+
|
|
892
|
+
def test_abs(self):
|
|
893
|
+
a = mx.array([-1.0, 1.0, -2.0, 3.0])
|
|
894
|
+
result = mx.abs(a)
|
|
895
|
+
expected = np.abs(a, dtype=np.float32)
|
|
896
|
+
self.assertTrue(np.allclose(result, expected))
|
|
897
|
+
|
|
898
|
+
self.assertTrue(np.allclose(a.abs(), abs(a)))
|
|
899
|
+
|
|
900
|
+
def test_negative(self):
|
|
901
|
+
a = mx.array([-1.0, 1.0, -2.0, 3.0])
|
|
902
|
+
result = mx.negative(a)
|
|
903
|
+
expected = np.negative(a, dtype=np.float32)
|
|
904
|
+
self.assertTrue(np.allclose(result, expected))
|
|
905
|
+
|
|
906
|
+
def test_sign(self):
|
|
907
|
+
a = mx.array([-1.0, 1.0, 0.0, -2.0, 3.0])
|
|
908
|
+
result = mx.sign(a)
|
|
909
|
+
expected = np.sign(a, dtype=np.float32)
|
|
910
|
+
self.assertTrue(np.allclose(result, expected))
|
|
911
|
+
|
|
912
|
+
a = mx.array([-1.0, 1.0, 0.0, -2.0, 3.0])
|
|
913
|
+
b = mx.array([-4.0, -3.0, 1.0, 0.0, 3.0])
|
|
914
|
+
c = a + b * 1j
|
|
915
|
+
result = mx.sign(c)
|
|
916
|
+
# np.sign differs in NumPy 1 and 2 so
|
|
917
|
+
# we manually implement the NumPy 2 version here.
|
|
918
|
+
expected = c / np.abs(c)
|
|
919
|
+
self.assertTrue(np.allclose(result, expected))
|
|
920
|
+
|
|
921
|
+
def test_logical_not(self):
|
|
922
|
+
a = mx.array([-1.0, 1.0, 0.0, 1.0, -2.0, 3.0])
|
|
923
|
+
result = mx.logical_not(a)
|
|
924
|
+
expected = np.logical_not(a)
|
|
925
|
+
self.assertTrue(np.array_equal(result, expected))
|
|
926
|
+
|
|
927
|
+
def test_logical_and(self):
|
|
928
|
+
a = mx.array([True, False, True, False])
|
|
929
|
+
b = mx.array([True, True, False, False])
|
|
930
|
+
result = mx.logical_and(a, b)
|
|
931
|
+
expected = np.logical_and(a, b)
|
|
932
|
+
self.assertTrue(np.array_equal(result, expected))
|
|
933
|
+
|
|
934
|
+
# test overloaded operator
|
|
935
|
+
result = a & b
|
|
936
|
+
self.assertTrue(np.array_equal(result, expected))
|
|
937
|
+
|
|
938
|
+
def test_logical_or(self):
|
|
939
|
+
a = mx.array([True, False, True, False])
|
|
940
|
+
b = mx.array([True, True, False, False])
|
|
941
|
+
result = mx.logical_or(a, b)
|
|
942
|
+
expected = np.logical_or(a, b)
|
|
943
|
+
self.assertTrue(np.array_equal(result, expected))
|
|
944
|
+
|
|
945
|
+
# test overloaded operator
|
|
946
|
+
result = a | b
|
|
947
|
+
self.assertTrue(np.array_equal(result, expected))
|
|
948
|
+
|
|
949
|
+
def test_logical_xor(self):
|
|
950
|
+
x = mx.array([True, True, False, False])
|
|
951
|
+
y = mx.array([True, False, True, False])
|
|
952
|
+
self.assertEqual(mx.logical_xor(x, y).tolist(), [False, True, True, False])
|
|
953
|
+
|
|
954
|
+
def test_trunc(self):
|
|
955
|
+
a = mx.array([-1.5, -0.5, 0.0, 0.5, 2.7])
|
|
956
|
+
self.assertEqual(mx.trunc(a).tolist(), [-1.0, 0.0, 0.0, 0.0, 2.0])
|
|
957
|
+
|
|
958
|
+
def test_square(self):
|
|
959
|
+
a = mx.array([0.1, 0.5, 1.0, 10.0])
|
|
960
|
+
result = mx.square(a)
|
|
961
|
+
expected = np.square(a, dtype=np.float32)
|
|
962
|
+
|
|
963
|
+
self.assertTrue(np.allclose(result, expected))
|
|
964
|
+
|
|
965
|
+
def test_sqrt(self):
|
|
966
|
+
a = mx.array([0.1, 0.5, 1.0, 10.0])
|
|
967
|
+
result = mx.sqrt(a)
|
|
968
|
+
expected = np.sqrt(a, dtype=np.float32)
|
|
969
|
+
self.assertTrue(np.allclose(result, expected))
|
|
970
|
+
|
|
971
|
+
def test_rsqrt(self):
|
|
972
|
+
a = mx.array([0.1, 0.5, 1.0, 10.0])
|
|
973
|
+
result = mx.rsqrt(a)
|
|
974
|
+
expected = 1.0 / np.sqrt(a, dtype=np.float32)
|
|
975
|
+
self.assertTrue(np.allclose(result, expected))
|
|
976
|
+
|
|
977
|
+
def test_reciprocal(self):
|
|
978
|
+
a = mx.array([0.1, 0.5, 1.0, 2.0])
|
|
979
|
+
result = mx.reciprocal(a)
|
|
980
|
+
expected = np.reciprocal(a, dtype=np.float32)
|
|
981
|
+
self.assertTrue(np.allclose(result, expected))
|
|
982
|
+
|
|
983
|
+
def test_logaddexp(self):
|
|
984
|
+
a = mx.array([0, 1, 2, 9.0])
|
|
985
|
+
b = mx.array([1, 0, 4, 2.5])
|
|
986
|
+
|
|
987
|
+
result = mx.logaddexp(a, b)
|
|
988
|
+
expected = np.logaddexp(a, b, dtype=np.float32)
|
|
989
|
+
|
|
990
|
+
self.assertTrue(np.allclose(result, expected))
|
|
991
|
+
|
|
992
|
+
# Complex test
|
|
993
|
+
|
|
994
|
+
a = mx.array([0, 1, 2, 9.0]) + 1j
|
|
995
|
+
b = mx.array([1, 0, 4, 2.5]) + 1j
|
|
996
|
+
|
|
997
|
+
result = mx.logaddexp(a, b)
|
|
998
|
+
expected = np_logaddexp(np.array(a), np.array(b))
|
|
999
|
+
|
|
1000
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1001
|
+
|
|
1002
|
+
a = mx.array([float("nan")])
|
|
1003
|
+
b = mx.array([0.0])
|
|
1004
|
+
self.assertTrue(math.isnan(mx.logaddexp(a, b).item()))
|
|
1005
|
+
|
|
1006
|
+
def test_log(self):
|
|
1007
|
+
a = mx.array([1, 0.5, 10, 100])
|
|
1008
|
+
result = mx.log(a)
|
|
1009
|
+
expected = np.log(a, dtype=np.float32)
|
|
1010
|
+
|
|
1011
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1012
|
+
|
|
1013
|
+
a = mx.array(1.0) + 1j * mx.array(2.0)
|
|
1014
|
+
result = mx.log(a)
|
|
1015
|
+
expected = np.log(np.array(a))
|
|
1016
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1017
|
+
|
|
1018
|
+
def test_log2(self):
|
|
1019
|
+
a = mx.array([0.5, 1, 2, 10, 16])
|
|
1020
|
+
result = mx.log2(a)
|
|
1021
|
+
expected = np.log2(a, dtype=np.float32)
|
|
1022
|
+
|
|
1023
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1024
|
+
|
|
1025
|
+
a = mx.array(1.0) + 1j * mx.array(2.0)
|
|
1026
|
+
result = mx.log2(a)
|
|
1027
|
+
expected = np.log2(np.array(a))
|
|
1028
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1029
|
+
|
|
1030
|
+
def test_log10(self):
|
|
1031
|
+
a = mx.array([0.1, 1, 10, 20, 100])
|
|
1032
|
+
result = mx.log10(a)
|
|
1033
|
+
expected = np.log10(a, dtype=np.float32)
|
|
1034
|
+
|
|
1035
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1036
|
+
|
|
1037
|
+
a = mx.array(1.0) + 1j * mx.array(2.0)
|
|
1038
|
+
result = mx.log10(a)
|
|
1039
|
+
expected = np.log10(np.array(a))
|
|
1040
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1041
|
+
|
|
1042
|
+
def test_exp(self):
|
|
1043
|
+
a = mx.array([0, 0.5, -0.5, 5])
|
|
1044
|
+
result = mx.exp(a)
|
|
1045
|
+
expected = np.exp(a, dtype=np.float32)
|
|
1046
|
+
|
|
1047
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1048
|
+
|
|
1049
|
+
def test_expm1(self):
|
|
1050
|
+
a = mx.array([-88, -87, 0, 0.5, -0.5, 5, 87, 88, 89, 90])
|
|
1051
|
+
result = mx.expm1(a)
|
|
1052
|
+
errs = np.seterr(over="ignore")
|
|
1053
|
+
expected = np.expm1(a)
|
|
1054
|
+
np.seterr(over=errs["over"])
|
|
1055
|
+
self.assertTrue(np.allclose(result, expected, rtol=1e-3, atol=1e-4))
|
|
1056
|
+
|
|
1057
|
+
def test_erf(self):
|
|
1058
|
+
inputs = [-5, 0.0, 0.5, 1.0, 2.0, 10.0]
|
|
1059
|
+
x = mx.array(inputs)
|
|
1060
|
+
expected = np.array([math.erf(i) for i in inputs])
|
|
1061
|
+
self.assertTrue(np.allclose(mx.erf(x), expected))
|
|
1062
|
+
|
|
1063
|
+
def test_erfinv(self):
|
|
1064
|
+
inputs = [-5.0, -1.0, 0.5, 0.0, 0.5, 1.0, 5.0]
|
|
1065
|
+
x = mx.array(inputs)
|
|
1066
|
+
# Output of:
|
|
1067
|
+
# scipy.special.erfinv([-5.0, -1.0, 0.5, 0.0, 0.5, 1.0, 5.0])
|
|
1068
|
+
expected = np.array(
|
|
1069
|
+
[
|
|
1070
|
+
float("nan"),
|
|
1071
|
+
-float("inf"),
|
|
1072
|
+
0.47693628,
|
|
1073
|
+
0.0,
|
|
1074
|
+
0.47693628,
|
|
1075
|
+
float("inf"),
|
|
1076
|
+
float("nan"),
|
|
1077
|
+
]
|
|
1078
|
+
).astype(np.float32)
|
|
1079
|
+
self.assertTrue(np.allclose(mx.erfinv(x), expected, equal_nan=True))
|
|
1080
|
+
|
|
1081
|
+
result = mx.erfinv(mx.array([0.9999999403953552] * 8))
|
|
1082
|
+
expected = mx.array([3.8325066566467285] * 8)
|
|
1083
|
+
self.assertTrue(mx.allclose(result, expected))
|
|
1084
|
+
|
|
1085
|
+
def test_sin(self):
|
|
1086
|
+
a = mx.array(
|
|
1087
|
+
[0, math.pi / 4, math.pi / 2, math.pi, 3 * math.pi / 4, 2 * math.pi]
|
|
1088
|
+
)
|
|
1089
|
+
result = mx.sin(a)
|
|
1090
|
+
expected = np.sin(a, dtype=np.float32)
|
|
1091
|
+
|
|
1092
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1093
|
+
|
|
1094
|
+
def test_cos(self):
|
|
1095
|
+
a = mx.array(
|
|
1096
|
+
[0, math.pi / 4, math.pi / 2, math.pi, 3 * math.pi / 4, 2 * math.pi]
|
|
1097
|
+
)
|
|
1098
|
+
result = mx.cos(a)
|
|
1099
|
+
expected = np.cos(a, dtype=np.float32)
|
|
1100
|
+
|
|
1101
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1102
|
+
|
|
1103
|
+
def test_degrees(self):
|
|
1104
|
+
a = mx.array(
|
|
1105
|
+
[0, math.pi / 4, math.pi / 2, math.pi, 3 * math.pi / 4, 2 * math.pi]
|
|
1106
|
+
)
|
|
1107
|
+
result = mx.degrees(a)
|
|
1108
|
+
expected = np.degrees(a, dtype=np.float32)
|
|
1109
|
+
|
|
1110
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1111
|
+
|
|
1112
|
+
def test_radians(self):
|
|
1113
|
+
a = mx.array([0.0, 45.0, 90.0, 180.0, 270.0, 360.0])
|
|
1114
|
+
result = mx.radians(a)
|
|
1115
|
+
expected = np.radians(a, dtype=np.float32)
|
|
1116
|
+
|
|
1117
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1118
|
+
|
|
1119
|
+
def test_log1p(self):
|
|
1120
|
+
a = mx.array([1, 0.5, 10, 100])
|
|
1121
|
+
result = mx.log1p(a)
|
|
1122
|
+
expected = np.log1p(a, dtype=np.float32)
|
|
1123
|
+
|
|
1124
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1125
|
+
|
|
1126
|
+
# Complex test
|
|
1127
|
+
a = mx.array([1, 0.5, 10, 100]) + 1j
|
|
1128
|
+
result = mx.log1p(a)
|
|
1129
|
+
expected = np.log1p(a, dtype=np.complex64)
|
|
1130
|
+
|
|
1131
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1132
|
+
|
|
1133
|
+
def test_sigmoid(self):
|
|
1134
|
+
a = mx.array([0.0, 1.0, -1.0, 5.0, -5.0])
|
|
1135
|
+
result = mx.sigmoid(a)
|
|
1136
|
+
expected = 1 / (1 + np.exp(-a, dtype=np.float32))
|
|
1137
|
+
self.assertTrue(np.allclose(result, expected))
|
|
1138
|
+
|
|
1139
|
+
# Low precision
|
|
1140
|
+
a = mx.array(-8.0).astype(mx.float16)
|
|
1141
|
+
self.assertNotEqual(mx.sigmoid(a).item(), 0.0)
|
|
1142
|
+
a = mx.array(8.0).astype(mx.float16)
|
|
1143
|
+
self.assertNotEqual(mx.sigmoid(a).item(), 1.0)
|
|
1144
|
+
|
|
1145
|
+
def test_allclose(self):
|
|
1146
|
+
a = mx.array(1.0)
|
|
1147
|
+
b = mx.array(1.0)
|
|
1148
|
+
|
|
1149
|
+
self.assertTrue(mx.allclose(a, b).item())
|
|
1150
|
+
|
|
1151
|
+
b = mx.array(1.1)
|
|
1152
|
+
self.assertFalse(mx.allclose(a, b).item())
|
|
1153
|
+
self.assertTrue(mx.allclose(a, b, 0.1).item())
|
|
1154
|
+
self.assertFalse(mx.allclose(a, b, 0.01).item())
|
|
1155
|
+
self.assertTrue(mx.allclose(a, b, 0.01, 0.1).item())
|
|
1156
|
+
|
|
1157
|
+
c = mx.array(float("inf"))
|
|
1158
|
+
self.assertTrue(mx.allclose(c, c).item())
|
|
1159
|
+
|
|
1160
|
+
def test_isclose(self):
|
|
1161
|
+
a = mx.array([float("inf"), float("inf"), float("-inf")])
|
|
1162
|
+
b = mx.array([float("inf"), float("-inf"), float("-inf")])
|
|
1163
|
+
|
|
1164
|
+
self.assertListEqual(mx.isclose(a, b).tolist(), [True, False, True])
|
|
1165
|
+
|
|
1166
|
+
a = mx.array([np.nan])
|
|
1167
|
+
self.assertListEqual(mx.isclose(a, a).tolist(), [False])
|
|
1168
|
+
|
|
1169
|
+
a = mx.array([np.nan])
|
|
1170
|
+
self.assertListEqual(mx.isclose(a, a, equal_nan=True).tolist(), [True])
|
|
1171
|
+
|
|
1172
|
+
def test_all(self):
|
|
1173
|
+
a = mx.array([[True, False], [True, True]])
|
|
1174
|
+
|
|
1175
|
+
self.assertFalse(mx.all(a).item())
|
|
1176
|
+
self.assertEqual(mx.all(a, keepdims=True).shape, (1, 1))
|
|
1177
|
+
self.assertFalse(mx.all(a, axis=[0, 1]).item())
|
|
1178
|
+
self.assertEqual(mx.all(a, axis=[0]).tolist(), [True, False])
|
|
1179
|
+
self.assertEqual(mx.all(a, axis=[1]).tolist(), [False, True])
|
|
1180
|
+
self.assertEqual(mx.all(a, axis=0).tolist(), [True, False])
|
|
1181
|
+
self.assertEqual(mx.all(a, axis=1).tolist(), [False, True])
|
|
1182
|
+
|
|
1183
|
+
def test_any(self):
|
|
1184
|
+
a = mx.array([[True, False], [False, False]])
|
|
1185
|
+
|
|
1186
|
+
self.assertTrue(mx.any(a).item())
|
|
1187
|
+
self.assertEqual(mx.any(a, keepdims=True).shape, (1, 1))
|
|
1188
|
+
self.assertTrue(mx.any(a, axis=[0, 1]).item())
|
|
1189
|
+
self.assertEqual(mx.any(a, axis=[0]).tolist(), [True, False])
|
|
1190
|
+
self.assertEqual(mx.any(a, axis=[1]).tolist(), [True, False])
|
|
1191
|
+
self.assertEqual(mx.any(a, axis=0).tolist(), [True, False])
|
|
1192
|
+
self.assertEqual(mx.any(a, axis=1).tolist(), [True, False])
|
|
1193
|
+
|
|
1194
|
+
def test_stop_gradient(self):
|
|
1195
|
+
def func(x):
|
|
1196
|
+
return mx.sum(2 * x + mx.stop_gradient(3 * x))
|
|
1197
|
+
|
|
1198
|
+
x = mx.array([0.0, 0.1, -3])
|
|
1199
|
+
expected = [2, 2, 2]
|
|
1200
|
+
|
|
1201
|
+
self.assertListEqual(mx.grad(func)(x).tolist(), expected)
|
|
1202
|
+
|
|
1203
|
+
def test_kron(self):
|
|
1204
|
+
# Basic vector test
|
|
1205
|
+
x = mx.array([1, 2])
|
|
1206
|
+
y = mx.array([3, 4])
|
|
1207
|
+
z = mx.kron(x, y)
|
|
1208
|
+
self.assertEqual(z.tolist(), [3, 4, 6, 8])
|
|
1209
|
+
|
|
1210
|
+
# Basic matrix test
|
|
1211
|
+
x = mx.array([[1, 2], [3, 4]])
|
|
1212
|
+
y = mx.array([[0, 5], [6, 7]])
|
|
1213
|
+
z = mx.kron(x, y)
|
|
1214
|
+
self.assertEqual(
|
|
1215
|
+
z.tolist(),
|
|
1216
|
+
[[0, 5, 0, 10], [6, 7, 12, 14], [0, 15, 0, 20], [18, 21, 24, 28]],
|
|
1217
|
+
)
|
|
1218
|
+
|
|
1219
|
+
# Test with different dimensions
|
|
1220
|
+
x = mx.array([1, 2]) # (2,)
|
|
1221
|
+
y = mx.array([[3, 4], [5, 6]]) # (2, 2)
|
|
1222
|
+
z = mx.kron(x, y)
|
|
1223
|
+
self.assertEqual(z.tolist(), [[3, 4, 6, 8], [5, 6, 10, 12]])
|
|
1224
|
+
|
|
1225
|
+
# Test with empty array
|
|
1226
|
+
x = mx.array([])
|
|
1227
|
+
y = mx.array([1, 2])
|
|
1228
|
+
with self.assertRaises(ValueError):
|
|
1229
|
+
mx.kron(x, y)
|
|
1230
|
+
|
|
1231
|
+
def test_take(self):
|
|
1232
|
+
# Shape: 4 x 3 x 2
|
|
1233
|
+
l = [
|
|
1234
|
+
[[1, 3], [-2, -2], [-3, -2]],
|
|
1235
|
+
[[2, 4], [-3, 2], [-4, -2]],
|
|
1236
|
+
[[2, 3], [2, 4], [2, 1]],
|
|
1237
|
+
[[1, -5], [3, -1], [2, 3]],
|
|
1238
|
+
]
|
|
1239
|
+
|
|
1240
|
+
a = mx.array(l)
|
|
1241
|
+
a_npy = np.array(l)
|
|
1242
|
+
|
|
1243
|
+
indices = [0, -1]
|
|
1244
|
+
flatten_take = mx.take(a, mx.array(indices)).tolist()
|
|
1245
|
+
flatten_take_expected = np.take(a_npy, np.array(indices)).tolist()
|
|
1246
|
+
self.assertListEqual(flatten_take, flatten_take_expected)
|
|
1247
|
+
|
|
1248
|
+
indices = [-1, 2, 0]
|
|
1249
|
+
axis_take = mx.take(a, mx.array(indices), axis=0).tolist()
|
|
1250
|
+
axis_take_expected = np.take(a_npy, np.array(indices), axis=0).tolist()
|
|
1251
|
+
self.assertListEqual(axis_take, axis_take_expected)
|
|
1252
|
+
|
|
1253
|
+
indices = [0, 0, -2]
|
|
1254
|
+
axis_take = mx.take(a, mx.array(indices), axis=1).tolist()
|
|
1255
|
+
axis_take_expected = np.take(a_npy, np.array(indices), axis=1).tolist()
|
|
1256
|
+
self.assertListEqual(axis_take, axis_take_expected)
|
|
1257
|
+
|
|
1258
|
+
indices = [0, -1, -1]
|
|
1259
|
+
axis_take = mx.take(a, mx.array(indices), axis=-1).tolist()
|
|
1260
|
+
axis_take_expected = np.take(a_npy, np.array(indices), axis=-1).tolist()
|
|
1261
|
+
self.assertListEqual(axis_take, axis_take_expected)
|
|
1262
|
+
|
|
1263
|
+
a_npy = np.arange(8 * 8 * 8, dtype=np.int32)
|
|
1264
|
+
a_npy = a_npy.reshape((8, 8, 8))
|
|
1265
|
+
idx_npy = np.arange(6, dtype=np.uint32)
|
|
1266
|
+
idx_npy = idx_npy.reshape((2, 3))
|
|
1267
|
+
a_mlx = mx.array(a_npy)
|
|
1268
|
+
idx_mlx = mx.array(idx_npy)
|
|
1269
|
+
|
|
1270
|
+
a_npy_taken = np.take(a_npy, idx_npy)
|
|
1271
|
+
a_mlx_taken = mx.take(a_mlx, idx_mlx)
|
|
1272
|
+
self.assertEqual(a_npy_taken.shape, a_mlx_taken.shape)
|
|
1273
|
+
self.assertListEqual(a_npy_taken.tolist(), a_mlx_taken.tolist())
|
|
1274
|
+
|
|
1275
|
+
a_npy_taken = np.take(a_npy, idx_npy, axis=0)
|
|
1276
|
+
a_mlx_taken = mx.take(a_mlx, idx_mlx, axis=0)
|
|
1277
|
+
self.assertEqual(a_npy_taken.shape, a_mlx_taken.shape)
|
|
1278
|
+
self.assertListEqual(a_npy_taken.tolist(), a_mlx_taken.tolist())
|
|
1279
|
+
|
|
1280
|
+
a_npy_taken = np.take(a_npy, idx_npy, axis=1)
|
|
1281
|
+
a_mlx_taken = mx.take(a_mlx, idx_mlx, axis=1)
|
|
1282
|
+
self.assertEqual(a_npy_taken.shape, a_mlx_taken.shape)
|
|
1283
|
+
self.assertListEqual(a_npy_taken.tolist(), a_mlx_taken.tolist())
|
|
1284
|
+
|
|
1285
|
+
a_npy_taken = np.take(a_npy, idx_npy, axis=2)
|
|
1286
|
+
a_mlx_taken = mx.take(a_mlx, idx_mlx, axis=2)
|
|
1287
|
+
self.assertEqual(a_npy_taken.shape, a_mlx_taken.shape)
|
|
1288
|
+
self.assertListEqual(a_npy_taken.tolist(), a_mlx_taken.tolist())
|
|
1289
|
+
|
|
1290
|
+
# Take with integer index
|
|
1291
|
+
a = mx.arange(8).reshape(2, 4)
|
|
1292
|
+
out = mx.take(a, 1, axis=0)
|
|
1293
|
+
self.assertTrue(mx.array_equal(out, mx.array([4, 5, 6, 7])))
|
|
1294
|
+
out = mx.take(a, 1, axis=1)
|
|
1295
|
+
self.assertTrue(mx.array_equal(out, mx.array([1, 5])))
|
|
1296
|
+
|
|
1297
|
+
# Take with multi-dim scalar preserves dims
|
|
1298
|
+
out = mx.take(a, mx.array(1), axis=0)
|
|
1299
|
+
self.assertEqual(out.shape, (4,))
|
|
1300
|
+
|
|
1301
|
+
out = mx.take(a, mx.array([1]), axis=0)
|
|
1302
|
+
self.assertEqual(out.shape, (1, 4))
|
|
1303
|
+
|
|
1304
|
+
out = mx.take(a, mx.array([[1]]), axis=0)
|
|
1305
|
+
self.assertEqual(out.shape, (1, 1, 4))
|
|
1306
|
+
|
|
1307
|
+
# Take from empty array works in some cases
|
|
1308
|
+
a = mx.zeros((4, 0))
|
|
1309
|
+
out = mx.take(a, mx.array([1, 2]), axis=0)
|
|
1310
|
+
self.assertEqual(out.shape, (2, 0))
|
|
1311
|
+
self.assertEqual(out.dtype, a.dtype)
|
|
1312
|
+
with self.assertRaises(ValueError):
|
|
1313
|
+
mx.take(a, mx.array([[1]]), axis=1)
|
|
1314
|
+
|
|
1315
|
+
def test_take_along_axis(self):
|
|
1316
|
+
a_np = np.arange(8).reshape(2, 2, 2)
|
|
1317
|
+
a_mlx = mx.array(a_np)
|
|
1318
|
+
idx_np = np.array([1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0])
|
|
1319
|
+
idx_mlx = mx.array(idx_np)
|
|
1320
|
+
|
|
1321
|
+
for ax in [None, 0, 1, 2]:
|
|
1322
|
+
if ax == None:
|
|
1323
|
+
shape = [-1]
|
|
1324
|
+
else:
|
|
1325
|
+
shape = [2] * 3
|
|
1326
|
+
shape[ax] = 3
|
|
1327
|
+
out_np = np.take_along_axis(a_np, idx_np.reshape(shape), axis=ax)
|
|
1328
|
+
out_mlx = mx.take_along_axis(a_mlx, mx.reshape(idx_mlx, shape), axis=ax)
|
|
1329
|
+
self.assertTrue(np.array_equal(out_np, np.array(out_mlx)))
|
|
1330
|
+
|
|
1331
|
+
def test_put_along_axis(self):
|
|
1332
|
+
for ax in [None, 0, 1, 2]:
|
|
1333
|
+
a_np = np.arange(16).reshape(2, 2, 4).astype(np.int32)
|
|
1334
|
+
a_mlx = mx.array(a_np)
|
|
1335
|
+
|
|
1336
|
+
if ax == None:
|
|
1337
|
+
idx_np = np.random.permutation(a_np.size)
|
|
1338
|
+
values_np = np.random.randint(low=0, high=100, size=(16,))
|
|
1339
|
+
else:
|
|
1340
|
+
shape = list(a_np.shape)
|
|
1341
|
+
shape[ax] = 2
|
|
1342
|
+
idx_np = np.random.choice(a_np.shape[ax], replace=False, size=(2,))
|
|
1343
|
+
idx_np = np.expand_dims(idx_np, list(range(1, 2 - ax + 1)))
|
|
1344
|
+
idx_np = np.broadcast_to(idx_np, shape)
|
|
1345
|
+
values_np = np.random.randint(low=0, high=100, size=shape)
|
|
1346
|
+
|
|
1347
|
+
idx_np.astype(np.int32)
|
|
1348
|
+
values_np.astype(a_np.dtype)
|
|
1349
|
+
|
|
1350
|
+
idx_mlx = mx.array(idx_np)
|
|
1351
|
+
values_mlx = mx.array(values_np)
|
|
1352
|
+
|
|
1353
|
+
np.put_along_axis(a_np, idx_np, values_np, axis=ax)
|
|
1354
|
+
out_mlx = mx.put_along_axis(a_mlx, idx_mlx, values_mlx, axis=ax)
|
|
1355
|
+
self.assertTrue(np.array_equal(a_np, out_mlx))
|
|
1356
|
+
|
|
1357
|
+
source = mx.zeros((1, 1, 8, 32))
|
|
1358
|
+
indices = mx.array([0, 2, 4, 5]).reshape((1, 1, 4, 1))
|
|
1359
|
+
update = mx.array(1.0)
|
|
1360
|
+
|
|
1361
|
+
out_mlx = mx.put_along_axis(source, indices, update, axis=-2)
|
|
1362
|
+
out_np = np.array(source)
|
|
1363
|
+
np.put_along_axis(out_np, np.array(indices), np.array(update), axis=-2)
|
|
1364
|
+
self.assertTrue(np.array_equal(out_np, np.array(out_mlx)))
|
|
1365
|
+
|
|
1366
|
+
a = mx.array([], mx.float32)
|
|
1367
|
+
b = mx.put_along_axis(a, a, a, axis=None)
|
|
1368
|
+
mx.eval(b)
|
|
1369
|
+
self.assertEqual(b.size, 0)
|
|
1370
|
+
self.assertEqual(b.shape, a.shape)
|
|
1371
|
+
|
|
1372
|
+
# 64-bit outputs are not supported by the Metal scatter and should
|
|
1373
|
+
# raise a clean error rather than failing the Metal JIT build. The CPU
|
|
1374
|
+
# and CUDA backends handle them fine.
|
|
1375
|
+
idx = mx.array([[0], [1], [2], [3]])
|
|
1376
|
+
for dt in (mx.int64, mx.uint64):
|
|
1377
|
+
x = mx.zeros((4, 8), dtype=dt)
|
|
1378
|
+
upd = mx.ones((4, 1), dtype=dt)
|
|
1379
|
+
if mx.metal.is_available():
|
|
1380
|
+
with self.assertRaises(ValueError):
|
|
1381
|
+
mx.eval(mx.put_along_axis(x, idx, upd, axis=1, stream=mx.gpu))
|
|
1382
|
+
out = mx.put_along_axis(x, idx, upd, axis=1, stream=mx.cpu)
|
|
1383
|
+
self.assertEqual(out.dtype, dt)
|
|
1384
|
+
mx.eval(out)
|
|
1385
|
+
|
|
1386
|
+
def test_split(self):
|
|
1387
|
+
a = mx.array([1, 2, 3])
|
|
1388
|
+
splits = mx.split(a, 3)
|
|
1389
|
+
for e, x in enumerate(splits):
|
|
1390
|
+
self.assertEqual(x.item(), e + 1)
|
|
1391
|
+
|
|
1392
|
+
a = mx.array([[1, 2], [3, 4], [5, 6]])
|
|
1393
|
+
x, y, z = mx.split(a, 3, axis=0)
|
|
1394
|
+
self.assertEqual(x.tolist(), [[1, 2]])
|
|
1395
|
+
self.assertEqual(y.tolist(), [[3, 4]])
|
|
1396
|
+
self.assertEqual(z.tolist(), [[5, 6]])
|
|
1397
|
+
|
|
1398
|
+
with self.assertRaises(ValueError):
|
|
1399
|
+
mx.split(a, 3, axis=2)
|
|
1400
|
+
|
|
1401
|
+
a = mx.arange(8)
|
|
1402
|
+
x, y, z = mx.split(a, [1, 5])
|
|
1403
|
+
self.assertEqual(x.tolist(), [0])
|
|
1404
|
+
self.assertEqual(y.tolist(), [1, 2, 3, 4])
|
|
1405
|
+
self.assertEqual(z.tolist(), [5, 6, 7])
|
|
1406
|
+
|
|
1407
|
+
def test_flip(self):
|
|
1408
|
+
a_np = np.arange(6).reshape(2, 3)
|
|
1409
|
+
a = mx.array(a_np)
|
|
1410
|
+
for axis in [None, 0, 1, -1, (0, 1)]:
|
|
1411
|
+
self.assertTrue(
|
|
1412
|
+
np.array_equal(mx.flip(a, axis=axis), np.flip(a_np, axis=axis)),
|
|
1413
|
+
msg=f"axis={axis}",
|
|
1414
|
+
)
|
|
1415
|
+
|
|
1416
|
+
# 1D
|
|
1417
|
+
b_np = np.array([1, 2, 3, 4])
|
|
1418
|
+
self.assertTrue(np.array_equal(mx.flip(mx.array(b_np)), np.flip(b_np)))
|
|
1419
|
+
|
|
1420
|
+
with self.assertRaises(ValueError):
|
|
1421
|
+
mx.flip(a, axis=2)
|
|
1422
|
+
|
|
1423
|
+
def test_unstack(self):
|
|
1424
|
+
a_np = np.arange(6).reshape(3, 2)
|
|
1425
|
+
a = mx.array(a_np)
|
|
1426
|
+
for axis in [0, 1, -1]:
|
|
1427
|
+
parts = mx.unstack(a, axis=axis)
|
|
1428
|
+
expected = np.unstack(a_np, axis=axis)
|
|
1429
|
+
self.assertEqual(len(parts), len(expected))
|
|
1430
|
+
for p, e in zip(parts, expected):
|
|
1431
|
+
self.assertTrue(np.array_equal(p, e))
|
|
1432
|
+
self.assertEqual(p.shape, e.shape)
|
|
1433
|
+
|
|
1434
|
+
# Default axis is 0.
|
|
1435
|
+
self.assertTrue(np.array_equal(mx.unstack(a)[1], np.unstack(a_np)[1]))
|
|
1436
|
+
|
|
1437
|
+
# stack is the inverse of unstack.
|
|
1438
|
+
self.assertTrue(mx.array_equal(mx.stack(mx.unstack(a, axis=1), axis=1), a))
|
|
1439
|
+
|
|
1440
|
+
with self.assertRaises(ValueError):
|
|
1441
|
+
mx.unstack(a, axis=2)
|
|
1442
|
+
|
|
1443
|
+
def test_split_invalid_num_splits(self):
|
|
1444
|
+
"""Regression: split with num_splits <= 0 should raise, not crash."""
|
|
1445
|
+
a = mx.arange(6)
|
|
1446
|
+
|
|
1447
|
+
# num_splits = 0: should raise cleanly (was UB via divide-by-zero)
|
|
1448
|
+
with self.assertRaises(ValueError):
|
|
1449
|
+
mx.split(a, 0)
|
|
1450
|
+
|
|
1451
|
+
# num_splits = -1: should raise cleanly (was SIGBUS via huge allocation)
|
|
1452
|
+
with self.assertRaises(ValueError):
|
|
1453
|
+
mx.split(a, -1)
|
|
1454
|
+
|
|
1455
|
+
# Also check with explicit axis
|
|
1456
|
+
b = mx.zeros((4, 6))
|
|
1457
|
+
with self.assertRaises(ValueError):
|
|
1458
|
+
mx.split(b, 0, axis=1)
|
|
1459
|
+
with self.assertRaises(ValueError):
|
|
1460
|
+
mx.split(b, -2, axis=0)
|
|
1461
|
+
|
|
1462
|
+
def test_arange_overload_dispatch(self):
|
|
1463
|
+
with self.assertRaises(ValueError):
|
|
1464
|
+
a = mx.arange(float("nan"), 1, 5)
|
|
1465
|
+
with self.assertRaises(ValueError):
|
|
1466
|
+
a = mx.arange(0, float("nan"), 5)
|
|
1467
|
+
with self.assertRaises(ValueError):
|
|
1468
|
+
a = mx.arange(0, 2, float("nan"))
|
|
1469
|
+
with self.assertRaises(ValueError):
|
|
1470
|
+
a = mx.arange(0, float("inf"), float("inf"))
|
|
1471
|
+
with self.assertRaises(ValueError):
|
|
1472
|
+
a = mx.arange(float("inf"), 1, float("inf"))
|
|
1473
|
+
with self.assertRaises(ValueError):
|
|
1474
|
+
a = mx.arange(float("inf"), 1, 5)
|
|
1475
|
+
with self.assertRaises(TypeError):
|
|
1476
|
+
INT_MAX = 2147483647
|
|
1477
|
+
a = mx.arange(0, INT_MAX + 1, 1)
|
|
1478
|
+
|
|
1479
|
+
a = mx.arange(5)
|
|
1480
|
+
expected = [0, 1, 2, 3, 4]
|
|
1481
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1482
|
+
|
|
1483
|
+
a = mx.arange(1, 5)
|
|
1484
|
+
expected = [1, 2, 3, 4]
|
|
1485
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1486
|
+
|
|
1487
|
+
a = mx.arange(-3, step=-1)
|
|
1488
|
+
expected = [0, -1, -2]
|
|
1489
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1490
|
+
|
|
1491
|
+
a = mx.arange(stop=2, step=0.5)
|
|
1492
|
+
expected = [0, 0.5, 1.0, 1.5]
|
|
1493
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1494
|
+
|
|
1495
|
+
with self.assertRaises(TypeError):
|
|
1496
|
+
mx.arange(start=1, step=2)
|
|
1497
|
+
|
|
1498
|
+
a = mx.arange(stop=3)
|
|
1499
|
+
expected = [0, 1, 2]
|
|
1500
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1501
|
+
|
|
1502
|
+
# A zero step has no defined length; it must raise rather than divide by
|
|
1503
|
+
# zero and cast the resulting nan/inf to int (undefined behavior).
|
|
1504
|
+
with self.assertRaises(ValueError):
|
|
1505
|
+
mx.arange(2, 2, 0)
|
|
1506
|
+
with self.assertRaises(ValueError):
|
|
1507
|
+
mx.arange(0, 5, 0)
|
|
1508
|
+
|
|
1509
|
+
def test_arange_inferred_dtype(self):
|
|
1510
|
+
a = mx.arange(5)
|
|
1511
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1512
|
+
|
|
1513
|
+
a = mx.arange(5.0)
|
|
1514
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1515
|
+
|
|
1516
|
+
a = mx.arange(1, 3.0)
|
|
1517
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1518
|
+
|
|
1519
|
+
a = mx.arange(1, 3, dtype=mx.float32)
|
|
1520
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1521
|
+
|
|
1522
|
+
a = mx.arange(1, 5, 1)
|
|
1523
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1524
|
+
|
|
1525
|
+
a = mx.arange(1.0, 5, 1)
|
|
1526
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1527
|
+
|
|
1528
|
+
a = mx.arange(1, 5.0, 1)
|
|
1529
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1530
|
+
|
|
1531
|
+
a = mx.arange(1, 5, 1.0)
|
|
1532
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1533
|
+
|
|
1534
|
+
a = mx.arange(1.0, 3.0, 0.2, dtype=mx.int32)
|
|
1535
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1536
|
+
|
|
1537
|
+
def test_arange_corner_cases_cast(self):
|
|
1538
|
+
a = mx.arange(0, 3, 0.2, dtype=mx.int32)
|
|
1539
|
+
expected = [0] * 15
|
|
1540
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1541
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1542
|
+
|
|
1543
|
+
a = mx.arange(-1, -4, -0.9, dtype=mx.int32)
|
|
1544
|
+
expected = [-1] * 4
|
|
1545
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1546
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1547
|
+
|
|
1548
|
+
a = mx.arange(-1, -20, -1.2, dtype=mx.int32)
|
|
1549
|
+
expected = [
|
|
1550
|
+
-1,
|
|
1551
|
+
-2,
|
|
1552
|
+
-3,
|
|
1553
|
+
-4,
|
|
1554
|
+
-5,
|
|
1555
|
+
-6,
|
|
1556
|
+
-7,
|
|
1557
|
+
-8,
|
|
1558
|
+
-9,
|
|
1559
|
+
-10,
|
|
1560
|
+
-11,
|
|
1561
|
+
-12,
|
|
1562
|
+
-13,
|
|
1563
|
+
-14,
|
|
1564
|
+
-15,
|
|
1565
|
+
-16,
|
|
1566
|
+
]
|
|
1567
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1568
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1569
|
+
|
|
1570
|
+
a = mx.arange(0, 10, 100)
|
|
1571
|
+
expected = [0]
|
|
1572
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1573
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
1574
|
+
|
|
1575
|
+
a = mx.arange(10, 0, 1)
|
|
1576
|
+
expected = []
|
|
1577
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1578
|
+
|
|
1579
|
+
a = mx.arange(10, 0, float("inf"))
|
|
1580
|
+
expected = []
|
|
1581
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1582
|
+
|
|
1583
|
+
a = mx.arange(0, 10, float("inf"))
|
|
1584
|
+
expected = [0]
|
|
1585
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1586
|
+
|
|
1587
|
+
a = mx.arange(0, -10, float("-inf"))
|
|
1588
|
+
expected = [0]
|
|
1589
|
+
self.assertListEqual(a.tolist(), expected)
|
|
1590
|
+
|
|
1591
|
+
def test_hanning_general(self):
|
|
1592
|
+
a = mx.hanning(10)
|
|
1593
|
+
expected = np.hanning(10)
|
|
1594
|
+
self.assertTrue(np.allclose(a, expected, atol=1e-5))
|
|
1595
|
+
|
|
1596
|
+
a = mx.hanning(1)
|
|
1597
|
+
self.assertEqual(a.item(), 1.0)
|
|
1598
|
+
|
|
1599
|
+
a = mx.hanning(0)
|
|
1600
|
+
self.assertEqual(a.size, 0)
|
|
1601
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1602
|
+
|
|
1603
|
+
def test_hamming_general(self):
|
|
1604
|
+
a = mx.hamming(10)
|
|
1605
|
+
expected = np.hamming(10)
|
|
1606
|
+
self.assertTrue(np.allclose(a, expected, atol=1e-5))
|
|
1607
|
+
|
|
1608
|
+
a = mx.hamming(1)
|
|
1609
|
+
self.assertEqual(a.item(), 1.0)
|
|
1610
|
+
|
|
1611
|
+
a = mx.hamming(0)
|
|
1612
|
+
self.assertEqual(a.size, 0)
|
|
1613
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1614
|
+
|
|
1615
|
+
def test_bartlett_general(self):
|
|
1616
|
+
a = mx.bartlett(10)
|
|
1617
|
+
expected = np.bartlett(10)
|
|
1618
|
+
self.assertTrue(np.allclose(a, expected, atol=1e-5))
|
|
1619
|
+
|
|
1620
|
+
a = mx.bartlett(1)
|
|
1621
|
+
self.assertEqual(a.item(), 1.0)
|
|
1622
|
+
|
|
1623
|
+
a = mx.bartlett(0)
|
|
1624
|
+
self.assertEqual(a.size, 0)
|
|
1625
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1626
|
+
|
|
1627
|
+
def test_blackman_general(self):
|
|
1628
|
+
a = mx.blackman(10)
|
|
1629
|
+
expected = np.blackman(10)
|
|
1630
|
+
self.assertTrue(np.allclose(a, expected, atol=1e-5))
|
|
1631
|
+
|
|
1632
|
+
a = mx.blackman(1)
|
|
1633
|
+
self.assertEqual(a.item(), 1.0)
|
|
1634
|
+
|
|
1635
|
+
a = mx.blackman(0)
|
|
1636
|
+
self.assertEqual(a.size, 0)
|
|
1637
|
+
self.assertEqual(a.dtype, mx.float32)
|
|
1638
|
+
|
|
1639
|
+
def test_unary_ops(self):
|
|
1640
|
+
def test_ops(npop, mlxop, x, y, atol, rtol):
|
|
1641
|
+
r_np = npop(x)
|
|
1642
|
+
r_mlx = mlxop(y)
|
|
1643
|
+
mx.eval(r_mlx)
|
|
1644
|
+
self.assertTrue(np.allclose(r_np, r_mlx, atol=atol, rtol=rtol))
|
|
1645
|
+
|
|
1646
|
+
x = np.random.rand(18, 28, 38)
|
|
1647
|
+
for op in ["abs", "exp", "log", "square", "sqrt"]:
|
|
1648
|
+
with self.subTest(op=op):
|
|
1649
|
+
float_dtypes = [("float16", 1e-3, 1e-3), ("float32", 1e-6, 1e-5)]
|
|
1650
|
+
|
|
1651
|
+
for dtype, atol, rtol in float_dtypes:
|
|
1652
|
+
with self.subTest(dtype=dtype):
|
|
1653
|
+
x_ = x.astype(getattr(np, dtype))
|
|
1654
|
+
y_ = mx.array(x_)
|
|
1655
|
+
test_ops(getattr(np, op), getattr(mx, op), x_, y_, atol, rtol)
|
|
1656
|
+
|
|
1657
|
+
def test_unary_ops_from_non_array(self):
|
|
1658
|
+
unary_ops = [
|
|
1659
|
+
"abs",
|
|
1660
|
+
"exp",
|
|
1661
|
+
"log",
|
|
1662
|
+
"square",
|
|
1663
|
+
"sqrt",
|
|
1664
|
+
"sin",
|
|
1665
|
+
"cos",
|
|
1666
|
+
"tan",
|
|
1667
|
+
"sinh",
|
|
1668
|
+
"cosh",
|
|
1669
|
+
"tanh",
|
|
1670
|
+
"sign",
|
|
1671
|
+
"negative",
|
|
1672
|
+
"expm1",
|
|
1673
|
+
"arcsin",
|
|
1674
|
+
"arccos",
|
|
1675
|
+
"arctan",
|
|
1676
|
+
"arcsinh",
|
|
1677
|
+
"arctanh",
|
|
1678
|
+
"degrees",
|
|
1679
|
+
"radians",
|
|
1680
|
+
"log2",
|
|
1681
|
+
"log10",
|
|
1682
|
+
"log1p",
|
|
1683
|
+
"floor",
|
|
1684
|
+
"ceil",
|
|
1685
|
+
"conjugate",
|
|
1686
|
+
]
|
|
1687
|
+
|
|
1688
|
+
x = 0.5
|
|
1689
|
+
x_np = np.random.rand(10).astype(np.float32)
|
|
1690
|
+
for op in unary_ops:
|
|
1691
|
+
with self.subTest(op=op):
|
|
1692
|
+
# Test from scalar
|
|
1693
|
+
expected = getattr(np, op)(x)
|
|
1694
|
+
out = getattr(mx, op)(x)
|
|
1695
|
+
|
|
1696
|
+
# Check close
|
|
1697
|
+
self.assertTrue(np.allclose(expected, out, equal_nan=True))
|
|
1698
|
+
|
|
1699
|
+
# Test from NumPy
|
|
1700
|
+
expected = getattr(np, op)(x_np)
|
|
1701
|
+
out = getattr(mx, op)(x_np)
|
|
1702
|
+
|
|
1703
|
+
# Check close
|
|
1704
|
+
self.assertTrue(np.allclose(expected, np.array(out), equal_nan=True))
|
|
1705
|
+
|
|
1706
|
+
def test_trig_ops(self):
|
|
1707
|
+
def test_ops(npop, mlxop, x, y, atol, rtol):
|
|
1708
|
+
r_np = npop(x)
|
|
1709
|
+
r_mlx = mlxop(y)
|
|
1710
|
+
mx.eval(r_mlx)
|
|
1711
|
+
|
|
1712
|
+
self.assertTrue(
|
|
1713
|
+
np.allclose(r_np, r_mlx, atol=atol, rtol=rtol, equal_nan=True)
|
|
1714
|
+
)
|
|
1715
|
+
|
|
1716
|
+
x = np.random.rand(9, 12, 18)
|
|
1717
|
+
xi = np.random.rand(9, 12, 18)
|
|
1718
|
+
base_ops = ["sin", "cos", "tan"]
|
|
1719
|
+
hyperbolic_ops = ["sinh", "cosh", "tanh"]
|
|
1720
|
+
all_fwd_ops = base_ops + hyperbolic_ops
|
|
1721
|
+
|
|
1722
|
+
for op in all_fwd_ops:
|
|
1723
|
+
with self.subTest(op=op):
|
|
1724
|
+
float_dtypes = [("float16", 1e-3, 1e-3), ("float32", 1e-6, 1e-5)]
|
|
1725
|
+
|
|
1726
|
+
for dtype, atol, rtol in float_dtypes:
|
|
1727
|
+
with self.subTest(dtype=dtype):
|
|
1728
|
+
x_ = x.astype(getattr(np, dtype))
|
|
1729
|
+
y_ = mx.array(x_)
|
|
1730
|
+
test_ops(getattr(np, op), getattr(mx, op), x_, y_, atol, rtol)
|
|
1731
|
+
|
|
1732
|
+
with self.subTest(op=op):
|
|
1733
|
+
dtype = "complex64"
|
|
1734
|
+
with self.subTest(dtype=dtype):
|
|
1735
|
+
x_ = x + 1.0j * xi
|
|
1736
|
+
x_ = x_.astype(getattr(np, dtype))
|
|
1737
|
+
y_ = mx.array(x_)
|
|
1738
|
+
test_ops(getattr(np, op), getattr(mx, op), x_, y_, 1e-5, 1e-5)
|
|
1739
|
+
|
|
1740
|
+
with self.subTest(op="arc" + op):
|
|
1741
|
+
float_dtypes = [("float16", 1e-3, 1e-3), ("float32", 1e-6, 1e-5)]
|
|
1742
|
+
op_inv = "arc" + op
|
|
1743
|
+
|
|
1744
|
+
for dtype, atol, rtol in float_dtypes:
|
|
1745
|
+
with self.subTest(dtype=dtype):
|
|
1746
|
+
np_op_fwd = getattr(np, op)
|
|
1747
|
+
x_ = np_op_fwd(x).astype(getattr(np, dtype))
|
|
1748
|
+
y_ = mx.array(x_)
|
|
1749
|
+
test_ops(
|
|
1750
|
+
getattr(np, op_inv), getattr(mx, op_inv), x_, y_, atol, rtol
|
|
1751
|
+
)
|
|
1752
|
+
|
|
1753
|
+
# Test grads
|
|
1754
|
+
np_vjp_funcs = {
|
|
1755
|
+
"sin": lambda primal, cotan: cotan * np.cos(primal),
|
|
1756
|
+
"cos": lambda primal, cotan: -cotan * np.sin(primal),
|
|
1757
|
+
"tan": lambda primal, cotan: cotan / (np.cos(primal) ** 2),
|
|
1758
|
+
"sinh": lambda primal, cotan: cotan * np.cosh(primal),
|
|
1759
|
+
"cosh": lambda primal, cotan: cotan * np.sinh(primal),
|
|
1760
|
+
"tanh": lambda primal, cotan: cotan / (np.cosh(primal) ** 2),
|
|
1761
|
+
"arcsin": lambda primal, cotan: cotan / np.sqrt(1.0 - primal**2),
|
|
1762
|
+
"arccos": lambda primal, cotan: -cotan / np.sqrt(1.0 - primal**2),
|
|
1763
|
+
"arctan": lambda primal, cotan: cotan / (1.0 + primal**2),
|
|
1764
|
+
"arctan2": lambda primal, cotan: cotan / (1.0 + primal**2),
|
|
1765
|
+
"arcsinh": lambda primal, cotan: cotan / np.sqrt(primal**2 + 1),
|
|
1766
|
+
"arccosh": lambda primal, cotan: cotan / np.sqrt(primal**2 - 1),
|
|
1767
|
+
"arctanh": lambda primal, cotan: cotan / (1.0 - primal**2),
|
|
1768
|
+
}
|
|
1769
|
+
with self.subTest(name="grads"):
|
|
1770
|
+
for op in all_fwd_ops:
|
|
1771
|
+
with self.subTest(op=op):
|
|
1772
|
+
primal_np = xi.astype(np.float32)
|
|
1773
|
+
primal_mx = mx.array(primal_np)
|
|
1774
|
+
x_ = x.astype(np.float32)
|
|
1775
|
+
y_ = mx.array(x_)
|
|
1776
|
+
op_ = op
|
|
1777
|
+
|
|
1778
|
+
np_vjp = lambda x: np_vjp_funcs[op_](primal_np, x)
|
|
1779
|
+
mx_vjp = lambda x: mx.vjp(getattr(mx, op_), [primal_mx], [x])[1][0]
|
|
1780
|
+
test_ops(np_vjp, mx_vjp, x_, y_, 1e-5, 1e-5)
|
|
1781
|
+
|
|
1782
|
+
with self.subTest(op="arc" + op):
|
|
1783
|
+
np_op_fwd = getattr(np, op)
|
|
1784
|
+
primal_np = np_op_fwd(xi).astype(np.float32)
|
|
1785
|
+
|
|
1786
|
+
# To avoid divide by zero error
|
|
1787
|
+
if op == "cosh":
|
|
1788
|
+
primal_np[np.isclose(primal_np, 1.0)] += 1e-3
|
|
1789
|
+
elif op == "cos":
|
|
1790
|
+
primal_np[np.isclose(primal_np, 1.0)] -= 1e-3
|
|
1791
|
+
|
|
1792
|
+
primal_mx = mx.array(primal_np)
|
|
1793
|
+
x_ = x.astype(np.float32)
|
|
1794
|
+
y_ = mx.array(x_)
|
|
1795
|
+
op_ = "arc" + op
|
|
1796
|
+
|
|
1797
|
+
np_vjp = lambda x: np_vjp_funcs[op_](primal_np, x)
|
|
1798
|
+
mx_vjp = lambda x: mx.vjp(getattr(mx, op_), [primal_mx], [x])[1][0]
|
|
1799
|
+
test_ops(np_vjp, mx_vjp, x_, y_, 1e-5, 1e-5)
|
|
1800
|
+
|
|
1801
|
+
def test_binary_ops(self):
|
|
1802
|
+
def test_ops(npop, mlxop, x1, x2, y1, y2, atol):
|
|
1803
|
+
r_np = npop(x1, x2)
|
|
1804
|
+
r_mlx = mlxop(y1, y2)
|
|
1805
|
+
mx.eval(r_mlx)
|
|
1806
|
+
self.assertTrue(np.allclose(r_np, r_mlx, atol=atol))
|
|
1807
|
+
|
|
1808
|
+
r_np = npop(x1[:1], x2)
|
|
1809
|
+
r_mlx = mlxop(y1[:1], y2)
|
|
1810
|
+
mx.eval(r_mlx)
|
|
1811
|
+
self.assertTrue(np.allclose(r_np, r_mlx, atol=atol))
|
|
1812
|
+
|
|
1813
|
+
r_np = npop(x1[:, :1], x2)
|
|
1814
|
+
r_mlx = mlxop(y1[:, :1], y2)
|
|
1815
|
+
mx.eval(r_mlx)
|
|
1816
|
+
self.assertTrue(np.allclose(r_np, r_mlx, atol=atol))
|
|
1817
|
+
|
|
1818
|
+
r_np = npop(x1[:, :, :1], x2)
|
|
1819
|
+
r_mlx = mlxop(y1[:, :, :1], y2)
|
|
1820
|
+
mx.eval(r_mlx)
|
|
1821
|
+
self.assertTrue(np.allclose(r_np, r_mlx, atol=atol))
|
|
1822
|
+
|
|
1823
|
+
x1 = np.maximum(np.random.rand(18, 28, 38), 0.1)
|
|
1824
|
+
x2 = np.maximum(np.random.rand(18, 28, 38), 0.1)
|
|
1825
|
+
y1 = mx.array(x1)
|
|
1826
|
+
y2 = mx.array(x2)
|
|
1827
|
+
mx.eval(y1, y2)
|
|
1828
|
+
for op in [
|
|
1829
|
+
"add",
|
|
1830
|
+
"subtract",
|
|
1831
|
+
"multiply",
|
|
1832
|
+
"divide",
|
|
1833
|
+
"floor_divide",
|
|
1834
|
+
"maximum",
|
|
1835
|
+
"minimum",
|
|
1836
|
+
"power",
|
|
1837
|
+
]:
|
|
1838
|
+
with self.subTest(op=op):
|
|
1839
|
+
int_dtypes = [
|
|
1840
|
+
"int8",
|
|
1841
|
+
"int16",
|
|
1842
|
+
"int32",
|
|
1843
|
+
"int64",
|
|
1844
|
+
"uint8",
|
|
1845
|
+
"uint16",
|
|
1846
|
+
"uint32",
|
|
1847
|
+
"uint64",
|
|
1848
|
+
]
|
|
1849
|
+
float_dtypes = ["float16", "float32"]
|
|
1850
|
+
|
|
1851
|
+
dtypes = {
|
|
1852
|
+
"divide": float_dtypes,
|
|
1853
|
+
"power": float_dtypes,
|
|
1854
|
+
"floor_divide": ["float32"] + int_dtypes,
|
|
1855
|
+
}
|
|
1856
|
+
dtypes = dtypes.get(op, int_dtypes + float_dtypes)
|
|
1857
|
+
|
|
1858
|
+
for dtype in dtypes:
|
|
1859
|
+
atol = 1e-3 if dtype == "float16" else 1e-6
|
|
1860
|
+
with self.subTest(dtype=dtype):
|
|
1861
|
+
m = 10 if dtype in int_dtypes else 1
|
|
1862
|
+
x1_ = (x1 * m).astype(getattr(np, dtype))
|
|
1863
|
+
x2_ = (x2 * m).astype(getattr(np, dtype))
|
|
1864
|
+
y1_ = mx.array(x1_)
|
|
1865
|
+
y2_ = mx.array(x2_)
|
|
1866
|
+
test_ops(
|
|
1867
|
+
getattr(np, op), getattr(mx, op), x1_, x2_, y1_, y2_, atol
|
|
1868
|
+
)
|
|
1869
|
+
|
|
1870
|
+
def test_irregular_binary_ops(self):
|
|
1871
|
+
# Check transposed binary ops
|
|
1872
|
+
dims = [2, 3, 4, 5]
|
|
1873
|
+
size = 3
|
|
1874
|
+
trial_mul = 2
|
|
1875
|
+
np.random.seed(0)
|
|
1876
|
+
for d in dims:
|
|
1877
|
+
anp = np.random.randint(-20, 20, (size**d,)).reshape([size] * d)
|
|
1878
|
+
bnp = np.random.randint(-20, 20, (size**d,)).reshape([size] * d)
|
|
1879
|
+
for _ in range(trial_mul * d):
|
|
1880
|
+
amlx = mx.array(anp)
|
|
1881
|
+
bmlx = mx.array(bnp)
|
|
1882
|
+
a_t = np.random.permutation(d).tolist()
|
|
1883
|
+
b_t = np.random.permutation(d).tolist()
|
|
1884
|
+
outnp = np.add(anp.transpose(a_t), bnp.transpose(b_t))
|
|
1885
|
+
outmlx = mx.add(mx.transpose(amlx, a_t), mx.transpose(bmlx, b_t))
|
|
1886
|
+
self.assertTrue(np.array_equal(outnp, outmlx))
|
|
1887
|
+
|
|
1888
|
+
# Check broadcast binary ops
|
|
1889
|
+
for d in dims:
|
|
1890
|
+
anp = np.random.randint(-20, 20, (size**d,)).reshape([size] * d)
|
|
1891
|
+
for n_bsx in range(d):
|
|
1892
|
+
bnp = np.random.randint(-20, 20, (size**n_bsx,)).reshape([size] * n_bsx)
|
|
1893
|
+
for _ in range(trial_mul * d):
|
|
1894
|
+
amlx = mx.array(anp)
|
|
1895
|
+
bmlx = mx.array(bnp)
|
|
1896
|
+
b_shape = [1] * (d - n_bsx) + [size] * n_bsx
|
|
1897
|
+
np.random.shuffle(b_shape)
|
|
1898
|
+
outnp = np.add(anp, bnp.reshape(b_shape))
|
|
1899
|
+
outmlx = mx.add(amlx, mx.reshape(bmlx, b_shape))
|
|
1900
|
+
self.assertTrue(np.array_equal(outnp, outmlx))
|
|
1901
|
+
|
|
1902
|
+
# Check strided binary ops
|
|
1903
|
+
for d in dims:
|
|
1904
|
+
a = np.random.randint(-20, 20, (10,) * d)
|
|
1905
|
+
b = np.random.randint(-20, 20, (10,) * d)
|
|
1906
|
+
a_ = mx.array(a)
|
|
1907
|
+
b_ = mx.array(b)
|
|
1908
|
+
for t in permutations(range(d)):
|
|
1909
|
+
for s in range(d):
|
|
1910
|
+
idx = tuple(
|
|
1911
|
+
[slice(None)] * s
|
|
1912
|
+
+ [slice(None, None, 2)]
|
|
1913
|
+
+ [slice(None)] * (d - s - 1)
|
|
1914
|
+
)
|
|
1915
|
+
c = a.transpose(t)[idx] + b[idx]
|
|
1916
|
+
c_ = mx.transpose(a_, t)[idx] + b_[idx]
|
|
1917
|
+
self.assertTrue(np.array_equal(c, c_))
|
|
1918
|
+
|
|
1919
|
+
def test_softmax(self):
|
|
1920
|
+
cases = [(np.float32, 1e-6), (np.float16, 1e-3)]
|
|
1921
|
+
|
|
1922
|
+
for dtype, atol in cases:
|
|
1923
|
+
a_npy = np.random.randn(16, 8, 32).astype(dtype)
|
|
1924
|
+
a_mlx = mx.array(a_npy)
|
|
1925
|
+
|
|
1926
|
+
def np_softmax(x, axis):
|
|
1927
|
+
ex = np.exp(x - np.max(x, axis=axis, keepdims=True))
|
|
1928
|
+
return ex / np.sum(ex, axis=axis, keepdims=True)
|
|
1929
|
+
|
|
1930
|
+
for axes in (None, 0, 1, 2, (0, 1), (1, 2), (0, 2), (0, 1, 2)):
|
|
1931
|
+
b_npy = np_softmax(a_npy, axes)
|
|
1932
|
+
b_mlx = mx.softmax(a_mlx, axes)
|
|
1933
|
+
self.assertTrue(np.allclose(b_npy, b_mlx, atol=atol))
|
|
1934
|
+
|
|
1935
|
+
for s in [100, 2049, 4097, 8193]:
|
|
1936
|
+
a = np.full(s, -np.inf)
|
|
1937
|
+
a[-1] = 0.0
|
|
1938
|
+
a = mx.softmax(mx.array(a))
|
|
1939
|
+
self.assertFalse(np.any(np.isnan(a)))
|
|
1940
|
+
self.assertTrue((a[:-1] < 1e-9).all())
|
|
1941
|
+
self.assertEqual(a[-1], 1)
|
|
1942
|
+
|
|
1943
|
+
# Sliced inputs
|
|
1944
|
+
y = mx.random.uniform(shape=(8, 4))
|
|
1945
|
+
out = mx.softmax(y[:, 0:2], axis=-1)
|
|
1946
|
+
self.assertAlmostEqual(out.sum().item(), 8.0, 5)
|
|
1947
|
+
|
|
1948
|
+
# Precise
|
|
1949
|
+
for t in [mx.float16, mx.bfloat16]:
|
|
1950
|
+
a = (10 * mx.random.normal(shape=(1024,))).astype(t)
|
|
1951
|
+
out_expect = mx.softmax(a.astype(mx.float32)).astype(t)
|
|
1952
|
+
out = mx.softmax(a, axis=-1, precise=True)
|
|
1953
|
+
self.assertTrue(mx.allclose(out_expect, out, atol=1e-6))
|
|
1954
|
+
|
|
1955
|
+
# All Infs give NaNs
|
|
1956
|
+
for n in [127, 128, 129]:
|
|
1957
|
+
x = mx.full((n,), vals=-float("inf"))
|
|
1958
|
+
self.assertTrue(mx.all(mx.isnan(mx.softmax(x))))
|
|
1959
|
+
|
|
1960
|
+
# Transposed inputs
|
|
1961
|
+
a = mx.random.uniform(shape=(32, 32, 32))
|
|
1962
|
+
b = mx.softmax(a, axis=-1)
|
|
1963
|
+
c = mx.softmax(a.swapaxes(0, 1), axis=-1).swapaxes(0, 1)
|
|
1964
|
+
self.assertEqual((b - c).abs().max().item(), 0.0)
|
|
1965
|
+
|
|
1966
|
+
with self.assertRaises(ValueError):
|
|
1967
|
+
mx.softmax(mx.array(1.0), axis=-1)
|
|
1968
|
+
|
|
1969
|
+
def test_concatenate(self):
|
|
1970
|
+
a_npy = np.random.randn(32, 32, 32)
|
|
1971
|
+
b_npy = np.random.randn(32, 32, 32)
|
|
1972
|
+
a_mlx = mx.array(a_npy)
|
|
1973
|
+
b_mlx = mx.array(b_npy)
|
|
1974
|
+
|
|
1975
|
+
for axis in (None, 0, 1, 2):
|
|
1976
|
+
for p in permutations([0, 1, 2]):
|
|
1977
|
+
c_npy = np.concatenate([a_npy, np.transpose(b_npy, p)], axis=axis)
|
|
1978
|
+
c_mlx = mx.concatenate([a_mlx, mx.transpose(b_mlx, p)], axis=axis)
|
|
1979
|
+
self.assertEqual(list(c_npy.shape), list(c_mlx.shape))
|
|
1980
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, atol=1e-6))
|
|
1981
|
+
|
|
1982
|
+
with self.assertRaises(ValueError):
|
|
1983
|
+
a = mx.array([[1, 2], [1, 2], [1, 2]])
|
|
1984
|
+
b = mx.array([1, 2])
|
|
1985
|
+
mx.concatenate([a, b], axis=0)
|
|
1986
|
+
|
|
1987
|
+
# Cocnatenate with 0-sized array
|
|
1988
|
+
a = mx.zeros((2, 0, 2))
|
|
1989
|
+
b = mx.zeros((2, 2, 2))
|
|
1990
|
+
out = mx.concatenate([a, b], axis=1)
|
|
1991
|
+
self.assertTrue(mx.array_equal(out, b))
|
|
1992
|
+
|
|
1993
|
+
def test_meshgrid(self):
|
|
1994
|
+
x = mx.array([1, 2, 3], dtype=mx.int32)
|
|
1995
|
+
y = np.array([1, 2, 3], dtype=np.int32)
|
|
1996
|
+
|
|
1997
|
+
# Test single input
|
|
1998
|
+
a_mlx = mx.meshgrid(x)
|
|
1999
|
+
a_np = np.meshgrid(y)
|
|
2000
|
+
self.assertEqualArray(a_mlx[0], mx.array(a_np[0]))
|
|
2001
|
+
|
|
2002
|
+
# Test sparse
|
|
2003
|
+
a_mlx, b_mlx, c_mlx = mx.meshgrid(x, x, x, sparse=True)
|
|
2004
|
+
a_np, b_np, c_np = np.meshgrid(y, y, y, sparse=True)
|
|
2005
|
+
self.assertEqualArray(a_mlx, mx.array(a_np))
|
|
2006
|
+
self.assertEqualArray(b_mlx, mx.array(b_np))
|
|
2007
|
+
self.assertEqualArray(c_mlx, mx.array(c_np))
|
|
2008
|
+
|
|
2009
|
+
# Test different lengths
|
|
2010
|
+
x = mx.array([1, 2], dtype=mx.int32)
|
|
2011
|
+
y = mx.array([1, 2, 3], dtype=mx.int32)
|
|
2012
|
+
z = np.array([1, 2], dtype=np.int32)
|
|
2013
|
+
w = np.array([1, 2, 3], dtype=np.int32)
|
|
2014
|
+
a_mlx, b_mlx = mx.meshgrid(x, y)
|
|
2015
|
+
a_np, b_np = np.meshgrid(z, w)
|
|
2016
|
+
self.assertEqualArray(a_mlx, mx.array(a_np))
|
|
2017
|
+
self.assertEqualArray(b_mlx, mx.array(b_np))
|
|
2018
|
+
|
|
2019
|
+
# Test empty input
|
|
2020
|
+
x = mx.array([], dtype=mx.int32)
|
|
2021
|
+
y = np.array([], dtype=np.int32)
|
|
2022
|
+
a_mlx = mx.meshgrid(x)
|
|
2023
|
+
a_np = np.meshgrid(y)
|
|
2024
|
+
self.assertEqualArray(a_mlx[0], mx.array(a_np[0]))
|
|
2025
|
+
|
|
2026
|
+
# Test float32 input
|
|
2027
|
+
x = mx.array([1.1, 2.2, 3.3], dtype=mx.float32)
|
|
2028
|
+
y = np.array([1.1, 2.2, 3.3], dtype=np.float32)
|
|
2029
|
+
a_mlx = mx.meshgrid(x, x, x)
|
|
2030
|
+
a_np = np.meshgrid(y, y, y)
|
|
2031
|
+
self.assertEqualArray(a_mlx[0], mx.array(a_np[0]))
|
|
2032
|
+
self.assertEqualArray(a_mlx[1], mx.array(a_np[1]))
|
|
2033
|
+
self.assertEqualArray(a_mlx[2], mx.array(a_np[2]))
|
|
2034
|
+
|
|
2035
|
+
# Test ij indexing
|
|
2036
|
+
x = mx.array([1.1, 2.2, 3.3, 4.4, 5.5], dtype=mx.float32)
|
|
2037
|
+
y = np.array([1.1, 2.2, 3.3, 4.4, 5.5], dtype=np.float32)
|
|
2038
|
+
a_mlx = mx.meshgrid(x, x, indexing="ij")
|
|
2039
|
+
a_np = np.meshgrid(y, y, indexing="ij")
|
|
2040
|
+
self.assertEqualArray(a_mlx[0], mx.array(a_np[0]))
|
|
2041
|
+
self.assertEqualArray(a_mlx[1], mx.array(a_np[1]))
|
|
2042
|
+
|
|
2043
|
+
# Test different lengths, sparse, and ij indexing
|
|
2044
|
+
a = mx.array([1, 2], dtype=mx.int64)
|
|
2045
|
+
b = mx.array([1, 2, 3], dtype=mx.int64)
|
|
2046
|
+
c = mx.array([1, 2, 3, 4], dtype=mx.int64)
|
|
2047
|
+
x = np.array([1, 2], dtype=np.int64)
|
|
2048
|
+
y = np.array([1, 2, 3], dtype=np.int64)
|
|
2049
|
+
z = np.array([1, 2, 3, 4], dtype=np.int64)
|
|
2050
|
+
a_mlx, b_mlx, c_mlx = mx.meshgrid(a, b, c, sparse=True, indexing="ij")
|
|
2051
|
+
a_np, b_np, c_np = np.meshgrid(x, y, z, sparse=True, indexing="ij")
|
|
2052
|
+
self.assertEqualArray(a_mlx, mx.array(a_np))
|
|
2053
|
+
self.assertEqualArray(b_mlx, mx.array(b_np))
|
|
2054
|
+
self.assertEqualArray(c_mlx, mx.array(c_np))
|
|
2055
|
+
|
|
2056
|
+
def test_pad(self):
|
|
2057
|
+
pad_width_and_values = [
|
|
2058
|
+
([(1, 1), (1, 1), (1, 1)], 0),
|
|
2059
|
+
([(1, 1), (1, 1), (1, 1)], 5),
|
|
2060
|
+
([(3, 0), (0, 2), (5, 7)], 0),
|
|
2061
|
+
([(3, 0), (0, 2), (5, 7)], -7),
|
|
2062
|
+
([(0, 0), (0, 0), (0, 0)], 0),
|
|
2063
|
+
]
|
|
2064
|
+
|
|
2065
|
+
for pw, v in pad_width_and_values:
|
|
2066
|
+
with self.subTest(pad_width=pw, value=v):
|
|
2067
|
+
a_npy = np.random.randn(16, 16, 16).astype(np.float32)
|
|
2068
|
+
a_mlx = mx.array(a_npy)
|
|
2069
|
+
|
|
2070
|
+
b_npy = np.pad(a_npy, pw, constant_values=v)
|
|
2071
|
+
b_mlx = mx.pad(a_mlx, pw, constant_values=v)
|
|
2072
|
+
|
|
2073
|
+
self.assertEqual(list(b_npy.shape), list(b_mlx.shape))
|
|
2074
|
+
self.assertTrue(np.allclose(b_npy, b_mlx, atol=1e-6))
|
|
2075
|
+
|
|
2076
|
+
b_npy = np.pad(a_npy, pw, mode="edge")
|
|
2077
|
+
b_mlx = mx.pad(a_mlx, pw, mode="edge")
|
|
2078
|
+
|
|
2079
|
+
self.assertEqual(list(b_npy.shape), list(b_mlx.shape))
|
|
2080
|
+
self.assertTrue(np.allclose(b_npy, b_mlx, atol=1e-6))
|
|
2081
|
+
|
|
2082
|
+
a = mx.zeros((1, 1, 1))
|
|
2083
|
+
self.assertEqual(mx.pad(a, 1).shape, (3, 3, 3))
|
|
2084
|
+
self.assertEqual(mx.pad(a, (1,)).shape, (3, 3, 3))
|
|
2085
|
+
self.assertEqual(mx.pad(a, [1]).shape, (3, 3, 3))
|
|
2086
|
+
self.assertEqual(mx.pad(a, (1, 2)).shape, (4, 4, 4))
|
|
2087
|
+
self.assertEqual(mx.pad(a, [(1, 2)]).shape, (4, 4, 4))
|
|
2088
|
+
self.assertEqual(mx.pad(a, ((1, 2),)).shape, (4, 4, 4))
|
|
2089
|
+
self.assertEqual(mx.pad(a, ((1, 2), (2, 1), (2, 2))).shape, (4, 4, 5))
|
|
2090
|
+
|
|
2091
|
+
# Test grads
|
|
2092
|
+
a_fwd = mx.array(np.random.rand(16, 16).astype(np.float32))
|
|
2093
|
+
a_bwd = mx.ones((22, 22))
|
|
2094
|
+
f = lambda x: mx.pad(x, ((4, 2), (2, 4)))
|
|
2095
|
+
|
|
2096
|
+
_, df = mx.vjp(f, [a_fwd], [a_bwd])
|
|
2097
|
+
self.assertTrue(mx.allclose(a_bwd[4:-2, 2:-4], df[0]).item())
|
|
2098
|
+
|
|
2099
|
+
def test_where(self):
|
|
2100
|
+
self.assertCmpNumpy([True, mx.array([[1, 2], [3, 4]]), 1], mx.where, np.where)
|
|
2101
|
+
self.assertCmpNumpy([True, 1, mx.array([[1, 2], [3, 4]])], mx.where, np.where)
|
|
2102
|
+
self.assertCmpNumpy(
|
|
2103
|
+
[
|
|
2104
|
+
mx.array([[True, False], [False, True]]),
|
|
2105
|
+
mx.array([[1, 2], [3, 4]]),
|
|
2106
|
+
mx.array([5, 6]),
|
|
2107
|
+
],
|
|
2108
|
+
mx.where,
|
|
2109
|
+
np.where,
|
|
2110
|
+
)
|
|
2111
|
+
|
|
2112
|
+
# Check non-contiguous input with several dimensions
|
|
2113
|
+
shape = [1, 2, 2, 3, 3, 1]
|
|
2114
|
+
strides = [16, 4, 1, 4, 1, 1]
|
|
2115
|
+
x = mx.ones(shape=(1, 4, 4, 1))
|
|
2116
|
+
x = mx.as_strided(x, shape, strides)
|
|
2117
|
+
out = mx.where(mx.isnan(x), mx.nan, x)
|
|
2118
|
+
self.assertTrue(mx.allclose(out, mx.ones_like(out)))
|
|
2119
|
+
|
|
2120
|
+
def test_nan_to_num(self):
|
|
2121
|
+
a = mx.array([6, float("inf"), 2, 0])
|
|
2122
|
+
out_mx = mx.nan_to_num(a)
|
|
2123
|
+
out_np = np.nan_to_num(a)
|
|
2124
|
+
self.assertTrue(np.allclose(out_mx, out_np))
|
|
2125
|
+
|
|
2126
|
+
for t in [mx.float32, mx.float16]:
|
|
2127
|
+
a = mx.array([float("inf"), 6.9, float("nan"), float("-inf")])
|
|
2128
|
+
out_mx = mx.nan_to_num(a)
|
|
2129
|
+
out_np = np.nan_to_num(a)
|
|
2130
|
+
self.assertTrue(np.allclose(out_mx, out_np))
|
|
2131
|
+
|
|
2132
|
+
a = mx.array([float("inf"), 6.9, float("nan"), float("-inf")]).astype(t)
|
|
2133
|
+
out_np = np.nan_to_num(a, nan=0.0, posinf=1000, neginf=-1000)
|
|
2134
|
+
out_mx = mx.nan_to_num(a, nan=0.0, posinf=1000, neginf=-1000)
|
|
2135
|
+
self.assertTrue(np.allclose(out_mx, out_np))
|
|
2136
|
+
|
|
2137
|
+
def test_as_strided(self):
|
|
2138
|
+
x_npy = np.random.randn(128).astype(np.float32)
|
|
2139
|
+
x_mlx = mx.array(x_npy)
|
|
2140
|
+
|
|
2141
|
+
shapes = [(10, 10), (5, 5), (2, 20), (10,)]
|
|
2142
|
+
strides = [(3, 3), (7, 1), (1, 5), (4,)]
|
|
2143
|
+
for shape, stride in zip(shapes, strides):
|
|
2144
|
+
for offset in [0, 1, 3]:
|
|
2145
|
+
y_npy = np.lib.stride_tricks.as_strided(
|
|
2146
|
+
x_npy[offset:], shape, np.multiply(stride, 4)
|
|
2147
|
+
)
|
|
2148
|
+
y_mlx = mx.as_strided(x_mlx, shape, stride, offset)
|
|
2149
|
+
self.assertTrue(np.array_equal(y_npy, y_mlx))
|
|
2150
|
+
|
|
2151
|
+
x = mx.random.uniform(shape=(32,))
|
|
2152
|
+
y = mx.as_strided(x, (x.size,), (-1,), x.size - 1)
|
|
2153
|
+
self.assertTrue(mx.array_equal(y, x[::-1]))
|
|
2154
|
+
|
|
2155
|
+
def test_logcumsumexp(self):
|
|
2156
|
+
npop = np.logaddexp.accumulate
|
|
2157
|
+
mxop = mx.logcumsumexp
|
|
2158
|
+
|
|
2159
|
+
a_npy = np.random.randn(32, 32, 32).astype(np.float32)
|
|
2160
|
+
a_mlx = mx.array(a_npy)
|
|
2161
|
+
|
|
2162
|
+
for axis in (0, 1, 2):
|
|
2163
|
+
c_npy = npop(a_npy, axis=axis)
|
|
2164
|
+
c_mlx = mxop(a_mlx, axis=axis)
|
|
2165
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, rtol=1e-3, atol=1e-3))
|
|
2166
|
+
|
|
2167
|
+
edge_cases_npy = [
|
|
2168
|
+
np.float32([-float("inf")] * 8),
|
|
2169
|
+
np.float32([-float("inf"), 0, -float("inf")]),
|
|
2170
|
+
np.float32([-float("inf"), float("inf"), -float("inf")]),
|
|
2171
|
+
]
|
|
2172
|
+
edge_cases_mlx = [mx.array(a) for a in edge_cases_npy]
|
|
2173
|
+
|
|
2174
|
+
for a_npy, a_mlx in zip(edge_cases_npy, edge_cases_mlx):
|
|
2175
|
+
c_npy = npop(a_npy, axis=0)
|
|
2176
|
+
c_mlx = mxop(a_mlx, axis=0)
|
|
2177
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, rtol=1e-3, atol=1e-3))
|
|
2178
|
+
|
|
2179
|
+
# Complex tests
|
|
2180
|
+
|
|
2181
|
+
a_npy = np.array([1, 2, 3]).astype(np.float32) + 1j
|
|
2182
|
+
a_mlx = mx.array(a_npy)
|
|
2183
|
+
c_npy = np_cumlogaddexp(a_npy, axis=-1)
|
|
2184
|
+
c_mlx = mxop(a_mlx, axis=-1)
|
|
2185
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, rtol=1e-3, atol=1e-3))
|
|
2186
|
+
|
|
2187
|
+
def test_scans(self):
|
|
2188
|
+
a_npy = np.random.randn(32, 32, 32).astype(np.float32)
|
|
2189
|
+
a_mlx = mx.array(a_npy)
|
|
2190
|
+
|
|
2191
|
+
for op in ["cumsum", "cumprod"]:
|
|
2192
|
+
npop = getattr(np, op)
|
|
2193
|
+
mxop = getattr(mx, op)
|
|
2194
|
+
for axis in (None, 0, 1, 2):
|
|
2195
|
+
c_npy = npop(a_npy, axis=axis)
|
|
2196
|
+
c_mlx = mxop(a_mlx, axis=axis)
|
|
2197
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, rtol=1e-3, atol=1e-3))
|
|
2198
|
+
|
|
2199
|
+
# Complex test
|
|
2200
|
+
|
|
2201
|
+
a_npy = np.random.randn(32, 32, 32).astype(np.float32) + 0.5j
|
|
2202
|
+
a_mlx = mx.array(a_npy)
|
|
2203
|
+
|
|
2204
|
+
for op in ["cumsum", "cumprod"]:
|
|
2205
|
+
npop = getattr(np, op)
|
|
2206
|
+
mxop = getattr(mx, op)
|
|
2207
|
+
for axis in (None, 0, 1, 2):
|
|
2208
|
+
c_npy = npop(a_npy, axis=axis)
|
|
2209
|
+
c_mlx = mxop(a_mlx, axis=axis)
|
|
2210
|
+
self.assertTrue(np.allclose(c_npy, c_mlx, rtol=1e-3, atol=1e-3))
|
|
2211
|
+
|
|
2212
|
+
a_mlx = mx.random.randint(shape=(32, 32, 32), low=-100, high=100)
|
|
2213
|
+
for dt in [mx.int32, mx.int64]:
|
|
2214
|
+
mxx = a_mlx.astype(dt)
|
|
2215
|
+
npx = np.array(mxx)
|
|
2216
|
+
for op in ["cumsum", "cumprod"]:
|
|
2217
|
+
npop = getattr(np, op)
|
|
2218
|
+
mxop = getattr(mx, op)
|
|
2219
|
+
for axis in (None, 0, 1, 2):
|
|
2220
|
+
c_npy = npop(npx, axis=axis, dtype=npx.dtype)
|
|
2221
|
+
c_mlx = mxop(mxx, axis=axis)
|
|
2222
|
+
self.assertTrue(np.array_equal(c_npy, c_mlx))
|
|
2223
|
+
|
|
2224
|
+
a_mlx = mx.random.randint(shape=(32, 32, 32), low=-100, high=100)
|
|
2225
|
+
for op in ["cumsum", "cumprod", "cummax", "cummin"]:
|
|
2226
|
+
mxop = getattr(mx, op)
|
|
2227
|
+
c1 = mxop(a_mlx, axis=2)
|
|
2228
|
+
c2 = mxop(a_mlx, axis=2, inclusive=False, reverse=False)
|
|
2229
|
+
self.assertTrue(mx.array_equal(c1[:, :, :-1], c2[:, :, 1:]))
|
|
2230
|
+
c1 = mxop(a_mlx, axis=1)
|
|
2231
|
+
c2 = mxop(a_mlx, axis=1, inclusive=False, reverse=False)
|
|
2232
|
+
self.assertTrue(mx.array_equal(c1[:, :-1, :], c2[:, 1:, :]))
|
|
2233
|
+
c1 = mxop(a_mlx, axis=0)
|
|
2234
|
+
c2 = mxop(a_mlx, axis=0, inclusive=False, reverse=False)
|
|
2235
|
+
self.assertTrue(mx.array_equal(c1[:-1, :, :], c2[1:, :, :]))
|
|
2236
|
+
|
|
2237
|
+
rev_idx = mx.arange(31, -1, -1)
|
|
2238
|
+
c1 = mxop(a_mlx[:, :, rev_idx], axis=2)[:, :, rev_idx]
|
|
2239
|
+
c2 = mxop(a_mlx, axis=2, inclusive=True, reverse=True)
|
|
2240
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2241
|
+
c1 = mxop(a_mlx[:, rev_idx, :], axis=1)[:, rev_idx, :]
|
|
2242
|
+
c2 = mxop(a_mlx, axis=1, inclusive=True, reverse=True)
|
|
2243
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2244
|
+
c1 = mxop(a_mlx[rev_idx, :, :], axis=0)[rev_idx, :, :]
|
|
2245
|
+
c2 = mxop(a_mlx, axis=0, inclusive=True, reverse=True)
|
|
2246
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2247
|
+
|
|
2248
|
+
rev_idx = mx.arange(31, -1, -1)
|
|
2249
|
+
c1 = mxop(a_mlx[:, :, rev_idx], axis=2)[:, :, rev_idx][:, :, 1:]
|
|
2250
|
+
c2 = mxop(a_mlx, axis=2, inclusive=False, reverse=True)[:, :, :-1]
|
|
2251
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2252
|
+
c1 = mxop(a_mlx[:, rev_idx, :], axis=1)[:, rev_idx, :][:, 1:, :]
|
|
2253
|
+
c2 = mxop(a_mlx, axis=1, inclusive=False, reverse=True)[:, :-1, :]
|
|
2254
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2255
|
+
c1 = mxop(a_mlx[rev_idx, :, :], axis=0)[rev_idx, :, :][1:, :, :]
|
|
2256
|
+
c2 = mxop(a_mlx, axis=0, inclusive=False, reverse=True)[:-1, :, :]
|
|
2257
|
+
self.assertTrue(mx.array_equal(c1, c2))
|
|
2258
|
+
|
|
2259
|
+
a = mx.random.uniform(shape=(8, 32))
|
|
2260
|
+
mat = mx.tri(32)
|
|
2261
|
+
for t in [mx.float16, mx.bfloat16]:
|
|
2262
|
+
a_t = a.astype(t)
|
|
2263
|
+
mat_t = mat.astype(t)
|
|
2264
|
+
out = mx.cumsum(a_t, axis=-1)
|
|
2265
|
+
expected = (mat_t * a_t[:, None, :]).sum(axis=-1)
|
|
2266
|
+
self.assertTrue(mx.allclose(out, expected, rtol=0.02, atol=1e-3))
|
|
2267
|
+
sizes = [1023, 1024, 1025, 2047, 2048, 2049]
|
|
2268
|
+
for s in sizes:
|
|
2269
|
+
a = mx.ones((s,), mx.int32)
|
|
2270
|
+
out = mx.cumsum(a)
|
|
2271
|
+
expected = mx.arange(1, s + 1, dtype=mx.int32)
|
|
2272
|
+
self.assertTrue(mx.array_equal(expected, out))
|
|
2273
|
+
|
|
2274
|
+
# non-contiguous scan
|
|
2275
|
+
a = mx.ones((s, 2), mx.int32)
|
|
2276
|
+
out = mx.cumsum(a, axis=0)
|
|
2277
|
+
expected = mx.repeat(expected[:, None], 2, axis=1)
|
|
2278
|
+
self.assertTrue(mx.array_equal(expected, out))
|
|
2279
|
+
|
|
2280
|
+
# Test donation
|
|
2281
|
+
def fn(its):
|
|
2282
|
+
x = mx.ones((32,))
|
|
2283
|
+
for _ in range(its):
|
|
2284
|
+
x = mx.cumsum(x)
|
|
2285
|
+
return x
|
|
2286
|
+
|
|
2287
|
+
mx.synchronize()
|
|
2288
|
+
mx.eval(fn(2))
|
|
2289
|
+
mx.synchronize()
|
|
2290
|
+
mem2 = mx.get_peak_memory()
|
|
2291
|
+
mx.eval(fn(4))
|
|
2292
|
+
mx.synchronize()
|
|
2293
|
+
mem4 = mx.get_peak_memory()
|
|
2294
|
+
self.assertEqual(mem2, mem4)
|
|
2295
|
+
|
|
2296
|
+
def test_diff(self):
|
|
2297
|
+
a = mx.array([1, 2, 4, 7, 0])
|
|
2298
|
+
self.assertEqual(mx.diff(a).tolist(), [1, 2, 3, -7])
|
|
2299
|
+
self.assertEqual(mx.diff(a, n=2).tolist(), [1, 1, -10])
|
|
2300
|
+
self.assertEqual(mx.diff(a, n=0).tolist(), a.tolist())
|
|
2301
|
+
|
|
2302
|
+
m = mx.array([[1, 3, 6], [0, 5, 6]])
|
|
2303
|
+
self.assertEqual(mx.diff(m, axis=0).tolist(), [[-1, 2, 0]])
|
|
2304
|
+
self.assertEqual(mx.diff(m, axis=1).tolist(), [[2, 3], [5, 1]])
|
|
2305
|
+
|
|
2306
|
+
with self.assertRaises(ValueError):
|
|
2307
|
+
mx.diff(a, axis=1)
|
|
2308
|
+
|
|
2309
|
+
def test_squeeze_expand(self):
|
|
2310
|
+
a = mx.zeros((2, 1, 2, 1))
|
|
2311
|
+
self.assertEqual(mx.squeeze(a).shape, (2, 2))
|
|
2312
|
+
self.assertEqual(mx.squeeze(a, 1).shape, (2, 2, 1))
|
|
2313
|
+
self.assertEqual(mx.squeeze(a, [1, 3]).shape, (2, 2))
|
|
2314
|
+
self.assertEqual(a.squeeze().shape, (2, 2))
|
|
2315
|
+
self.assertEqual(a.squeeze(1).shape, (2, 2, 1))
|
|
2316
|
+
self.assertEqual(a.squeeze([1, 3]).shape, (2, 2))
|
|
2317
|
+
|
|
2318
|
+
a = mx.zeros((2, 2))
|
|
2319
|
+
self.assertEqual(mx.squeeze(a).shape, (2, 2))
|
|
2320
|
+
|
|
2321
|
+
self.assertEqual(mx.expand_dims(a, 0).shape, (1, 2, 2))
|
|
2322
|
+
self.assertEqual(mx.expand_dims(a, (0, 1)).shape, (1, 1, 2, 2))
|
|
2323
|
+
self.assertEqual(mx.expand_dims(a, [0, -1]).shape, (1, 2, 2, 1))
|
|
2324
|
+
|
|
2325
|
+
def test_sort(self):
|
|
2326
|
+
shape = (6, 4, 10)
|
|
2327
|
+
tests = product(
|
|
2328
|
+
("int32", "float32", "complex64"), # type
|
|
2329
|
+
(None, 0, 1, 2), # axis
|
|
2330
|
+
(True, False), # strided
|
|
2331
|
+
)
|
|
2332
|
+
for dtype, axis, strided in tests:
|
|
2333
|
+
with self.subTest(dtype=dtype, axis=axis, strided=strided):
|
|
2334
|
+
np.random.seed(0)
|
|
2335
|
+
np_dtype = getattr(np, dtype)
|
|
2336
|
+
if np.issubdtype(np_dtype, np.complexfloating):
|
|
2337
|
+
a_np = (
|
|
2338
|
+
np.random.uniform(0, 100, size=shape)
|
|
2339
|
+
+ 1j * np.random.uniform(0, 100, size=shape)
|
|
2340
|
+
).astype(np_dtype)
|
|
2341
|
+
else:
|
|
2342
|
+
a_np = np.random.uniform(0, 100, size=shape).astype(np_dtype)
|
|
2343
|
+
a_mx = mx.array(a_np)
|
|
2344
|
+
if strided:
|
|
2345
|
+
a_mx = a_mx[::2, :, ::2]
|
|
2346
|
+
a_np = a_np[::2, :, ::2]
|
|
2347
|
+
|
|
2348
|
+
b_np = np.sort(a_np, axis=axis)
|
|
2349
|
+
b_mx = mx.sort(a_mx, axis=axis)
|
|
2350
|
+
|
|
2351
|
+
self.assertTrue(np.array_equal(b_np, b_mx))
|
|
2352
|
+
self.assertEqual(b_mx.dtype, a_mx.dtype)
|
|
2353
|
+
|
|
2354
|
+
c_np = np.argsort(a_np, axis=axis)
|
|
2355
|
+
c_mx = mx.argsort(a_mx, axis=axis)
|
|
2356
|
+
d_np = np.take_along_axis(a_np, c_np, axis=axis)
|
|
2357
|
+
d_mx = mx.take_along_axis(a_mx, c_mx, axis=axis)
|
|
2358
|
+
|
|
2359
|
+
self.assertTrue(np.array_equal(d_np, d_mx))
|
|
2360
|
+
self.assertEqual(c_mx.dtype, mx.uint32)
|
|
2361
|
+
|
|
2362
|
+
# Set random seed
|
|
2363
|
+
np.random.seed(0)
|
|
2364
|
+
|
|
2365
|
+
# Test multi-block sort
|
|
2366
|
+
for strided in (False, True):
|
|
2367
|
+
with self.subTest(strided=strided):
|
|
2368
|
+
a_np = np.random.normal(size=(32769,)).astype(np.float32)
|
|
2369
|
+
a_mx = mx.array(a_np)
|
|
2370
|
+
|
|
2371
|
+
if strided:
|
|
2372
|
+
a_mx = a_mx[::3]
|
|
2373
|
+
a_np = a_np[::3]
|
|
2374
|
+
|
|
2375
|
+
b_np = np.sort(a_np)
|
|
2376
|
+
b_mx = mx.sort(a_mx)
|
|
2377
|
+
|
|
2378
|
+
self.assertTrue(np.array_equal(b_np, b_mx))
|
|
2379
|
+
self.assertEqual(b_mx.dtype, a_mx.dtype)
|
|
2380
|
+
|
|
2381
|
+
# Test multi-dum multi-block sort
|
|
2382
|
+
a_np = np.random.normal(size=(2, 4, 32769)).astype(np.float32)
|
|
2383
|
+
a_mx = mx.array(a_np)
|
|
2384
|
+
|
|
2385
|
+
if strided:
|
|
2386
|
+
a_mx = a_mx[..., ::3]
|
|
2387
|
+
a_np = a_np[..., ::3]
|
|
2388
|
+
|
|
2389
|
+
b_np = np.sort(a_np, axis=-1)
|
|
2390
|
+
b_mx = mx.sort(a_mx, axis=-1)
|
|
2391
|
+
|
|
2392
|
+
self.assertTrue(np.array_equal(b_np, b_mx))
|
|
2393
|
+
self.assertEqual(b_mx.dtype, a_mx.dtype)
|
|
2394
|
+
|
|
2395
|
+
a_np = np.random.normal(size=(2, 32769, 4)).astype(np.float32)
|
|
2396
|
+
a_mx = mx.array(a_np)
|
|
2397
|
+
|
|
2398
|
+
if strided:
|
|
2399
|
+
a_mx = a_mx[:, ::3]
|
|
2400
|
+
a_np = a_np[:, ::3]
|
|
2401
|
+
|
|
2402
|
+
b_np = np.sort(a_np, axis=1)
|
|
2403
|
+
b_mx = mx.sort(a_mx, axis=1)
|
|
2404
|
+
|
|
2405
|
+
self.assertTrue(np.array_equal(b_np, b_mx))
|
|
2406
|
+
self.assertEqual(b_mx.dtype, a_mx.dtype)
|
|
2407
|
+
|
|
2408
|
+
# test 0 strides
|
|
2409
|
+
a_np = np.array([1, 0, 2, 1, 3, 0, 4, 0])
|
|
2410
|
+
a_mx = mx.array(a_np)
|
|
2411
|
+
b_np = np.broadcast_to(a_np, (16, 8))
|
|
2412
|
+
b_mx = mx.broadcast_to(a_mx, (16, 8))
|
|
2413
|
+
mx.eval(b_mx)
|
|
2414
|
+
for axis in (0, 1):
|
|
2415
|
+
c_np = np.sort(b_np, axis=axis)
|
|
2416
|
+
c_mx = mx.sort(b_mx, axis=axis)
|
|
2417
|
+
self.assertTrue(np.array_equal(c_np, c_mx))
|
|
2418
|
+
self.assertEqual(b_mx.dtype, c_mx.dtype)
|
|
2419
|
+
|
|
2420
|
+
# Test very large array
|
|
2421
|
+
if mx.default_device() == mx.gpu:
|
|
2422
|
+
a_np = np.random.normal(20, 20, size=(2**22)).astype(np.float32)
|
|
2423
|
+
a_mx = mx.array(a_np)
|
|
2424
|
+
|
|
2425
|
+
b_np = np.sort(a_np)
|
|
2426
|
+
b_mx = mx.sort(a_mx)
|
|
2427
|
+
self.assertTrue(np.array_equal(b_np, b_mx))
|
|
2428
|
+
|
|
2429
|
+
# 1D strided sort
|
|
2430
|
+
a = mx.array([[4, 3], [2, 1], [5, 4], [3, 2]])
|
|
2431
|
+
out = mx.argsort(a[:, 1])
|
|
2432
|
+
expected = mx.array([1, 3, 0, 2], dtype=mx.uint32)
|
|
2433
|
+
self.assertTrue(mx.array_equal(out, expected))
|
|
2434
|
+
|
|
2435
|
+
# Test array with singleton dim
|
|
2436
|
+
out = mx.sort(mx.array([1, 2, 3]), axis=0)
|
|
2437
|
+
self.assertTrue(mx.array_equal(out, mx.array([1, 2, 3])))
|
|
2438
|
+
|
|
2439
|
+
x = np.random.uniform(size=(1, 4, 8, 1)).astype(np.float32)
|
|
2440
|
+
y_np = np.sort(x, axis=-2)
|
|
2441
|
+
y_mx = mx.sort(mx.array(x), axis=-2)
|
|
2442
|
+
self.assertTrue(np.array_equal(y_np, y_mx))
|
|
2443
|
+
|
|
2444
|
+
# Test many segments
|
|
2445
|
+
a = mx.random.uniform(shape=(512, 128))
|
|
2446
|
+
y_mx = mx.sort(a, axis=-1)
|
|
2447
|
+
y_np = np.sort(np.array(a), axis=-1)
|
|
2448
|
+
self.assertTrue(np.array_equal(y_np, y_mx))
|
|
2449
|
+
|
|
2450
|
+
def test_partition(self):
|
|
2451
|
+
shape = (3, 4, 5)
|
|
2452
|
+
for dtype in ("int32", "float32"):
|
|
2453
|
+
for axis in (None, 0, 1, 2):
|
|
2454
|
+
for kth in (-2, 0, 2):
|
|
2455
|
+
with self.subTest(dtype=dtype, axis=axis, kth=kth):
|
|
2456
|
+
np.random.seed(0)
|
|
2457
|
+
np_dtype = getattr(np, dtype)
|
|
2458
|
+
a_np = np.random.uniform(0, 100, size=shape).astype(np_dtype)
|
|
2459
|
+
a_mx = mx.array(a_np)
|
|
2460
|
+
|
|
2461
|
+
b_np = np.partition(a_np, kth, axis=axis)
|
|
2462
|
+
b_mx = mx.partition(a_mx, kth, axis=axis)
|
|
2463
|
+
|
|
2464
|
+
c_np = np.take(b_np, (kth,), axis=axis)
|
|
2465
|
+
c_mx = np.take(np.array(b_mx), (kth,), axis=axis)
|
|
2466
|
+
|
|
2467
|
+
self.assertTrue(np.array_equal(c_np, c_mx))
|
|
2468
|
+
self.assertEqual(b_mx.dtype, a_mx.dtype)
|
|
2469
|
+
|
|
2470
|
+
if kth >= 0:
|
|
2471
|
+
top_k_mx = mx.topk(a_mx, kth, axis=axis)
|
|
2472
|
+
top_k_np = np.take(
|
|
2473
|
+
np.partition(a_np, -kth, axis=axis), (-kth,), axis=axis
|
|
2474
|
+
)
|
|
2475
|
+
self.assertTrue(np.all(top_k_np <= top_k_mx))
|
|
2476
|
+
self.assertEqual(top_k_mx.dtype, a_mx.dtype)
|
|
2477
|
+
N = a_mx.shape[axis] if axis is not None else a_mx.size
|
|
2478
|
+
M = top_k_mx.shape[axis or 0]
|
|
2479
|
+
self.assertEqual(M, (kth + N) % N)
|
|
2480
|
+
|
|
2481
|
+
def test_argpartition(self):
|
|
2482
|
+
x = mx.broadcast_to(mx.array([1, 2, 3]), (2, 3))
|
|
2483
|
+
out = mx.argpartition(x, kth=1, axis=0)
|
|
2484
|
+
expected = mx.array([[0, 0, 0], [1, 1, 1]])
|
|
2485
|
+
self.assertTrue(mx.array_equal(out, expected))
|
|
2486
|
+
|
|
2487
|
+
x = mx.array([[1, 2], [3, 4]]).T
|
|
2488
|
+
out = mx.argpartition(x, kth=1, axis=0)
|
|
2489
|
+
expected = mx.array([[0, 0], [1, 1]])
|
|
2490
|
+
self.assertTrue(mx.array_equal(out, expected))
|
|
2491
|
+
|
|
2492
|
+
@unittest.skipIf(
|
|
2493
|
+
os.getenv("LOW_MEMORY", None) is not None,
|
|
2494
|
+
"This test requires a lot of memory",
|
|
2495
|
+
)
|
|
2496
|
+
def test_large_binary(self):
|
|
2497
|
+
a = mx.ones([1000, 2147484], mx.int8)
|
|
2498
|
+
b = mx.ones([2147484], mx.int8)
|
|
2499
|
+
self.assertEqual((a + b)[0, 0].item(), 2)
|
|
2500
|
+
|
|
2501
|
+
def test_eye(self):
|
|
2502
|
+
self.assertCmpNumpy([3], mx.eye, np.eye)
|
|
2503
|
+
# Test for non-square matrix
|
|
2504
|
+
self.assertCmpNumpy([3, 4], mx.eye, np.eye)
|
|
2505
|
+
# Test with positive k parameter
|
|
2506
|
+
self.assertCmpNumpy([3, 4], mx.eye, np.eye, k=1)
|
|
2507
|
+
# Test with negative k parameter
|
|
2508
|
+
self.assertCmpNumpy([5, 6], mx.eye, np.eye, k=-2)
|
|
2509
|
+
|
|
2510
|
+
def test_stack(self):
|
|
2511
|
+
a = mx.ones((2,))
|
|
2512
|
+
np_a = np.ones((2,))
|
|
2513
|
+
b = mx.ones((2,))
|
|
2514
|
+
np_b = np.ones((2,))
|
|
2515
|
+
|
|
2516
|
+
# One dimensional stack axis=0
|
|
2517
|
+
c = mx.stack([a, b])
|
|
2518
|
+
np_c = np.stack([np_a, np_b])
|
|
2519
|
+
self.assertTrue(np.array_equal(c, np_c))
|
|
2520
|
+
|
|
2521
|
+
# One dimensional stack axis=1
|
|
2522
|
+
c = mx.stack([a, b], axis=1)
|
|
2523
|
+
np_c = np.stack([np_a, np_b], axis=1)
|
|
2524
|
+
self.assertTrue(np.array_equal(c, np_c))
|
|
2525
|
+
|
|
2526
|
+
a = mx.ones((1, 2))
|
|
2527
|
+
np_a = np.ones((1, 2))
|
|
2528
|
+
b = mx.ones((1, 2))
|
|
2529
|
+
np_b = np.ones((1, 2))
|
|
2530
|
+
|
|
2531
|
+
# Two dimensional stack axis=0
|
|
2532
|
+
c = mx.stack([a, b])
|
|
2533
|
+
np_c = np.stack([np_a, np_b])
|
|
2534
|
+
self.assertTrue(np.array_equal(c, np_c))
|
|
2535
|
+
|
|
2536
|
+
# Two dimensional stack axis=1
|
|
2537
|
+
c = mx.stack([a, b], axis=1)
|
|
2538
|
+
np_c = np.stack([np_a, np_b], axis=1)
|
|
2539
|
+
self.assertTrue(np.array_equal(c, np_c))
|
|
2540
|
+
|
|
2541
|
+
def test_flatten(self):
|
|
2542
|
+
x = mx.zeros([2, 3, 4])
|
|
2543
|
+
self.assertEqual(mx.flatten(x).shape, (2 * 3 * 4,))
|
|
2544
|
+
self.assertEqual(mx.flatten(x, start_axis=1).shape, (2, 3 * 4))
|
|
2545
|
+
self.assertEqual(mx.flatten(x, end_axis=1).shape, (2 * 3, 4))
|
|
2546
|
+
self.assertEqual(x.flatten().shape, (2 * 3 * 4,))
|
|
2547
|
+
self.assertEqual(x.flatten(start_axis=1).shape, (2, 3 * 4))
|
|
2548
|
+
self.assertEqual(x.flatten(end_axis=1).shape, (2 * 3, 4))
|
|
2549
|
+
|
|
2550
|
+
def test_clip(self):
|
|
2551
|
+
a = np.array([1, 4, 3, 8, 5], np.int32)
|
|
2552
|
+
expected = np.clip(a, 2, 6)
|
|
2553
|
+
clipped = mx.clip(mx.array(a), 2, 6)
|
|
2554
|
+
self.assertTrue(np.array_equal(clipped, expected))
|
|
2555
|
+
|
|
2556
|
+
a = np.array([-1, 1, 0, 5], np.int32)
|
|
2557
|
+
expected = np.clip(a, 0, None)
|
|
2558
|
+
clipped = mx.clip(mx.array(a), 0, None)
|
|
2559
|
+
self.assertTrue(np.array_equal(clipped, expected))
|
|
2560
|
+
|
|
2561
|
+
a = np.array([2, 3, 4, 5], np.int32)
|
|
2562
|
+
expected = np.clip(a, None, 4)
|
|
2563
|
+
clipped = mx.clip(mx.array(a), None, 4)
|
|
2564
|
+
self.assertTrue(np.array_equal(clipped, expected))
|
|
2565
|
+
|
|
2566
|
+
mins = np.array([3, 1, 5, 5])
|
|
2567
|
+
a = np.array([2, 3, 4, 5], np.int32)
|
|
2568
|
+
expected = np.clip(a, mins, 4)
|
|
2569
|
+
clipped = mx.clip(mx.array(a), mx.array(mins), 4)
|
|
2570
|
+
self.assertTrue(np.array_equal(clipped, expected))
|
|
2571
|
+
|
|
2572
|
+
maxs = np.array([5, -1, 2, 9])
|
|
2573
|
+
a = np.array([2, 3, 4, 5], np.int32)
|
|
2574
|
+
expected = np.clip(a, mins, maxs)
|
|
2575
|
+
clipped = mx.clip(mx.array(a), mx.array(mins), mx.array(maxs))
|
|
2576
|
+
self.assertTrue(np.array_equal(clipped, expected))
|
|
2577
|
+
|
|
2578
|
+
# Check clip output types
|
|
2579
|
+
a = mx.array([1, 2, 3], mx.int16)
|
|
2580
|
+
out_t = mx.clip(a, a_min=0, a_max=5).dtype
|
|
2581
|
+
self.assertEqual(out_t, mx.int16)
|
|
2582
|
+
|
|
2583
|
+
out_t = mx.clip(a, a_min=0.0, a_max=5).dtype
|
|
2584
|
+
self.assertEqual(out_t, mx.float32)
|
|
2585
|
+
|
|
2586
|
+
a = mx.array([1, 2, 3], mx.float16)
|
|
2587
|
+
out_t = mx.clip(a, a_min=0.0, a_max=5).dtype
|
|
2588
|
+
self.assertEqual(out_t, mx.float16)
|
|
2589
|
+
|
|
2590
|
+
a = mx.array([1, 2, 3], mx.float16)
|
|
2591
|
+
out_t = mx.clip(a, a_min=0.0, a_max=mx.array(1.0)).dtype
|
|
2592
|
+
self.assertEqual(out_t, mx.float32)
|
|
2593
|
+
|
|
2594
|
+
def test_linspace(self):
|
|
2595
|
+
# Test default num = 50
|
|
2596
|
+
a = mx.linspace(0, 1)
|
|
2597
|
+
expected = mx.array(np.linspace(0, 1))
|
|
2598
|
+
self.assertEqualArray(a, expected)
|
|
2599
|
+
|
|
2600
|
+
# Test int64 dtype
|
|
2601
|
+
b = mx.linspace(0, 10, 5, mx.int64)
|
|
2602
|
+
expected = mx.array(np.linspace(0, 10, 5, dtype=int))
|
|
2603
|
+
self.assertEqualArray(b, expected)
|
|
2604
|
+
|
|
2605
|
+
# Test negative sequence with float start and stop
|
|
2606
|
+
c = mx.linspace(-2.7, -0.7, 7)
|
|
2607
|
+
expected = mx.array(np.linspace(-2.7, -0.7, 7))
|
|
2608
|
+
self.assertEqualArray(c, expected)
|
|
2609
|
+
|
|
2610
|
+
# Test irrational step size of 1/9
|
|
2611
|
+
d = mx.linspace(0, 1, 10)
|
|
2612
|
+
expected = mx.array(np.linspace(0, 1, 10))
|
|
2613
|
+
self.assertEqualArray(d, expected)
|
|
2614
|
+
|
|
2615
|
+
# Test num equal to 1
|
|
2616
|
+
d = mx.linspace(1, 10, 1)
|
|
2617
|
+
expected = mx.array(np.linspace(1, 10, 1))
|
|
2618
|
+
self.assertEqualArray(d, expected)
|
|
2619
|
+
|
|
2620
|
+
# Ensure that the start and stop are always the ones provided
|
|
2621
|
+
ranges = mx.random.normal((16, 2)).tolist()
|
|
2622
|
+
nums = (2 + mx.random.uniform(shape=(16,)) * 10).astype(mx.uint32).tolist()
|
|
2623
|
+
for (a, b), n in zip(ranges, nums):
|
|
2624
|
+
d = mx.linspace(a, b, n).tolist()
|
|
2625
|
+
self.assertEqual(d[0], a)
|
|
2626
|
+
self.assertEqual(d[-1], b)
|
|
2627
|
+
|
|
2628
|
+
def test_repeat(self):
|
|
2629
|
+
# Setup data for the tests
|
|
2630
|
+
data = mx.array([[[13, 3], [16, 6]], [[14, 4], [15, 5]], [[11, 1], [12, 2]]])
|
|
2631
|
+
# Test repeat 0 times
|
|
2632
|
+
self.assertCmpNumpy([data, 0], mx.repeat, np.repeat)
|
|
2633
|
+
# Test repeat 0 times along an axis preserves the unrepeated dimensions
|
|
2634
|
+
self.assertCmpNumpy([data, 0], mx.repeat, np.repeat, axis=0)
|
|
2635
|
+
self.assertCmpNumpy([data, 0], mx.repeat, np.repeat, axis=1)
|
|
2636
|
+
# Test repeat along axis 0
|
|
2637
|
+
self.assertCmpNumpy([data, 2], mx.repeat, np.repeat, axis=0)
|
|
2638
|
+
# Test repeat along axis 1
|
|
2639
|
+
self.assertCmpNumpy([data, 2], mx.repeat, np.repeat, axis=1)
|
|
2640
|
+
# Test repeat along the last axis (default)
|
|
2641
|
+
self.assertCmpNumpy([data, 2], mx.repeat, np.repeat)
|
|
2642
|
+
# Test repeat with a 1D array along axis 0
|
|
2643
|
+
self.assertCmpNumpy([mx.array([1, 3, 2]), 3], mx.repeat, np.repeat, axis=0)
|
|
2644
|
+
# Test repeat with a 2D array along axis 0
|
|
2645
|
+
self.assertCmpNumpy(
|
|
2646
|
+
[mx.array([[1, 2, 3], [4, 5, 4], [0, 1, 2]]), 2],
|
|
2647
|
+
mx.repeat,
|
|
2648
|
+
np.repeat,
|
|
2649
|
+
axis=0,
|
|
2650
|
+
)
|
|
2651
|
+
|
|
2652
|
+
def test_tensordot(self):
|
|
2653
|
+
# No fp16 matmuls on common cpu backend
|
|
2654
|
+
if not self.is_apple_silicon:
|
|
2655
|
+
dtypes = [mx.float32]
|
|
2656
|
+
else:
|
|
2657
|
+
dtypes = [mx.float16, mx.float32]
|
|
2658
|
+
for dtype in dtypes:
|
|
2659
|
+
with self.subTest(dtype=dtype):
|
|
2660
|
+
self.assertCmpNumpy(
|
|
2661
|
+
[(3, 4, 5), (4, 3, 2)],
|
|
2662
|
+
mx.tensordot,
|
|
2663
|
+
np.tensordot,
|
|
2664
|
+
dtype=dtype,
|
|
2665
|
+
axes=([1, 0], [0, 1]),
|
|
2666
|
+
)
|
|
2667
|
+
self.assertCmpNumpy(
|
|
2668
|
+
[(3, 4, 5), (4, 5, 6)],
|
|
2669
|
+
mx.tensordot,
|
|
2670
|
+
np.tensordot,
|
|
2671
|
+
dtype=dtype,
|
|
2672
|
+
axes=2,
|
|
2673
|
+
)
|
|
2674
|
+
self.assertCmpNumpy(
|
|
2675
|
+
[(3, 5, 4, 6), (6, 4, 5, 3)],
|
|
2676
|
+
mx.tensordot,
|
|
2677
|
+
np.tensordot,
|
|
2678
|
+
dtype=dtype,
|
|
2679
|
+
axes=([2, 1, 3], [1, 2, 0]),
|
|
2680
|
+
)
|
|
2681
|
+
|
|
2682
|
+
def test_inner(self):
|
|
2683
|
+
self.assertCmpNumpy([(3,), (3,)], mx.inner, np.inner)
|
|
2684
|
+
self.assertCmpNumpy([(1, 1, 2), (3, 2)], mx.inner, np.inner)
|
|
2685
|
+
self.assertCmpNumpy([(2, 3, 4), (4,)], mx.inner, np.inner)
|
|
2686
|
+
|
|
2687
|
+
def test_vecdot(self):
|
|
2688
|
+
a = mx.array([[1, 2, 3], [4, 5, 6]])
|
|
2689
|
+
b = mx.array([[7, 8, 9], [10, 11, 12]])
|
|
2690
|
+
self.assertEqual(mx.vecdot(a, b).tolist(), [50, 167])
|
|
2691
|
+
self.assertEqual(mx.vecdot(a, b, axis=0).tolist(), [47, 71, 99])
|
|
2692
|
+
|
|
2693
|
+
a = mx.array([1 + 2j, 3 + 4j])
|
|
2694
|
+
b = mx.array([5 + 6j, 7 + 8j])
|
|
2695
|
+
expected = np.vdot(np.array([1 + 2j, 3 + 4j]), np.array([5 + 6j, 7 + 8j]))
|
|
2696
|
+
self.assertTrue(np.allclose(mx.vecdot(a, b), expected))
|
|
2697
|
+
|
|
2698
|
+
xp = mx.array(1.0).__array_namespace__()
|
|
2699
|
+
self.assertEqual(xp.vecdot(mx.array([1, 2]), mx.array([3, 4])).item(), 11)
|
|
2700
|
+
|
|
2701
|
+
with self.assertRaises(ValueError):
|
|
2702
|
+
mx.vecdot(mx.array(1), mx.array([1]))
|
|
2703
|
+
with self.assertRaises(ValueError):
|
|
2704
|
+
mx.vecdot(mx.array([1, 2]), mx.array([1, 2]), axis=1)
|
|
2705
|
+
with self.assertRaises(ValueError):
|
|
2706
|
+
mx.vecdot(mx.array([1, 2]), mx.array([1]))
|
|
2707
|
+
|
|
2708
|
+
def test_outer(self):
|
|
2709
|
+
self.assertCmpNumpy([(3,), (3,)], mx.outer, np.outer)
|
|
2710
|
+
self.assertCmpNumpy(
|
|
2711
|
+
[
|
|
2712
|
+
mx.ones(
|
|
2713
|
+
5,
|
|
2714
|
+
),
|
|
2715
|
+
mx.linspace(-2, 2, 5),
|
|
2716
|
+
],
|
|
2717
|
+
mx.outer,
|
|
2718
|
+
np.outer,
|
|
2719
|
+
)
|
|
2720
|
+
self.assertCmpNumpy(
|
|
2721
|
+
[
|
|
2722
|
+
1j * mx.linspace(2, -2, 5),
|
|
2723
|
+
mx.ones(
|
|
2724
|
+
5,
|
|
2725
|
+
),
|
|
2726
|
+
],
|
|
2727
|
+
mx.outer,
|
|
2728
|
+
np.outer,
|
|
2729
|
+
)
|
|
2730
|
+
|
|
2731
|
+
def test_divmod(self):
|
|
2732
|
+
# A few sizes for the inputs with and without broadcasting
|
|
2733
|
+
sizes = [
|
|
2734
|
+
((1,), (1,)),
|
|
2735
|
+
((1,), (10,)),
|
|
2736
|
+
((10,), (1,)),
|
|
2737
|
+
((3,), (3,)),
|
|
2738
|
+
((2, 2, 2), (1, 2, 1)),
|
|
2739
|
+
((2, 1, 2), (1, 2, 1)),
|
|
2740
|
+
((2, 2, 2, 2), (2, 2, 2, 2)),
|
|
2741
|
+
]
|
|
2742
|
+
types = [np.uint16, np.uint32, np.int32, np.float16, np.float32]
|
|
2743
|
+
for s1, s2 in sizes:
|
|
2744
|
+
for t in types:
|
|
2745
|
+
a_np = np.random.uniform(1, 100, size=s1).astype(t)
|
|
2746
|
+
b_np = np.random.uniform(1, 100, size=s2).astype(t)
|
|
2747
|
+
np_out = np.divmod(a_np, b_np)
|
|
2748
|
+
mx_out = mx.divmod(mx.array(a_np), mx.array(b_np))
|
|
2749
|
+
self.assertTrue(
|
|
2750
|
+
np.allclose(np_out[0], mx_out[0]), msg=f"Shapes {s1} {s2}, Type {t}"
|
|
2751
|
+
)
|
|
2752
|
+
|
|
2753
|
+
def test_tile(self):
|
|
2754
|
+
self.assertCmpNumpy([(2,), [2]], mx.tile, np.tile)
|
|
2755
|
+
self.assertCmpNumpy([(2, 3, 4), [2]], mx.tile, np.tile)
|
|
2756
|
+
self.assertCmpNumpy([(2, 3, 4), [2, 1]], mx.tile, np.tile)
|
|
2757
|
+
self.assertCmpNumpy(
|
|
2758
|
+
[
|
|
2759
|
+
(2, 3, 4),
|
|
2760
|
+
[
|
|
2761
|
+
2,
|
|
2762
|
+
2,
|
|
2763
|
+
],
|
|
2764
|
+
],
|
|
2765
|
+
mx.tile,
|
|
2766
|
+
np.tile,
|
|
2767
|
+
)
|
|
2768
|
+
self.assertCmpNumpy([(3,), [2, 2, 2]], mx.tile, np.tile)
|
|
2769
|
+
|
|
2770
|
+
def test_empty_matmuls(self):
|
|
2771
|
+
a = mx.array([])
|
|
2772
|
+
b = mx.array([])
|
|
2773
|
+
self.assertEqual(mx.inner(a, b).item(), 0.0)
|
|
2774
|
+
|
|
2775
|
+
a = mx.zeros((10, 0))
|
|
2776
|
+
b = mx.zeros((0, 10))
|
|
2777
|
+
out = a @ b
|
|
2778
|
+
self.assertTrue(mx.array_equal(out, mx.zeros((10, 10))))
|
|
2779
|
+
|
|
2780
|
+
def test_diagonal(self):
|
|
2781
|
+
x = mx.array(
|
|
2782
|
+
[
|
|
2783
|
+
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]],
|
|
2784
|
+
[[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]],
|
|
2785
|
+
]
|
|
2786
|
+
)
|
|
2787
|
+
expected = [[0, 13], [4, 17], [8, 21]]
|
|
2788
|
+
|
|
2789
|
+
self.assertListEqual(mx.diagonal(x, 0, -1, 0).tolist(), expected)
|
|
2790
|
+
|
|
2791
|
+
expected = [[1, 14], [5, 18], [9, 22]]
|
|
2792
|
+
self.assertListEqual(mx.diagonal(x, -1, 2, 0).tolist(), expected)
|
|
2793
|
+
|
|
2794
|
+
def test_diag(self):
|
|
2795
|
+
# Test 1D input
|
|
2796
|
+
x = mx.array([1, 2, 3, 4])
|
|
2797
|
+
expected = mx.array([[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]])
|
|
2798
|
+
result = mx.diag(x)
|
|
2799
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2800
|
+
|
|
2801
|
+
# Test 1D with offset
|
|
2802
|
+
x = mx.array([2, 6])
|
|
2803
|
+
result = mx.diag(x, k=5)
|
|
2804
|
+
expected = mx.array(np.diag(x, k=5))
|
|
2805
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2806
|
+
|
|
2807
|
+
# Test 2D input
|
|
2808
|
+
x = mx.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
|
|
2809
|
+
expected = mx.array([1, 5, 9])
|
|
2810
|
+
result = mx.diag(x)
|
|
2811
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2812
|
+
|
|
2813
|
+
# Test with offset
|
|
2814
|
+
expected = mx.array([2, 6])
|
|
2815
|
+
result = mx.diag(x, 1)
|
|
2816
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2817
|
+
|
|
2818
|
+
# Test non-square
|
|
2819
|
+
x = mx.array([[1, 2, 3], [4, 5, 6]])
|
|
2820
|
+
result = mx.diag(x)
|
|
2821
|
+
expected = mx.array(np.diag(x))
|
|
2822
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2823
|
+
|
|
2824
|
+
result = mx.diag(x, k=10)
|
|
2825
|
+
expected = mx.array(np.diag(x, k=10))
|
|
2826
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2827
|
+
|
|
2828
|
+
result = mx.diag(x, k=-10)
|
|
2829
|
+
expected = mx.array(np.diag(x, k=-10))
|
|
2830
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2831
|
+
|
|
2832
|
+
result = mx.diag(x, k=-1)
|
|
2833
|
+
expected = mx.array(np.diag(x, k=-1))
|
|
2834
|
+
self.assertTrue(mx.array_equal(result, expected))
|
|
2835
|
+
|
|
2836
|
+
def test_trace(self):
|
|
2837
|
+
a_mx = mx.arange(9, dtype=mx.int64).reshape((3, 3))
|
|
2838
|
+
a_np = np.arange(9, dtype=np.int64).reshape((3, 3))
|
|
2839
|
+
|
|
2840
|
+
# Test 2D array
|
|
2841
|
+
result = mx.trace(a_mx)
|
|
2842
|
+
expected = np.trace(a_np)
|
|
2843
|
+
self.assertEqualArray(result, mx.array(expected))
|
|
2844
|
+
|
|
2845
|
+
# Test dtype
|
|
2846
|
+
result = mx.trace(a_mx, dtype=mx.float16)
|
|
2847
|
+
expected = np.trace(a_np, dtype=np.float16)
|
|
2848
|
+
self.assertEqualArray(result, mx.array(expected))
|
|
2849
|
+
|
|
2850
|
+
# Test offset
|
|
2851
|
+
result = mx.trace(a_mx, offset=1)
|
|
2852
|
+
expected = np.trace(a_np, offset=1)
|
|
2853
|
+
self.assertEqualArray(result, mx.array(expected))
|
|
2854
|
+
|
|
2855
|
+
# Test axis1 and axis2
|
|
2856
|
+
b_mx = mx.arange(27, dtype=mx.int64).reshape(3, 3, 3)
|
|
2857
|
+
b_np = np.arange(27, dtype=np.int64).reshape(3, 3, 3)
|
|
2858
|
+
|
|
2859
|
+
result = mx.trace(b_mx, axis1=1, axis2=2)
|
|
2860
|
+
expected = np.trace(b_np, axis1=1, axis2=2)
|
|
2861
|
+
self.assertEqualArray(result, mx.array(expected))
|
|
2862
|
+
|
|
2863
|
+
# Test offset, axis1, axis2, and dtype
|
|
2864
|
+
result = mx.trace(b_mx, offset=1, axis1=1, axis2=2, dtype=mx.float32)
|
|
2865
|
+
expected = np.trace(b_np, offset=1, axis1=1, axis2=2, dtype=np.float32)
|
|
2866
|
+
self.assertEqualArray(result, mx.array(expected))
|
|
2867
|
+
|
|
2868
|
+
def test_atleast_1d(self):
|
|
2869
|
+
# Test 1D input
|
|
2870
|
+
arrays = [
|
|
2871
|
+
[1],
|
|
2872
|
+
[1, 2, 3],
|
|
2873
|
+
[1, 2, 3, 4],
|
|
2874
|
+
[[1], [2], [3]],
|
|
2875
|
+
[[1, 2], [3, 4]],
|
|
2876
|
+
[[1, 2, 3], [4, 5, 6]],
|
|
2877
|
+
[[[[1]], [[2]], [[3]]]],
|
|
2878
|
+
]
|
|
2879
|
+
|
|
2880
|
+
mx_arrays = [mx.atleast_1d(mx.array(x)) for x in arrays]
|
|
2881
|
+
atleast_arrays = mx.atleast_1d(*mx_arrays)
|
|
2882
|
+
|
|
2883
|
+
for i, array in enumerate(arrays):
|
|
2884
|
+
mx_res = mx.atleast_1d(mx.array(array))
|
|
2885
|
+
np_res = np.atleast_1d(np.array(array))
|
|
2886
|
+
self.assertEqual(mx_res.shape, np_res.shape)
|
|
2887
|
+
self.assertEqual(mx_res.ndim, np_res.ndim)
|
|
2888
|
+
self.assertTrue(mx.array_equal(mx_res, atleast_arrays[i]))
|
|
2889
|
+
|
|
2890
|
+
def test_atleast_2d(self):
|
|
2891
|
+
# Test 1D input
|
|
2892
|
+
arrays = [
|
|
2893
|
+
[1],
|
|
2894
|
+
[1, 2, 3],
|
|
2895
|
+
[1, 2, 3, 4],
|
|
2896
|
+
[[1], [2], [3]],
|
|
2897
|
+
[[1, 2], [3, 4]],
|
|
2898
|
+
[[1, 2, 3], [4, 5, 6]],
|
|
2899
|
+
[[[[1]], [[2]], [[3]]]],
|
|
2900
|
+
]
|
|
2901
|
+
|
|
2902
|
+
mx_arrays = [mx.atleast_2d(mx.array(x)) for x in arrays]
|
|
2903
|
+
atleast_arrays = mx.atleast_2d(*mx_arrays)
|
|
2904
|
+
|
|
2905
|
+
for i, array in enumerate(arrays):
|
|
2906
|
+
mx_res = mx.atleast_2d(mx.array(array))
|
|
2907
|
+
np_res = np.atleast_2d(np.array(array))
|
|
2908
|
+
self.assertEqual(mx_res.shape, np_res.shape)
|
|
2909
|
+
self.assertEqual(mx_res.ndim, np_res.ndim)
|
|
2910
|
+
self.assertTrue(mx.array_equal(mx_res, atleast_arrays[i]))
|
|
2911
|
+
|
|
2912
|
+
def test_atleast_3d(self):
|
|
2913
|
+
# Test 1D input
|
|
2914
|
+
arrays = [
|
|
2915
|
+
[1],
|
|
2916
|
+
[1, 2, 3],
|
|
2917
|
+
[1, 2, 3, 4],
|
|
2918
|
+
[[1], [2], [3]],
|
|
2919
|
+
[[1, 2], [3, 4]],
|
|
2920
|
+
[[1, 2, 3], [4, 5, 6]],
|
|
2921
|
+
[[[[1]], [[2]], [[3]]]],
|
|
2922
|
+
]
|
|
2923
|
+
|
|
2924
|
+
mx_arrays = [mx.atleast_3d(mx.array(x)) for x in arrays]
|
|
2925
|
+
atleast_arrays = mx.atleast_3d(*mx_arrays)
|
|
2926
|
+
|
|
2927
|
+
for i, array in enumerate(arrays):
|
|
2928
|
+
mx_res = mx.atleast_3d(mx.array(array))
|
|
2929
|
+
np_res = np.atleast_3d(np.array(array))
|
|
2930
|
+
self.assertEqual(mx_res.shape, np_res.shape)
|
|
2931
|
+
self.assertEqual(mx_res.ndim, np_res.ndim)
|
|
2932
|
+
self.assertTrue(mx.array_equal(mx_res, atleast_arrays[i]))
|
|
2933
|
+
|
|
2934
|
+
def test_issubdtype(self):
|
|
2935
|
+
self.assertTrue(mx.issubdtype(mx.bfloat16, mx.inexact))
|
|
2936
|
+
|
|
2937
|
+
cats = [
|
|
2938
|
+
"complexfloating",
|
|
2939
|
+
"floating",
|
|
2940
|
+
"inexact",
|
|
2941
|
+
"signedinteger",
|
|
2942
|
+
"unsignedinteger",
|
|
2943
|
+
"integer",
|
|
2944
|
+
"number",
|
|
2945
|
+
"generic",
|
|
2946
|
+
"bool_",
|
|
2947
|
+
"uint8",
|
|
2948
|
+
"uint16",
|
|
2949
|
+
"uint32",
|
|
2950
|
+
"uint64",
|
|
2951
|
+
"int8",
|
|
2952
|
+
"int16",
|
|
2953
|
+
"int32",
|
|
2954
|
+
"int64",
|
|
2955
|
+
"float16",
|
|
2956
|
+
"float32",
|
|
2957
|
+
"complex64",
|
|
2958
|
+
]
|
|
2959
|
+
|
|
2960
|
+
for a in cats:
|
|
2961
|
+
for b in cats:
|
|
2962
|
+
self.assertEqual(
|
|
2963
|
+
mx.issubdtype(getattr(mx, a), getattr(mx, b)),
|
|
2964
|
+
np.issubdtype(getattr(np, a), getattr(np, b)),
|
|
2965
|
+
f"mx and np don't aggree on {a}, {b}",
|
|
2966
|
+
)
|
|
2967
|
+
|
|
2968
|
+
def test_bitwise_ops(self):
|
|
2969
|
+
types = [
|
|
2970
|
+
mx.uint8,
|
|
2971
|
+
mx.uint16,
|
|
2972
|
+
mx.uint32,
|
|
2973
|
+
mx.uint64,
|
|
2974
|
+
mx.int8,
|
|
2975
|
+
mx.int16,
|
|
2976
|
+
mx.int32,
|
|
2977
|
+
mx.int64,
|
|
2978
|
+
]
|
|
2979
|
+
a = mx.random.randint(0, 4096, (1000,))
|
|
2980
|
+
b = mx.random.randint(0, 4096, (1000,))
|
|
2981
|
+
for op in ["bitwise_and", "bitwise_or", "bitwise_xor"]:
|
|
2982
|
+
for t in types:
|
|
2983
|
+
a_mlx = a.astype(t)
|
|
2984
|
+
b_mlx = b.astype(t)
|
|
2985
|
+
a_np = np.array(a_mlx)
|
|
2986
|
+
b_np = np.array(b_mlx)
|
|
2987
|
+
out_mlx = getattr(mx, op)(a_mlx, b_mlx)
|
|
2988
|
+
out_np = getattr(np, op)(a_np, b_np)
|
|
2989
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
2990
|
+
for op in ["left_shift", "right_shift"]:
|
|
2991
|
+
for t in types:
|
|
2992
|
+
a_mlx = a.astype(t)
|
|
2993
|
+
b_mlx = mx.random.randint(0, t.size, (1000,)).astype(t)
|
|
2994
|
+
a_np = np.array(a_mlx)
|
|
2995
|
+
b_np = np.array(b_mlx)
|
|
2996
|
+
out_mlx = getattr(mx, op)(a_mlx, b_mlx)
|
|
2997
|
+
out_np = getattr(np, op)(a_np, b_np)
|
|
2998
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
2999
|
+
|
|
3000
|
+
for t in types:
|
|
3001
|
+
a_mlx = a.astype(t)
|
|
3002
|
+
a_np = np.array(a_mlx)
|
|
3003
|
+
|
|
3004
|
+
out_mlx = ~a_mlx
|
|
3005
|
+
out_np = ~a_np
|
|
3006
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
3007
|
+
|
|
3008
|
+
out_mlx = mx.bitwise_invert(a_mlx)
|
|
3009
|
+
out_np = mx.bitwise_invert(a_np)
|
|
3010
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
3011
|
+
|
|
3012
|
+
# Check broadcasting
|
|
3013
|
+
a = mx.ones((3, 1, 5), dtype=mx.bool_)
|
|
3014
|
+
b = mx.zeros((1, 2, 5), dtype=mx.bool_)
|
|
3015
|
+
c = a | b
|
|
3016
|
+
self.assertEqual(c.shape, (3, 2, 5))
|
|
3017
|
+
self.assertTrue(mx.array_equal(c, mx.ones((3, 2, 5), dtype=mx.bool_)))
|
|
3018
|
+
|
|
3019
|
+
def test_bitwise_grad(self):
|
|
3020
|
+
a = np.random.randint(0, 10, size=(4, 3))
|
|
3021
|
+
b = np.random.randint(0, 10, size=(4, 3))
|
|
3022
|
+
cotangent = np.random.randint(0, 10, size=(4, 3))
|
|
3023
|
+
a = mx.array(a)
|
|
3024
|
+
b = mx.array(b)
|
|
3025
|
+
cotangent = mx.array(cotangent)
|
|
3026
|
+
|
|
3027
|
+
def bitwise(a, b):
|
|
3028
|
+
return a.astype(mx.int32) & b.astype(mx.int32)
|
|
3029
|
+
|
|
3030
|
+
_, vjps = mx.vjp(bitwise, [a, b], [cotangent])
|
|
3031
|
+
for vjp in vjps:
|
|
3032
|
+
self.assertFalse(np.any(np.array(vjp)))
|
|
3033
|
+
|
|
3034
|
+
def test_conjugate(self):
|
|
3035
|
+
shape = (3, 5, 7)
|
|
3036
|
+
a = np.random.normal(size=shape) + 1j * np.random.normal(size=shape)
|
|
3037
|
+
a = a.astype(np.complex64)
|
|
3038
|
+
ops = ["conjugate", "conj"]
|
|
3039
|
+
for op in ops:
|
|
3040
|
+
out_mlx = getattr(mx, op)(mx.array(a))
|
|
3041
|
+
out_np = getattr(np, op)(a)
|
|
3042
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
3043
|
+
out_mlx = mx.array(a).conj()
|
|
3044
|
+
out_np = a.conj()
|
|
3045
|
+
self.assertTrue(np.array_equal(np.array(out_mlx), out_np))
|
|
3046
|
+
|
|
3047
|
+
b = np.random.normal(size=shape) + 1j * np.random.normal(size=shape)
|
|
3048
|
+
b = b.astype(np.complex64)
|
|
3049
|
+
|
|
3050
|
+
_, vjps = mx.vjp(mx.conj, [mx.array(a)], [mx.array(b)])
|
|
3051
|
+
self.assertTrue(np.array_equal(np.array(vjps[0]), b.conj()))
|
|
3052
|
+
|
|
3053
|
+
out_mlx, jvps = mx.jvp(mx.conj, [mx.array(a)], [mx.array(b)])
|
|
3054
|
+
self.assertTrue(np.array_equal(np.array(out_mlx[0]), a.conj()))
|
|
3055
|
+
self.assertTrue(np.array_equal(np.array(jvps[0]), b.conj()))
|
|
3056
|
+
|
|
3057
|
+
def test_view(self):
|
|
3058
|
+
# Check scalar
|
|
3059
|
+
out = mx.array(1, mx.int8).view(mx.uint8).item()
|
|
3060
|
+
self.assertEqual(out, 1)
|
|
3061
|
+
|
|
3062
|
+
a = mx.random.randint(shape=(4, 2, 4), low=-100, high=100)
|
|
3063
|
+
a_np = np.array(a)
|
|
3064
|
+
|
|
3065
|
+
for t in ["bool_", "int16", "float32", "int64"]:
|
|
3066
|
+
out = a.view(getattr(mx, t))
|
|
3067
|
+
expected = a_np.view(getattr(np, t))
|
|
3068
|
+
self.assertTrue(np.array_equal(out, expected, equal_nan=True))
|
|
3069
|
+
|
|
3070
|
+
# Irregular strides
|
|
3071
|
+
a = mx.random.randint(shape=(2, 4), low=-100, high=100)
|
|
3072
|
+
a = mx.broadcast_to(a, shape=(4, 2, 4))
|
|
3073
|
+
|
|
3074
|
+
for t in ["bool_", "int16", "float32", "int64"]:
|
|
3075
|
+
out = a.view(getattr(mx, t))
|
|
3076
|
+
a_out = out.view(mx.int32)
|
|
3077
|
+
self.assertTrue(mx.array_equal(a_out, a, equal_nan=True))
|
|
3078
|
+
|
|
3079
|
+
a = mx.random.randint(shape=(4, 4), low=-100, high=100).T
|
|
3080
|
+
for t in ["bool_", "int16", "float32", "int64"]:
|
|
3081
|
+
out = a.view(getattr(mx, t))
|
|
3082
|
+
a_out = out.view(mx.int32)
|
|
3083
|
+
self.assertTrue(mx.array_equal(a_out, a, equal_nan=True))
|
|
3084
|
+
|
|
3085
|
+
def _hadamard(self, N):
|
|
3086
|
+
# Matches scipy.linalg.hadamard
|
|
3087
|
+
H = np.array([[1]], dtype=np.int64)
|
|
3088
|
+
for i in range(0, np.log2(N).astype(np.int64)):
|
|
3089
|
+
H = np.vstack((np.hstack((H, H)), np.hstack((H, -H))))
|
|
3090
|
+
return H
|
|
3091
|
+
|
|
3092
|
+
@unittest.skipIf("CI" in os.environ, "too slow in CI")
|
|
3093
|
+
def test_hadamard(self):
|
|
3094
|
+
with self.assertRaises(ValueError):
|
|
3095
|
+
mx.hadamard_transform(mx.array([]))
|
|
3096
|
+
|
|
3097
|
+
h28_str = """
|
|
3098
|
+
+------++----++-+--+-+--++--
|
|
3099
|
+
-+-----+++-----+-+--+-+--++-
|
|
3100
|
+
--+-----+++---+-+-+----+--++
|
|
3101
|
+
---+-----+++---+-+-+-+--+--+
|
|
3102
|
+
----+-----+++---+-+-+++--+--
|
|
3103
|
+
-----+-----++++--+-+--++--+-
|
|
3104
|
+
------++----++-+--+-+--++--+
|
|
3105
|
+
--++++-+-------++--+++-+--+-
|
|
3106
|
+
---++++-+-----+-++--+-+-+--+
|
|
3107
|
+
+---+++--+----++-++--+-+-+--
|
|
3108
|
+
++---++---+----++-++--+-+-+-
|
|
3109
|
+
+++---+----+----++-++--+-+-+
|
|
3110
|
+
++++--------+-+--++-++--+-+-
|
|
3111
|
+
-++++--------+++--++--+--+-+
|
|
3112
|
+
-+-++-++--++--+--------++++-
|
|
3113
|
+
+-+-++--+--++--+--------++++
|
|
3114
|
+
-+-+-++--+--++--+----+---+++
|
|
3115
|
+
+-+-+-++--+--+---+---++---++
|
|
3116
|
+
++-+-+-++--+------+--+++---+
|
|
3117
|
+
-++-+-+-++--+------+-++++---
|
|
3118
|
+
+-++-+---++--+------+-++++--
|
|
3119
|
+
-++--++-+-++-+++----++------
|
|
3120
|
+
+-++--++-+-++-+++-----+-----
|
|
3121
|
+
++-++---+-+-++-+++-----+----
|
|
3122
|
+
-++-++-+-+-+-+--+++-----+---
|
|
3123
|
+
--++-++++-+-+----+++-----+--
|
|
3124
|
+
+--++-+-++-+-+----+++-----+-
|
|
3125
|
+
++--++-+-++-+-+----++------+
|
|
3126
|
+
"""
|
|
3127
|
+
|
|
3128
|
+
def parse_h_string(h_str):
|
|
3129
|
+
return np.array(
|
|
3130
|
+
[[1 if s == "+" else -1 for s in row] for row in h_str.split()]
|
|
3131
|
+
)
|
|
3132
|
+
|
|
3133
|
+
h28 = parse_h_string(h28_str)
|
|
3134
|
+
|
|
3135
|
+
x = mx.array(5)
|
|
3136
|
+
y = mx.hadamard_transform(x)
|
|
3137
|
+
self.assertEqual(y.item(), 5)
|
|
3138
|
+
|
|
3139
|
+
x = mx.array(5)
|
|
3140
|
+
y = mx.hadamard_transform(x, scale=0.2)
|
|
3141
|
+
self.assertEqual(y.item(), 1)
|
|
3142
|
+
|
|
3143
|
+
x = mx.random.normal((8, 8, 1))
|
|
3144
|
+
y = mx.hadamard_transform(x)
|
|
3145
|
+
self.assertTrue(mx.all(y == x).item())
|
|
3146
|
+
|
|
3147
|
+
# Too slow to compare to numpy so let's compare CPU to GPU
|
|
3148
|
+
if mx.default_device() == mx.gpu:
|
|
3149
|
+
rk = mx.random.key(42)
|
|
3150
|
+
for k in range(14, 17):
|
|
3151
|
+
for m in [1, 3, 5, 7]:
|
|
3152
|
+
x = mx.random.normal((4, m * 2**k), key=rk)
|
|
3153
|
+
y1 = mx.hadamard_transform(x, stream=mx.cpu)
|
|
3154
|
+
y2 = mx.hadamard_transform(x, stream=mx.gpu)
|
|
3155
|
+
self.assertLess(mx.abs(y1 - y2).max().item(), 5e-6)
|
|
3156
|
+
|
|
3157
|
+
np.random.seed(7)
|
|
3158
|
+
tests = product([np.float32, np.float16, np.int32], [1, 28], range(1, 14))
|
|
3159
|
+
for dtype, m, k in tests:
|
|
3160
|
+
# skip large m=28 cases because they're very slow in NumPy
|
|
3161
|
+
if m > 1 and k > 8:
|
|
3162
|
+
continue
|
|
3163
|
+
with self.subTest(dtype=dtype, m=m, k=k):
|
|
3164
|
+
n = m * 2**k
|
|
3165
|
+
b = 4
|
|
3166
|
+
scale = 0.34
|
|
3167
|
+
x = np.random.normal(size=(b, n)).astype(dtype)
|
|
3168
|
+
# contiguity check
|
|
3169
|
+
x = mx.array(x)[::2]
|
|
3170
|
+
y = mx.hadamard_transform(x, scale=scale)
|
|
3171
|
+
mx.eval(y)
|
|
3172
|
+
h = (
|
|
3173
|
+
self._hadamard(2**k)
|
|
3174
|
+
if m == 1
|
|
3175
|
+
else np.kron(h28, self._hadamard(2**k))
|
|
3176
|
+
)
|
|
3177
|
+
y_np = np.einsum("ij,bj->bi", h, x) * scale
|
|
3178
|
+
atol = 2e-4 if dtype == np.float32 else 5e-2 * k
|
|
3179
|
+
np.testing.assert_allclose(y, y_np, atol=atol)
|
|
3180
|
+
|
|
3181
|
+
# bfloat16 emulation on M1 means 2**14 doesn't fit in threadgroup memory
|
|
3182
|
+
if dtype == np.float16 and k < 14:
|
|
3183
|
+
y_bf16 = mx.hadamard_transform(x.astype(mx.bfloat16), scale=scale)
|
|
3184
|
+
np.testing.assert_allclose(
|
|
3185
|
+
y_bf16.astype(mx.float16), y, atol=atol * 2
|
|
3186
|
+
)
|
|
3187
|
+
|
|
3188
|
+
def test_hadamard_grad_vmap(self):
|
|
3189
|
+
np.random.seed(4)
|
|
3190
|
+
|
|
3191
|
+
for k in range(2, 8):
|
|
3192
|
+
n = 2**k
|
|
3193
|
+
x = np.random.normal(size=(n,))
|
|
3194
|
+
h = self._hadamard(n)
|
|
3195
|
+
c = np.random.normal(size=(n,))
|
|
3196
|
+
x = mx.array(x).astype(mx.float32)
|
|
3197
|
+
h = mx.array(h).astype(mx.float32)
|
|
3198
|
+
c = mx.array(c).astype(mx.float32)
|
|
3199
|
+
|
|
3200
|
+
def hadamard_transform(x):
|
|
3201
|
+
return h @ x / mx.sqrt(x.shape[-1])
|
|
3202
|
+
|
|
3203
|
+
out = mx.vjp(hadamard_transform, [x], [c])
|
|
3204
|
+
out_t = mx.vjp(mx.hadamard_transform, [x], [c])
|
|
3205
|
+
np.testing.assert_allclose(out, out_t, atol=1e-4)
|
|
3206
|
+
|
|
3207
|
+
for axis in (0, 1, 2):
|
|
3208
|
+
vht = mx.vmap(mx.vmap(hadamard_transform, 0, 0), axis, axis)
|
|
3209
|
+
vht_t = mx.vmap(mx.vmap(mx.hadamard_transform, 0, 0), axis, axis)
|
|
3210
|
+
|
|
3211
|
+
xb = mx.array(np.random.normal(size=(n, n, n)))
|
|
3212
|
+
out = vht(xb)
|
|
3213
|
+
out_t = vht_t(xb)
|
|
3214
|
+
np.testing.assert_allclose(out, out_t, atol=1e-4)
|
|
3215
|
+
|
|
3216
|
+
def test_roll(self):
|
|
3217
|
+
x = mx.arange(10).reshape(2, 5)
|
|
3218
|
+
|
|
3219
|
+
for s in [-2, -1, 0, 1, 2]:
|
|
3220
|
+
y1 = np.roll(x, s)
|
|
3221
|
+
y2 = mx.roll(x, s)
|
|
3222
|
+
self.assertTrue(mx.array_equal(y1, y2).item())
|
|
3223
|
+
|
|
3224
|
+
y1 = np.roll(x, (s, s, s))
|
|
3225
|
+
y2 = mx.roll(x, (s, s, s))
|
|
3226
|
+
self.assertTrue(mx.array_equal(y1, y2).item())
|
|
3227
|
+
|
|
3228
|
+
shifts = [
|
|
3229
|
+
1,
|
|
3230
|
+
2,
|
|
3231
|
+
-1,
|
|
3232
|
+
-2,
|
|
3233
|
+
(1, 1),
|
|
3234
|
+
(-1, 2),
|
|
3235
|
+
(33, 33),
|
|
3236
|
+
]
|
|
3237
|
+
axes = [
|
|
3238
|
+
0,
|
|
3239
|
+
1,
|
|
3240
|
+
(1, 0),
|
|
3241
|
+
(0, 1),
|
|
3242
|
+
(0, 0),
|
|
3243
|
+
(1, 1),
|
|
3244
|
+
]
|
|
3245
|
+
for s, a in product(shifts, axes):
|
|
3246
|
+
y1 = np.roll(x, s, a)
|
|
3247
|
+
y2 = mx.roll(x, s, a)
|
|
3248
|
+
self.assertTrue(mx.array_equal(y1, y2).item())
|
|
3249
|
+
|
|
3250
|
+
def test_roll_errors(self):
|
|
3251
|
+
x = mx.array([])
|
|
3252
|
+
result = mx.roll(x, [0], [0])
|
|
3253
|
+
self.assertTrue(mx.array_equal(result, x))
|
|
3254
|
+
|
|
3255
|
+
def test_real_imag(self):
|
|
3256
|
+
x = mx.random.uniform(shape=(4, 4))
|
|
3257
|
+
out = mx.real(x)
|
|
3258
|
+
self.assertTrue(mx.array_equal(x, out))
|
|
3259
|
+
|
|
3260
|
+
out = mx.imag(x)
|
|
3261
|
+
self.assertTrue(mx.array_equal(mx.zeros_like(x), out))
|
|
3262
|
+
|
|
3263
|
+
y = mx.random.uniform(shape=(4, 4))
|
|
3264
|
+
z = x + 1j * y
|
|
3265
|
+
self.assertEqual(mx.real(z).dtype, mx.float32)
|
|
3266
|
+
self.assertTrue(mx.array_equal(mx.real(z), x))
|
|
3267
|
+
self.assertEqual(mx.imag(z).dtype, mx.float32)
|
|
3268
|
+
self.assertTrue(mx.array_equal(mx.imag(z), y))
|
|
3269
|
+
|
|
3270
|
+
def test_dynamic_slicing(self):
|
|
3271
|
+
x = mx.random.randint(0, 100, shape=(4, 4, 4))
|
|
3272
|
+
expected = x[1:, 2:, 3:]
|
|
3273
|
+
out = mx.slice(x, mx.array([1, 2, 3]), (0, 1, 2), (3, 2, 1))
|
|
3274
|
+
self.assertTrue(mx.array_equal(expected, out))
|
|
3275
|
+
|
|
3276
|
+
x = mx.arange(5 * 6 * 7 * 8).reshape(5, 6, 7, 8)
|
|
3277
|
+
expected = x[1:3, 2:4, 3:5, 4:6]
|
|
3278
|
+
out = mx.slice(x, mx.array([1, 2, 3, 4]), (0, 1, 2, 3), (2, 2, 2, 2))
|
|
3279
|
+
self.assertTrue(mx.array_equal(expected, out))
|
|
3280
|
+
|
|
3281
|
+
x = mx.zeros(shape=(4, 4, 4))
|
|
3282
|
+
update = mx.random.randint(0, 100, shape=(3, 2, 1))
|
|
3283
|
+
out = mx.slice_update(x, update, mx.array([1, 2, 3]), (0, 1, 2))
|
|
3284
|
+
expected = mx.zeros_like(x)
|
|
3285
|
+
expected[1:, 2:, 3:] = update
|
|
3286
|
+
self.assertTrue(mx.array_equal(expected, out))
|
|
3287
|
+
|
|
3288
|
+
def test_broadcast_arrays(self):
|
|
3289
|
+
a = mx.array(1)
|
|
3290
|
+
b = mx.array(1.0)
|
|
3291
|
+
a, b = mx.broadcast_arrays(a, b)
|
|
3292
|
+
self.assertEqual(a.shape, ())
|
|
3293
|
+
self.assertEqual(a.dtype, mx.int32)
|
|
3294
|
+
self.assertEqual(b.shape, ())
|
|
3295
|
+
self.assertEqual(b.dtype, mx.float32)
|
|
3296
|
+
|
|
3297
|
+
a, b = mx.broadcast_arrays(mx.zeros((3, 1, 2)), mx.zeros((4, 1)))
|
|
3298
|
+
self.assertEqual(a.shape, (3, 4, 2))
|
|
3299
|
+
self.assertEqual(b.shape, (3, 4, 2))
|
|
3300
|
+
|
|
3301
|
+
def test_slice_update_reversed(self):
|
|
3302
|
+
a = mx.array([1, 2, 3, 4])
|
|
3303
|
+
b = a[::-1]
|
|
3304
|
+
b[::2] = 0
|
|
3305
|
+
self.assertTrue(mx.array_equal(b, mx.array([0, 3, 0, 1])))
|
|
3306
|
+
|
|
3307
|
+
def test_slice_with_negative_stride(self):
|
|
3308
|
+
a = mx.random.uniform(shape=(128, 4))
|
|
3309
|
+
out = a[::-1]
|
|
3310
|
+
self.assertTrue(mx.array_equal(out[-1, :], a[0, :]))
|
|
3311
|
+
|
|
3312
|
+
a = mx.arange(8)
|
|
3313
|
+
for _ in range(4):
|
|
3314
|
+
a = a[::-1]
|
|
3315
|
+
self.assertTrue(mx.array_equal(a, mx.arange(8)))
|
|
3316
|
+
|
|
3317
|
+
def test_complex_ops(self):
|
|
3318
|
+
x = mx.array(
|
|
3319
|
+
[
|
|
3320
|
+
3.0 + 4.0j,
|
|
3321
|
+
-5.0 + 12.0j,
|
|
3322
|
+
-8.0 + 0.0j,
|
|
3323
|
+
0.0 + 9.0j,
|
|
3324
|
+
0.0 + 0.0j,
|
|
3325
|
+
]
|
|
3326
|
+
)
|
|
3327
|
+
|
|
3328
|
+
ops = ["arccos", "arcsin", "arctan", "square", "sqrt"]
|
|
3329
|
+
for op in ops:
|
|
3330
|
+
with self.subTest(op=op):
|
|
3331
|
+
np_op = getattr(np, op)
|
|
3332
|
+
mx_op = getattr(mx, op)
|
|
3333
|
+
self.assertTrue(np.allclose(mx_op(x), np_op(x)))
|
|
3334
|
+
|
|
3335
|
+
x = mx.array(
|
|
3336
|
+
[
|
|
3337
|
+
3.0 + 4.0j,
|
|
3338
|
+
-5.0 + 12.0j,
|
|
3339
|
+
-8.0 + 0.0j,
|
|
3340
|
+
0.0 + 9.0j,
|
|
3341
|
+
9.0 + 1.0j,
|
|
3342
|
+
]
|
|
3343
|
+
)
|
|
3344
|
+
self.assertTrue(np.allclose(mx.rsqrt(x), 1.0 / np.sqrt(x)))
|
|
3345
|
+
|
|
3346
|
+
def test_complex_power(self):
|
|
3347
|
+
out = mx.power(mx.array(0j), 2)
|
|
3348
|
+
self.assertEqual(out.item(), 0j)
|
|
3349
|
+
|
|
3350
|
+
out = mx.power(mx.array(0j), float("nan"))
|
|
3351
|
+
self.assertTrue(mx.isnan(out))
|
|
3352
|
+
|
|
3353
|
+
def test_irregular_alignments(self):
|
|
3354
|
+
# Unaligned unary op
|
|
3355
|
+
a = mx.ones((64, 1))
|
|
3356
|
+
b = -a[1:]
|
|
3357
|
+
self.assertTrue(mx.all(b == -1.0))
|
|
3358
|
+
|
|
3359
|
+
# Unaligned binary op
|
|
3360
|
+
a = mx.ones((64, 1))
|
|
3361
|
+
b = a[1:]
|
|
3362
|
+
c = b + b
|
|
3363
|
+
self.assertTrue(mx.all(c == 2.0))
|
|
3364
|
+
|
|
3365
|
+
# Unaligned ternary op
|
|
3366
|
+
a = mx.ones((64, 1))
|
|
3367
|
+
b = mx.zeros((63, 1))
|
|
3368
|
+
c = mx.ones((63, 1)).astype(mx.bool_)
|
|
3369
|
+
d = mx.where(c, a[1:], b)
|
|
3370
|
+
self.assertTrue(mx.all(d == 1.0))
|
|
3371
|
+
|
|
3372
|
+
def test_integer_power(self):
|
|
3373
|
+
x = mx.power(2, mx.array([8, 8, 8, 8, 8, 8, 8, 8]))
|
|
3374
|
+
self.assertTrue(mx.all(x == 256))
|
|
3375
|
+
|
|
3376
|
+
# Doesn't hang
|
|
3377
|
+
x = mx.power(2, -1)
|
|
3378
|
+
|
|
3379
|
+
def test_depends(self):
|
|
3380
|
+
a = mx.array([1.0, 2.0, 3.0])
|
|
3381
|
+
b = mx.exp(a)
|
|
3382
|
+
c = mx.log(a)
|
|
3383
|
+
out = mx.depends([b], [c])[0]
|
|
3384
|
+
self.assertTrue(mx.array_equal(out, b))
|
|
3385
|
+
|
|
3386
|
+
a = mx.array([1.0, 2.0, 3.0])
|
|
3387
|
+
b = mx.exp(a)
|
|
3388
|
+
c = mx.log(a)
|
|
3389
|
+
out = mx.depends(b, c)
|
|
3390
|
+
self.assertTrue(mx.array_equal(out, b))
|
|
3391
|
+
|
|
3392
|
+
def test_masked_scatter(self):
|
|
3393
|
+
# boolean mask updates matching numpy semantics
|
|
3394
|
+
a = mx.array([1.0, 2.0, 3.0])
|
|
3395
|
+
mask = mx.array([True, False, True])
|
|
3396
|
+
src = mx.array([5.0, 6.0])
|
|
3397
|
+
expected = mx.array([5.0, 2.0, 6.0])
|
|
3398
|
+
a[mask] = src
|
|
3399
|
+
self.assertTrue(mx.array_equal(a, expected))
|
|
3400
|
+
|
|
3401
|
+
# non-boolean mask raises
|
|
3402
|
+
b = mx.array([1.0, 2.0, 3.0])
|
|
3403
|
+
bad_mask = mx.array([1, 0, 1])
|
|
3404
|
+
src = mx.array([4.0, 5.0])
|
|
3405
|
+
with self.assertRaises((TypeError, ValueError)):
|
|
3406
|
+
b[bad_mask] = src
|
|
3407
|
+
|
|
3408
|
+
# mask matching leading dimension selects entire trailing slices
|
|
3409
|
+
c = mx.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
|
|
3410
|
+
mask = mx.array([True, False])
|
|
3411
|
+
src = mx.array([2.0, 3.0, 4.0])
|
|
3412
|
+
expected = mx.array([[2.0, 3.0, 4.0], [1.0, 1.0, 1.0]])
|
|
3413
|
+
c[mask] = src
|
|
3414
|
+
self.assertTrue(mx.array_equal(c, expected))
|
|
3415
|
+
|
|
3416
|
+
# scalar source applies to all selected entries
|
|
3417
|
+
c = mx.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
|
|
3418
|
+
mask = mx.array([True, False])
|
|
3419
|
+
src = 2.0
|
|
3420
|
+
expected = mx.array([[2.0, 2.0, 2.0], [1.0, 1.0, 1.0]])
|
|
3421
|
+
c[mask] = src
|
|
3422
|
+
self.assertTrue(mx.array_equal(c, expected))
|
|
3423
|
+
|
|
3424
|
+
# mask with no updates leaves values unchanged
|
|
3425
|
+
d = mx.array([[7.0, 8.0], [9.0, 10.0]])
|
|
3426
|
+
mask = mx.zeros_like(d).astype(mx.bool_)
|
|
3427
|
+
src = mx.array([1.0])
|
|
3428
|
+
d[mask] = src
|
|
3429
|
+
self.assertTrue(mx.array_equal(d, mx.array([[7.0, 8.0], [9.0, 10.0]])))
|
|
3430
|
+
|
|
3431
|
+
# empty mask leaves array unchanged
|
|
3432
|
+
e = mx.zeros((0,), dtype=mx.float32)
|
|
3433
|
+
mask = mx.zeros((0,), dtype=mx.bool_)
|
|
3434
|
+
src = mx.zeros((0,), dtype=mx.float32)
|
|
3435
|
+
e[mask] = src
|
|
3436
|
+
self.assertTrue(mx.array_equal(e, mx.zeros((0,), dtype=mx.float32)))
|
|
3437
|
+
|
|
3438
|
+
# strided target, mask, and source derived from slices
|
|
3439
|
+
target = mx.arange(10.0, dtype=mx.float32)[1::2]
|
|
3440
|
+
mask = mx.array(
|
|
3441
|
+
[False, True, False, False, True, False, False, True, False, False],
|
|
3442
|
+
dtype=mx.bool_,
|
|
3443
|
+
)[1::2]
|
|
3444
|
+
src = mx.arange(-4.0, 0.0, dtype=mx.float32)[::2]
|
|
3445
|
+
|
|
3446
|
+
target[mask] = src
|
|
3447
|
+
self.assertTrue(
|
|
3448
|
+
mx.array_equal(
|
|
3449
|
+
target, mx.array([-4.0, 3.0, 5.0, -2.0, 9.0], dtype=mx.float32)
|
|
3450
|
+
)
|
|
3451
|
+
)
|
|
3452
|
+
|
|
3453
|
+
def test_broadcast_shapes(self):
|
|
3454
|
+
# Basic broadcasting
|
|
3455
|
+
self.assertEqual(mx.broadcast_shapes((1, 2, 3), (3,)), (1, 2, 3))
|
|
3456
|
+
self.assertEqual(mx.broadcast_shapes((4, 1, 6), (5, 6)), (4, 5, 6))
|
|
3457
|
+
self.assertEqual(mx.broadcast_shapes((5, 1, 4), (1, 3, 4)), (5, 3, 4))
|
|
3458
|
+
|
|
3459
|
+
# Multiple arguments
|
|
3460
|
+
self.assertEqual(mx.broadcast_shapes((1, 1), (1, 8), (7, 1)), (7, 8))
|
|
3461
|
+
self.assertEqual(
|
|
3462
|
+
mx.broadcast_shapes((6, 1, 5), (1, 7, 1), (6, 7, 5)), (6, 7, 5)
|
|
3463
|
+
)
|
|
3464
|
+
|
|
3465
|
+
# Same shapes
|
|
3466
|
+
self.assertEqual(mx.broadcast_shapes((3, 4, 5), (3, 4, 5)), (3, 4, 5))
|
|
3467
|
+
|
|
3468
|
+
# Single argument
|
|
3469
|
+
self.assertEqual(mx.broadcast_shapes((2, 3)), (2, 3))
|
|
3470
|
+
|
|
3471
|
+
# Empty shapes
|
|
3472
|
+
self.assertEqual(mx.broadcast_shapes((), ()), ())
|
|
3473
|
+
self.assertEqual(mx.broadcast_shapes((), (1,)), (1,))
|
|
3474
|
+
self.assertEqual(mx.broadcast_shapes((1,), ()), (1,))
|
|
3475
|
+
|
|
3476
|
+
# Broadcasting with zeroes
|
|
3477
|
+
self.assertEqual(mx.broadcast_shapes((0,), (0,)), (0,))
|
|
3478
|
+
self.assertEqual(mx.broadcast_shapes((1, 0, 5), (3, 1, 5)), (3, 0, 5))
|
|
3479
|
+
self.assertEqual(mx.broadcast_shapes((5, 0), (0, 5, 0)), (0, 5, 0))
|
|
3480
|
+
|
|
3481
|
+
# Error cases
|
|
3482
|
+
with self.assertRaises(ValueError):
|
|
3483
|
+
mx.broadcast_shapes((3, 4), (4, 3))
|
|
3484
|
+
|
|
3485
|
+
with self.assertRaises(ValueError):
|
|
3486
|
+
mx.broadcast_shapes((2, 3, 4), (2, 5, 4))
|
|
3487
|
+
|
|
3488
|
+
with self.assertRaises(ValueError):
|
|
3489
|
+
mx.broadcast_shapes()
|
|
3490
|
+
|
|
3491
|
+
def test_sort_nan(self):
|
|
3492
|
+
for dtype in [mx.float32, mx.float16, mx.bfloat16]:
|
|
3493
|
+
with self.subTest(dtype=dtype):
|
|
3494
|
+
x = mx.array([3.0, mx.nan, 2.0, 0.0], dtype=dtype)
|
|
3495
|
+
expected = mx.array([0.0, 2.0, 3.0, mx.nan], dtype=dtype)
|
|
3496
|
+
self.assertTrue(mx.array_equal(mx.sort(x), expected, equal_nan=True))
|
|
3497
|
+
|
|
3498
|
+
x = mx.array([3.0 + 1j, mx.nan + 2j, 2.0 + 1j, 0.0 + 1j])
|
|
3499
|
+
expected = mx.array([0.0 + 1j, 2.0 + 1j, 3.0 + 1j, mx.nan + 2j])
|
|
3500
|
+
self.assertTrue(mx.array_equal(mx.sort(x), expected, equal_nan=True))
|
|
3501
|
+
|
|
3502
|
+
def test_argsort_nan(self):
|
|
3503
|
+
for dtype in [mx.float32, mx.float16, mx.bfloat16]:
|
|
3504
|
+
with self.subTest(dtype=dtype):
|
|
3505
|
+
x = mx.array([3.0, mx.nan, 2.0, 0.0], dtype=dtype)
|
|
3506
|
+
expected = mx.array([0.0, 2.0, 3.0, mx.nan], dtype=dtype)
|
|
3507
|
+
indices = mx.argsort(x)
|
|
3508
|
+
sorted_x = mx.take(x, indices)
|
|
3509
|
+
self.assertTrue(mx.array_equal(sorted_x, expected, equal_nan=True))
|
|
3510
|
+
|
|
3511
|
+
def test_to_from_fp8(self):
|
|
3512
|
+
vals = mx.array(
|
|
3513
|
+
[448, 256, 192, 128, 96, 64, 48, 32, 24, 16, 12, 8, 6, 4, 3, 2, 0.015625]
|
|
3514
|
+
)
|
|
3515
|
+
self.assertTrue(mx.array_equal(mx.from_fp8(mx.to_fp8(vals)), vals))
|
|
3516
|
+
self.assertTrue(mx.array_equal(mx.from_fp8(mx.to_fp8(-vals)), -vals))
|
|
3517
|
+
|
|
3518
|
+
|
|
3519
|
+
if __name__ == "__main__":
|
|
3520
|
+
mlx_tests.MLXTestRunner()
|