executorch 1.1.0__cp313-cp313-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.
Files changed (2784) hide show
  1. executorch/backends/__init__.py +0 -0
  2. executorch/backends/aoti/aoti_backend.py +271 -0
  3. executorch/backends/aoti/aoti_partitioner.py +109 -0
  4. executorch/backends/aoti/passes/replace_view_copy_with_view.py +118 -0
  5. executorch/backends/apple/coreml/compiler/__init__.py +9 -0
  6. executorch/backends/apple/coreml/compiler/coreml_preprocess.py +588 -0
  7. executorch/backends/apple/coreml/compiler/enumerated_shape_utils.py +244 -0
  8. executorch/backends/apple/coreml/compiler/torch_ops.py +219 -0
  9. executorch/backends/apple/coreml/executorchcoreml.pyi +10 -0
  10. executorch/backends/apple/coreml/logging.py +24 -0
  11. executorch/backends/apple/coreml/partition/__init__.py +9 -0
  12. executorch/backends/apple/coreml/partition/coreml_partitioner.py +307 -0
  13. executorch/backends/apple/coreml/quantizer/__init__.py +9 -0
  14. executorch/backends/apple/coreml/quantizer/_annotation_config.py +130 -0
  15. executorch/backends/apple/coreml/quantizer/_coreml_quantizer.py +628 -0
  16. executorch/backends/apple/coreml/quantizer/_coreml_quantizer_utils.py +800 -0
  17. executorch/backends/apple/coreml/quantizer/coreml_quantizer.py +7 -0
  18. executorch/backends/apple/coreml/recipes/__init__.py +17 -0
  19. executorch/backends/apple/coreml/recipes/coreml_recipe_provider.py +413 -0
  20. executorch/backends/apple/coreml/recipes/coreml_recipe_types.py +53 -0
  21. executorch/backends/apple/coreml/runtime/test/export_stateful_model.py +77 -0
  22. executorch/backends/apple/coreml/test/test_coreml_partitioner.py +348 -0
  23. executorch/backends/apple/coreml/test/test_coreml_quantizer.py +172 -0
  24. executorch/backends/apple/coreml/test/test_coreml_recipes.py +552 -0
  25. executorch/backends/apple/coreml/test/test_coreml_utils.py +19 -0
  26. executorch/backends/apple/coreml/test/test_enumerated_shapes.py +112 -0
  27. executorch/backends/apple/coreml/test/test_torch_ops.py +333 -0
  28. executorch/backends/apple/coreml/test/tester.py +121 -0
  29. executorch/backends/apple/metal/metal_backend.py +67 -0
  30. executorch/backends/apple/metal/metal_partitioner.py +25 -0
  31. executorch/backends/apple/metal/tests/__init__.py +5 -0
  32. executorch/backends/apple/metal/tests/test_metal_backend.py +79 -0
  33. executorch/backends/apple/metal/tests/test_metal_partitioner.py +172 -0
  34. executorch/backends/apple/mps/__init__.py +10 -0
  35. executorch/backends/apple/mps/mps_preprocess.py +301 -0
  36. executorch/backends/apple/mps/operators/__init__.py +77 -0
  37. executorch/backends/apple/mps/operators/activation_ops.py +99 -0
  38. executorch/backends/apple/mps/operators/binary_ops.py +156 -0
  39. executorch/backends/apple/mps/operators/clamp_ops.py +60 -0
  40. executorch/backends/apple/mps/operators/constant_ops.py +128 -0
  41. executorch/backends/apple/mps/operators/convolution_ops.py +70 -0
  42. executorch/backends/apple/mps/operators/indexing_ops.py +225 -0
  43. executorch/backends/apple/mps/operators/linear_algebra_ops.py +52 -0
  44. executorch/backends/apple/mps/operators/node_visitor.py +473 -0
  45. executorch/backends/apple/mps/operators/normalization_ops.py +97 -0
  46. executorch/backends/apple/mps/operators/op_clone.py +54 -0
  47. executorch/backends/apple/mps/operators/op_getitem.py +29 -0
  48. executorch/backends/apple/mps/operators/op_quant_dequant.py +142 -0
  49. executorch/backends/apple/mps/operators/op_skip_ops.py +24 -0
  50. executorch/backends/apple/mps/operators/pad_ops.py +37 -0
  51. executorch/backends/apple/mps/operators/pooling_ops.py +142 -0
  52. executorch/backends/apple/mps/operators/range_ops.py +53 -0
  53. executorch/backends/apple/mps/operators/reduce_ops.py +39 -0
  54. executorch/backends/apple/mps/operators/shape_ops.py +263 -0
  55. executorch/backends/apple/mps/operators/unary_ops.py +130 -0
  56. executorch/backends/apple/mps/partition/__init__.py +10 -0
  57. executorch/backends/apple/mps/partition/mps_partitioner.py +133 -0
  58. executorch/backends/apple/mps/serialization/mps_graph_schema.py +817 -0
  59. executorch/backends/apple/mps/serialization/mps_graph_serialize.py +34 -0
  60. executorch/backends/apple/mps/serialization/schema.fbs +523 -0
  61. executorch/backends/apple/mps/test/test_mps.py +2507 -0
  62. executorch/backends/apple/mps/test/test_mps_binary_ops.py +296 -0
  63. executorch/backends/apple/mps/test/test_mps_indexing_ops.py +264 -0
  64. executorch/backends/apple/mps/test/test_mps_linear.py +523 -0
  65. executorch/backends/apple/mps/test/test_mps_models.py +416 -0
  66. executorch/backends/apple/mps/test/test_mps_unary_ops.py +26 -0
  67. executorch/backends/apple/mps/test/test_mps_utils.py +326 -0
  68. executorch/backends/apple/mps/utils/mps_utils.py +82 -0
  69. executorch/backends/apple/mps/utils/quant_utils.py +41 -0
  70. executorch/backends/arm/_passes/__init__.py +134 -0
  71. executorch/backends/arm/_passes/_debug_passes.py +58 -0
  72. executorch/backends/arm/_passes/annotate_decomposed_matmul.py +127 -0
  73. executorch/backends/arm/_passes/annotate_output_dim_order_pass.py +26 -0
  74. executorch/backends/arm/_passes/arm_pass.py +95 -0
  75. executorch/backends/arm/_passes/arm_pass_manager.py +462 -0
  76. executorch/backends/arm/_passes/arm_pass_utils.py +281 -0
  77. executorch/backends/arm/_passes/broadcast_args_pass.py +72 -0
  78. executorch/backends/arm/_passes/cast_int64_pass.py +70 -0
  79. executorch/backends/arm/_passes/cast_to_int32_pass.py +67 -0
  80. executorch/backends/arm/_passes/conv1d_unsqueeze_pass.py +98 -0
  81. executorch/backends/arm/_passes/convert_elu_params.py +67 -0
  82. executorch/backends/arm/_passes/convert_expand_copy_to_repeat.py +77 -0
  83. executorch/backends/arm/_passes/convert_full_like_to_full_pass.py +42 -0
  84. executorch/backends/arm/_passes/convert_int64_const_ops_to_int32.py +81 -0
  85. executorch/backends/arm/_passes/convert_int64_output_ops_to_int32.py +155 -0
  86. executorch/backends/arm/_passes/convert_minmax_pass.py +166 -0
  87. executorch/backends/arm/_passes/convert_permute_singleton_to_view_pass.py +64 -0
  88. executorch/backends/arm/_passes/convert_split_to_slice.py +132 -0
  89. executorch/backends/arm/_passes/convert_squeezes_to_view.py +36 -0
  90. executorch/backends/arm/_passes/convert_to_clamp_pass.py +45 -0
  91. executorch/backends/arm/_passes/decompose_acosh_pass.py +77 -0
  92. executorch/backends/arm/_passes/decompose_adaptive_avg_pool2d_pass.py +112 -0
  93. executorch/backends/arm/_passes/decompose_add_sub_alpha_pass.py +98 -0
  94. executorch/backends/arm/_passes/decompose_addmm_pass.py +72 -0
  95. executorch/backends/arm/_passes/decompose_any_pass.py +114 -0
  96. executorch/backends/arm/_passes/decompose_asin_and_acos_pass.py +236 -0
  97. executorch/backends/arm/_passes/decompose_asinh_pass.py +74 -0
  98. executorch/backends/arm/_passes/decompose_atan_pass.py +142 -0
  99. executorch/backends/arm/_passes/decompose_atanh_pass.py +86 -0
  100. executorch/backends/arm/_passes/decompose_avg_pool2d_pass.py +154 -0
  101. executorch/backends/arm/_passes/decompose_batch_norm_no_stats.py +233 -0
  102. executorch/backends/arm/_passes/decompose_cosh_pass.py +72 -0
  103. executorch/backends/arm/_passes/decompose_cosine_similarity_pass.py +92 -0
  104. executorch/backends/arm/_passes/decompose_cumsum_pass.py +167 -0
  105. executorch/backends/arm/_passes/decompose_div_pass.py +61 -0
  106. executorch/backends/arm/_passes/decompose_div_tensor_mode.py +94 -0
  107. executorch/backends/arm/_passes/decompose_elu_pass.py +107 -0
  108. executorch/backends/arm/_passes/decompose_embedding_pass.py +126 -0
  109. executorch/backends/arm/_passes/decompose_expm1_pass.py +163 -0
  110. executorch/backends/arm/_passes/decompose_floor_divide_pass.py +75 -0
  111. executorch/backends/arm/_passes/decompose_gelu_pass.py +172 -0
  112. executorch/backends/arm/_passes/decompose_glu_pass.py +81 -0
  113. executorch/backends/arm/_passes/decompose_grouped_conv_pass.py +185 -0
  114. executorch/backends/arm/_passes/decompose_groupnorm_pass.py +227 -0
  115. executorch/backends/arm/_passes/decompose_int16_activation_conv_pass.py +137 -0
  116. executorch/backends/arm/_passes/decompose_int_pow_pass.py +64 -0
  117. executorch/backends/arm/_passes/decompose_layernorm_pass.py +203 -0
  118. executorch/backends/arm/_passes/decompose_leaky_relu_pass.py +76 -0
  119. executorch/backends/arm/_passes/decompose_linalg_vector_norm_pass.py +92 -0
  120. executorch/backends/arm/_passes/decompose_linear_pass.py +109 -0
  121. executorch/backends/arm/_passes/decompose_log1p_pass.py +97 -0
  122. executorch/backends/arm/_passes/decompose_logit_pass.py +119 -0
  123. executorch/backends/arm/_passes/decompose_masked_fill_pass.py +58 -0
  124. executorch/backends/arm/_passes/decompose_maxpool2d_with_dilation_pass.py +218 -0
  125. executorch/backends/arm/_passes/decompose_meandim_pass.py +283 -0
  126. executorch/backends/arm/_passes/decompose_ne_pass.py +74 -0
  127. executorch/backends/arm/_passes/decompose_quant_nodes.py +156 -0
  128. executorch/backends/arm/_passes/decompose_remainder_pass.py +70 -0
  129. executorch/backends/arm/_passes/decompose_round_pass.py +96 -0
  130. executorch/backends/arm/_passes/decompose_sdpa_pass.py +36 -0
  131. executorch/backends/arm/_passes/decompose_select.py +75 -0
  132. executorch/backends/arm/_passes/decompose_select_scatter_pass.py +143 -0
  133. executorch/backends/arm/_passes/decompose_sign_pass.py +78 -0
  134. executorch/backends/arm/_passes/decompose_silu_pass.py +41 -0
  135. executorch/backends/arm/_passes/decompose_sinh_pass.py +77 -0
  136. executorch/backends/arm/_passes/decompose_softmax_pass.py +93 -0
  137. executorch/backends/arm/_passes/decompose_softmax_unstable_pass.py +86 -0
  138. executorch/backends/arm/_passes/decompose_sqrt_pass.py +53 -0
  139. executorch/backends/arm/_passes/decompose_sum_pass.py +93 -0
  140. executorch/backends/arm/_passes/decompose_tan_pass.py +51 -0
  141. executorch/backends/arm/_passes/decompose_tosa_unsupported_clamp_pass.py +97 -0
  142. executorch/backends/arm/_passes/decompose_var_pass.py +109 -0
  143. executorch/backends/arm/_passes/decorate_fp32_to_int32_casting_pass.py +88 -0
  144. executorch/backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py +394 -0
  145. executorch/backends/arm/_passes/fuse_batch_norm2d_pass.py +241 -0
  146. executorch/backends/arm/_passes/fuse_constant_ops_pass.py +272 -0
  147. executorch/backends/arm/_passes/fuse_duplicate_users_pass.py +165 -0
  148. executorch/backends/arm/_passes/fuse_equal_placeholders_pass.py +104 -0
  149. executorch/backends/arm/_passes/fuse_quantized_activation_pass.py +80 -0
  150. executorch/backends/arm/_passes/fuse_view_copy_transform_pass.py +14 -0
  151. executorch/backends/arm/_passes/insert_int32_casts_after_int64_placeholders.py +130 -0
  152. executorch/backends/arm/_passes/insert_rescales_pass.py +584 -0
  153. executorch/backends/arm/_passes/insert_table_ops.py +305 -0
  154. executorch/backends/arm/_passes/match_arg_dtype_pass.py +104 -0
  155. executorch/backends/arm/_passes/match_arg_ranks_pass.py +114 -0
  156. executorch/backends/arm/_passes/mm_to_bmm_pass.py +104 -0
  157. executorch/backends/arm/_passes/normalize_while_initial_args_pass.py +113 -0
  158. executorch/backends/arm/_passes/promote_bool_operands_pass.py +88 -0
  159. executorch/backends/arm/_passes/quant_args.py +125 -0
  160. executorch/backends/arm/_passes/remove_getitem_pass.py +14 -0
  161. executorch/backends/arm/_passes/remove_graph_asserts_pass.py +18 -0
  162. executorch/backends/arm/_passes/remove_noop_pass.py +40 -0
  163. executorch/backends/arm/_passes/replace_inf_and_limit_values_pass.py +73 -0
  164. executorch/backends/arm/_passes/replace_scalar_with_tensor_pass.py +121 -0
  165. executorch/backends/arm/_passes/rewrite_bool_bitwise_not_to_logical_not_pass.py +43 -0
  166. executorch/backends/arm/_passes/rewrite_bool_to_fp32_cast_via_int8_pass.py +77 -0
  167. executorch/backends/arm/_passes/rewrite_conv_pass.py +336 -0
  168. executorch/backends/arm/_passes/rewrite_matmul.py +98 -0
  169. executorch/backends/arm/_passes/rewrite_upsample.py +93 -0
  170. executorch/backends/arm/_passes/scalars_to_attribute_pass.py +97 -0
  171. executorch/backends/arm/_passes/size_adjust_input_pass.py +227 -0
  172. executorch/backends/arm/_passes/to_tosa_memory_format_pass.py +454 -0
  173. executorch/backends/arm/_passes/unsqueeze_before_repeat_pass.py +66 -0
  174. executorch/backends/arm/_passes/unsqueeze_scalar_placeholders_pass.py +85 -0
  175. executorch/backends/arm/arm_vela.py +137 -0
  176. executorch/backends/arm/common/__init__.py +4 -0
  177. executorch/backends/arm/common/annotation_meta.py +39 -0
  178. executorch/backends/arm/common/arm_compile_spec.py +271 -0
  179. executorch/backends/arm/common/debug.py +79 -0
  180. executorch/backends/arm/common/pipeline_config.py +59 -0
  181. executorch/backends/arm/common/type.py +28 -0
  182. executorch/backends/arm/constants.py +48 -0
  183. executorch/backends/arm/debug/__init__.py +4 -0
  184. executorch/backends/arm/debug/schema.py +145 -0
  185. executorch/backends/arm/ethosu/__init__.py +11 -0
  186. executorch/backends/arm/ethosu/backend.py +115 -0
  187. executorch/backends/arm/ethosu/compile_spec.py +117 -0
  188. executorch/backends/arm/ethosu/partitioner.py +35 -0
  189. executorch/backends/arm/operator_support/__init__.py +23 -0
  190. executorch/backends/arm/operator_support/clone_dim_order_support.py +82 -0
  191. executorch/backends/arm/operator_support/control_flow_support.py +162 -0
  192. executorch/backends/arm/operator_support/convolution_support.py +160 -0
  193. executorch/backends/arm/operator_support/embedding_support.py +61 -0
  194. executorch/backends/arm/operator_support/ethos_u55_support.py +598 -0
  195. executorch/backends/arm/operator_support/index_select_support.py +60 -0
  196. executorch/backends/arm/operator_support/index_tensor_support.py +160 -0
  197. executorch/backends/arm/operator_support/minmax_support.py +61 -0
  198. executorch/backends/arm/operator_support/pool_2d_support.py +214 -0
  199. executorch/backends/arm/operator_support/reduce_sum_support.py +76 -0
  200. executorch/backends/arm/operator_support/right_shift_support.py +52 -0
  201. executorch/backends/arm/operator_support/slice_copy_support.py +48 -0
  202. executorch/backends/arm/operator_support/to_dim_order_copy_support.py +200 -0
  203. executorch/backends/arm/operator_support/tosa_profile_supported_op_lists.py +251 -0
  204. executorch/backends/arm/operator_support/tosa_supported_operators.py +748 -0
  205. executorch/backends/arm/operator_support/where_support.py +77 -0
  206. executorch/backends/arm/operators/__init__.py +71 -0
  207. executorch/backends/arm/operators/node_visitor.py +177 -0
  208. executorch/backends/arm/operators/op_abs.py +59 -0
  209. executorch/backends/arm/operators/op_add.py +60 -0
  210. executorch/backends/arm/operators/op_amax.py +72 -0
  211. executorch/backends/arm/operators/op_amin.py +73 -0
  212. executorch/backends/arm/operators/op_any.py +61 -0
  213. executorch/backends/arm/operators/op_avg_pool2d.py +142 -0
  214. executorch/backends/arm/operators/op_bitwise_not.py +62 -0
  215. executorch/backends/arm/operators/op_cat.py +68 -0
  216. executorch/backends/arm/operators/op_ceil.py +56 -0
  217. executorch/backends/arm/operators/op_clamp.py +118 -0
  218. executorch/backends/arm/operators/op_cond_if.py +56 -0
  219. executorch/backends/arm/operators/op_constant_pad_nd.py +117 -0
  220. executorch/backends/arm/operators/op_cos.py +49 -0
  221. executorch/backends/arm/operators/op_eq.py +64 -0
  222. executorch/backends/arm/operators/op_erf.py +54 -0
  223. executorch/backends/arm/operators/op_exp.py +54 -0
  224. executorch/backends/arm/operators/op_floor.py +56 -0
  225. executorch/backends/arm/operators/op_ge.py +64 -0
  226. executorch/backends/arm/operators/op_gt.py +64 -0
  227. executorch/backends/arm/operators/op_index_select.py +109 -0
  228. executorch/backends/arm/operators/op_index_tensor.py +247 -0
  229. executorch/backends/arm/operators/op_le.py +64 -0
  230. executorch/backends/arm/operators/op_log.py +50 -0
  231. executorch/backends/arm/operators/op_logical_not.py +62 -0
  232. executorch/backends/arm/operators/op_lt.py +64 -0
  233. executorch/backends/arm/operators/op_max_pool2d.py +108 -0
  234. executorch/backends/arm/operators/op_maximum.py +66 -0
  235. executorch/backends/arm/operators/op_minimum.py +67 -0
  236. executorch/backends/arm/operators/op_mul.py +61 -0
  237. executorch/backends/arm/operators/op_neg.py +92 -0
  238. executorch/backends/arm/operators/op_permute.py +150 -0
  239. executorch/backends/arm/operators/op_pow.py +63 -0
  240. executorch/backends/arm/operators/op_reciprocal.py +51 -0
  241. executorch/backends/arm/operators/op_repeat.py +77 -0
  242. executorch/backends/arm/operators/op_rshift_tensor.py +62 -0
  243. executorch/backends/arm/operators/op_rsqrt.py +51 -0
  244. executorch/backends/arm/operators/op_sigmoid.py +50 -0
  245. executorch/backends/arm/operators/op_sin.py +49 -0
  246. executorch/backends/arm/operators/op_slice.py +151 -0
  247. executorch/backends/arm/operators/op_sub.py +63 -0
  248. executorch/backends/arm/operators/op_sum.py +64 -0
  249. executorch/backends/arm/operators/op_tanh.py +51 -0
  250. executorch/backends/arm/operators/op_to_dim_order_copy.py +49 -0
  251. executorch/backends/arm/operators/op_tosa_conv2d.py +139 -0
  252. executorch/backends/arm/operators/op_tosa_conv3d.py +24 -0
  253. executorch/backends/arm/operators/op_tosa_depthwise_conv2d.py +32 -0
  254. executorch/backends/arm/operators/op_tosa_matmul.py +102 -0
  255. executorch/backends/arm/operators/op_tosa_rescale.py +261 -0
  256. executorch/backends/arm/operators/op_tosa_resize.py +124 -0
  257. executorch/backends/arm/operators/op_tosa_table.py +72 -0
  258. executorch/backends/arm/operators/op_tosa_transpose.py +71 -0
  259. executorch/backends/arm/operators/op_view.py +81 -0
  260. executorch/backends/arm/operators/op_where.py +75 -0
  261. executorch/backends/arm/operators/op_while.py +103 -0
  262. executorch/backends/arm/operators/operator_validation_utils.py +201 -0
  263. executorch/backends/arm/operators/ops_binary.py +112 -0
  264. executorch/backends/arm/operators/ops_identity.py +80 -0
  265. executorch/backends/arm/process_node.py +230 -0
  266. executorch/backends/arm/quantizer/__init__.py +35 -0
  267. executorch/backends/arm/quantizer/arm_quantizer.py +710 -0
  268. executorch/backends/arm/quantizer/arm_quantizer_utils.py +76 -0
  269. executorch/backends/arm/quantizer/quantization_annotator.py +815 -0
  270. executorch/backends/arm/quantizer/quantization_config.py +228 -0
  271. executorch/backends/arm/scripts/collect_testname_resources.py +194 -0
  272. executorch/backends/arm/scripts/parse_test_names.py +271 -0
  273. executorch/backends/arm/test/common.py +302 -0
  274. executorch/backends/arm/test/conftest.py +134 -0
  275. executorch/backends/arm/test/misc/test_bn_relu_folding_qat.py +124 -0
  276. executorch/backends/arm/test/misc/test_call_operator_submodule.py +72 -0
  277. executorch/backends/arm/test/misc/test_compile_spec.py +55 -0
  278. executorch/backends/arm/test/misc/test_conv_relu_residual_add.py +108 -0
  279. executorch/backends/arm/test/misc/test_custom_partition.py +183 -0
  280. executorch/backends/arm/test/misc/test_debug_feats.py +316 -0
  281. executorch/backends/arm/test/misc/test_debug_hook.py +186 -0
  282. executorch/backends/arm/test/misc/test_dim_order.py +127 -0
  283. executorch/backends/arm/test/misc/test_dw_convs_with_shared_weights.py +46 -0
  284. executorch/backends/arm/test/misc/test_extract_io_params_tosa.py +92 -0
  285. executorch/backends/arm/test/misc/test_int64.py +112 -0
  286. executorch/backends/arm/test/misc/test_lifted_tensor.py +146 -0
  287. executorch/backends/arm/test/misc/test_mixed_type_lowering.py +83 -0
  288. executorch/backends/arm/test/misc/test_model_evaluator.py +58 -0
  289. executorch/backends/arm/test/misc/test_multiple_delegates.py +53 -0
  290. executorch/backends/arm/test/misc/test_multiple_outputs.py +70 -0
  291. executorch/backends/arm/test/misc/test_non_persistent_buffers.py +49 -0
  292. executorch/backends/arm/test/misc/test_outputs_order.py +122 -0
  293. executorch/backends/arm/test/misc/test_partition_decomposed_quantized_ops.py +181 -0
  294. executorch/backends/arm/test/misc/test_pass_pipeline_config.py +35 -0
  295. executorch/backends/arm/test/misc/test_pass_required_order.py +97 -0
  296. executorch/backends/arm/test/misc/test_qat_training_loop.py +100 -0
  297. executorch/backends/arm/test/misc/test_quant_custom_meta.py +105 -0
  298. executorch/backends/arm/test/misc/test_rescale_range.py +130 -0
  299. executorch/backends/arm/test/misc/test_save_exported_model.py +64 -0
  300. executorch/backends/arm/test/misc/test_tosa_dialect_conv2d.py +220 -0
  301. executorch/backends/arm/test/misc/test_tosa_dialect_dw_conv2d.py +227 -0
  302. executorch/backends/arm/test/misc/test_tosa_spec.py +169 -0
  303. executorch/backends/arm/test/models/stable_diffusion/stable_diffusion_module_test_configs.py +114 -0
  304. executorch/backends/arm/test/models/stable_diffusion/test_CLIPTextModelWithProjection.py +168 -0
  305. executorch/backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py +193 -0
  306. executorch/backends/arm/test/models/stable_diffusion/test_T5EncoderModel.py +161 -0
  307. executorch/backends/arm/test/models/stable_diffusion/test_vae_AutoencoderKL.py +118 -0
  308. executorch/backends/arm/test/models/test_conformer.py +138 -0
  309. executorch/backends/arm/test/models/test_deit_tiny_arm.py +120 -0
  310. executorch/backends/arm/test/models/test_dl3_arm.py +118 -0
  311. executorch/backends/arm/test/models/test_inception_v3_arm.py +120 -0
  312. executorch/backends/arm/test/models/test_llama.py +227 -0
  313. executorch/backends/arm/test/models/test_lstm_arm.py +194 -0
  314. executorch/backends/arm/test/models/test_mobilenet_v2_arm.py +179 -0
  315. executorch/backends/arm/test/models/test_mobilenet_v3_arm.py +113 -0
  316. executorch/backends/arm/test/models/test_nn_functional.py +124 -0
  317. executorch/backends/arm/test/models/test_nn_modules.py +161 -0
  318. executorch/backends/arm/test/models/test_nss.py +146 -0
  319. executorch/backends/arm/test/models/test_resnet18.py +98 -0
  320. executorch/backends/arm/test/models/test_torch_functions.py +151 -0
  321. executorch/backends/arm/test/models/test_w2l_arm.py +136 -0
  322. executorch/backends/arm/test/ops/test_abs.py +101 -0
  323. executorch/backends/arm/test/ops/test_acos.py +121 -0
  324. executorch/backends/arm/test/ops/test_acosh.py +137 -0
  325. executorch/backends/arm/test/ops/test_adaptive_avg_pool2d.py +242 -0
  326. executorch/backends/arm/test/ops/test_add.py +291 -0
  327. executorch/backends/arm/test/ops/test_addmm.py +285 -0
  328. executorch/backends/arm/test/ops/test_alias_copy.py +114 -0
  329. executorch/backends/arm/test/ops/test_amax.py +191 -0
  330. executorch/backends/arm/test/ops/test_amin.py +205 -0
  331. executorch/backends/arm/test/ops/test_any.py +210 -0
  332. executorch/backends/arm/test/ops/test_arange.py +258 -0
  333. executorch/backends/arm/test/ops/test_asin.py +105 -0
  334. executorch/backends/arm/test/ops/test_asinh.py +104 -0
  335. executorch/backends/arm/test/ops/test_at.py +256 -0
  336. executorch/backends/arm/test/ops/test_atan.py +111 -0
  337. executorch/backends/arm/test/ops/test_atanh.py +112 -0
  338. executorch/backends/arm/test/ops/test_avg_pool2d.py +295 -0
  339. executorch/backends/arm/test/ops/test_batch_norm.py +385 -0
  340. executorch/backends/arm/test/ops/test_bitwise.py +672 -0
  341. executorch/backends/arm/test/ops/test_bitwise_not.py +115 -0
  342. executorch/backends/arm/test/ops/test_bmm.py +193 -0
  343. executorch/backends/arm/test/ops/test_cat.py +219 -0
  344. executorch/backends/arm/test/ops/test_ceil.py +125 -0
  345. executorch/backends/arm/test/ops/test_clamp.py +474 -0
  346. executorch/backends/arm/test/ops/test_clone.py +150 -0
  347. executorch/backends/arm/test/ops/test_cond.py +338 -0
  348. executorch/backends/arm/test/ops/test_constant_pad_nd.py +119 -0
  349. executorch/backends/arm/test/ops/test_conv1d.py +356 -0
  350. executorch/backends/arm/test/ops/test_conv2d.py +592 -0
  351. executorch/backends/arm/test/ops/test_conv3d.py +711 -0
  352. executorch/backends/arm/test/ops/test_conv_combos.py +668 -0
  353. executorch/backends/arm/test/ops/test_conv_constant_pad_nd.py +145 -0
  354. executorch/backends/arm/test/ops/test_copy.py +171 -0
  355. executorch/backends/arm/test/ops/test_cos.py +115 -0
  356. executorch/backends/arm/test/ops/test_cosh.py +111 -0
  357. executorch/backends/arm/test/ops/test_cumsum.py +122 -0
  358. executorch/backends/arm/test/ops/test_depthwise_conv.py +404 -0
  359. executorch/backends/arm/test/ops/test_div.py +151 -0
  360. executorch/backends/arm/test/ops/test_div_tensor_mode.py +151 -0
  361. executorch/backends/arm/test/ops/test_elu.py +133 -0
  362. executorch/backends/arm/test/ops/test_embedding.py +146 -0
  363. executorch/backends/arm/test/ops/test_eq.py +286 -0
  364. executorch/backends/arm/test/ops/test_erf.py +96 -0
  365. executorch/backends/arm/test/ops/test_exp.py +110 -0
  366. executorch/backends/arm/test/ops/test_expand.py +153 -0
  367. executorch/backends/arm/test/ops/test_expm1.py +113 -0
  368. executorch/backends/arm/test/ops/test_eye.py +156 -0
  369. executorch/backends/arm/test/ops/test_fill_scalar.py +108 -0
  370. executorch/backends/arm/test/ops/test_floor.py +125 -0
  371. executorch/backends/arm/test/ops/test_floor_div.py +156 -0
  372. executorch/backends/arm/test/ops/test_full.py +255 -0
  373. executorch/backends/arm/test/ops/test_ge.py +292 -0
  374. executorch/backends/arm/test/ops/test_gelu.py +156 -0
  375. executorch/backends/arm/test/ops/test_glu.py +130 -0
  376. executorch/backends/arm/test/ops/test_group_norm.py +200 -0
  377. executorch/backends/arm/test/ops/test_gt.py +293 -0
  378. executorch/backends/arm/test/ops/test_hardsigmoid.py +114 -0
  379. executorch/backends/arm/test/ops/test_hardswish.py +104 -0
  380. executorch/backends/arm/test/ops/test_hardtanh.py +113 -0
  381. executorch/backends/arm/test/ops/test_index_select.py +177 -0
  382. executorch/backends/arm/test/ops/test_index_tensor.py +467 -0
  383. executorch/backends/arm/test/ops/test_layer_norm.py +186 -0
  384. executorch/backends/arm/test/ops/test_le.py +296 -0
  385. executorch/backends/arm/test/ops/test_leaky_relu.py +125 -0
  386. executorch/backends/arm/test/ops/test_linalg_vector_norm.py +160 -0
  387. executorch/backends/arm/test/ops/test_linear.py +389 -0
  388. executorch/backends/arm/test/ops/test_log.py +100 -0
  389. executorch/backends/arm/test/ops/test_log1p.py +78 -0
  390. executorch/backends/arm/test/ops/test_logical.py +429 -0
  391. executorch/backends/arm/test/ops/test_logit.py +119 -0
  392. executorch/backends/arm/test/ops/test_logsoftmax.py +124 -0
  393. executorch/backends/arm/test/ops/test_lshift.py +220 -0
  394. executorch/backends/arm/test/ops/test_lt.py +293 -0
  395. executorch/backends/arm/test/ops/test_masked_fill.py +171 -0
  396. executorch/backends/arm/test/ops/test_matmul.py +289 -0
  397. executorch/backends/arm/test/ops/test_max_pool.py +329 -0
  398. executorch/backends/arm/test/ops/test_maximum.py +98 -0
  399. executorch/backends/arm/test/ops/test_mean_dim.py +388 -0
  400. executorch/backends/arm/test/ops/test_minimum.py +98 -0
  401. executorch/backends/arm/test/ops/test_mm.py +93 -0
  402. executorch/backends/arm/test/ops/test_mul.py +376 -0
  403. executorch/backends/arm/test/ops/test_multihead_attention.py +138 -0
  404. executorch/backends/arm/test/ops/test_ne.py +243 -0
  405. executorch/backends/arm/test/ops/test_neg.py +99 -0
  406. executorch/backends/arm/test/ops/test_ones.py +152 -0
  407. executorch/backends/arm/test/ops/test_permute.py +256 -0
  408. executorch/backends/arm/test/ops/test_pixel_shuffling.py +237 -0
  409. executorch/backends/arm/test/ops/test_pow.py +204 -0
  410. executorch/backends/arm/test/ops/test_reciprocal.py +112 -0
  411. executorch/backends/arm/test/ops/test_relu.py +166 -0
  412. executorch/backends/arm/test/ops/test_remainder.py +199 -0
  413. executorch/backends/arm/test/ops/test_repeat.py +162 -0
  414. executorch/backends/arm/test/ops/test_round.py +111 -0
  415. executorch/backends/arm/test/ops/test_rshift.py +226 -0
  416. executorch/backends/arm/test/ops/test_rsqrt.py +153 -0
  417. executorch/backends/arm/test/ops/test_rsub.py +126 -0
  418. executorch/backends/arm/test/ops/test_scalar_tensor.py +135 -0
  419. executorch/backends/arm/test/ops/test_scalars.py +438 -0
  420. executorch/backends/arm/test/ops/test_sdpa.py +73 -0
  421. executorch/backends/arm/test/ops/test_select.py +219 -0
  422. executorch/backends/arm/test/ops/test_select_scatter.py +173 -0
  423. executorch/backends/arm/test/ops/test_sigmoid.py +357 -0
  424. executorch/backends/arm/test/ops/test_sigmoid_32bit.py +177 -0
  425. executorch/backends/arm/test/ops/test_sign.py +113 -0
  426. executorch/backends/arm/test/ops/test_silu.py +174 -0
  427. executorch/backends/arm/test/ops/test_sin.py +108 -0
  428. executorch/backends/arm/test/ops/test_sinh.py +103 -0
  429. executorch/backends/arm/test/ops/test_slice.py +217 -0
  430. executorch/backends/arm/test/ops/test_softmax.py +121 -0
  431. executorch/backends/arm/test/ops/test_split.py +312 -0
  432. executorch/backends/arm/test/ops/test_sqrt.py +112 -0
  433. executorch/backends/arm/test/ops/test_squeeze.py +291 -0
  434. executorch/backends/arm/test/ops/test_stack.py +150 -0
  435. executorch/backends/arm/test/ops/test_sub.py +366 -0
  436. executorch/backends/arm/test/ops/test_sum.py +161 -0
  437. executorch/backends/arm/test/ops/test_t_copy.py +115 -0
  438. executorch/backends/arm/test/ops/test_tan.py +146 -0
  439. executorch/backends/arm/test/ops/test_tanh.py +169 -0
  440. executorch/backends/arm/test/ops/test_to_copy.py +296 -0
  441. executorch/backends/arm/test/ops/test_transpose_copy.py +114 -0
  442. executorch/backends/arm/test/ops/test_unary_combos.py +144 -0
  443. executorch/backends/arm/test/ops/test_unbind.py +82 -0
  444. executorch/backends/arm/test/ops/test_unflatten.py +107 -0
  445. executorch/backends/arm/test/ops/test_unsqueeze.py +107 -0
  446. executorch/backends/arm/test/ops/test_upsample_bilinear2d.py +443 -0
  447. executorch/backends/arm/test/ops/test_upsample_nearest2d.py +520 -0
  448. executorch/backends/arm/test/ops/test_var.py +394 -0
  449. executorch/backends/arm/test/ops/test_view.py +253 -0
  450. executorch/backends/arm/test/ops/test_where.py +285 -0
  451. executorch/backends/arm/test/ops/test_while.py +264 -0
  452. executorch/backends/arm/test/ops/test_zeros.py +158 -0
  453. executorch/backends/arm/test/passes/test_broadcast_args_pass.py +57 -0
  454. executorch/backends/arm/test/passes/test_cast_int64_pass.py +49 -0
  455. executorch/backends/arm/test/passes/test_convert_expand_copy_to_repeat.py +51 -0
  456. executorch/backends/arm/test/passes/test_convert_int64_const_ops_to_int32.py +529 -0
  457. executorch/backends/arm/test/passes/test_convert_int64_output_ops_to_int32.py +129 -0
  458. executorch/backends/arm/test/passes/test_convert_permute_singleton_to_view_pass.py +100 -0
  459. executorch/backends/arm/test/passes/test_convert_split_to_slice.py +75 -0
  460. executorch/backends/arm/test/passes/test_convert_to_clamp.py +92 -0
  461. executorch/backends/arm/test/passes/test_decompose_avg_pool2d_pass.py +82 -0
  462. executorch/backends/arm/test/passes/test_decompose_cosine_similarity_pass.py +58 -0
  463. executorch/backends/arm/test/passes/test_decompose_div_pass.py +70 -0
  464. executorch/backends/arm/test/passes/test_decompose_int_pow_pass.py +80 -0
  465. executorch/backends/arm/test/passes/test_decompose_layernorm_pass.py +69 -0
  466. executorch/backends/arm/test/passes/test_decompose_linalg_vector_norm_pass.py +107 -0
  467. executorch/backends/arm/test/passes/test_decompose_meandim_pass.py +137 -0
  468. executorch/backends/arm/test/passes/test_decompose_quant_nodes.py +44 -0
  469. executorch/backends/arm/test/passes/test_decompose_softmax_pass.py +103 -0
  470. executorch/backends/arm/test/passes/test_decompose_tosa_unsupported_clamp_pass.py +73 -0
  471. executorch/backends/arm/test/passes/test_decompose_var_pass.py +89 -0
  472. executorch/backends/arm/test/passes/test_decorate_fp32_to_int32_casting_pass.py +85 -0
  473. executorch/backends/arm/test/passes/test_fold_qdq_pass.py +51 -0
  474. executorch/backends/arm/test/passes/test_fuse_batchnorm_pass.py +164 -0
  475. executorch/backends/arm/test/passes/test_fuse_constant_ops_pass.py +177 -0
  476. executorch/backends/arm/test/passes/test_fuse_duplicate_users_pass.py +70 -0
  477. executorch/backends/arm/test/passes/test_fuse_equal_placeholders_ops_pass.py +170 -0
  478. executorch/backends/arm/test/passes/test_fuse_view_copy.py +82 -0
  479. executorch/backends/arm/test/passes/test_insert_int32_casts_after_int64_placeholders_pass.py +114 -0
  480. executorch/backends/arm/test/passes/test_insert_rescale_i32_pass.py +107 -0
  481. executorch/backends/arm/test/passes/test_insert_table_ops_pass.py +47 -0
  482. executorch/backends/arm/test/passes/test_int32_cast_embedding_pass.py +46 -0
  483. executorch/backends/arm/test/passes/test_ioquantization_pass.py +48 -0
  484. executorch/backends/arm/test/passes/test_promote_bool_operands_pass.py +103 -0
  485. executorch/backends/arm/test/passes/test_remove_clone_pass.py +45 -0
  486. executorch/backends/arm/test/passes/test_replace_inf_values_pass.py +96 -0
  487. executorch/backends/arm/test/passes/test_rescale_pass.py +81 -0
  488. executorch/backends/arm/test/passes/test_rewrite_conv_pass.py +20 -0
  489. executorch/backends/arm/test/passes/test_to_tosa_memory_format.py +213 -0
  490. executorch/backends/arm/test/passes/test_unsqueeze_before_repeat_pass.py +62 -0
  491. executorch/backends/arm/test/quantizer/test_conv_relu_fusing.py +118 -0
  492. executorch/backends/arm/test/quantizer/test_generic_annotater.py +109 -0
  493. executorch/backends/arm/test/quantizer/test_partial_quantization.py +104 -0
  494. executorch/backends/arm/test/quantizer/test_selective_quantization.py +212 -0
  495. executorch/backends/arm/test/quantizer/test_set_module_name.py +158 -0
  496. executorch/backends/arm/test/quantizer/test_tosa_quantizer_validate.py +55 -0
  497. executorch/backends/arm/test/runner_utils.py +840 -0
  498. executorch/backends/arm/test/test_memory_allocator_log.py +170 -0
  499. executorch/backends/arm/test/test_model.py +345 -0
  500. executorch/backends/arm/test/tester/__init__.py +6 -0
  501. executorch/backends/arm/test/tester/analyze_output_utils.py +346 -0
  502. executorch/backends/arm/test/tester/arm_tester.py +1149 -0
  503. executorch/backends/arm/test/tester/quantize.py +43 -0
  504. executorch/backends/arm/test/tester/serialize.py +78 -0
  505. executorch/backends/arm/test/tester/test_pipeline.py +1190 -0
  506. executorch/backends/arm/tosa/__init__.py +9 -0
  507. executorch/backends/arm/tosa/backend.py +443 -0
  508. executorch/backends/arm/tosa/compile_spec.py +48 -0
  509. executorch/backends/arm/tosa/dialect/__init__.py +15 -0
  510. executorch/backends/arm/tosa/dialect/lib.py +85 -0
  511. executorch/backends/arm/tosa/dialect/ops/conv2d.py +111 -0
  512. executorch/backends/arm/tosa/dialect/ops/conv3d.py +74 -0
  513. executorch/backends/arm/tosa/dialect/ops/depthwise_conv2d.py +56 -0
  514. executorch/backends/arm/tosa/dialect/ops/matmul.py +56 -0
  515. executorch/backends/arm/tosa/dialect/ops/rescale.py +53 -0
  516. executorch/backends/arm/tosa/dialect/ops/resize.py +66 -0
  517. executorch/backends/arm/tosa/dialect/ops/table.py +53 -0
  518. executorch/backends/arm/tosa/dialect/ops/transpose.py +35 -0
  519. executorch/backends/arm/tosa/dialect/ops_registration.py +68 -0
  520. executorch/backends/arm/tosa/mapping.py +309 -0
  521. executorch/backends/arm/tosa/partitioner.py +486 -0
  522. executorch/backends/arm/tosa/schemas/__init__.py +4 -0
  523. executorch/backends/arm/tosa/schemas/tosa_1.0.fbs +559 -0
  524. executorch/backends/arm/tosa/specification.py +406 -0
  525. executorch/backends/arm/tosa/utils.py +304 -0
  526. executorch/backends/arm/util/_factory.py +59 -0
  527. executorch/backends/arm/util/arm_model_evaluator.py +388 -0
  528. executorch/backends/arm/vgf/__init__.py +11 -0
  529. executorch/backends/arm/vgf/backend.py +172 -0
  530. executorch/backends/arm/vgf/compile_spec.py +73 -0
  531. executorch/backends/arm/vgf/model_converter.py +34 -0
  532. executorch/backends/arm/vgf/partitioner.py +35 -0
  533. executorch/backends/cadence/aot/__init__.py +5 -0
  534. executorch/backends/cadence/aot/compiler.py +484 -0
  535. executorch/backends/cadence/aot/compiler_funcs.py +203 -0
  536. executorch/backends/cadence/aot/compiler_utils.py +293 -0
  537. executorch/backends/cadence/aot/decompose_ops.py +120 -0
  538. executorch/backends/cadence/aot/export_example.py +117 -0
  539. executorch/backends/cadence/aot/functions.yaml +470 -0
  540. executorch/backends/cadence/aot/functions_fusion_g3.yaml +191 -0
  541. executorch/backends/cadence/aot/functions_hifi.yaml +565 -0
  542. executorch/backends/cadence/aot/functions_vision.yaml +275 -0
  543. executorch/backends/cadence/aot/fuse_ops.py +1138 -0
  544. executorch/backends/cadence/aot/graph_builder.py +142 -0
  545. executorch/backends/cadence/aot/memory_constraints.py +731 -0
  546. executorch/backends/cadence/aot/memory_planning.py +469 -0
  547. executorch/backends/cadence/aot/memory_planning_algo.py +341 -0
  548. executorch/backends/cadence/aot/ops_registrations.py +2841 -0
  549. executorch/backends/cadence/aot/pass_utils.py +274 -0
  550. executorch/backends/cadence/aot/passes.py +132 -0
  551. executorch/backends/cadence/aot/program_builder.py +138 -0
  552. executorch/backends/cadence/aot/quantizer/fusion_pass.py +743 -0
  553. executorch/backends/cadence/aot/quantizer/patterns.py +738 -0
  554. executorch/backends/cadence/aot/quantizer/quantizer.py +409 -0
  555. executorch/backends/cadence/aot/quantizer/utils.py +288 -0
  556. executorch/backends/cadence/aot/ref_implementations.py +2210 -0
  557. executorch/backends/cadence/aot/remove_ops.py +936 -0
  558. executorch/backends/cadence/aot/reorder_ops.py +843 -0
  559. executorch/backends/cadence/aot/replace_ops.py +2526 -0
  560. executorch/backends/cadence/aot/simplify_ops.py +221 -0
  561. executorch/backends/cadence/aot/tests/test_decompose_ops_passes.py +80 -0
  562. executorch/backends/cadence/aot/tests/test_fusion_ops_passes.py +1023 -0
  563. executorch/backends/cadence/aot/tests/test_graph_builder.py +104 -0
  564. executorch/backends/cadence/aot/tests/test_idma_ops.py +31 -0
  565. executorch/backends/cadence/aot/tests/test_memory_passes.py +1367 -0
  566. executorch/backends/cadence/aot/tests/test_pass_filter.py +167 -0
  567. executorch/backends/cadence/aot/tests/test_program_builder.py +222 -0
  568. executorch/backends/cadence/aot/tests/test_quantizer_ops.py +649 -0
  569. executorch/backends/cadence/aot/tests/test_ref_implementations.py +3151 -0
  570. executorch/backends/cadence/aot/tests/test_remove_ops_passes.py +977 -0
  571. executorch/backends/cadence/aot/tests/test_reorder_ops_passes.py +635 -0
  572. executorch/backends/cadence/aot/tests/test_replace_ops_passes.py +2777 -0
  573. executorch/backends/cadence/aot/tests/test_simplify_ops_passes.py +160 -0
  574. executorch/backends/cadence/aot/tests/test_type_dispatch_passes.py +481 -0
  575. executorch/backends/cadence/aot/type_dispatch.py +190 -0
  576. executorch/backends/cadence/aot/typing_stubs.py +22 -0
  577. executorch/backends/cadence/aot/utils.py +363 -0
  578. executorch/backends/cadence/runtime/__init__.py +13 -0
  579. executorch/backends/cadence/runtime/etdump.py +173 -0
  580. executorch/backends/cadence/runtime/executor.py +202 -0
  581. executorch/backends/cadence/runtime/runtime.py +156 -0
  582. executorch/backends/cadence/runtime/utils.py +100 -0
  583. executorch/backends/cadence/utils/FACTO/calibrator/__init__.py +0 -0
  584. executorch/backends/cadence/utils/FACTO/calibrator/runner.py +190 -0
  585. executorch/backends/cadence/utils/FACTO/examples/example.py +59 -0
  586. executorch/backends/cadence/utils/FACTO/examples/minimal_example.py +21 -0
  587. executorch/backends/cadence/utils/FACTO/examples/random_seed.py +35 -0
  588. executorch/backends/cadence/utils/FACTO/facto/__init__.py +0 -0
  589. executorch/backends/cadence/utils/FACTO/facto/inputgen/__init__.py +0 -0
  590. executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/__init__.py +0 -0
  591. executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/engine.py +129 -0
  592. executorch/backends/cadence/utils/FACTO/facto/inputgen/argtuple/gen.py +47 -0
  593. executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/__init__.py +0 -0
  594. executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/engine.py +291 -0
  595. executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/gen.py +139 -0
  596. executorch/backends/cadence/utils/FACTO/facto/inputgen/argument/type.py +134 -0
  597. executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/__init__.py +0 -0
  598. executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/engine.py +54 -0
  599. executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/model.py +133 -0
  600. executorch/backends/cadence/utils/FACTO/facto/inputgen/attribute/solve.py +125 -0
  601. executorch/backends/cadence/utils/FACTO/facto/inputgen/specs/__init__.py +0 -0
  602. executorch/backends/cadence/utils/FACTO/facto/inputgen/specs/model.py +149 -0
  603. executorch/backends/cadence/utils/FACTO/facto/inputgen/utils/__init__.py +0 -0
  604. executorch/backends/cadence/utils/FACTO/facto/inputgen/utils/random_manager.py +33 -0
  605. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/__init__.py +0 -0
  606. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/constants.py +9 -0
  607. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/gen.py +283 -0
  608. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/solve.py +142 -0
  609. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/space.py +450 -0
  610. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/type.py +105 -0
  611. executorch/backends/cadence/utils/FACTO/facto/inputgen/variable/utils.py +30 -0
  612. executorch/backends/cadence/utils/FACTO/facto/specdb/db.py +4361 -0
  613. executorch/backends/cadence/utils/FACTO/facto/specdb/default.py +36 -0
  614. executorch/backends/cadence/utils/FACTO/facto/specdb/dtypes.py +25 -0
  615. executorch/backends/cadence/utils/FACTO/facto/specdb/function.py +537 -0
  616. executorch/backends/cadence/utils/FACTO/setup.py +19 -0
  617. executorch/backends/cadence/utils/FACTO/test/inputgen/test_argtuple_engine.py +53 -0
  618. executorch/backends/cadence/utils/FACTO/test/inputgen/test_argtuple_generator.py +58 -0
  619. executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_attributes.py +78 -0
  620. executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_generator.py +98 -0
  621. executorch/backends/cadence/utils/FACTO/test/inputgen/test_argument_types.py +28 -0
  622. executorch/backends/cadence/utils/FACTO/test/inputgen/test_attribute_engine.py +62 -0
  623. executorch/backends/cadence/utils/FACTO/test/inputgen/test_attribute_solver.py +83 -0
  624. executorch/backends/cadence/utils/FACTO/test/inputgen/test_constraints.py +27 -0
  625. executorch/backends/cadence/utils/FACTO/test/inputgen/test_meta_arg_engine.py +70 -0
  626. executorch/backends/cadence/utils/FACTO/test/inputgen/test_specs.py +48 -0
  627. executorch/backends/cadence/utils/FACTO/test/inputgen/test_structural_engine.py +32 -0
  628. executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_generation.py +80 -0
  629. executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_solving.py +193 -0
  630. executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_space.py +231 -0
  631. executorch/backends/cadence/utils/FACTO/test/inputgen/test_variable_types.py +71 -0
  632. executorch/backends/cadence/utils/facto_util.py +611 -0
  633. executorch/backends/cadence/utils/gen_header.py +49 -0
  634. executorch/backends/cadence/utils/post_compilation.py +173 -0
  635. executorch/backends/cortex_m/ops/operators.py +890 -0
  636. executorch/backends/cortex_m/ops/operators.yaml +78 -0
  637. executorch/backends/cortex_m/passes/__init__.py +12 -0
  638. executorch/backends/cortex_m/passes/activation_fusion_pass.py +181 -0
  639. executorch/backends/cortex_m/passes/clamp_hardswish_pass.py +37 -0
  640. executorch/backends/cortex_m/passes/convert_to_cortex_m_pass.py +318 -0
  641. executorch/backends/cortex_m/passes/cortex_m_pass_manager.py +73 -0
  642. executorch/backends/cortex_m/passes/decompose_hardswish_pass.py +127 -0
  643. executorch/backends/cortex_m/passes/passes_utils.py +226 -0
  644. executorch/backends/cortex_m/passes/quantized_op_fusion_pass.py +255 -0
  645. executorch/backends/cortex_m/passes/replace_quant_nodes_pass.py +67 -0
  646. executorch/backends/cortex_m/quantizer/__init__.py +18 -0
  647. executorch/backends/cortex_m/quantizer/operator_configs.py +74 -0
  648. executorch/backends/cortex_m/quantizer/quantization_configs.py +121 -0
  649. executorch/backends/cortex_m/quantizer/quantizer.py +500 -0
  650. executorch/backends/cortex_m/test/misc/test_quantization.py +359 -0
  651. executorch/backends/cortex_m/test/models/__init__.py +4 -0
  652. executorch/backends/cortex_m/test/models/test_mobilenet_v3.py +74 -0
  653. executorch/backends/cortex_m/test/ops/__init__.py +4 -0
  654. executorch/backends/cortex_m/test/ops/test_activation.py +528 -0
  655. executorch/backends/cortex_m/test/ops/test_add.py +182 -0
  656. executorch/backends/cortex_m/test/ops/test_avg_pool2d.py +99 -0
  657. executorch/backends/cortex_m/test/ops/test_conv.py +342 -0
  658. executorch/backends/cortex_m/test/ops/test_linear.py +130 -0
  659. executorch/backends/cortex_m/test/ops/test_lstm.py +98 -0
  660. executorch/backends/cortex_m/test/ops/test_maximum.py +83 -0
  661. executorch/backends/cortex_m/test/ops/test_minimum.py +104 -0
  662. executorch/backends/cortex_m/test/ops/test_mul.py +156 -0
  663. executorch/backends/cortex_m/test/ops/test_softmax.py +84 -0
  664. executorch/backends/cortex_m/test/ops/test_transpose.py +102 -0
  665. executorch/backends/cortex_m/test/test_helpers_passes_utils.py +103 -0
  666. executorch/backends/cortex_m/test/test_replace_quant_nodes.py +134 -0
  667. executorch/backends/cortex_m/test/tester.py +113 -0
  668. executorch/backends/cuda/__init__.py +5 -0
  669. executorch/backends/cuda/cuda_backend.py +250 -0
  670. executorch/backends/cuda/cuda_partitioner.py +25 -0
  671. executorch/backends/cuda/passes/__init__.py +0 -0
  672. executorch/backends/cuda/passes/move_cond_predicate_to_cpu.py +90 -0
  673. executorch/backends/cuda/passes/tests/__init__.py +0 -0
  674. executorch/backends/cuda/passes/tests/test_move_cond_predicate_to_cpu.py +553 -0
  675. executorch/backends/cuda/tests/__init__.py +5 -0
  676. executorch/backends/cuda/tests/test_cuda_export.py +327 -0
  677. executorch/backends/cuda/tests/test_cuda_partitioner.py +224 -0
  678. executorch/backends/cuda/triton/__init__.py +17 -0
  679. executorch/backends/cuda/triton/kernels/__init__.py +11 -0
  680. executorch/backends/cuda/triton/kernels/sdpa.py +827 -0
  681. executorch/backends/cuda/triton/replacement_pass.py +130 -0
  682. executorch/backends/example/example_backend.py +41 -0
  683. executorch/backends/example/example_backend_delegate_passes/merge_to_dim_pass.py +83 -0
  684. executorch/backends/example/example_backend_delegate_passes/permute_memory_formats_pass.py +143 -0
  685. executorch/backends/example/example_operators/adaptive_avg_pool2d.py +47 -0
  686. executorch/backends/example/example_operators/add.py +44 -0
  687. executorch/backends/example/example_operators/conv2d.py +52 -0
  688. executorch/backends/example/example_operators/conv_relu.py +49 -0
  689. executorch/backends/example/example_operators/dropout.py +44 -0
  690. executorch/backends/example/example_operators/flatten.py +40 -0
  691. executorch/backends/example/example_operators/linear.py +62 -0
  692. executorch/backends/example/example_operators/op_base.py +15 -0
  693. executorch/backends/example/example_operators/ops.py +32 -0
  694. executorch/backends/example/example_operators/utils.py +34 -0
  695. executorch/backends/example/example_partitioner.py +88 -0
  696. executorch/backends/example/example_quantizer.py +108 -0
  697. executorch/backends/example/test_example_delegate.py +112 -0
  698. executorch/backends/mediatek/__init__.py +5 -0
  699. executorch/backends/mediatek/_passes/__init__.py +0 -0
  700. executorch/backends/mediatek/_passes/decompose_scaled_dot_product_attention.py +79 -0
  701. executorch/backends/mediatek/partitioner.py +107 -0
  702. executorch/backends/mediatek/preprocess.py +214 -0
  703. executorch/backends/mediatek/quantizer/__init__.py +4 -0
  704. executorch/backends/mediatek/quantizer/annotator.py +263 -0
  705. executorch/backends/mediatek/quantizer/qconfig.py +174 -0
  706. executorch/backends/mediatek/quantizer/quantizer.py +45 -0
  707. executorch/backends/nxp/_passes/remove_getitem_pass.py +105 -0
  708. executorch/backends/nxp/aten_passes/convert_unsqueeze_to_view.py +79 -0
  709. executorch/backends/nxp/aten_passes/decompose_split_to_slices_pass.py +193 -0
  710. executorch/backends/nxp/aten_passes/fuse_batch_norm_with_conv_pass.py +146 -0
  711. executorch/backends/nxp/aten_passes/fuse_batch_norm_with_linear_pass.py +150 -0
  712. executorch/backends/nxp/aten_passes/fuse_linear_and_add_pass.py +204 -0
  713. executorch/backends/nxp/aten_passes/move_activation_before_concat.py +102 -0
  714. executorch/backends/nxp/aten_passes/neutron_aten_pass_manager.py +80 -0
  715. executorch/backends/nxp/aten_passes/remove_nodes_with_known_outputs.py +196 -0
  716. executorch/backends/nxp/aten_passes/split_group_convolution.py +281 -0
  717. executorch/backends/nxp/aten_passes/split_gru_based_on_num_layers.py +307 -0
  718. executorch/backends/nxp/backend/custom_delegation_options.py +19 -0
  719. executorch/backends/nxp/backend/edge_helper.py +222 -0
  720. executorch/backends/nxp/backend/edge_program_converter.py +247 -0
  721. executorch/backends/nxp/backend/ir/conversion_config.py +54 -0
  722. executorch/backends/nxp/backend/ir/conversion_context.py +38 -0
  723. executorch/backends/nxp/backend/ir/converter/__init__.py +0 -0
  724. executorch/backends/nxp/backend/ir/converter/builder/__init__.py +0 -0
  725. executorch/backends/nxp/backend/ir/converter/builder/aten_model_builder_director.py +142 -0
  726. executorch/backends/nxp/backend/ir/converter/builder/model_builder.py +1720 -0
  727. executorch/backends/nxp/backend/ir/converter/builder/quantization_verification.py +377 -0
  728. executorch/backends/nxp/backend/ir/converter/conversion/__init__.py +0 -0
  729. executorch/backends/nxp/backend/ir/converter/conversion/aten_translator.py +71 -0
  730. executorch/backends/nxp/backend/ir/converter/conversion/common.py +207 -0
  731. executorch/backends/nxp/backend/ir/converter/conversion/translator.py +689 -0
  732. executorch/backends/nxp/backend/ir/converter/node_converter.py +234 -0
  733. executorch/backends/nxp/backend/ir/converter/node_converters/__init__.py +4 -0
  734. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/__init__.py +101 -0
  735. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/abs_converter.py +35 -0
  736. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/adaptive_avg_pool_2d_converter.py +68 -0
  737. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/add_tensor_converter.py +57 -0
  738. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/addmm_converter.py +62 -0
  739. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/avg_pool_2d_converter.py +101 -0
  740. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/cat_converter.py +209 -0
  741. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/clone_converter.py +118 -0
  742. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/constant_pad_nd_converter.py +160 -0
  743. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/convolution_converter.py +535 -0
  744. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/hardtanh_converter.py +47 -0
  745. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/max_pool_2d_converter.py +104 -0
  746. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mean_dim_converter.py +112 -0
  747. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mm_converter.py +59 -0
  748. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/mul_tensor_converter.py +61 -0
  749. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/permute_copy_converter.py +468 -0
  750. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/qdq_dequantize_converter.py +116 -0
  751. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/qdq_quantize_converter.py +46 -0
  752. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/relu_converter.py +33 -0
  753. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sigmoid_converter.py +35 -0
  754. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/slice_tensor_converter.py +158 -0
  755. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/softmax_converter.py +62 -0
  756. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/sub_tensor_converter.py +59 -0
  757. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/tanh_converter.py +33 -0
  758. executorch/backends/nxp/backend/ir/converter/node_converters/ops_converters/view_copy_converter.py +220 -0
  759. executorch/backends/nxp/backend/ir/converter/node_converters/shared/__init__.py +0 -0
  760. executorch/backends/nxp/backend/ir/converter/node_converters/shared/conv_utils.py +105 -0
  761. executorch/backends/nxp/backend/ir/converter/node_converters/shared/recurrent_utils.py +64 -0
  762. executorch/backends/nxp/backend/ir/converter/node_converters/shared/reduce_utils.py +97 -0
  763. executorch/backends/nxp/backend/ir/converter/node_converters/shared/reshape_transposition.py +233 -0
  764. executorch/backends/nxp/backend/ir/converter/quantization_utils.py +149 -0
  765. executorch/backends/nxp/backend/ir/converter/tensor_utils.py +50 -0
  766. executorch/backends/nxp/backend/ir/lib/__init__.py +0 -0
  767. executorch/backends/nxp/backend/ir/lib/tflite/ATan2Options.py +50 -0
  768. executorch/backends/nxp/backend/ir/lib/tflite/AbsOptions.py +50 -0
  769. executorch/backends/nxp/backend/ir/lib/tflite/ActivationFunctionType.py +12 -0
  770. executorch/backends/nxp/backend/ir/lib/tflite/AddNOptions.py +50 -0
  771. executorch/backends/nxp/backend/ir/lib/tflite/AddOptions.py +82 -0
  772. executorch/backends/nxp/backend/ir/lib/tflite/ArgMaxOptions.py +65 -0
  773. executorch/backends/nxp/backend/ir/lib/tflite/ArgMinOptions.py +65 -0
  774. executorch/backends/nxp/backend/ir/lib/tflite/AssignVariableOptions.py +50 -0
  775. executorch/backends/nxp/backend/ir/lib/tflite/BatchMatMulOptions.py +101 -0
  776. executorch/backends/nxp/backend/ir/lib/tflite/BatchToSpaceNDOptions.py +50 -0
  777. executorch/backends/nxp/backend/ir/lib/tflite/BidirectionalSequenceLSTMOptions.py +160 -0
  778. executorch/backends/nxp/backend/ir/lib/tflite/BidirectionalSequenceRNNOptions.py +126 -0
  779. executorch/backends/nxp/backend/ir/lib/tflite/BitcastOptions.py +50 -0
  780. executorch/backends/nxp/backend/ir/lib/tflite/BitwiseXorOptions.py +50 -0
  781. executorch/backends/nxp/backend/ir/lib/tflite/BroadcastToOptions.py +50 -0
  782. executorch/backends/nxp/backend/ir/lib/tflite/BucketizeOptions.py +98 -0
  783. executorch/backends/nxp/backend/ir/lib/tflite/Buffer.py +132 -0
  784. executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOperator.py +212 -0
  785. executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOptions.py +133 -0
  786. executorch/backends/nxp/backend/ir/lib/tflite/BuiltinOptions2.py +27 -0
  787. executorch/backends/nxp/backend/ir/lib/tflite/CallOnceOptions.py +65 -0
  788. executorch/backends/nxp/backend/ir/lib/tflite/CallOptions.py +67 -0
  789. executorch/backends/nxp/backend/ir/lib/tflite/CastOptions.py +80 -0
  790. executorch/backends/nxp/backend/ir/lib/tflite/CombinerType.py +9 -0
  791. executorch/backends/nxp/backend/ir/lib/tflite/ConcatEmbeddingsOptions.py +163 -0
  792. executorch/backends/nxp/backend/ir/lib/tflite/ConcatenationOptions.py +80 -0
  793. executorch/backends/nxp/backend/ir/lib/tflite/Conv2DOptions.py +155 -0
  794. executorch/backends/nxp/backend/ir/lib/tflite/Conv3DOptions.py +170 -0
  795. executorch/backends/nxp/backend/ir/lib/tflite/CosOptions.py +50 -0
  796. executorch/backends/nxp/backend/ir/lib/tflite/CumsumOptions.py +84 -0
  797. executorch/backends/nxp/backend/ir/lib/tflite/CustomOptionsFormat.py +7 -0
  798. executorch/backends/nxp/backend/ir/lib/tflite/CustomQuantization.py +98 -0
  799. executorch/backends/nxp/backend/ir/lib/tflite/DensifyOptions.py +50 -0
  800. executorch/backends/nxp/backend/ir/lib/tflite/DepthToSpaceOptions.py +65 -0
  801. executorch/backends/nxp/backend/ir/lib/tflite/DepthwiseConv2DOptions.py +157 -0
  802. executorch/backends/nxp/backend/ir/lib/tflite/DequantizeOptions.py +50 -0
  803. executorch/backends/nxp/backend/ir/lib/tflite/DilateOptions.py +50 -0
  804. executorch/backends/nxp/backend/ir/lib/tflite/DimensionMetadata.py +152 -0
  805. executorch/backends/nxp/backend/ir/lib/tflite/DimensionType.py +8 -0
  806. executorch/backends/nxp/backend/ir/lib/tflite/DivOptions.py +65 -0
  807. executorch/backends/nxp/backend/ir/lib/tflite/DynamicUpdateSliceOptions.py +52 -0
  808. executorch/backends/nxp/backend/ir/lib/tflite/EmbeddingLookupSparseOptions.py +67 -0
  809. executorch/backends/nxp/backend/ir/lib/tflite/EqualOptions.py +50 -0
  810. executorch/backends/nxp/backend/ir/lib/tflite/ExpOptions.py +50 -0
  811. executorch/backends/nxp/backend/ir/lib/tflite/ExpandDimsOptions.py +50 -0
  812. executorch/backends/nxp/backend/ir/lib/tflite/FakeQuantOptions.py +116 -0
  813. executorch/backends/nxp/backend/ir/lib/tflite/FillOptions.py +50 -0
  814. executorch/backends/nxp/backend/ir/lib/tflite/FloorDivOptions.py +50 -0
  815. executorch/backends/nxp/backend/ir/lib/tflite/FloorModOptions.py +50 -0
  816. executorch/backends/nxp/backend/ir/lib/tflite/FullyConnectedOptions.py +129 -0
  817. executorch/backends/nxp/backend/ir/lib/tflite/FullyConnectedOptionsWeightsFormat.py +8 -0
  818. executorch/backends/nxp/backend/ir/lib/tflite/GatherNdOptions.py +50 -0
  819. executorch/backends/nxp/backend/ir/lib/tflite/GatherOptions.py +80 -0
  820. executorch/backends/nxp/backend/ir/lib/tflite/GeluOptions.py +67 -0
  821. executorch/backends/nxp/backend/ir/lib/tflite/GreaterEqualOptions.py +50 -0
  822. executorch/backends/nxp/backend/ir/lib/tflite/GreaterOptions.py +50 -0
  823. executorch/backends/nxp/backend/ir/lib/tflite/HardSwishOptions.py +50 -0
  824. executorch/backends/nxp/backend/ir/lib/tflite/HashtableFindOptions.py +50 -0
  825. executorch/backends/nxp/backend/ir/lib/tflite/HashtableImportOptions.py +52 -0
  826. executorch/backends/nxp/backend/ir/lib/tflite/HashtableOptions.py +95 -0
  827. executorch/backends/nxp/backend/ir/lib/tflite/HashtableSizeOptions.py +50 -0
  828. executorch/backends/nxp/backend/ir/lib/tflite/IfOptions.py +80 -0
  829. executorch/backends/nxp/backend/ir/lib/tflite/Int32Vector.py +98 -0
  830. executorch/backends/nxp/backend/ir/lib/tflite/L2NormOptions.py +65 -0
  831. executorch/backends/nxp/backend/ir/lib/tflite/LSHProjectionOptions.py +65 -0
  832. executorch/backends/nxp/backend/ir/lib/tflite/LSHProjectionType.py +9 -0
  833. executorch/backends/nxp/backend/ir/lib/tflite/LSTMKernelType.py +8 -0
  834. executorch/backends/nxp/backend/ir/lib/tflite/LSTMOptions.py +131 -0
  835. executorch/backends/nxp/backend/ir/lib/tflite/LeakyReluOptions.py +67 -0
  836. executorch/backends/nxp/backend/ir/lib/tflite/LessEqualOptions.py +50 -0
  837. executorch/backends/nxp/backend/ir/lib/tflite/LessOptions.py +50 -0
  838. executorch/backends/nxp/backend/ir/lib/tflite/LocalResponseNormalizationOptions.py +118 -0
  839. executorch/backends/nxp/backend/ir/lib/tflite/LogSoftmaxOptions.py +50 -0
  840. executorch/backends/nxp/backend/ir/lib/tflite/LogicalAndOptions.py +50 -0
  841. executorch/backends/nxp/backend/ir/lib/tflite/LogicalNotOptions.py +50 -0
  842. executorch/backends/nxp/backend/ir/lib/tflite/LogicalOrOptions.py +50 -0
  843. executorch/backends/nxp/backend/ir/lib/tflite/MatrixDiagOptions.py +50 -0
  844. executorch/backends/nxp/backend/ir/lib/tflite/MatrixSetDiagOptions.py +50 -0
  845. executorch/backends/nxp/backend/ir/lib/tflite/MaximumMinimumOptions.py +50 -0
  846. executorch/backends/nxp/backend/ir/lib/tflite/Metadata.py +84 -0
  847. executorch/backends/nxp/backend/ir/lib/tflite/MirrorPadMode.py +8 -0
  848. executorch/backends/nxp/backend/ir/lib/tflite/MirrorPadOptions.py +65 -0
  849. executorch/backends/nxp/backend/ir/lib/tflite/Model.py +352 -0
  850. executorch/backends/nxp/backend/ir/lib/tflite/MulOptions.py +65 -0
  851. executorch/backends/nxp/backend/ir/lib/tflite/NegOptions.py +50 -0
  852. executorch/backends/nxp/backend/ir/lib/tflite/NonMaxSuppressionV4Options.py +52 -0
  853. executorch/backends/nxp/backend/ir/lib/tflite/NonMaxSuppressionV5Options.py +52 -0
  854. executorch/backends/nxp/backend/ir/lib/tflite/NotEqualOptions.py +50 -0
  855. executorch/backends/nxp/backend/ir/lib/tflite/OneHotOptions.py +65 -0
  856. executorch/backends/nxp/backend/ir/lib/tflite/Operator.py +428 -0
  857. executorch/backends/nxp/backend/ir/lib/tflite/OperatorCode.py +112 -0
  858. executorch/backends/nxp/backend/ir/lib/tflite/PackOptions.py +80 -0
  859. executorch/backends/nxp/backend/ir/lib/tflite/PadOptions.py +50 -0
  860. executorch/backends/nxp/backend/ir/lib/tflite/PadV2Options.py +50 -0
  861. executorch/backends/nxp/backend/ir/lib/tflite/Padding.py +8 -0
  862. executorch/backends/nxp/backend/ir/lib/tflite/Pool2DOptions.py +140 -0
  863. executorch/backends/nxp/backend/ir/lib/tflite/PowOptions.py +50 -0
  864. executorch/backends/nxp/backend/ir/lib/tflite/QuantizationDetails.py +8 -0
  865. executorch/backends/nxp/backend/ir/lib/tflite/QuantizationParameters.py +295 -0
  866. executorch/backends/nxp/backend/ir/lib/tflite/QuantizeOptions.py +50 -0
  867. executorch/backends/nxp/backend/ir/lib/tflite/RNNOptions.py +82 -0
  868. executorch/backends/nxp/backend/ir/lib/tflite/RandomOptions.py +80 -0
  869. executorch/backends/nxp/backend/ir/lib/tflite/RangeOptions.py +50 -0
  870. executorch/backends/nxp/backend/ir/lib/tflite/RankOptions.py +50 -0
  871. executorch/backends/nxp/backend/ir/lib/tflite/ReadVariableOptions.py +50 -0
  872. executorch/backends/nxp/backend/ir/lib/tflite/ReduceWindowFunction.py +13 -0
  873. executorch/backends/nxp/backend/ir/lib/tflite/ReduceWindowOptions.py +65 -0
  874. executorch/backends/nxp/backend/ir/lib/tflite/ReducerOptions.py +67 -0
  875. executorch/backends/nxp/backend/ir/lib/tflite/ReshapeOptions.py +98 -0
  876. executorch/backends/nxp/backend/ir/lib/tflite/ResizeBilinearOptions.py +84 -0
  877. executorch/backends/nxp/backend/ir/lib/tflite/ResizeNearestNeighborOptions.py +86 -0
  878. executorch/backends/nxp/backend/ir/lib/tflite/ReverseSequenceOptions.py +82 -0
  879. executorch/backends/nxp/backend/ir/lib/tflite/ReverseV2Options.py +50 -0
  880. executorch/backends/nxp/backend/ir/lib/tflite/Rfft2dOptions.py +50 -0
  881. executorch/backends/nxp/backend/ir/lib/tflite/RightShiftOptions.py +50 -0
  882. executorch/backends/nxp/backend/ir/lib/tflite/RngAlgorithm.py +9 -0
  883. executorch/backends/nxp/backend/ir/lib/tflite/SVDFOptions.py +97 -0
  884. executorch/backends/nxp/backend/ir/lib/tflite/ScatterNdOptions.py +50 -0
  885. executorch/backends/nxp/backend/ir/lib/tflite/SegmentSumOptions.py +50 -0
  886. executorch/backends/nxp/backend/ir/lib/tflite/SelectOptions.py +50 -0
  887. executorch/backends/nxp/backend/ir/lib/tflite/SelectV2Options.py +50 -0
  888. executorch/backends/nxp/backend/ir/lib/tflite/SequenceRNNOptions.py +99 -0
  889. executorch/backends/nxp/backend/ir/lib/tflite/ShapeOptions.py +65 -0
  890. executorch/backends/nxp/backend/ir/lib/tflite/SignOptions.py +50 -0
  891. executorch/backends/nxp/backend/ir/lib/tflite/SignatureDef.py +172 -0
  892. executorch/backends/nxp/backend/ir/lib/tflite/SkipGramOptions.py +97 -0
  893. executorch/backends/nxp/backend/ir/lib/tflite/SliceOptions.py +50 -0
  894. executorch/backends/nxp/backend/ir/lib/tflite/SoftmaxOptions.py +67 -0
  895. executorch/backends/nxp/backend/ir/lib/tflite/SpaceToBatchNDOptions.py +50 -0
  896. executorch/backends/nxp/backend/ir/lib/tflite/SpaceToDepthOptions.py +65 -0
  897. executorch/backends/nxp/backend/ir/lib/tflite/SparseIndexVector.py +10 -0
  898. executorch/backends/nxp/backend/ir/lib/tflite/SparseToDenseOptions.py +67 -0
  899. executorch/backends/nxp/backend/ir/lib/tflite/SparsityParameters.py +190 -0
  900. executorch/backends/nxp/backend/ir/lib/tflite/SplitOptions.py +65 -0
  901. executorch/backends/nxp/backend/ir/lib/tflite/SplitVOptions.py +65 -0
  902. executorch/backends/nxp/backend/ir/lib/tflite/SquareOptions.py +50 -0
  903. executorch/backends/nxp/backend/ir/lib/tflite/SquaredDifferenceOptions.py +52 -0
  904. executorch/backends/nxp/backend/ir/lib/tflite/SqueezeOptions.py +98 -0
  905. executorch/backends/nxp/backend/ir/lib/tflite/StablehloBroadcastInDimOptions.py +102 -0
  906. executorch/backends/nxp/backend/ir/lib/tflite/StablehloCompareOptions.py +86 -0
  907. executorch/backends/nxp/backend/ir/lib/tflite/StablehloComparisonDirection.py +12 -0
  908. executorch/backends/nxp/backend/ir/lib/tflite/StablehloComparisonType.py +11 -0
  909. executorch/backends/nxp/backend/ir/lib/tflite/StablehloConcatenateOptions.py +67 -0
  910. executorch/backends/nxp/backend/ir/lib/tflite/StablehloConvolutionOptions.py +634 -0
  911. executorch/backends/nxp/backend/ir/lib/tflite/StablehloCustomCallOptions.py +214 -0
  912. executorch/backends/nxp/backend/ir/lib/tflite/StablehloDotGeneralOptions.py +304 -0
  913. executorch/backends/nxp/backend/ir/lib/tflite/StablehloDynamicSliceOptions.py +100 -0
  914. executorch/backends/nxp/backend/ir/lib/tflite/StablehloGatherOptions.py +276 -0
  915. executorch/backends/nxp/backend/ir/lib/tflite/StablehloIotaOptions.py +65 -0
  916. executorch/backends/nxp/backend/ir/lib/tflite/StablehloPadOptions.py +194 -0
  917. executorch/backends/nxp/backend/ir/lib/tflite/StablehloPrecisionConfig.py +9 -0
  918. executorch/backends/nxp/backend/ir/lib/tflite/StablehloReduceOptions.py +115 -0
  919. executorch/backends/nxp/backend/ir/lib/tflite/StablehloReduceWindowOptions.py +307 -0
  920. executorch/backends/nxp/backend/ir/lib/tflite/StablehloRngBitGeneratorOptions.py +67 -0
  921. executorch/backends/nxp/backend/ir/lib/tflite/StablehloScatterOptions.py +268 -0
  922. executorch/backends/nxp/backend/ir/lib/tflite/StablehloSliceOptions.py +194 -0
  923. executorch/backends/nxp/backend/ir/lib/tflite/StablehloSortOptions.py +97 -0
  924. executorch/backends/nxp/backend/ir/lib/tflite/StablehloTransposeOptions.py +100 -0
  925. executorch/backends/nxp/backend/ir/lib/tflite/StablehloWhileOptions.py +80 -0
  926. executorch/backends/nxp/backend/ir/lib/tflite/StridedSliceOptions.py +142 -0
  927. executorch/backends/nxp/backend/ir/lib/tflite/SubGraph.py +251 -0
  928. executorch/backends/nxp/backend/ir/lib/tflite/SubOptions.py +82 -0
  929. executorch/backends/nxp/backend/ir/lib/tflite/Tensor.py +317 -0
  930. executorch/backends/nxp/backend/ir/lib/tflite/TensorMap.py +84 -0
  931. executorch/backends/nxp/backend/ir/lib/tflite/TensorType.py +24 -0
  932. executorch/backends/nxp/backend/ir/lib/tflite/TileOptions.py +50 -0
  933. executorch/backends/nxp/backend/ir/lib/tflite/TopKV2Options.py +50 -0
  934. executorch/backends/nxp/backend/ir/lib/tflite/TransposeConvOptions.py +125 -0
  935. executorch/backends/nxp/backend/ir/lib/tflite/TransposeOptions.py +50 -0
  936. executorch/backends/nxp/backend/ir/lib/tflite/Uint16Vector.py +98 -0
  937. executorch/backends/nxp/backend/ir/lib/tflite/Uint8Vector.py +98 -0
  938. executorch/backends/nxp/backend/ir/lib/tflite/UnidirectionalSequenceLSTMOptions.py +164 -0
  939. executorch/backends/nxp/backend/ir/lib/tflite/UniqueOptions.py +65 -0
  940. executorch/backends/nxp/backend/ir/lib/tflite/UnpackOptions.py +80 -0
  941. executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentMaxOptions.py +52 -0
  942. executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentMinOptions.py +52 -0
  943. executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentProdOptions.py +52 -0
  944. executorch/backends/nxp/backend/ir/lib/tflite/UnsortedSegmentSumOptions.py +52 -0
  945. executorch/backends/nxp/backend/ir/lib/tflite/VarHandleOptions.py +84 -0
  946. executorch/backends/nxp/backend/ir/lib/tflite/VariantSubType.py +130 -0
  947. executorch/backends/nxp/backend/ir/lib/tflite/WhereOptions.py +50 -0
  948. executorch/backends/nxp/backend/ir/lib/tflite/WhileOptions.py +80 -0
  949. executorch/backends/nxp/backend/ir/lib/tflite/ZerosLikeOptions.py +50 -0
  950. executorch/backends/nxp/backend/ir/lib/tflite/__init__.py +0 -0
  951. executorch/backends/nxp/backend/ir/logger.py +341 -0
  952. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/__init__.py +0 -0
  953. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/graph_utils.py +115 -0
  954. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/operator_rules.py +102 -0
  955. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/__init__.py +0 -0
  956. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/base_optimization.py +41 -0
  957. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/permute_fully_connected_weights_after_reshape.py +121 -0
  958. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizations/prune_transpose_operators.py +174 -0
  959. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/optimizer.py +127 -0
  960. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/pattern_matcher.py +925 -0
  961. executorch/backends/nxp/backend/ir/neutron_ir_post_processing/tensor_rules.py +710 -0
  962. executorch/backends/nxp/backend/ir/tensor_formatting.py +69 -0
  963. executorch/backends/nxp/backend/ir/tflite_generator/__init__.py +0 -0
  964. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/__init__.py +0 -0
  965. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/abs_options.py +25 -0
  966. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/add_n_options.py +32 -0
  967. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/add_options.py +46 -0
  968. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/arg_max_options.py +28 -0
  969. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/arg_min_options.py +28 -0
  970. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/average_pool_2d_options.py +63 -0
  971. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/batch_mat_mul_options.py +45 -0
  972. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bidirectional_sequence_lstm_options.py +65 -0
  973. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bidirectional_sequence_rnn_options.py +53 -0
  974. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/bitwise_xor_options.py +23 -0
  975. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/broadcast_to_options.py +25 -0
  976. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/cast_options.py +32 -0
  977. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/concatenation_options.py +38 -0
  978. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/conv_2d_options.py +59 -0
  979. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/conv_3d_options.py +67 -0
  980. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/cum_sum_options.py +30 -0
  981. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/depth_to_space_options.py +29 -0
  982. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/depthwise_conv_2d_options.py +69 -0
  983. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/dequantize_options.py +24 -0
  984. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/div_options.py +43 -0
  985. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/equal_options.py +23 -0
  986. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/exp_options.py +23 -0
  987. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/floor_mod_options.py +23 -0
  988. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/fully_connected_options.py +57 -0
  989. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gather_nd_options.py +23 -0
  990. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gather_options.py +30 -0
  991. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/gelu_options.py +27 -0
  992. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/greater_equal_options.py +25 -0
  993. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/greater_options.py +23 -0
  994. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/hard_swish_options.py +23 -0
  995. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/leaky_relu_options.py +32 -0
  996. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/less_equal_options.py +23 -0
  997. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/less_options.py +23 -0
  998. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/log_softmax_options.py +30 -0
  999. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_and_options.py +23 -0
  1000. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_not_options.py +23 -0
  1001. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/logical_or_options.py +23 -0
  1002. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/lrn_options.py +45 -0
  1003. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/lstm_options.py +60 -0
  1004. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/max_pool_2d_options.py +63 -0
  1005. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/maximum_options.py +21 -0
  1006. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mean_options.py +28 -0
  1007. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/minimum_options.py +21 -0
  1008. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mirror_pad_options.py +60 -0
  1009. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/mul_options.py +36 -0
  1010. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/multinomial_options.py +30 -0
  1011. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/neg_options.py +23 -0
  1012. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/not_equal_options.py +23 -0
  1013. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/one_hot_options.py +27 -0
  1014. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pad_options.py +27 -0
  1015. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pad_v2_options.py +27 -0
  1016. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/pow_options.py +24 -0
  1017. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/quantize_options.py +30 -0
  1018. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/range_options.py +23 -0
  1019. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_max_options.py +28 -0
  1020. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_min_options.py +28 -0
  1021. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reduce_prod_options.py +28 -0
  1022. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reshape_options.py +53 -0
  1023. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/resize_bilinear_options.py +34 -0
  1024. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/resize_nearest_neighbor_options.py +37 -0
  1025. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/reverse_sequence_options.py +32 -0
  1026. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/scatter_nd_options.py +23 -0
  1027. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/select_v2_options.py +24 -0
  1028. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/shape_options.py +34 -0
  1029. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sign_options.py +22 -0
  1030. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/slice_options.py +29 -0
  1031. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/softmax_options.py +36 -0
  1032. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/space_to_depth_options.py +29 -0
  1033. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/split_options.py +27 -0
  1034. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/split_v_options.py +27 -0
  1035. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/square_options.py +23 -0
  1036. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/squared_difference_options.py +25 -0
  1037. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/squeeze_options.py +42 -0
  1038. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/strided_slice_options.py +35 -0
  1039. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sub_options.py +46 -0
  1040. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/sum_options.py +28 -0
  1041. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/tile_options.py +23 -0
  1042. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/transpose_conv_options.py +50 -0
  1043. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/transpose_options.py +30 -0
  1044. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/unidirectional_sequence_lstm_options.py +67 -0
  1045. executorch/backends/nxp/backend/ir/tflite_generator/builtin_options/unidirectional_sequence_rnn_options.py +49 -0
  1046. executorch/backends/nxp/backend/ir/tflite_generator/custom_options/flex_transpose_options.py +78 -0
  1047. executorch/backends/nxp/backend/ir/tflite_generator/meta/__init__.py +0 -0
  1048. executorch/backends/nxp/backend/ir/tflite_generator/meta/meta.py +255 -0
  1049. executorch/backends/nxp/backend/ir/tflite_generator/meta/types.py +198 -0
  1050. executorch/backends/nxp/backend/ir/tflite_generator/tflite_model.py +814 -0
  1051. executorch/backends/nxp/backend/neutron_converter_manager.py +117 -0
  1052. executorch/backends/nxp/backend/neutron_operator_support.py +79 -0
  1053. executorch/backends/nxp/backend/neutron_target_spec.py +143 -0
  1054. executorch/backends/nxp/backend/node_format.py +26 -0
  1055. executorch/backends/nxp/backend/node_format_inference.py +294 -0
  1056. executorch/backends/nxp/edge_passes/move_auxiliary_operator_into_separate_qdq_cluster_pass.py +254 -0
  1057. executorch/backends/nxp/edge_passes/neutron_edge_pass.py +55 -0
  1058. executorch/backends/nxp/edge_passes/neutron_edge_pass_manager.py +29 -0
  1059. executorch/backends/nxp/edge_passes/remove_additional_quantize_dequantize_nodes_pass.py +111 -0
  1060. executorch/backends/nxp/edge_passes/remove_as_strided_copy_nodes.py +66 -0
  1061. executorch/backends/nxp/edge_passes/remove_io_quant_ops_pass.py +79 -0
  1062. executorch/backends/nxp/neutron_node_extraction.py +152 -0
  1063. executorch/backends/nxp/neutron_partitioner.py +421 -0
  1064. executorch/backends/nxp/neutron_pass_manager.py +50 -0
  1065. executorch/backends/nxp/nxp_backend.py +391 -0
  1066. executorch/backends/nxp/quantizer/neutron_quantizer.py +353 -0
  1067. executorch/backends/nxp/quantizer/patterns.py +1089 -0
  1068. executorch/backends/nxp/quantizer/utils.py +195 -0
  1069. executorch/backends/nxp/tests/executorch_pipeline.py +184 -0
  1070. executorch/backends/nxp/tests/executors.py +401 -0
  1071. executorch/backends/nxp/tests/ir/__init__.py +0 -0
  1072. executorch/backends/nxp/tests/ir/converter/__init__.py +0 -0
  1073. executorch/backends/nxp/tests/ir/converter/node_converter/__init__.py +0 -0
  1074. executorch/backends/nxp/tests/ir/converter/node_converter/test_abs_converter.py +91 -0
  1075. executorch/backends/nxp/tests/ir/converter/node_converter/test_adaptive_avg_pool2d_converter.py +148 -0
  1076. executorch/backends/nxp/tests/ir/converter/node_converter/test_add_tensor_converter.py +161 -0
  1077. executorch/backends/nxp/tests/ir/converter/node_converter/test_addmm_converter.py +96 -0
  1078. executorch/backends/nxp/tests/ir/converter/node_converter/test_avg_pool2d_converter.py +221 -0
  1079. executorch/backends/nxp/tests/ir/converter/node_converter/test_cat_converter.py +495 -0
  1080. executorch/backends/nxp/tests/ir/converter/node_converter/test_clone_converter.py +344 -0
  1081. executorch/backends/nxp/tests/ir/converter/node_converter/test_constant_pad_nd_converter.py +188 -0
  1082. executorch/backends/nxp/tests/ir/converter/node_converter/test_conv_converter.py +680 -0
  1083. executorch/backends/nxp/tests/ir/converter/node_converter/test_hardtanh_converter.py +107 -0
  1084. executorch/backends/nxp/tests/ir/converter/node_converter/test_max_pool_2d_converter.py +132 -0
  1085. executorch/backends/nxp/tests/ir/converter/node_converter/test_mean_dim_converter.py +280 -0
  1086. executorch/backends/nxp/tests/ir/converter/node_converter/test_mm_converter.py +96 -0
  1087. executorch/backends/nxp/tests/ir/converter/node_converter/test_mul_tensor_converter.py +212 -0
  1088. executorch/backends/nxp/tests/ir/converter/node_converter/test_permute_copy_converter.py +426 -0
  1089. executorch/backends/nxp/tests/ir/converter/node_converter/test_relu_converter.py +114 -0
  1090. executorch/backends/nxp/tests/ir/converter/node_converter/test_sigmoid_converter.py +78 -0
  1091. executorch/backends/nxp/tests/ir/converter/node_converter/test_slice_tensor_converter.py +244 -0
  1092. executorch/backends/nxp/tests/ir/converter/node_converter/test_softmax_converter.py +115 -0
  1093. executorch/backends/nxp/tests/ir/converter/node_converter/test_sub_tensor_converter.py +181 -0
  1094. executorch/backends/nxp/tests/ir/converter/node_converter/test_tanh_converter.py +90 -0
  1095. executorch/backends/nxp/tests/ir/converter/node_converter/test_view_copy_converter.py +509 -0
  1096. executorch/backends/nxp/tests/ir/edge_passes/__init__.py +0 -0
  1097. executorch/backends/nxp/tests/ir/edge_passes/test_remove_io_quant_ops_pass.py +127 -0
  1098. executorch/backends/nxp/tests/models.py +737 -0
  1099. executorch/backends/nxp/tests/test_batch_norm_fusion.py +233 -0
  1100. executorch/backends/nxp/tests/test_context_sensitive_delegation.py +71 -0
  1101. executorch/backends/nxp/tests/test_convert_unsqueeze_to_view.py +143 -0
  1102. executorch/backends/nxp/tests/test_decompose_split_to_slices.py +315 -0
  1103. executorch/backends/nxp/tests/test_edge_passes.py +382 -0
  1104. executorch/backends/nxp/tests/test_gru_splitting.py +267 -0
  1105. executorch/backends/nxp/tests/test_integration.py +53 -0
  1106. executorch/backends/nxp/tests/test_linear_and_add_fusion.py +653 -0
  1107. executorch/backends/nxp/tests/test_move_activation_before_concatenation.py +905 -0
  1108. executorch/backends/nxp/tests/test_neutron_backend.py +63 -0
  1109. executorch/backends/nxp/tests/test_neutron_backend_executor.py +327 -0
  1110. executorch/backends/nxp/tests/test_neutron_converter_manager.py +59 -0
  1111. executorch/backends/nxp/tests/test_node_format_inference.py +91 -0
  1112. executorch/backends/nxp/tests/test_operator_selector.py +24 -0
  1113. executorch/backends/nxp/tests/test_per_channel_conversion.py +182 -0
  1114. executorch/backends/nxp/tests/test_qdq_clustering_conv.py +31 -0
  1115. executorch/backends/nxp/tests/test_quantizer.py +703 -0
  1116. executorch/backends/nxp/tests/test_removing_dead_code.py +65 -0
  1117. executorch/backends/nxp/tests/test_removing_nodes_with_known_outputs.py +116 -0
  1118. executorch/backends/nxp/tests/test_split_group_convolution.py +291 -0
  1119. executorch/backends/nxp/tests/use_qat.py +11 -0
  1120. executorch/backends/openvino/__init__.py +5 -0
  1121. executorch/backends/openvino/partitioner.py +238 -0
  1122. executorch/backends/openvino/preprocess.py +62 -0
  1123. executorch/backends/openvino/quantizer/__init__.py +3 -0
  1124. executorch/backends/openvino/quantizer/observers.py +186 -0
  1125. executorch/backends/openvino/quantizer/quantizer.py +595 -0
  1126. executorch/backends/openvino/tests/models/test_classification.py +38 -0
  1127. executorch/backends/openvino/tests/ops/base_openvino_op_test.py +86 -0
  1128. executorch/backends/openvino/tests/ops/test_add.py +22 -0
  1129. executorch/backends/openvino/tests/ops/test_addmm.py +28 -0
  1130. executorch/backends/openvino/tests/ops/test_arange.py +23 -0
  1131. executorch/backends/openvino/tests/ops/test_batch_norm.py +61 -0
  1132. executorch/backends/openvino/tests/ops/test_convolution.py +296 -0
  1133. executorch/backends/openvino/tests/ops/test_mean.py +90 -0
  1134. executorch/backends/openvino/tests/ops/test_permute.py +33 -0
  1135. executorch/backends/openvino/tests/ops/test_pooling.py +91 -0
  1136. executorch/backends/openvino/tests/ops/test_unary_ops.py +37 -0
  1137. executorch/backends/openvino/tests/ops/test_view.py +35 -0
  1138. executorch/backends/openvino/tests/test_runner.py +76 -0
  1139. executorch/backends/qualcomm/__init__.py +13 -0
  1140. executorch/backends/qualcomm/_passes/__init__.py +101 -0
  1141. executorch/backends/qualcomm/_passes/annotate_adaptive_avg_pool1d.py +43 -0
  1142. executorch/backends/qualcomm/_passes/annotate_quant_attrs.py +145 -0
  1143. executorch/backends/qualcomm/_passes/annotate_stack.py +44 -0
  1144. executorch/backends/qualcomm/_passes/annotate_unbind.py +42 -0
  1145. executorch/backends/qualcomm/_passes/build_quant_io.py +49 -0
  1146. executorch/backends/qualcomm/_passes/canonicalize_conv.py +204 -0
  1147. executorch/backends/qualcomm/_passes/convert_bmm_to_matmul.py +83 -0
  1148. executorch/backends/qualcomm/_passes/convert_linear_to_conv2d.py +232 -0
  1149. executorch/backends/qualcomm/_passes/convert_mha_to_sha.py +626 -0
  1150. executorch/backends/qualcomm/_passes/convert_square_to_pow.py +38 -0
  1151. executorch/backends/qualcomm/_passes/decompose_any.py +64 -0
  1152. executorch/backends/qualcomm/_passes/decompose_binary_alpha.py +61 -0
  1153. executorch/backends/qualcomm/_passes/decompose_cdist.py +69 -0
  1154. executorch/backends/qualcomm/_passes/decompose_col_im.py +121 -0
  1155. executorch/backends/qualcomm/_passes/decompose_einsum.py +51 -0
  1156. executorch/backends/qualcomm/_passes/decompose_expm1.py +46 -0
  1157. executorch/backends/qualcomm/_passes/decompose_floor_divide.py +62 -0
  1158. executorch/backends/qualcomm/_passes/decompose_glu.py +55 -0
  1159. executorch/backends/qualcomm/_passes/decompose_linalg_vector_norm.py +75 -0
  1160. executorch/backends/qualcomm/_passes/decompose_maxpool3d.py +133 -0
  1161. executorch/backends/qualcomm/_passes/decompose_minmaxdim.py +109 -0
  1162. executorch/backends/qualcomm/_passes/decompose_roll.py +78 -0
  1163. executorch/backends/qualcomm/_passes/decompose_silu.py +45 -0
  1164. executorch/backends/qualcomm/_passes/decompose_threshold.py +61 -0
  1165. executorch/backends/qualcomm/_passes/decompose_triu.py +71 -0
  1166. executorch/backends/qualcomm/_passes/decompose_wrap_with_autocast.py +79 -0
  1167. executorch/backends/qualcomm/_passes/expand_broadcast_tensor_shape.py +67 -0
  1168. executorch/backends/qualcomm/_passes/fixed_linear_keep_dim.py +95 -0
  1169. executorch/backends/qualcomm/_passes/fold_qdq.py +80 -0
  1170. executorch/backends/qualcomm/_passes/fuse_consecutive_cast.py +116 -0
  1171. executorch/backends/qualcomm/_passes/fuse_consecutive_transpose.py +109 -0
  1172. executorch/backends/qualcomm/_passes/i64_to_i32.py +184 -0
  1173. executorch/backends/qualcomm/_passes/insert_io_qdq.py +154 -0
  1174. executorch/backends/qualcomm/_passes/insert_requantize.py +111 -0
  1175. executorch/backends/qualcomm/_passes/insert_reshape_for_reduce_ops.py +59 -0
  1176. executorch/backends/qualcomm/_passes/layout_transform.py +355 -0
  1177. executorch/backends/qualcomm/_passes/lift_constant_scalar_operands.py +186 -0
  1178. executorch/backends/qualcomm/_passes/qnn_pass_manager.py +271 -0
  1179. executorch/backends/qualcomm/_passes/recompose_pad_maxpool2d.py +147 -0
  1180. executorch/backends/qualcomm/_passes/recompose_pixel_unshuffle.py +81 -0
  1181. executorch/backends/qualcomm/_passes/recompose_rms_norm.py +155 -0
  1182. executorch/backends/qualcomm/_passes/reduce_dynamic_range.py +60 -0
  1183. executorch/backends/qualcomm/_passes/remove_0d_tensor.py +36 -0
  1184. executorch/backends/qualcomm/_passes/remove_redundancy.py +73 -0
  1185. executorch/backends/qualcomm/_passes/replace_arange_args.py +48 -0
  1186. executorch/backends/qualcomm/_passes/replace_inf_values.py +60 -0
  1187. executorch/backends/qualcomm/_passes/seq_mse.py +224 -0
  1188. executorch/backends/qualcomm/_passes/tag_quant_io.py +45 -0
  1189. executorch/backends/qualcomm/_passes/utils.py +283 -0
  1190. executorch/backends/qualcomm/builders/__init__.py +221 -0
  1191. executorch/backends/qualcomm/builders/node_visitor.py +518 -0
  1192. executorch/backends/qualcomm/builders/node_visitor_manager.py +79 -0
  1193. executorch/backends/qualcomm/builders/op_abs.py +57 -0
  1194. executorch/backends/qualcomm/builders/op_adaptive_avg_pool2d.py +126 -0
  1195. executorch/backends/qualcomm/builders/op_adaptive_max_pool2d.py +151 -0
  1196. executorch/backends/qualcomm/builders/op_add.py +62 -0
  1197. executorch/backends/qualcomm/builders/op_amax.py +90 -0
  1198. executorch/backends/qualcomm/builders/op_amin.py +90 -0
  1199. executorch/backends/qualcomm/builders/op_and.py +60 -0
  1200. executorch/backends/qualcomm/builders/op_arange.py +41 -0
  1201. executorch/backends/qualcomm/builders/op_argmax.py +78 -0
  1202. executorch/backends/qualcomm/builders/op_argmin.py +78 -0
  1203. executorch/backends/qualcomm/builders/op_asin.py +56 -0
  1204. executorch/backends/qualcomm/builders/op_atan.py +55 -0
  1205. executorch/backends/qualcomm/builders/op_avg_pool2d.py +168 -0
  1206. executorch/backends/qualcomm/builders/op_avg_pool3d.py +299 -0
  1207. executorch/backends/qualcomm/builders/op_batch_norm.py +151 -0
  1208. executorch/backends/qualcomm/builders/op_binary.py +84 -0
  1209. executorch/backends/qualcomm/builders/op_bmm.py +59 -0
  1210. executorch/backends/qualcomm/builders/op_cat.py +89 -0
  1211. executorch/backends/qualcomm/builders/op_ceil.py +56 -0
  1212. executorch/backends/qualcomm/builders/op_clamp.py +80 -0
  1213. executorch/backends/qualcomm/builders/op_conv.py +263 -0
  1214. executorch/backends/qualcomm/builders/op_copy.py +112 -0
  1215. executorch/backends/qualcomm/builders/op_cos.py +56 -0
  1216. executorch/backends/qualcomm/builders/op_cum_sum.py +87 -0
  1217. executorch/backends/qualcomm/builders/op_custom_op.py +93 -0
  1218. executorch/backends/qualcomm/builders/op_depth_to_space.py +78 -0
  1219. executorch/backends/qualcomm/builders/op_dequantize.py +72 -0
  1220. executorch/backends/qualcomm/builders/op_div.py +62 -0
  1221. executorch/backends/qualcomm/builders/op_elu.py +68 -0
  1222. executorch/backends/qualcomm/builders/op_embedding.py +79 -0
  1223. executorch/backends/qualcomm/builders/op_eq.py +62 -0
  1224. executorch/backends/qualcomm/builders/op_exp.py +60 -0
  1225. executorch/backends/qualcomm/builders/op_expand.py +84 -0
  1226. executorch/backends/qualcomm/builders/op_flip.py +81 -0
  1227. executorch/backends/qualcomm/builders/op_floor.py +56 -0
  1228. executorch/backends/qualcomm/builders/op_full.py +41 -0
  1229. executorch/backends/qualcomm/builders/op_full_like.py +41 -0
  1230. executorch/backends/qualcomm/builders/op_gather.py +76 -0
  1231. executorch/backends/qualcomm/builders/op_ge.py +62 -0
  1232. executorch/backends/qualcomm/builders/op_gelu.py +57 -0
  1233. executorch/backends/qualcomm/builders/op_grid_sampler_2d.py +162 -0
  1234. executorch/backends/qualcomm/builders/op_group_norm.py +94 -0
  1235. executorch/backends/qualcomm/builders/op_gt.py +62 -0
  1236. executorch/backends/qualcomm/builders/op_hardsigmoid.py +78 -0
  1237. executorch/backends/qualcomm/builders/op_hardswish.py +57 -0
  1238. executorch/backends/qualcomm/builders/op_hardtanh.py +79 -0
  1239. executorch/backends/qualcomm/builders/op_index.py +85 -0
  1240. executorch/backends/qualcomm/builders/op_index_put.py +481 -0
  1241. executorch/backends/qualcomm/builders/op_index_select.py +81 -0
  1242. executorch/backends/qualcomm/builders/op_instance_norm.py +112 -0
  1243. executorch/backends/qualcomm/builders/op_layer_norm.py +113 -0
  1244. executorch/backends/qualcomm/builders/op_le.py +62 -0
  1245. executorch/backends/qualcomm/builders/op_linear.py +98 -0
  1246. executorch/backends/qualcomm/builders/op_log.py +58 -0
  1247. executorch/backends/qualcomm/builders/op_log_softmax.py +81 -0
  1248. executorch/backends/qualcomm/builders/op_logical_not.py +56 -0
  1249. executorch/backends/qualcomm/builders/op_lt.py +62 -0
  1250. executorch/backends/qualcomm/builders/op_matmul.py +59 -0
  1251. executorch/backends/qualcomm/builders/op_max.py +62 -0
  1252. executorch/backends/qualcomm/builders/op_max_dim.py +89 -0
  1253. executorch/backends/qualcomm/builders/op_max_pool2d.py +145 -0
  1254. executorch/backends/qualcomm/builders/op_mean_dim.py +100 -0
  1255. executorch/backends/qualcomm/builders/op_min.py +62 -0
  1256. executorch/backends/qualcomm/builders/op_min_dim.py +89 -0
  1257. executorch/backends/qualcomm/builders/op_mul.py +62 -0
  1258. executorch/backends/qualcomm/builders/op_ne.py +62 -0
  1259. executorch/backends/qualcomm/builders/op_neg.py +54 -0
  1260. executorch/backends/qualcomm/builders/op_or.py +60 -0
  1261. executorch/backends/qualcomm/builders/op_pad.py +97 -0
  1262. executorch/backends/qualcomm/builders/op_pow.py +75 -0
  1263. executorch/backends/qualcomm/builders/op_prelu.py +81 -0
  1264. executorch/backends/qualcomm/builders/op_quantize.py +73 -0
  1265. executorch/backends/qualcomm/builders/op_relu.py +58 -0
  1266. executorch/backends/qualcomm/builders/op_repeat.py +68 -0
  1267. executorch/backends/qualcomm/builders/op_reshape.py +55 -0
  1268. executorch/backends/qualcomm/builders/op_resize.py +85 -0
  1269. executorch/backends/qualcomm/builders/op_rms_norm.py +132 -0
  1270. executorch/backends/qualcomm/builders/op_round.py +58 -0
  1271. executorch/backends/qualcomm/builders/op_rsqrt.py +58 -0
  1272. executorch/backends/qualcomm/builders/op_scalar_tensor.py +51 -0
  1273. executorch/backends/qualcomm/builders/op_select_copy.py +89 -0
  1274. executorch/backends/qualcomm/builders/op_sigmoid.py +58 -0
  1275. executorch/backends/qualcomm/builders/op_sign.py +56 -0
  1276. executorch/backends/qualcomm/builders/op_sin.py +56 -0
  1277. executorch/backends/qualcomm/builders/op_skip_ops.py +55 -0
  1278. executorch/backends/qualcomm/builders/op_slice_copy.py +95 -0
  1279. executorch/backends/qualcomm/builders/op_slice_scatter.py +122 -0
  1280. executorch/backends/qualcomm/builders/op_softmax.py +79 -0
  1281. executorch/backends/qualcomm/builders/op_space_to_depth.py +78 -0
  1282. executorch/backends/qualcomm/builders/op_split_with_sizes.py +99 -0
  1283. executorch/backends/qualcomm/builders/op_sqrt.py +60 -0
  1284. executorch/backends/qualcomm/builders/op_squeeze.py +57 -0
  1285. executorch/backends/qualcomm/builders/op_stack.py +71 -0
  1286. executorch/backends/qualcomm/builders/op_sub.py +62 -0
  1287. executorch/backends/qualcomm/builders/op_sum_int_list.py +84 -0
  1288. executorch/backends/qualcomm/builders/op_tanh.py +57 -0
  1289. executorch/backends/qualcomm/builders/op_to.py +149 -0
  1290. executorch/backends/qualcomm/builders/op_topk.py +112 -0
  1291. executorch/backends/qualcomm/builders/op_transpose.py +76 -0
  1292. executorch/backends/qualcomm/builders/op_unbind.py +73 -0
  1293. executorch/backends/qualcomm/builders/op_unsqueeze.py +57 -0
  1294. executorch/backends/qualcomm/builders/op_upsample_bilinear2d.py +68 -0
  1295. executorch/backends/qualcomm/builders/op_upsample_nearest2d.py +68 -0
  1296. executorch/backends/qualcomm/builders/op_where.py +82 -0
  1297. executorch/backends/qualcomm/builders/op_xor.py +60 -0
  1298. executorch/backends/qualcomm/builders/qnn_constants.py +630 -0
  1299. executorch/backends/qualcomm/builders/utils.py +160 -0
  1300. executorch/backends/qualcomm/debugger/format_outputs.py +221 -0
  1301. executorch/backends/qualcomm/debugger/metrics_evaluator.py +90 -0
  1302. executorch/backends/qualcomm/debugger/qnn_intermediate_debugger.py +328 -0
  1303. executorch/backends/qualcomm/debugger/utils.py +435 -0
  1304. executorch/backends/qualcomm/partition/common_defs.py +44 -0
  1305. executorch/backends/qualcomm/partition/qnn_partitioner.py +225 -0
  1306. executorch/backends/qualcomm/partition/utils.py +75 -0
  1307. executorch/backends/qualcomm/qnn_preprocess.py +218 -0
  1308. executorch/backends/qualcomm/quantizer/annotators.py +1501 -0
  1309. executorch/backends/qualcomm/quantizer/custom_annotation.py +499 -0
  1310. executorch/backends/qualcomm/quantizer/observers/concat_observer.py +74 -0
  1311. executorch/backends/qualcomm/quantizer/observers/per_block_param_observer.py +145 -0
  1312. executorch/backends/qualcomm/quantizer/observers/per_channel_param_observer.py +113 -0
  1313. executorch/backends/qualcomm/quantizer/qconfig.py +802 -0
  1314. executorch/backends/qualcomm/quantizer/quant_recipe.py +402 -0
  1315. executorch/backends/qualcomm/quantizer/quantizer.py +507 -0
  1316. executorch/backends/qualcomm/recipes/__init__.py +16 -0
  1317. executorch/backends/qualcomm/recipes/qnn_recipe_provider.py +179 -0
  1318. executorch/backends/qualcomm/recipes/qnn_recipe_types.py +28 -0
  1319. executorch/backends/qualcomm/scripts/download_qnn_sdk.py +642 -0
  1320. executorch/backends/qualcomm/serialization/qc_compiler_spec.fbs +299 -0
  1321. executorch/backends/qualcomm/serialization/qc_schema.py +240 -0
  1322. executorch/backends/qualcomm/serialization/qc_schema_serialize.py +59 -0
  1323. executorch/backends/qualcomm/tests/models.py +2393 -0
  1324. executorch/backends/qualcomm/tests/test_passes.py +154 -0
  1325. executorch/backends/qualcomm/tests/test_qnn_delegate.py +8454 -0
  1326. executorch/backends/qualcomm/tests/tester.py +113 -0
  1327. executorch/backends/qualcomm/tests/utils.py +770 -0
  1328. executorch/backends/qualcomm/utils/constants.py +49 -0
  1329. executorch/backends/qualcomm/utils/qnn_manager_lifecycle.py +88 -0
  1330. executorch/backends/qualcomm/utils/utils.py +1302 -0
  1331. executorch/backends/samsung/_passes/annotate_qparams.py +201 -0
  1332. executorch/backends/samsung/_passes/annotate_scalar_parameters.py +65 -0
  1333. executorch/backends/samsung/_passes/conv1d_to_conv2d.py +97 -0
  1334. executorch/backends/samsung/_passes/customized_constant_prop.py +40 -0
  1335. executorch/backends/samsung/_passes/fold_qdq.py +36 -0
  1336. executorch/backends/samsung/_passes/fuse_conv_act.py +77 -0
  1337. executorch/backends/samsung/_passes/insert_qdq.py +164 -0
  1338. executorch/backends/samsung/_passes/remove_useless_ops.py +87 -0
  1339. executorch/backends/samsung/_passes/replace_scalar_ops.py +46 -0
  1340. executorch/backends/samsung/_passes/utils.py +15 -0
  1341. executorch/backends/samsung/builders/__init__.py +97 -0
  1342. executorch/backends/samsung/builders/node_visitor.py +116 -0
  1343. executorch/backends/samsung/builders/op_add.py +41 -0
  1344. executorch/backends/samsung/builders/op_avg_pool2d.py +70 -0
  1345. executorch/backends/samsung/builders/op_batch_norm.py +56 -0
  1346. executorch/backends/samsung/builders/op_bmm.py +43 -0
  1347. executorch/backends/samsung/builders/op_cat.py +50 -0
  1348. executorch/backends/samsung/builders/op_clamp.py +47 -0
  1349. executorch/backends/samsung/builders/op_constant_pad_nd.py +56 -0
  1350. executorch/backends/samsung/builders/op_conv2d.py +89 -0
  1351. executorch/backends/samsung/builders/op_dequantize.py +19 -0
  1352. executorch/backends/samsung/builders/op_div.py +42 -0
  1353. executorch/backends/samsung/builders/op_embedding.py +41 -0
  1354. executorch/backends/samsung/builders/op_expand_copy.py +77 -0
  1355. executorch/backends/samsung/builders/op_gelu.py +40 -0
  1356. executorch/backends/samsung/builders/op_getitem.py +32 -0
  1357. executorch/backends/samsung/builders/op_hardsigmoid.py +35 -0
  1358. executorch/backends/samsung/builders/op_hardswish.py +35 -0
  1359. executorch/backends/samsung/builders/op_hardtanh.py +42 -0
  1360. executorch/backends/samsung/builders/op_layer_norm.py +53 -0
  1361. executorch/backends/samsung/builders/op_leaky_relu.py +58 -0
  1362. executorch/backends/samsung/builders/op_linear.py +51 -0
  1363. executorch/backends/samsung/builders/op_log_softmax.py +39 -0
  1364. executorch/backends/samsung/builders/op_max_pool2d.py +96 -0
  1365. executorch/backends/samsung/builders/op_maximum.py +37 -0
  1366. executorch/backends/samsung/builders/op_mean_dim.py +49 -0
  1367. executorch/backends/samsung/builders/op_minimum.py +39 -0
  1368. executorch/backends/samsung/builders/op_mul.py +43 -0
  1369. executorch/backends/samsung/builders/op_permute.py +37 -0
  1370. executorch/backends/samsung/builders/op_pixel_shuffle.py +38 -0
  1371. executorch/backends/samsung/builders/op_quantize.py +60 -0
  1372. executorch/backends/samsung/builders/op_relu.py +37 -0
  1373. executorch/backends/samsung/builders/op_reshape.py +34 -0
  1374. executorch/backends/samsung/builders/op_rsqrt.py +35 -0
  1375. executorch/backends/samsung/builders/op_select.py +52 -0
  1376. executorch/backends/samsung/builders/op_slice_copy.py +59 -0
  1377. executorch/backends/samsung/builders/op_softmax.py +39 -0
  1378. executorch/backends/samsung/builders/op_sqrt.py +35 -0
  1379. executorch/backends/samsung/builders/op_squeeze.py +37 -0
  1380. executorch/backends/samsung/builders/op_sub.py +39 -0
  1381. executorch/backends/samsung/builders/op_to_copy.py +44 -0
  1382. executorch/backends/samsung/builders/op_unsqueeze.py +35 -0
  1383. executorch/backends/samsung/builders/op_upsample_bilinear2d.py +53 -0
  1384. executorch/backends/samsung/builders/op_upsample_nearest2d.py +52 -0
  1385. executorch/backends/samsung/builders/utils.py +64 -0
  1386. executorch/backends/samsung/enn_preprocess.py +110 -0
  1387. executorch/backends/samsung/partition/enn_partitioner.py +134 -0
  1388. executorch/backends/samsung/quantizer/__init__.py +10 -0
  1389. executorch/backends/samsung/quantizer/annotator.py +871 -0
  1390. executorch/backends/samsung/quantizer/qconfig.py +174 -0
  1391. executorch/backends/samsung/quantizer/quantizer.py +65 -0
  1392. executorch/backends/samsung/serialization/compile_options.py +77 -0
  1393. executorch/backends/samsung/serialization/compile_options_def.fbs +23 -0
  1394. executorch/backends/samsung/serialization/enn_graph_schema.py +141 -0
  1395. executorch/backends/samsung/test/models/test_deeplab_v3.py +28 -0
  1396. executorch/backends/samsung/test/models/test_edsr.py +30 -0
  1397. executorch/backends/samsung/test/models/test_inception_v3.py +30 -0
  1398. executorch/backends/samsung/test/models/test_inception_v4.py +30 -0
  1399. executorch/backends/samsung/test/models/test_mobilenet_v2.py +28 -0
  1400. executorch/backends/samsung/test/models/test_mobilenet_v3.py +33 -0
  1401. executorch/backends/samsung/test/models/test_resnet18.py +30 -0
  1402. executorch/backends/samsung/test/models/test_resnet50.py +30 -0
  1403. executorch/backends/samsung/test/models/test_torchvision_vit.py +32 -0
  1404. executorch/backends/samsung/test/models/test_wav2letter.py +28 -0
  1405. executorch/backends/samsung/test/ops/test_add.py +63 -0
  1406. executorch/backends/samsung/test/ops/test_avg_pool2d.py +66 -0
  1407. executorch/backends/samsung/test/ops/test_batch_norm.py +52 -0
  1408. executorch/backends/samsung/test/ops/test_bmm.py +50 -0
  1409. executorch/backends/samsung/test/ops/test_cat.py +49 -0
  1410. executorch/backends/samsung/test/ops/test_clamp.py +50 -0
  1411. executorch/backends/samsung/test/ops/test_constant_pad_nd.py +46 -0
  1412. executorch/backends/samsung/test/ops/test_conv2d.py +95 -0
  1413. executorch/backends/samsung/test/ops/test_div.py +50 -0
  1414. executorch/backends/samsung/test/ops/test_embedding.py +46 -0
  1415. executorch/backends/samsung/test/ops/test_expand_copy.py +46 -0
  1416. executorch/backends/samsung/test/ops/test_gelu.py +65 -0
  1417. executorch/backends/samsung/test/ops/test_leaky_relu.py +47 -0
  1418. executorch/backends/samsung/test/ops/test_linear.py +48 -0
  1419. executorch/backends/samsung/test/ops/test_log_softmax.py +46 -0
  1420. executorch/backends/samsung/test/ops/test_max_pool2d.py +72 -0
  1421. executorch/backends/samsung/test/ops/test_mean_dim.py +51 -0
  1422. executorch/backends/samsung/test/ops/test_minimum.py +45 -0
  1423. executorch/backends/samsung/test/ops/test_mul.py +63 -0
  1424. executorch/backends/samsung/test/ops/test_permute.py +55 -0
  1425. executorch/backends/samsung/test/ops/test_pixel_shuffle.py +49 -0
  1426. executorch/backends/samsung/test/ops/test_relu.py +65 -0
  1427. executorch/backends/samsung/test/ops/test_reshape.py +46 -0
  1428. executorch/backends/samsung/test/ops/test_rsqrt.py +46 -0
  1429. executorch/backends/samsung/test/ops/test_select.py +52 -0
  1430. executorch/backends/samsung/test/ops/test_slice_copy.py +46 -0
  1431. executorch/backends/samsung/test/ops/test_softmax.py +46 -0
  1432. executorch/backends/samsung/test/ops/test_sqrt.py +46 -0
  1433. executorch/backends/samsung/test/ops/test_squeeze.py +47 -0
  1434. executorch/backends/samsung/test/ops/test_sub.py +63 -0
  1435. executorch/backends/samsung/test/ops/test_to_copy.py +49 -0
  1436. executorch/backends/samsung/test/ops/test_unsqueeze.py +47 -0
  1437. executorch/backends/samsung/test/ops/test_upsample_bilinear2d.py +54 -0
  1438. executorch/backends/samsung/test/ops/test_upsample_nearest2d.py +53 -0
  1439. executorch/backends/samsung/test/tester/__init__.py +11 -0
  1440. executorch/backends/samsung/test/tester/samsung_tester.py +125 -0
  1441. executorch/backends/samsung/test/utils/__init__.py +11 -0
  1442. executorch/backends/samsung/test/utils/runtime_executor.py +186 -0
  1443. executorch/backends/samsung/utils/constants.py +45 -0
  1444. executorch/backends/samsung/utils/export_utils.py +93 -0
  1445. executorch/backends/samsung/utils/utils.py +125 -0
  1446. executorch/backends/test/facto/__init__.py +0 -0
  1447. executorch/backends/test/facto/facto_specs.py +59 -0
  1448. executorch/backends/test/facto/test_facto.py +301 -0
  1449. executorch/backends/test/harness/__init__.py +3 -0
  1450. executorch/backends/test/harness/error_statistics.py +99 -0
  1451. executorch/backends/test/harness/stages/__init__.py +23 -0
  1452. executorch/backends/test/harness/stages/export.py +32 -0
  1453. executorch/backends/test/harness/stages/partition.py +26 -0
  1454. executorch/backends/test/harness/stages/quantize.py +128 -0
  1455. executorch/backends/test/harness/stages/run_passes.py +66 -0
  1456. executorch/backends/test/harness/stages/serialize.py +59 -0
  1457. executorch/backends/test/harness/stages/stage.py +91 -0
  1458. executorch/backends/test/harness/stages/to_edge.py +27 -0
  1459. executorch/backends/test/harness/stages/to_edge_transform_and_lower.py +50 -0
  1460. executorch/backends/test/harness/stages/to_executorch.py +54 -0
  1461. executorch/backends/test/harness/tester.py +478 -0
  1462. executorch/backends/test/harness/tests/test_error_statistics.py +67 -0
  1463. executorch/backends/test/suite/__init__.py +74 -0
  1464. executorch/backends/test/suite/conftest.py +182 -0
  1465. executorch/backends/test/suite/context.py +34 -0
  1466. executorch/backends/test/suite/discovery.py +100 -0
  1467. executorch/backends/test/suite/flow.py +150 -0
  1468. executorch/backends/test/suite/flows/__init__.py +7 -0
  1469. executorch/backends/test/suite/flows/arm.py +92 -0
  1470. executorch/backends/test/suite/flows/coreml.py +31 -0
  1471. executorch/backends/test/suite/flows/portable.py +19 -0
  1472. executorch/backends/test/suite/flows/qualcomm.py +61 -0
  1473. executorch/backends/test/suite/flows/vulkan.py +44 -0
  1474. executorch/backends/test/suite/flows/xnnpack.py +79 -0
  1475. executorch/backends/test/suite/generate_markdown_summary.py +249 -0
  1476. executorch/backends/test/suite/generate_markdown_summary_json.py +229 -0
  1477. executorch/backends/test/suite/models/__init__.py +7 -0
  1478. executorch/backends/test/suite/models/test_torchaudio.py +110 -0
  1479. executorch/backends/test/suite/models/test_torchvision.py +194 -0
  1480. executorch/backends/test/suite/operators/__init__.py +108 -0
  1481. executorch/backends/test/suite/operators/test_abs.py +60 -0
  1482. executorch/backends/test/suite/operators/test_adaptive_avgpool1d.py +102 -0
  1483. executorch/backends/test/suite/operators/test_adaptive_avgpool2d.py +112 -0
  1484. executorch/backends/test/suite/operators/test_adaptive_avgpool3d.py +112 -0
  1485. executorch/backends/test/suite/operators/test_adaptive_maxpool1d.py +125 -0
  1486. executorch/backends/test/suite/operators/test_adaptive_maxpool2d.py +135 -0
  1487. executorch/backends/test/suite/operators/test_adaptive_maxpool3d.py +135 -0
  1488. executorch/backends/test/suite/operators/test_add.py +76 -0
  1489. executorch/backends/test/suite/operators/test_amax.py +257 -0
  1490. executorch/backends/test/suite/operators/test_amin.py +259 -0
  1491. executorch/backends/test/suite/operators/test_argmax.py +201 -0
  1492. executorch/backends/test/suite/operators/test_argmin.py +201 -0
  1493. executorch/backends/test/suite/operators/test_avgpool1d.py +155 -0
  1494. executorch/backends/test/suite/operators/test_avgpool2d.py +168 -0
  1495. executorch/backends/test/suite/operators/test_avgpool3d.py +163 -0
  1496. executorch/backends/test/suite/operators/test_cat.py +176 -0
  1497. executorch/backends/test/suite/operators/test_ceil.py +60 -0
  1498. executorch/backends/test/suite/operators/test_clamp.py +86 -0
  1499. executorch/backends/test/suite/operators/test_conv1d.py +144 -0
  1500. executorch/backends/test/suite/operators/test_conv2d.py +167 -0
  1501. executorch/backends/test/suite/operators/test_conv3d.py +162 -0
  1502. executorch/backends/test/suite/operators/test_convtranspose1d.py +144 -0
  1503. executorch/backends/test/suite/operators/test_convtranspose2d.py +171 -0
  1504. executorch/backends/test/suite/operators/test_convtranspose3d.py +166 -0
  1505. executorch/backends/test/suite/operators/test_div.py +110 -0
  1506. executorch/backends/test/suite/operators/test_elu.py +49 -0
  1507. executorch/backends/test/suite/operators/test_embedding.py +89 -0
  1508. executorch/backends/test/suite/operators/test_embedding_bag.py +118 -0
  1509. executorch/backends/test/suite/operators/test_exp.py +65 -0
  1510. executorch/backends/test/suite/operators/test_expand.py +122 -0
  1511. executorch/backends/test/suite/operators/test_floor.py +57 -0
  1512. executorch/backends/test/suite/operators/test_floor_divide.py +216 -0
  1513. executorch/backends/test/suite/operators/test_gelu.py +52 -0
  1514. executorch/backends/test/suite/operators/test_glu.py +52 -0
  1515. executorch/backends/test/suite/operators/test_hardsigmoid.py +50 -0
  1516. executorch/backends/test/suite/operators/test_hardswish.py +50 -0
  1517. executorch/backends/test/suite/operators/test_hardtanh.py +57 -0
  1518. executorch/backends/test/suite/operators/test_index_put.py +455 -0
  1519. executorch/backends/test/suite/operators/test_index_select.py +128 -0
  1520. executorch/backends/test/suite/operators/test_leaky_relu.py +56 -0
  1521. executorch/backends/test/suite/operators/test_linear.py +124 -0
  1522. executorch/backends/test/suite/operators/test_log.py +80 -0
  1523. executorch/backends/test/suite/operators/test_log10.py +60 -0
  1524. executorch/backends/test/suite/operators/test_log1p.py +60 -0
  1525. executorch/backends/test/suite/operators/test_log2.py +60 -0
  1526. executorch/backends/test/suite/operators/test_logsigmoid.py +40 -0
  1527. executorch/backends/test/suite/operators/test_lstm.py +247 -0
  1528. executorch/backends/test/suite/operators/test_masked_fill.py +101 -0
  1529. executorch/backends/test/suite/operators/test_maxpool1d.py +185 -0
  1530. executorch/backends/test/suite/operators/test_maxpool2d.py +191 -0
  1531. executorch/backends/test/suite/operators/test_maxpool3d.py +189 -0
  1532. executorch/backends/test/suite/operators/test_mean.py +305 -0
  1533. executorch/backends/test/suite/operators/test_median.py +188 -0
  1534. executorch/backends/test/suite/operators/test_mul.py +66 -0
  1535. executorch/backends/test/suite/operators/test_neg.py +70 -0
  1536. executorch/backends/test/suite/operators/test_permute.py +109 -0
  1537. executorch/backends/test/suite/operators/test_pow.py +149 -0
  1538. executorch/backends/test/suite/operators/test_prelu.py +55 -0
  1539. executorch/backends/test/suite/operators/test_relu.py +45 -0
  1540. executorch/backends/test/suite/operators/test_reshape.py +82 -0
  1541. executorch/backends/test/suite/operators/test_round.py +129 -0
  1542. executorch/backends/test/suite/operators/test_rsqrt.py +76 -0
  1543. executorch/backends/test/suite/operators/test_select.py +89 -0
  1544. executorch/backends/test/suite/operators/test_sigmoid.py +40 -0
  1545. executorch/backends/test/suite/operators/test_silu.py +50 -0
  1546. executorch/backends/test/suite/operators/test_slice.py +146 -0
  1547. executorch/backends/test/suite/operators/test_split.py +119 -0
  1548. executorch/backends/test/suite/operators/test_sqrt.py +71 -0
  1549. executorch/backends/test/suite/operators/test_square.py +67 -0
  1550. executorch/backends/test/suite/operators/test_squeeze.py +86 -0
  1551. executorch/backends/test/suite/operators/test_stack.py +114 -0
  1552. executorch/backends/test/suite/operators/test_sub.py +84 -0
  1553. executorch/backends/test/suite/operators/test_tanh.py +40 -0
  1554. executorch/backends/test/suite/operators/test_threshold.py +71 -0
  1555. executorch/backends/test/suite/operators/test_transpose.py +143 -0
  1556. executorch/backends/test/suite/operators/test_trunc.py +73 -0
  1557. executorch/backends/test/suite/operators/test_unsqueeze.py +110 -0
  1558. executorch/backends/test/suite/operators/test_upsample_bilinear2d.py +273 -0
  1559. executorch/backends/test/suite/operators/test_upsample_nearest2d.py +137 -0
  1560. executorch/backends/test/suite/operators/test_view.py +82 -0
  1561. executorch/backends/test/suite/reporting.py +421 -0
  1562. executorch/backends/test/suite/runner.py +328 -0
  1563. executorch/backends/test/suite/tests/__init__.py +0 -0
  1564. executorch/backends/test/suite/tests/test_reporting.py +144 -0
  1565. executorch/backends/transforms/__init__.py +12 -0
  1566. executorch/backends/transforms/addmm_mm_to_linear.py +170 -0
  1567. executorch/backends/transforms/convert_dtype_pass.py +103 -0
  1568. executorch/backends/transforms/decompose_sdpa.py +120 -0
  1569. executorch/backends/transforms/duplicate_dynamic_quant_chain.py +195 -0
  1570. executorch/backends/transforms/fuse_batch_norm_with_conv.py +161 -0
  1571. executorch/backends/transforms/fuse_conv_with_clamp.py +77 -0
  1572. executorch/backends/transforms/fuse_view_copy.py +116 -0
  1573. executorch/backends/transforms/mean_to_sum_div.py +41 -0
  1574. executorch/backends/transforms/rank_0_to_rank_1.py +18 -0
  1575. executorch/backends/transforms/remove_clone_ops.py +109 -0
  1576. executorch/backends/transforms/remove_getitem_op.py +109 -0
  1577. executorch/backends/transforms/replace_scalar_with_tensor.py +93 -0
  1578. executorch/backends/transforms/test/test_create_delete_constant_placeholder.py +122 -0
  1579. executorch/backends/transforms/test/test_create_mutable_buffer.py +503 -0
  1580. executorch/backends/transforms/test/test_duplicate_dynamic_quant_chain.py +184 -0
  1581. executorch/backends/transforms/test/test_rank_0_to_rank_1.py +32 -0
  1582. executorch/backends/transforms/test/test_remove_clone_ops.py +197 -0
  1583. executorch/backends/transforms/utils.py +377 -0
  1584. executorch/backends/transforms/view_copy_to_squeeze_unsqueeze.py +135 -0
  1585. executorch/backends/vulkan/__init__.py +14 -0
  1586. executorch/backends/vulkan/_passes/__init__.py +37 -0
  1587. executorch/backends/vulkan/_passes/fold_qdq.py +40 -0
  1588. executorch/backends/vulkan/_passes/fuse_patterns.py +34 -0
  1589. executorch/backends/vulkan/_passes/fuse_quantized_ops.py +236 -0
  1590. executorch/backends/vulkan/_passes/insert_prepack_nodes.py +83 -0
  1591. executorch/backends/vulkan/_passes/remove_asserts.py +52 -0
  1592. executorch/backends/vulkan/_passes/remove_redundant_ops.py +72 -0
  1593. executorch/backends/vulkan/_passes/squeeze_unsqueeze_inputs.py +93 -0
  1594. executorch/backends/vulkan/_passes/tag_memory_meta_pass.py +485 -0
  1595. executorch/backends/vulkan/custom_ops_lib.py +597 -0
  1596. executorch/backends/vulkan/op_registry.py +885 -0
  1597. executorch/backends/vulkan/partitioner/vulkan_partitioner.py +401 -0
  1598. executorch/backends/vulkan/patterns/__init__.py +139 -0
  1599. executorch/backends/vulkan/patterns/pattern_registry.py +116 -0
  1600. executorch/backends/vulkan/patterns/quantized_binary.py +161 -0
  1601. executorch/backends/vulkan/patterns/quantized_convolution.py +260 -0
  1602. executorch/backends/vulkan/patterns/quantized_linear.py +500 -0
  1603. executorch/backends/vulkan/patterns/rope.py +173 -0
  1604. executorch/backends/vulkan/patterns/sdpa.py +155 -0
  1605. executorch/backends/vulkan/patterns/select_as_symint.py +104 -0
  1606. executorch/backends/vulkan/quantizer/vulkan_quantizer.py +183 -0
  1607. executorch/backends/vulkan/quantizer/vulkan_quantizer_utils.py +223 -0
  1608. executorch/backends/vulkan/runtime/gen_vulkan_spv.py +1517 -0
  1609. executorch/backends/vulkan/runtime/graph/ops/glsl/addmm_naive_buffer.yaml +19 -0
  1610. executorch/backends/vulkan/runtime/graph/ops/glsl/addmm_naive_texture3d.yaml +24 -0
  1611. executorch/backends/vulkan/runtime/graph/ops/glsl/addmm_optimized.yaml +43 -0
  1612. executorch/backends/vulkan/runtime/graph/ops/glsl/arange.yaml +19 -0
  1613. executorch/backends/vulkan/runtime/graph/ops/glsl/avg_pool2d.yaml +18 -0
  1614. executorch/backends/vulkan/runtime/graph/ops/glsl/batchnorm.yaml +11 -0
  1615. executorch/backends/vulkan/runtime/graph/ops/glsl/binary_op.yaml +118 -0
  1616. executorch/backends/vulkan/runtime/graph/ops/glsl/binary_q8ta_q8ta_q8to.yaml +19 -0
  1617. executorch/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_buffer.yaml +20 -0
  1618. executorch/backends/vulkan/runtime/graph/ops/glsl/binary_scalar_texture.yaml +20 -0
  1619. executorch/backends/vulkan/runtime/graph/ops/glsl/bitw8_image_to_nchw_nobitw8buffer.yaml +22 -0
  1620. executorch/backends/vulkan/runtime/graph/ops/glsl/buffer_to_buffer.yaml +20 -0
  1621. executorch/backends/vulkan/runtime/graph/ops/glsl/buffer_to_nchw.yaml +25 -0
  1622. executorch/backends/vulkan/runtime/graph/ops/glsl/choose_qparams_per_row.yaml +19 -0
  1623. executorch/backends/vulkan/runtime/graph/ops/glsl/clone.yaml +13 -0
  1624. executorch/backends/vulkan/runtime/graph/ops/glsl/col2im.yaml +19 -0
  1625. executorch/backends/vulkan/runtime/graph/ops/glsl/concat_buffer.yaml +15 -0
  1626. executorch/backends/vulkan/runtime/graph/ops/glsl/concat_texture.yaml +15 -0
  1627. executorch/backends/vulkan/runtime/graph/ops/glsl/conv1d.yaml +19 -0
  1628. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d.yaml +19 -0
  1629. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw.yaml +19 -0
  1630. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_output_tile.yaml +27 -0
  1631. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_prepack_weights.yaml +15 -0
  1632. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_q8ta_q8csw_q8to.yaml +20 -0
  1633. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_dw_sned_output_tile.yaml +25 -0
  1634. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_prepack_weights.yaml +15 -0
  1635. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw.yaml +21 -0
  1636. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw_q8ta_q8csw_q8to_tiled.yaml +20 -0
  1637. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_pw_s1p0.yaml +19 -0
  1638. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8csw_linear_tiled.yaml +22 -0
  1639. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_linear_tiled.yaml +22 -0
  1640. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_q8to.yaml +21 -0
  1641. executorch/backends/vulkan/runtime/graph/ops/glsl/conv2d_q8ta_q8csw_q8to_linear_tiled.yaml +21 -0
  1642. executorch/backends/vulkan/runtime/graph/ops/glsl/conv_transpose2d.yaml +19 -0
  1643. executorch/backends/vulkan/runtime/graph/ops/glsl/conv_transpose2d_prepack_weights.yaml +16 -0
  1644. executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_buffer.yaml +16 -0
  1645. executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_legacy.yaml +12 -0
  1646. executorch/backends/vulkan/runtime/graph/ops/glsl/embedding_texture.yaml +15 -0
  1647. executorch/backends/vulkan/runtime/graph/ops/glsl/expand_buffer.yaml +11 -0
  1648. executorch/backends/vulkan/runtime/graph/ops/glsl/flip.yaml +14 -0
  1649. executorch/backends/vulkan/runtime/graph/ops/glsl/full.yaml +20 -0
  1650. executorch/backends/vulkan/runtime/graph/ops/glsl/gather_buffer.yaml +18 -0
  1651. executorch/backends/vulkan/runtime/graph/ops/glsl/gather_texture.yaml +17 -0
  1652. executorch/backends/vulkan/runtime/graph/ops/glsl/grid_priors.yaml +12 -0
  1653. executorch/backends/vulkan/runtime/graph/ops/glsl/group_norm_reduce_texture.yaml +15 -0
  1654. executorch/backends/vulkan/runtime/graph/ops/glsl/group_norm_texture.yaml +15 -0
  1655. executorch/backends/vulkan/runtime/graph/ops/glsl/im2col.yaml +18 -0
  1656. executorch/backends/vulkan/runtime/graph/ops/glsl/im2col_packed_int8.yaml +15 -0
  1657. executorch/backends/vulkan/runtime/graph/ops/glsl/image_to_nchw.yaml +38 -0
  1658. executorch/backends/vulkan/runtime/graph/ops/glsl/index_select.yaml +13 -0
  1659. executorch/backends/vulkan/runtime/graph/ops/glsl/index_select_channel.yaml +13 -0
  1660. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_dq8ca_q4gsw_tiled.yaml +29 -0
  1661. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_coop.yaml +43 -0
  1662. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q4gsw_tiled.yaml +28 -0
  1663. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q8csw_tiled.yaml +28 -0
  1664. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_q8ta_q8csw_tiled.yaml +24 -0
  1665. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw.yaml +23 -0
  1666. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_coop.yaml +38 -0
  1667. executorch/backends/vulkan/runtime/graph/ops/glsl/linear_qcsnw_tiled.yaml +54 -0
  1668. executorch/backends/vulkan/runtime/graph/ops/glsl/max_pool2d.yaml +17 -0
  1669. executorch/backends/vulkan/runtime/graph/ops/glsl/native_layer_norm.yaml +16 -0
  1670. executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_bitw8_image_nobitw8buffer.yaml +22 -0
  1671. executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_buffer.yaml +25 -0
  1672. executorch/backends/vulkan/runtime/graph/ops/glsl/nchw_to_image.yaml +37 -0
  1673. executorch/backends/vulkan/runtime/graph/ops/glsl/no_op.yaml +24 -0
  1674. executorch/backends/vulkan/runtime/graph/ops/glsl/pack_int4_linear_weight_transposed_interleaved.yaml +19 -0
  1675. executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q4_linear_weight.yaml +14 -0
  1676. executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_conv2d_dw_weights.yaml +15 -0
  1677. executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_conv2d_weights.yaml +15 -0
  1678. executorch/backends/vulkan/runtime/graph/ops/glsl/pack_q8_linear_weight.yaml +14 -0
  1679. executorch/backends/vulkan/runtime/graph/ops/glsl/pad_channel.yaml +14 -0
  1680. executorch/backends/vulkan/runtime/graph/ops/glsl/pad_height_width.yaml +14 -0
  1681. executorch/backends/vulkan/runtime/graph/ops/glsl/permute_buffer.yaml +11 -0
  1682. executorch/backends/vulkan/runtime/graph/ops/glsl/permute_texture.yaml +11 -0
  1683. executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4h4w.yaml +25 -0
  1684. executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4h4w_with_group_sums.yaml +30 -0
  1685. executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_4w4c.yaml +23 -0
  1686. executorch/backends/vulkan/runtime/graph/ops/glsl/quantize_and_pack_im2col.yaml +18 -0
  1687. executorch/backends/vulkan/runtime/graph/ops/glsl/reduce.yaml +29 -0
  1688. executorch/backends/vulkan/runtime/graph/ops/glsl/reduce2d.yaml +29 -0
  1689. executorch/backends/vulkan/runtime/graph/ops/glsl/reduce_per_row_buffer.yaml +42 -0
  1690. executorch/backends/vulkan/runtime/graph/ops/glsl/repeat.yaml +14 -0
  1691. executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_channel.yaml +12 -0
  1692. executorch/backends/vulkan/runtime/graph/ops/glsl/repeat_interleave.yaml +12 -0
  1693. executorch/backends/vulkan/runtime/graph/ops/glsl/rotary_embedding.yaml +13 -0
  1694. executorch/backends/vulkan/runtime/graph/ops/glsl/scalar_tensor.yaml +27 -0
  1695. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_attn_weights_softmax.yaml +19 -0
  1696. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_attn_weights_coop.yaml +25 -0
  1697. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_attn_weights_tiled.yaml +26 -0
  1698. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_out_coop.yaml +25 -0
  1699. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_compute_out_tiled.yaml +26 -0
  1700. executorch/backends/vulkan/runtime/graph/ops/glsl/sdpa_kv_cache_update.yaml +23 -0
  1701. executorch/backends/vulkan/runtime/graph/ops/glsl/set_zero.yaml +8 -0
  1702. executorch/backends/vulkan/runtime/graph/ops/glsl/softmax.yaml +21 -0
  1703. executorch/backends/vulkan/runtime/graph/ops/glsl/split_buffer.yaml +18 -0
  1704. executorch/backends/vulkan/runtime/graph/ops/glsl/split_texture.yaml +17 -0
  1705. executorch/backends/vulkan/runtime/graph/ops/glsl/tan.yaml +13 -0
  1706. executorch/backends/vulkan/runtime/graph/ops/glsl/transfer_buffer.yaml +22 -0
  1707. executorch/backends/vulkan/runtime/graph/ops/glsl/transfer_texture.yaml +22 -0
  1708. executorch/backends/vulkan/runtime/graph/ops/glsl/unary_op.yaml +48 -0
  1709. executorch/backends/vulkan/runtime/graph/ops/glsl/unpack_4w4c_and_dequantize.yaml +23 -0
  1710. executorch/backends/vulkan/runtime/graph/ops/glsl/update_concat_offset.yaml +13 -0
  1711. executorch/backends/vulkan/runtime/graph/ops/glsl/upsample_2d.yaml +19 -0
  1712. executorch/backends/vulkan/runtime/graph/ops/glsl/var_buffer.yaml +16 -0
  1713. executorch/backends/vulkan/runtime/graph/ops/glsl/var_texture3d.yaml +16 -0
  1714. executorch/backends/vulkan/runtime/graph/ops/glsl/view.yaml +13 -0
  1715. executorch/backends/vulkan/runtime/graph/ops/glsl/view_buffer.yaml +20 -0
  1716. executorch/backends/vulkan/runtime/graph/ops/glsl/view_convert_buffer.yaml +22 -0
  1717. executorch/backends/vulkan/runtime/graph/ops/glsl/where.yaml +12 -0
  1718. executorch/backends/vulkan/serialization/schema.fbs +158 -0
  1719. executorch/backends/vulkan/serialization/vulkan_graph_builder.py +505 -0
  1720. executorch/backends/vulkan/serialization/vulkan_graph_schema.py +161 -0
  1721. executorch/backends/vulkan/serialization/vulkan_graph_serialize.py +274 -0
  1722. executorch/backends/vulkan/test/custom_ops/glsl/add.yaml +29 -0
  1723. executorch/backends/vulkan/test/glsl/all_shaders.yaml +68 -0
  1724. executorch/backends/vulkan/test/glsl/dynamic_dispatch_test.yaml +7 -0
  1725. executorch/backends/vulkan/test/glsl/reference_matmul_common.yaml +9 -0
  1726. executorch/backends/vulkan/test/op_tests/cases.py +2026 -0
  1727. executorch/backends/vulkan/test/op_tests/generate_op_benchmarks.py +88 -0
  1728. executorch/backends/vulkan/test/op_tests/generate_op_correctness_tests.py +90 -0
  1729. executorch/backends/vulkan/test/op_tests/utils/aten_types.py +31 -0
  1730. executorch/backends/vulkan/test/op_tests/utils/gen_benchmark_vk.py +350 -0
  1731. executorch/backends/vulkan/test/op_tests/utils/gen_computegraph.py +788 -0
  1732. executorch/backends/vulkan/test/op_tests/utils/gen_correctness_base.py +421 -0
  1733. executorch/backends/vulkan/test/op_tests/utils/gen_correctness_vk.py +164 -0
  1734. executorch/backends/vulkan/test/op_tests/utils/test_suite.py +53 -0
  1735. executorch/backends/vulkan/test/test_serialization.py +135 -0
  1736. executorch/backends/vulkan/test/test_vulkan_delegate.py +2696 -0
  1737. executorch/backends/vulkan/test/test_vulkan_delegate_header.py +104 -0
  1738. executorch/backends/vulkan/test/test_vulkan_passes.py +193 -0
  1739. executorch/backends/vulkan/test/tester.py +91 -0
  1740. executorch/backends/vulkan/test/utils.py +1111 -0
  1741. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/apiconventions.py +21 -0
  1742. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/base_generator.py +937 -0
  1743. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/cgenerator.py +549 -0
  1744. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/generator.py +1424 -0
  1745. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/parse_dependency.py +404 -0
  1746. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/reg.py +1885 -0
  1747. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/spec_tools/conventions.py +562 -0
  1748. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/spec_tools/util.py +58 -0
  1749. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/stripAPI.py +42 -0
  1750. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/vkconventions.py +314 -0
  1751. executorch/backends/vulkan/third-party/Vulkan-Headers/registry/vulkan_object.py +484 -0
  1752. executorch/backends/vulkan/third-party/VulkanMemoryAllocator/tools/GpuMemDumpVis/GpuMemDumpVis.py +333 -0
  1753. executorch/backends/vulkan/third-party/volk/generate.py +212 -0
  1754. executorch/backends/vulkan/tools/gpuinfo/glsl/buf_bandwidth.yaml +18 -0
  1755. executorch/backends/vulkan/tools/gpuinfo/glsl/buf_cacheline_size.yaml +12 -0
  1756. executorch/backends/vulkan/tools/gpuinfo/glsl/reg_count.yaml +16 -0
  1757. executorch/backends/vulkan/tools/gpuinfo/glsl/tex_bandwidth.yaml +15 -0
  1758. executorch/backends/vulkan/tools/gpuinfo/glsl/tex_cacheline_concurr.yaml +14 -0
  1759. executorch/backends/vulkan/tools/gpuinfo/glsl/warp_size.yaml +16 -0
  1760. executorch/backends/vulkan/utils.py +1474 -0
  1761. executorch/backends/vulkan/vulkan_preprocess.py +249 -0
  1762. executorch/backends/xnnpack/__init__.py +34 -0
  1763. executorch/backends/xnnpack/_passes/__init__.py +109 -0
  1764. executorch/backends/xnnpack/_passes/channels_last_tagged_reshape_pass.py +561 -0
  1765. executorch/backends/xnnpack/_passes/conv1d_unsqueeze_pass.py +203 -0
  1766. executorch/backends/xnnpack/_passes/convert_to_linear.py +198 -0
  1767. executorch/backends/xnnpack/_passes/convert_to_sdpa.py +114 -0
  1768. executorch/backends/xnnpack/_passes/convert_to_upsample_bilinear2d.py +65 -0
  1769. executorch/backends/xnnpack/_passes/decompose_cat.py +105 -0
  1770. executorch/backends/xnnpack/_passes/fuse_activation_pass.py +87 -0
  1771. executorch/backends/xnnpack/_passes/fuse_batch_norm.py +261 -0
  1772. executorch/backends/xnnpack/_passes/prelu_reshape_pass.py +75 -0
  1773. executorch/backends/xnnpack/_passes/propagate_custom_meta_pass.py +44 -0
  1774. executorch/backends/xnnpack/_passes/remove_redundant_copy_pass.py +158 -0
  1775. executorch/backends/xnnpack/_passes/xnnpack_pass.py +22 -0
  1776. executorch/backends/xnnpack/operators/__init__.py +61 -0
  1777. executorch/backends/xnnpack/operators/node_visitor.py +758 -0
  1778. executorch/backends/xnnpack/operators/op_abs.py +52 -0
  1779. executorch/backends/xnnpack/operators/op_add.py +77 -0
  1780. executorch/backends/xnnpack/operators/op_addmm.py +70 -0
  1781. executorch/backends/xnnpack/operators/op_avg_pooling2d.py +75 -0
  1782. executorch/backends/xnnpack/operators/op_bmm.py +54 -0
  1783. executorch/backends/xnnpack/operators/op_cat.py +121 -0
  1784. executorch/backends/xnnpack/operators/op_ceiling.py +52 -0
  1785. executorch/backends/xnnpack/operators/op_clamp.py +64 -0
  1786. executorch/backends/xnnpack/operators/op_clone.py +60 -0
  1787. executorch/backends/xnnpack/operators/op_conv2d.py +186 -0
  1788. executorch/backends/xnnpack/operators/op_cos.py +52 -0
  1789. executorch/backends/xnnpack/operators/op_div.py +56 -0
  1790. executorch/backends/xnnpack/operators/op_dynamic_dequantize_ops.py +114 -0
  1791. executorch/backends/xnnpack/operators/op_dynamic_quantize_ops.py +179 -0
  1792. executorch/backends/xnnpack/operators/op_elu.py +56 -0
  1793. executorch/backends/xnnpack/operators/op_exp.py +52 -0
  1794. executorch/backends/xnnpack/operators/op_floor.py +48 -0
  1795. executorch/backends/xnnpack/operators/op_gelu.py +52 -0
  1796. executorch/backends/xnnpack/operators/op_hardswish.py +52 -0
  1797. executorch/backends/xnnpack/operators/op_hardtanh.py +67 -0
  1798. executorch/backends/xnnpack/operators/op_leaky_relu.py +65 -0
  1799. executorch/backends/xnnpack/operators/op_linear.py +110 -0
  1800. executorch/backends/xnnpack/operators/op_log.py +52 -0
  1801. executorch/backends/xnnpack/operators/op_matrix_multiplication.py +66 -0
  1802. executorch/backends/xnnpack/operators/op_max_dim.py +206 -0
  1803. executorch/backends/xnnpack/operators/op_max_pool2d.py +136 -0
  1804. executorch/backends/xnnpack/operators/op_maximum.py +55 -0
  1805. executorch/backends/xnnpack/operators/op_mean_dim.py +78 -0
  1806. executorch/backends/xnnpack/operators/op_minimum.py +54 -0
  1807. executorch/backends/xnnpack/operators/op_multiply.py +84 -0
  1808. executorch/backends/xnnpack/operators/op_negate.py +51 -0
  1809. executorch/backends/xnnpack/operators/op_permute.py +87 -0
  1810. executorch/backends/xnnpack/operators/op_prelu.py +56 -0
  1811. executorch/backends/xnnpack/operators/op_quant_dequant.py +196 -0
  1812. executorch/backends/xnnpack/operators/op_relu.py +61 -0
  1813. executorch/backends/xnnpack/operators/op_rsqrt.py +52 -0
  1814. executorch/backends/xnnpack/operators/op_sigmoid.py +48 -0
  1815. executorch/backends/xnnpack/operators/op_sin.py +52 -0
  1816. executorch/backends/xnnpack/operators/op_skip_ops.py +89 -0
  1817. executorch/backends/xnnpack/operators/op_slice_copy.py +100 -0
  1818. executorch/backends/xnnpack/operators/op_softmax.py +58 -0
  1819. executorch/backends/xnnpack/operators/op_square.py +52 -0
  1820. executorch/backends/xnnpack/operators/op_square_root.py +52 -0
  1821. executorch/backends/xnnpack/operators/op_squeeze.py +145 -0
  1822. executorch/backends/xnnpack/operators/op_static_constant_pad.py +145 -0
  1823. executorch/backends/xnnpack/operators/op_static_resize_bilinear_2d.py +61 -0
  1824. executorch/backends/xnnpack/operators/op_sub.py +77 -0
  1825. executorch/backends/xnnpack/operators/op_tanh.py +52 -0
  1826. executorch/backends/xnnpack/operators/op_to_copy.py +91 -0
  1827. executorch/backends/xnnpack/operators/op_view_copy.py +96 -0
  1828. executorch/backends/xnnpack/operators/quant_params.py +412 -0
  1829. executorch/backends/xnnpack/partition/config/__init__.py +127 -0
  1830. executorch/backends/xnnpack/partition/config/gemm_configs.py +575 -0
  1831. executorch/backends/xnnpack/partition/config/generic_node_configs.py +711 -0
  1832. executorch/backends/xnnpack/partition/config/node_configs.py +148 -0
  1833. executorch/backends/xnnpack/partition/config/quant_affine_configs.py +56 -0
  1834. executorch/backends/xnnpack/partition/config/xnnpack_config.py +252 -0
  1835. executorch/backends/xnnpack/partition/graphs/bilinear_2d.py +55 -0
  1836. executorch/backends/xnnpack/partition/graphs/sdpa.py +86 -0
  1837. executorch/backends/xnnpack/partition/xnnpack_partitioner.py +160 -0
  1838. executorch/backends/xnnpack/quantizer/xnnpack_quantizer.py +462 -0
  1839. executorch/backends/xnnpack/quantizer/xnnpack_quantizer_utils.py +1121 -0
  1840. executorch/backends/xnnpack/recipes/__init__.py +19 -0
  1841. executorch/backends/xnnpack/recipes/xnnpack_recipe_provider.py +200 -0
  1842. executorch/backends/xnnpack/recipes/xnnpack_recipe_types.py +37 -0
  1843. executorch/backends/xnnpack/serialization/runtime_schema.fbs +389 -0
  1844. executorch/backends/xnnpack/serialization/schema.fbs +381 -0
  1845. executorch/backends/xnnpack/serialization/xnnpack_graph_schema.py +542 -0
  1846. executorch/backends/xnnpack/serialization/xnnpack_graph_serialize.py +373 -0
  1847. executorch/backends/xnnpack/test/__init__.py +0 -0
  1848. executorch/backends/xnnpack/test/models/deeplab_v3.py +42 -0
  1849. executorch/backends/xnnpack/test/models/edsr.py +55 -0
  1850. executorch/backends/xnnpack/test/models/emformer_rnnt.py +98 -0
  1851. executorch/backends/xnnpack/test/models/inception_v3.py +84 -0
  1852. executorch/backends/xnnpack/test/models/inception_v4.py +62 -0
  1853. executorch/backends/xnnpack/test/models/llama2_et_example.py +49 -0
  1854. executorch/backends/xnnpack/test/models/mobilebert.py +55 -0
  1855. executorch/backends/xnnpack/test/models/mobilenet_v2.py +103 -0
  1856. executorch/backends/xnnpack/test/models/mobilenet_v3.py +84 -0
  1857. executorch/backends/xnnpack/test/models/resnet.py +90 -0
  1858. executorch/backends/xnnpack/test/models/torchvision_vit.py +105 -0
  1859. executorch/backends/xnnpack/test/models/very_big_model.py +45 -0
  1860. executorch/backends/xnnpack/test/models/w2l.py +60 -0
  1861. executorch/backends/xnnpack/test/ops/test_abs.py +87 -0
  1862. executorch/backends/xnnpack/test/ops/test_add.py +266 -0
  1863. executorch/backends/xnnpack/test/ops/test_avgpool2d.py +92 -0
  1864. executorch/backends/xnnpack/test/ops/test_bilinear2d.py +152 -0
  1865. executorch/backends/xnnpack/test/ops/test_bmm.py +49 -0
  1866. executorch/backends/xnnpack/test/ops/test_cat.py +254 -0
  1867. executorch/backends/xnnpack/test/ops/test_ceil.py +63 -0
  1868. executorch/backends/xnnpack/test/ops/test_check_quant_params.py +107 -0
  1869. executorch/backends/xnnpack/test/ops/test_clamp.py +79 -0
  1870. executorch/backends/xnnpack/test/ops/test_clone.py +137 -0
  1871. executorch/backends/xnnpack/test/ops/test_conv1d.py +190 -0
  1872. executorch/backends/xnnpack/test/ops/test_conv2d.py +747 -0
  1873. executorch/backends/xnnpack/test/ops/test_cos.py +87 -0
  1874. executorch/backends/xnnpack/test/ops/test_div.py +78 -0
  1875. executorch/backends/xnnpack/test/ops/test_elu.py +98 -0
  1876. executorch/backends/xnnpack/test/ops/test_exp.py +70 -0
  1877. executorch/backends/xnnpack/test/ops/test_floor.py +58 -0
  1878. executorch/backends/xnnpack/test/ops/test_gelu.py +71 -0
  1879. executorch/backends/xnnpack/test/ops/test_hardswish.py +70 -0
  1880. executorch/backends/xnnpack/test/ops/test_hardtanh.py +83 -0
  1881. executorch/backends/xnnpack/test/ops/test_leaky_relu.py +131 -0
  1882. executorch/backends/xnnpack/test/ops/test_linear.py +1059 -0
  1883. executorch/backends/xnnpack/test/ops/test_log.py +45 -0
  1884. executorch/backends/xnnpack/test/ops/test_lstm.py +67 -0
  1885. executorch/backends/xnnpack/test/ops/test_max_dim.py +66 -0
  1886. executorch/backends/xnnpack/test/ops/test_maximum.py +66 -0
  1887. executorch/backends/xnnpack/test/ops/test_maxpool2d.py +221 -0
  1888. executorch/backends/xnnpack/test/ops/test_mean_dim.py +98 -0
  1889. executorch/backends/xnnpack/test/ops/test_minimum.py +49 -0
  1890. executorch/backends/xnnpack/test/ops/test_multiply.py +149 -0
  1891. executorch/backends/xnnpack/test/ops/test_negate.py +58 -0
  1892. executorch/backends/xnnpack/test/ops/test_permute.py +134 -0
  1893. executorch/backends/xnnpack/test/ops/test_pow.py +62 -0
  1894. executorch/backends/xnnpack/test/ops/test_prelu.py +50 -0
  1895. executorch/backends/xnnpack/test/ops/test_quantize_per_tensor.py +70 -0
  1896. executorch/backends/xnnpack/test/ops/test_relu.py +38 -0
  1897. executorch/backends/xnnpack/test/ops/test_rsqrt.py +45 -0
  1898. executorch/backends/xnnpack/test/ops/test_sigmoid.py +45 -0
  1899. executorch/backends/xnnpack/test/ops/test_sin.py +87 -0
  1900. executorch/backends/xnnpack/test/ops/test_slice_copy.py +170 -0
  1901. executorch/backends/xnnpack/test/ops/test_softmax.py +73 -0
  1902. executorch/backends/xnnpack/test/ops/test_sqrt.py +45 -0
  1903. executorch/backends/xnnpack/test/ops/test_square.py +48 -0
  1904. executorch/backends/xnnpack/test/ops/test_static_constant_pad.py +294 -0
  1905. executorch/backends/xnnpack/test/ops/test_sub.py +178 -0
  1906. executorch/backends/xnnpack/test/ops/test_tanh.py +43 -0
  1907. executorch/backends/xnnpack/test/ops/test_to_copy.py +113 -0
  1908. executorch/backends/xnnpack/test/passes/__init__.py +0 -0
  1909. executorch/backends/xnnpack/test/passes/test_activation_fusion.py +232 -0
  1910. executorch/backends/xnnpack/test/passes/test_batch_norm_fusion.py +179 -0
  1911. executorch/backends/xnnpack/test/passes/test_channels_last_tagged_reshape.py +635 -0
  1912. executorch/backends/xnnpack/test/passes/test_convert_to_linear.py +43 -0
  1913. executorch/backends/xnnpack/test/passes/test_decompose_cat_pass.py +112 -0
  1914. executorch/backends/xnnpack/test/passes/test_propagate_custom_meta_pass.py +185 -0
  1915. executorch/backends/xnnpack/test/passes/test_remove_get_item_pass.py +99 -0
  1916. executorch/backends/xnnpack/test/passes/test_remove_redundant_copy_pass.py +182 -0
  1917. executorch/backends/xnnpack/test/quantizer/test_pt2e_quantization.py +818 -0
  1918. executorch/backends/xnnpack/test/quantizer/test_representation.py +308 -0
  1919. executorch/backends/xnnpack/test/quantizer/test_xnnpack_quantizer.py +1217 -0
  1920. executorch/backends/xnnpack/test/recipes/test_xnnpack_recipes.py +320 -0
  1921. executorch/backends/xnnpack/test/serialization/test_serialization.py +50 -0
  1922. executorch/backends/xnnpack/test/serialization/test_xnnheader.py +104 -0
  1923. executorch/backends/xnnpack/test/test_xnnpack_partitioner.py +163 -0
  1924. executorch/backends/xnnpack/test/test_xnnpack_utils.py +532 -0
  1925. executorch/backends/xnnpack/test/test_xnnpack_utils_classes.py +44 -0
  1926. executorch/backends/xnnpack/test/tester/__init__.py +29 -0
  1927. executorch/backends/xnnpack/test/tester/tester.py +130 -0
  1928. executorch/backends/xnnpack/third-party/FP16/configure.py +65 -0
  1929. executorch/backends/xnnpack/third-party/FP16/confu.yaml +8 -0
  1930. executorch/backends/xnnpack/third-party/FP16/include/fp16/__init__.py +0 -0
  1931. executorch/backends/xnnpack/third-party/FP16/include/fp16/avx.py +50 -0
  1932. executorch/backends/xnnpack/third-party/FP16/include/fp16/avx2.py +53 -0
  1933. executorch/backends/xnnpack/third-party/FP16/test/peachpy/stubs.py +38 -0
  1934. executorch/backends/xnnpack/third-party/FXdiv/configure.py +30 -0
  1935. executorch/backends/xnnpack/third-party/FXdiv/confu.yaml +6 -0
  1936. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/aarch32_template.py +361 -0
  1937. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/aarch64_template.py +347 -0
  1938. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/arm_template.py +78 -0
  1939. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512bf16_template.py +81 -0
  1940. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512f_template.py +390 -0
  1941. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/avx512vnni_template.py +703 -0
  1942. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/base_architecture.py +276 -0
  1943. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/fma3_template.py +260 -0
  1944. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate.py +71 -0
  1945. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_bf16_f32_gemm_microkernels.py +39 -0
  1946. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_f32_gemm_microkernels.py +104 -0
  1947. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_gemm_microkernels_main.py +29 -0
  1948. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qd8_f32_qc4w_gemm_microkernels.py +69 -0
  1949. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qd8_f32_qc8w_gemm_microkernels.py +93 -0
  1950. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qs8_qc4w_gemm_microkernels.py +42 -0
  1951. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/generate_qs8_qc8w_gemm_microkernels.py +43 -0
  1952. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neondot_template.py +463 -0
  1953. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neonfma_template.py +248 -0
  1954. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/neonmlal_aarch32_template.py +394 -0
  1955. executorch/backends/xnnpack/third-party/XNNPACK/gemm_compiler/x64_template.py +512 -0
  1956. executorch/backends/xnnpack/third-party/XNNPACK/scripts/check_config.py +152 -0
  1957. executorch/backends/xnnpack/third-party/XNNPACK/scripts/check_files_changed.py +53 -0
  1958. executorch/backends/xnnpack/third-party/XNNPACK/scripts/generate-build-identifier.py +106 -0
  1959. executorch/backends/xnnpack/third-party/XNNPACK/scripts/sort-filenames.py +134 -0
  1960. executorch/backends/xnnpack/third-party/XNNPACK/test/bf16-f32-gemm-minmax.yaml +121 -0
  1961. executorch/backends/xnnpack/third-party/XNNPACK/test/bf16-gemm-minmax.yaml +106 -0
  1962. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-conv-hwc2chw.yaml +8 -0
  1963. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-dwconv2d-chw.yaml +88 -0
  1964. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-f32acc-gemm-minmax.yaml +42 -0
  1965. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-f32acc-igemm-minmax.yaml +42 -0
  1966. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-gemm-minmax.yaml +219 -0
  1967. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-ibilinear-chw.yaml +9 -0
  1968. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-ibilinear.yaml +12 -0
  1969. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-igemm-minmax.yaml +165 -0
  1970. executorch/backends/xnnpack/third-party/XNNPACK/test/f16-raddstoreexpminusmax.yaml +52 -0
  1971. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-argmaxpool.yaml +15 -0
  1972. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-conv-hwc2chw.yaml +32 -0
  1973. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-dwconv2d-chw.yaml +712 -0
  1974. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm-minmax.yaml +1572 -0
  1975. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm-relu.yaml +123 -0
  1976. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-gemm.yaml +127 -0
  1977. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ibilinear-chw.yaml +22 -0
  1978. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ibilinear.yaml +23 -0
  1979. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm-minmax.yaml +1001 -0
  1980. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm-relu.yaml +123 -0
  1981. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-igemm.yaml +123 -0
  1982. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-ppmm-minmax.yaml +122 -0
  1983. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc4w-gemm-minmax.yaml +277 -0
  1984. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm-minmax.yaml +757 -0
  1985. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm-relu.yaml +67 -0
  1986. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-qc8w-gemm.yaml +115 -0
  1987. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-raddexpminusmax.yaml +38 -0
  1988. executorch/backends/xnnpack/third-party/XNNPACK/test/f32-raddstoreexpminusmax.yaml +88 -0
  1989. executorch/backends/xnnpack/third-party/XNNPACK/test/pf16-gemm-minmax.yaml +20 -0
  1990. executorch/backends/xnnpack/third-party/XNNPACK/test/pf32-gemm-minmax.yaml +34 -0
  1991. executorch/backends/xnnpack/third-party/XNNPACK/test/pqs8-qc8w-gemm-minmax.yaml +20 -0
  1992. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qb4w-gemm-minmax.yaml +260 -0
  1993. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc4w-gemm-minmax.yaml +678 -0
  1994. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc8w-gemm-minmax.yaml +412 -0
  1995. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f16-qc8w-igemm-minmax.yaml +360 -0
  1996. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qb4w-gemm-minmax.yaml +537 -0
  1997. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc4w-gemm-minmax.yaml +2176 -0
  1998. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc8w-gemm-minmax.yaml +1564 -0
  1999. executorch/backends/xnnpack/third-party/XNNPACK/test/qd8-f32-qc8w-igemm-minmax.yaml +1035 -0
  2000. executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qb4w-gemm-minmax.yaml +54 -0
  2001. executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qc4w-gemm-minmax.yaml +66 -0
  2002. executorch/backends/xnnpack/third-party/XNNPACK/test/qp8-f32-qc8w-gemm-minmax.yaml +42 -0
  2003. executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc4w-gemm-minmax-fp32.yaml +345 -0
  2004. executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc8w-gemm-minmax-fp32.yaml +2029 -0
  2005. executorch/backends/xnnpack/third-party/XNNPACK/test/qs8-qc8w-igemm-minmax-fp32.yaml +1831 -0
  2006. executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-gemm-minmax-fp32.yaml +584 -0
  2007. executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-gemm-minmax-rndnu.yaml +148 -0
  2008. executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-igemm-minmax-fp32.yaml +581 -0
  2009. executorch/backends/xnnpack/third-party/XNNPACK/test/qu8-igemm-minmax-rndnu.yaml +110 -0
  2010. executorch/backends/xnnpack/third-party/XNNPACK/test/s8-ibilinear.yaml +22 -0
  2011. executorch/backends/xnnpack/third-party/XNNPACK/test/u8-ibilinear.yaml +22 -0
  2012. executorch/backends/xnnpack/third-party/XNNPACK/test/x8-lut.yaml +47 -0
  2013. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-argmaxpool-test.py +692 -0
  2014. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-conv-hwc-test.py +543 -0
  2015. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-conv-hwc2chw-test.py +591 -0
  2016. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-dwconv-test.py +339 -0
  2017. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-dwconv2d-chw-test.py +463 -0
  2018. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-gemm-test.py +1150 -0
  2019. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-ibilinear-chw-test.py +236 -0
  2020. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-ibilinear-test.py +237 -0
  2021. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-lut-test.py +164 -0
  2022. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-raddexpminusmax-test.py +159 -0
  2023. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-raddstoreexpminusmax-test.py +210 -0
  2024. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-reduce-discontiguous-test.py +495 -0
  2025. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-reduce-test.py +289 -0
  2026. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-spmm-test.py +554 -0
  2027. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-vbinary-test.py +179 -0
  2028. executorch/backends/xnnpack/third-party/XNNPACK/tools/generate-vunary-test.py +280 -0
  2029. executorch/backends/xnnpack/third-party/XNNPACK/tools/parse-microkernel-bench.py +189 -0
  2030. executorch/backends/xnnpack/third-party/XNNPACK/tools/primes.py +1015 -0
  2031. executorch/backends/xnnpack/third-party/XNNPACK/tools/update-microkernels.py +567 -0
  2032. executorch/backends/xnnpack/third-party/XNNPACK/tools/xngen.py +159 -0
  2033. executorch/backends/xnnpack/third-party/XNNPACK/tools/xnncommon.py +275 -0
  2034. executorch/backends/xnnpack/third-party/cpuinfo/configure.py +110 -0
  2035. executorch/backends/xnnpack/third-party/cpuinfo/confu.yaml +9 -0
  2036. executorch/backends/xnnpack/third-party/cpuinfo/deps/clog/configure.py +26 -0
  2037. executorch/backends/xnnpack/third-party/cpuinfo/deps/clog/confu.yaml +5 -0
  2038. executorch/backends/xnnpack/third-party/cpuinfo/scripts/android-device-dump.py +400 -0
  2039. executorch/backends/xnnpack/third-party/cpuinfo/scripts/arm-linux-filesystem-dump.py +107 -0
  2040. executorch/backends/xnnpack/third-party/cpuinfo/scripts/parse-x86-cpuid-dump.py +47 -0
  2041. executorch/backends/xnnpack/third-party/generate-cpuinfo-wrappers.py +93 -0
  2042. executorch/backends/xnnpack/third-party/pthreadpool/configure.py +38 -0
  2043. executorch/backends/xnnpack/third-party/pthreadpool/confu.yaml +8 -0
  2044. executorch/backends/xnnpack/utils/configs.py +49 -0
  2045. executorch/backends/xnnpack/utils/quant_utils.py +301 -0
  2046. executorch/backends/xnnpack/utils/utils.py +221 -0
  2047. executorch/backends/xnnpack/utils/xnnpack_constants.py +37 -0
  2048. executorch/backends/xnnpack/xnnpack_preprocess.py +194 -0
  2049. executorch/codegen/__init__.py +0 -0
  2050. executorch/codegen/api/__init__.py +0 -0
  2051. executorch/codegen/api/custom_ops.py +151 -0
  2052. executorch/codegen/api/et_cpp.py +368 -0
  2053. executorch/codegen/api/types/__init__.py +5 -0
  2054. executorch/codegen/api/types/signatures.py +77 -0
  2055. executorch/codegen/api/types/types.py +77 -0
  2056. executorch/codegen/api/unboxing.py +232 -0
  2057. executorch/codegen/gen.py +1049 -0
  2058. executorch/codegen/model.py +220 -0
  2059. executorch/codegen/parse.py +158 -0
  2060. executorch/codegen/test/test_executorch_custom_ops.py +153 -0
  2061. executorch/codegen/test/test_executorch_gen.py +698 -0
  2062. executorch/codegen/test/test_executorch_signatures.py +65 -0
  2063. executorch/codegen/test/test_executorch_types.py +121 -0
  2064. executorch/codegen/test/test_executorch_unboxing.py +165 -0
  2065. executorch/codegen/test/test_selective_build.py +51 -0
  2066. executorch/codegen/tools/__init__.py +0 -0
  2067. executorch/codegen/tools/combine_prim_ops_headers.py +164 -0
  2068. executorch/codegen/tools/gen_all_oplist.py +252 -0
  2069. executorch/codegen/tools/gen_oplist.py +369 -0
  2070. executorch/codegen/tools/gen_ops_def.py +96 -0
  2071. executorch/codegen/tools/gen_selected_op_variants.py +133 -0
  2072. executorch/codegen/tools/gen_selected_prim_ops.py +96 -0
  2073. executorch/codegen/tools/merge_yaml.py +125 -0
  2074. executorch/codegen/tools/selective_build.cp313-win_amd64.pyd +0 -0
  2075. executorch/codegen/tools/selective_build.pyi +23 -0
  2076. executorch/codegen/tools/test/test_gen_all_oplist.py +122 -0
  2077. executorch/codegen/tools/test/test_gen_oplist.py +263 -0
  2078. executorch/codegen/tools/test/test_gen_oplist_real_model.py +50 -0
  2079. executorch/codegen/tools/test/test_gen_selected_op_variants.py +204 -0
  2080. executorch/codegen/tools/test/test_tools_selective_build.py +129 -0
  2081. executorch/codegen/tools/yaml_util.py +15 -0
  2082. executorch/data/bin/__init__.py +44 -0
  2083. executorch/data/bin/flatc.exe +0 -0
  2084. executorch/data/lib/aoti_cuda_shims.lib +0 -0
  2085. executorch/devtools/__init__.py +19 -0
  2086. executorch/devtools/backend_debug/__init__.py +13 -0
  2087. executorch/devtools/backend_debug/delegation_info.py +183 -0
  2088. executorch/devtools/backend_debug/tests/test_delegation_info.py +79 -0
  2089. executorch/devtools/bundled_program/config.py +120 -0
  2090. executorch/devtools/bundled_program/core.py +395 -0
  2091. executorch/devtools/bundled_program/schema/__init__.py +9 -0
  2092. executorch/devtools/bundled_program/schema/bundled_program_schema.fbs +97 -0
  2093. executorch/devtools/bundled_program/schema/bundled_program_schema.py +99 -0
  2094. executorch/devtools/bundled_program/schema/scalar_type.fbs +43 -0
  2095. executorch/devtools/bundled_program/schema/test/test_schema.py +27 -0
  2096. executorch/devtools/bundled_program/serialize/__init__.py +122 -0
  2097. executorch/devtools/bundled_program/serialize/bundled_program_schema.fbs +97 -0
  2098. executorch/devtools/bundled_program/serialize/scalar_type.fbs +43 -0
  2099. executorch/devtools/bundled_program/serialize/test/test_serialize.py +37 -0
  2100. executorch/devtools/bundled_program/test/test_bundle_data.py +168 -0
  2101. executorch/devtools/bundled_program/test/test_config.py +131 -0
  2102. executorch/devtools/bundled_program/test/test_end2end.py +64 -0
  2103. executorch/devtools/bundled_program/util/test_util.py +289 -0
  2104. executorch/devtools/bundled_program/version.py +13 -0
  2105. executorch/devtools/debug_format/base_schema.py +61 -0
  2106. executorch/devtools/debug_format/et_schema.py +432 -0
  2107. executorch/devtools/etdump/etdump_schema_flatcc.fbs +181 -0
  2108. executorch/devtools/etdump/scalar_type.fbs +43 -0
  2109. executorch/devtools/etdump/schema_flatcc.py +154 -0
  2110. executorch/devtools/etdump/serialize.py +108 -0
  2111. executorch/devtools/etdump/tests/serialize_test.py +142 -0
  2112. executorch/devtools/etrecord/__init__.py +13 -0
  2113. executorch/devtools/etrecord/_etrecord.py +776 -0
  2114. executorch/devtools/etrecord/tests/etrecord_test.py +1748 -0
  2115. executorch/devtools/inspector/__init__.py +24 -0
  2116. executorch/devtools/inspector/_inspector.py +1495 -0
  2117. executorch/devtools/inspector/_inspector_utils.py +1286 -0
  2118. executorch/devtools/inspector/_intermediate_output_capturer.py +62 -0
  2119. executorch/devtools/inspector/inspector_cli.py +76 -0
  2120. executorch/devtools/inspector/numerical_comparator/__init__.py +25 -0
  2121. executorch/devtools/inspector/numerical_comparator/l1_numerical_comparator.py +27 -0
  2122. executorch/devtools/inspector/numerical_comparator/mse_numerical_comparator.py +29 -0
  2123. executorch/devtools/inspector/numerical_comparator/numerical_comparator_base.py +26 -0
  2124. executorch/devtools/inspector/numerical_comparator/snr_numerical_comparator.py +39 -0
  2125. executorch/devtools/inspector/tests/event_blocks_test.py +657 -0
  2126. executorch/devtools/inspector/tests/inspector_test.py +1263 -0
  2127. executorch/devtools/inspector/tests/inspector_test_utils.py +189 -0
  2128. executorch/devtools/inspector/tests/inspector_utils_test.py +896 -0
  2129. executorch/devtools/inspector/tests/intermediate_output_capturer_test.py +101 -0
  2130. executorch/devtools/inspector/tests/l1_comparator_test.py +49 -0
  2131. executorch/devtools/inspector/tests/mse_comparator_test.py +49 -0
  2132. executorch/devtools/inspector/tests/snr_comparator_test.py +52 -0
  2133. executorch/devtools/scripts/generate_profiling_csv.py +62 -0
  2134. executorch/devtools/size_analysis_tool/size_analysis_tool.py +180 -0
  2135. executorch/devtools/size_analysis_tool/size_analysis_tool_test.py +101 -0
  2136. executorch/devtools/visualization/__init__.py +13 -0
  2137. executorch/devtools/visualization/visualization_utils.py +301 -0
  2138. executorch/devtools/visualization/visualization_utils_test.py +177 -0
  2139. executorch/examples/apple/coreml/llama/export.py +224 -0
  2140. executorch/examples/apple/coreml/llama/export_static_llm_coreml.py +504 -0
  2141. executorch/examples/apple/coreml/llama/llama_transformer.py +958 -0
  2142. executorch/examples/apple/coreml/llama/run.py +206 -0
  2143. executorch/examples/apple/coreml/llama/run_lookahead.py +284 -0
  2144. executorch/examples/apple/coreml/llama/run_static_llm.py +293 -0
  2145. executorch/examples/apple/coreml/llama/test.py +48 -0
  2146. executorch/examples/apple/coreml/llama/utils.py +116 -0
  2147. executorch/examples/apple/coreml/scripts/debugger_cli.py +181 -0
  2148. executorch/examples/apple/coreml/scripts/export.py +280 -0
  2149. executorch/examples/apple/coreml/scripts/extract_coreml_models.py +77 -0
  2150. executorch/examples/apple/coreml/scripts/inspector_cli.py +64 -0
  2151. executorch/examples/apple/coreml/scripts/inspector_utils.py +425 -0
  2152. executorch/examples/apple/mps/scripts/bench_utils.py +108 -0
  2153. executorch/examples/apple/mps/scripts/mps_example.py +230 -0
  2154. executorch/examples/cuda/scripts/__init__.py +0 -0
  2155. executorch/examples/cuda/scripts/export.py +107 -0
  2156. executorch/examples/llm_pte_finetuning/__init__.py +19 -0
  2157. executorch/examples/llm_pte_finetuning/llama3_config.yaml +96 -0
  2158. executorch/examples/llm_pte_finetuning/model_exporter.py +87 -0
  2159. executorch/examples/llm_pte_finetuning/model_loading_lib.py +143 -0
  2160. executorch/examples/llm_pte_finetuning/phi3_alpaca_code_config.yaml +44 -0
  2161. executorch/examples/llm_pte_finetuning/phi3_config.yaml +42 -0
  2162. executorch/examples/llm_pte_finetuning/qwen_05b_config.yaml +43 -0
  2163. executorch/examples/llm_pte_finetuning/runner.py +135 -0
  2164. executorch/examples/llm_pte_finetuning/training_lib.py +157 -0
  2165. executorch/examples/models/__init__.py +98 -0
  2166. executorch/examples/models/checkpoint.py +114 -0
  2167. executorch/examples/models/codegen/__init__.py +16 -0
  2168. executorch/examples/models/codegen/convert_weight.py +93 -0
  2169. executorch/examples/models/deeplab_v3/__init__.py +9 -0
  2170. executorch/examples/models/deeplab_v3/model.py +50 -0
  2171. executorch/examples/models/deepseek-r1-distill-llama-8B/config/deepseek_xnnpack_q8da4w.yaml +16 -0
  2172. executorch/examples/models/deit_tiny/__init__.py +8 -0
  2173. executorch/examples/models/deit_tiny/model.py +36 -0
  2174. executorch/examples/models/edsr/__init__.py +11 -0
  2175. executorch/examples/models/edsr/model.py +28 -0
  2176. executorch/examples/models/efficient_sam/__init__.py +11 -0
  2177. executorch/examples/models/efficient_sam/efficient_sam_core/build_efficient_sam.py +25 -0
  2178. executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam.py +316 -0
  2179. executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam_decoder.py +373 -0
  2180. executorch/examples/models/efficient_sam/efficient_sam_core/efficient_sam_encoder.py +261 -0
  2181. executorch/examples/models/efficient_sam/efficient_sam_core/mlp.py +31 -0
  2182. executorch/examples/models/efficient_sam/efficient_sam_core/two_way_transformer.py +268 -0
  2183. executorch/examples/models/efficient_sam/model.py +34 -0
  2184. executorch/examples/models/emformer_rnnt/__init__.py +17 -0
  2185. executorch/examples/models/emformer_rnnt/model.py +132 -0
  2186. executorch/examples/models/gemma/__init__.py +16 -0
  2187. executorch/examples/models/gemma/convert_weights.py +104 -0
  2188. executorch/examples/models/gemma2/__init__.py +19 -0
  2189. executorch/examples/models/gemma2/convert_weights.py +113 -0
  2190. executorch/examples/models/gemma3/__init__.py +16 -0
  2191. executorch/examples/models/gemma3/convert_weights.py +110 -0
  2192. executorch/examples/models/glm/__init__.py +16 -0
  2193. executorch/examples/models/glm/convert_weights.py +79 -0
  2194. executorch/examples/models/granite/__init__.py +16 -0
  2195. executorch/examples/models/granite/convert_weights.py +106 -0
  2196. executorch/examples/models/inception_v3/__init__.py +11 -0
  2197. executorch/examples/models/inception_v3/model.py +28 -0
  2198. executorch/examples/models/inception_v4/__init__.py +11 -0
  2199. executorch/examples/models/inception_v4/model.py +26 -0
  2200. executorch/examples/models/internvl3/__init__.py +16 -0
  2201. executorch/examples/models/internvl3/convert_weights.py +82 -0
  2202. executorch/examples/models/lfm2/__init__.py +10 -0
  2203. executorch/examples/models/lfm2/config/lfm2_xnnpack_fp32.yaml +12 -0
  2204. executorch/examples/models/lfm2/config/lfm2_xnnpack_q8da4w.yaml +15 -0
  2205. executorch/examples/models/lfm2/convert_weights.py +74 -0
  2206. executorch/examples/models/lfm2/short_conv.py +112 -0
  2207. executorch/examples/models/llama/__init__.py +11 -0
  2208. executorch/examples/models/llama/attention.py +536 -0
  2209. executorch/examples/models/llama/config/llama_bf16.yaml +7 -0
  2210. executorch/examples/models/llama/config/llama_q8da4w.yaml +11 -0
  2211. executorch/examples/models/llama/config/llama_xnnpack.yaml +17 -0
  2212. executorch/examples/models/llama/config/llama_xnnpack_qat.yaml +23 -0
  2213. executorch/examples/models/llama/config/llama_xnnpack_spinquant.yaml +22 -0
  2214. executorch/examples/models/llama/config/test_llm_config.py +104 -0
  2215. executorch/examples/models/llama/convert_weights.py +61 -0
  2216. executorch/examples/models/llama/eval_llama.py +38 -0
  2217. executorch/examples/models/llama/eval_llama_lib.py +395 -0
  2218. executorch/examples/models/llama/evaluate/__init__.py +11 -0
  2219. executorch/examples/models/llama/evaluate/eager_eval.py +87 -0
  2220. executorch/examples/models/llama/experimental/__init__.py +0 -0
  2221. executorch/examples/models/llama/experimental/generate.py +190 -0
  2222. executorch/examples/models/llama/experimental/load_gguf_q4_0.py +184 -0
  2223. executorch/examples/models/llama/experimental/subclass.py +413 -0
  2224. executorch/examples/models/llama/experimental/test_subclass.py +28 -0
  2225. executorch/examples/models/llama/export_llama.py +56 -0
  2226. executorch/examples/models/llama/export_llama_lib.py +1560 -0
  2227. executorch/examples/models/llama/fairseq2.py +63 -0
  2228. executorch/examples/models/llama/feed_forward.py +68 -0
  2229. executorch/examples/models/llama/hf_download.py +50 -0
  2230. executorch/examples/models/llama/install_requirement_helper.py +29 -0
  2231. executorch/examples/models/llama/llama_transformer.py +289 -0
  2232. executorch/examples/models/llama/lora.py +48 -0
  2233. executorch/examples/models/llama/model.py +378 -0
  2234. executorch/examples/models/llama/model_args.py +173 -0
  2235. executorch/examples/models/llama/norm.py +55 -0
  2236. executorch/examples/models/llama/rope.py +327 -0
  2237. executorch/examples/models/llama/runner/eager.py +142 -0
  2238. executorch/examples/models/llama/runner/generation.py +234 -0
  2239. executorch/examples/models/llama/runner/native.py +145 -0
  2240. executorch/examples/models/llama/source_transformation/__init__.py +0 -0
  2241. executorch/examples/models/llama/source_transformation/apply_spin_quant_r1_r2.py +202 -0
  2242. executorch/examples/models/llama/source_transformation/attention.py +223 -0
  2243. executorch/examples/models/llama/source_transformation/attention_sink.py +312 -0
  2244. executorch/examples/models/llama/source_transformation/custom_kv_cache.py +598 -0
  2245. executorch/examples/models/llama/source_transformation/lora.py +153 -0
  2246. executorch/examples/models/llama/source_transformation/pre_quantization.py +204 -0
  2247. executorch/examples/models/llama/source_transformation/prune_vocab.py +119 -0
  2248. executorch/examples/models/llama/source_transformation/quantize.py +910 -0
  2249. executorch/examples/models/llama/source_transformation/rms_norm.py +23 -0
  2250. executorch/examples/models/llama/source_transformation/rope.py +39 -0
  2251. executorch/examples/models/llama/source_transformation/sdpa.py +550 -0
  2252. executorch/examples/models/llama/source_transformation/spin_quant.py +88 -0
  2253. executorch/examples/models/llama/source_transformation/test_attention_sink.py +514 -0
  2254. executorch/examples/models/llama/source_transformation/test_quantized_kv_cache.py +126 -0
  2255. executorch/examples/models/llama/source_transformation/test_quantized_sdpa.py +167 -0
  2256. executorch/examples/models/llama/source_transformation/test_sdpa_with_quantized_kv_cache.py +97 -0
  2257. executorch/examples/models/llama/static_attention.py +1257 -0
  2258. executorch/examples/models/llama/tests/test_export_llama_lib.py +50 -0
  2259. executorch/examples/models/llama/tests/test_pre_quantization_transforms.py +188 -0
  2260. executorch/examples/models/llama/tests/test_replace_kv_cache.py +158 -0
  2261. executorch/examples/models/llama/tests/test_ring_attention.py +359 -0
  2262. executorch/examples/models/llama/tests/test_ring_kv_cache.py +492 -0
  2263. executorch/examples/models/llama/tests/test_simple_sdpa.py +66 -0
  2264. executorch/examples/models/llama/tests/test_static_attention.py +363 -0
  2265. executorch/examples/models/llama/tokenizer/tiktoken.py +224 -0
  2266. executorch/examples/models/llama3_2_vision/__init__.py +14 -0
  2267. executorch/examples/models/llama3_2_vision/preprocess/__init__.py +0 -0
  2268. executorch/examples/models/llama3_2_vision/preprocess/export_preprocess.py +45 -0
  2269. executorch/examples/models/llama3_2_vision/preprocess/model.py +72 -0
  2270. executorch/examples/models/llama3_2_vision/preprocess/test_preprocess.py +338 -0
  2271. executorch/examples/models/llama3_2_vision/runner/eager.py +59 -0
  2272. executorch/examples/models/llama3_2_vision/runner/exported.py +94 -0
  2273. executorch/examples/models/llama3_2_vision/runner/generation.py +102 -0
  2274. executorch/examples/models/llama3_2_vision/runner/native.py +143 -0
  2275. executorch/examples/models/llama3_2_vision/text_decoder/model.py +199 -0
  2276. executorch/examples/models/llama3_2_vision/text_decoder/test/__init__.py +0 -0
  2277. executorch/examples/models/llama3_2_vision/text_decoder/test/test_text_decoder.py +89 -0
  2278. executorch/examples/models/llama3_2_vision/vision_encoder/__init__.py +12 -0
  2279. executorch/examples/models/llama3_2_vision/vision_encoder/model.py +96 -0
  2280. executorch/examples/models/llama3_2_vision/vision_encoder/test/__init__.py +0 -0
  2281. executorch/examples/models/llama3_2_vision/vision_encoder/test/test_vision_encoder.py +46 -0
  2282. executorch/examples/models/llava/__init__.py +11 -0
  2283. executorch/examples/models/llava/export_llava.py +365 -0
  2284. executorch/examples/models/llava/model.py +415 -0
  2285. executorch/examples/models/llava/test/test_llava.py +151 -0
  2286. executorch/examples/models/llava/test/test_pte.py +106 -0
  2287. executorch/examples/models/lstm/__init__.py +12 -0
  2288. executorch/examples/models/lstm/model.py +31 -0
  2289. executorch/examples/models/mobilebert/__init__.py +11 -0
  2290. executorch/examples/models/mobilebert/model.py +31 -0
  2291. executorch/examples/models/mobilenet_v2/__init__.py +12 -0
  2292. executorch/examples/models/mobilenet_v2/model.py +73 -0
  2293. executorch/examples/models/mobilenet_v3/__init__.py +11 -0
  2294. executorch/examples/models/mobilenet_v3/model.py +30 -0
  2295. executorch/examples/models/model_base.py +47 -0
  2296. executorch/examples/models/model_factory.py +60 -0
  2297. executorch/examples/models/moshi/mimi/test_mimi.py +245 -0
  2298. executorch/examples/models/parakeet/export_parakeet_tdt.py +591 -0
  2299. executorch/examples/models/phi-3-mini/__init__.py +11 -0
  2300. executorch/examples/models/phi-3-mini-lora/export_model.py +144 -0
  2301. executorch/examples/models/phi_4_mini/__init__.py +16 -0
  2302. executorch/examples/models/phi_4_mini/config/phi_4_mini_xnnpack.yaml +12 -0
  2303. executorch/examples/models/phi_4_mini/convert_weights.py +151 -0
  2304. executorch/examples/models/qwen2_5/__init__.py +16 -0
  2305. executorch/examples/models/qwen2_5/config/qwen2_5_xnnpack_q8da4w.yaml +14 -0
  2306. executorch/examples/models/qwen2_5/convert_weights.py +90 -0
  2307. executorch/examples/models/qwen3/__init__.py +16 -0
  2308. executorch/examples/models/qwen3/config/qwen3_xnnpack.yaml +18 -0
  2309. executorch/examples/models/qwen3/config/qwen3_xnnpack_q8da4w.yaml +20 -0
  2310. executorch/examples/models/qwen3/convert_weights.py +140 -0
  2311. executorch/examples/models/resnet/__init__.py +12 -0
  2312. executorch/examples/models/resnet/model.py +48 -0
  2313. executorch/examples/models/smollm2/__init__.py +16 -0
  2314. executorch/examples/models/smollm2/convert_weights.py +84 -0
  2315. executorch/examples/models/smollm3/__init__.py +16 -0
  2316. executorch/examples/models/smollm3/convert_weights.py +112 -0
  2317. executorch/examples/models/smolvlm/__init__.py +16 -0
  2318. executorch/examples/models/smolvlm/convert_weights.py +77 -0
  2319. executorch/examples/models/stable_diffusion/__init__.py +9 -0
  2320. executorch/examples/models/stable_diffusion/model.py +193 -0
  2321. executorch/examples/models/test/__init__.py +0 -0
  2322. executorch/examples/models/test/test_export.py +161 -0
  2323. executorch/examples/models/torchvision_vit/__init__.py +11 -0
  2324. executorch/examples/models/torchvision_vit/model.py +28 -0
  2325. executorch/examples/models/toy_model/__init__.py +25 -0
  2326. executorch/examples/models/toy_model/model.py +143 -0
  2327. executorch/examples/models/wav2letter/__init__.py +11 -0
  2328. executorch/examples/models/wav2letter/model.py +29 -0
  2329. executorch/examples/models/yolo12/export_and_validate.py +397 -0
  2330. executorch/examples/nxp/experimental/cifar_net/cifar_net.py +270 -0
  2331. executorch/examples/xnnpack/__init__.py +51 -0
  2332. executorch/examples/xnnpack/aot_compiler.py +148 -0
  2333. executorch/examples/xnnpack/quantization/example.py +205 -0
  2334. executorch/examples/xnnpack/quantization/utils.py +42 -0
  2335. executorch/exir/__init__.py +57 -0
  2336. executorch/exir/_serialize/__init__.py +20 -0
  2337. executorch/exir/_serialize/_cord.py +49 -0
  2338. executorch/exir/_serialize/_dataclass.py +145 -0
  2339. executorch/exir/_serialize/_flatbuffer.py +357 -0
  2340. executorch/exir/_serialize/_named_data_store.py +222 -0
  2341. executorch/exir/_serialize/_program.py +767 -0
  2342. executorch/exir/_serialize/_serialize.py +123 -0
  2343. executorch/exir/_serialize/data_serializer.py +80 -0
  2344. executorch/exir/_serialize/padding.py +39 -0
  2345. executorch/exir/_serialize/program.fbs +489 -0
  2346. executorch/exir/_serialize/scalar_type.fbs +43 -0
  2347. executorch/exir/_serialize/test/__init__.py +0 -0
  2348. executorch/exir/_serialize/test/test_cord.py +63 -0
  2349. executorch/exir/_serialize/test/test_flatbuffer.py +331 -0
  2350. executorch/exir/_serialize/test/test_named_data_store.py +212 -0
  2351. executorch/exir/_serialize/test/test_program.py +1265 -0
  2352. executorch/exir/_serialize/test/test_serialize.py +289 -0
  2353. executorch/exir/_warnings.py +44 -0
  2354. executorch/exir/backend/backend_api.py +794 -0
  2355. executorch/exir/backend/backend_details.py +150 -0
  2356. executorch/exir/backend/canonical_partitioners/all_node_partitioner.py +55 -0
  2357. executorch/exir/backend/canonical_partitioners/config_partitioner.py +262 -0
  2358. executorch/exir/backend/canonical_partitioners/duplicate_constant_node_pass.py +156 -0
  2359. executorch/exir/backend/canonical_partitioners/duplicate_dequant_node_pass.py +111 -0
  2360. executorch/exir/backend/canonical_partitioners/group_partitioner.py +371 -0
  2361. executorch/exir/backend/canonical_partitioners/pattern_op_partitioner.py +185 -0
  2362. executorch/exir/backend/compile_spec_schema.py +17 -0
  2363. executorch/exir/backend/operator_support.py +127 -0
  2364. executorch/exir/backend/partitioner.py +114 -0
  2365. executorch/exir/backend/test/backend_with_compiler_demo.py +142 -0
  2366. executorch/exir/backend/test/backend_with_delegate_mapping_demo.py +210 -0
  2367. executorch/exir/backend/test/backend_with_named_data_map.py +115 -0
  2368. executorch/exir/backend/test/backend_with_preprocess_all_demo.py +297 -0
  2369. executorch/exir/backend/test/demo_backend.py +35 -0
  2370. executorch/exir/backend/test/demos/rpc/executor_backend_partitioner.py +77 -0
  2371. executorch/exir/backend/test/demos/rpc/executor_backend_preprocess.py +39 -0
  2372. executorch/exir/backend/test/demos/rpc/test_rpc.py +189 -0
  2373. executorch/exir/backend/test/demos/test_delegate_aten_mode.py +72 -0
  2374. executorch/exir/backend/test/hta_partitioner_demo.py +288 -0
  2375. executorch/exir/backend/test/op_partitioner_demo.py +266 -0
  2376. executorch/exir/backend/test/test_backend_with_named_data_map.py +85 -0
  2377. executorch/exir/backend/test/test_backends.py +1463 -0
  2378. executorch/exir/backend/test/test_backends_lifted.py +1326 -0
  2379. executorch/exir/backend/test/test_backends_nested.py +258 -0
  2380. executorch/exir/backend/test/test_compatibility.py +118 -0
  2381. executorch/exir/backend/test/test_debug_handle_map.py +143 -0
  2382. executorch/exir/backend/test/test_delegate_map_builder.py +257 -0
  2383. executorch/exir/backend/test/test_graph_partition.py +248 -0
  2384. executorch/exir/backend/test/test_group_partitioner.py +1674 -0
  2385. executorch/exir/backend/test/test_lowered_backend_module.py +207 -0
  2386. executorch/exir/backend/test/test_partitioner.py +731 -0
  2387. executorch/exir/backend/test/test_passes.py +48 -0
  2388. executorch/exir/backend/test/test_to_backend_multi_method.py +595 -0
  2389. executorch/exir/backend/test/test_utils.py +264 -0
  2390. executorch/exir/backend/utils.py +661 -0
  2391. executorch/exir/capture/__init__.py +28 -0
  2392. executorch/exir/capture/_capture.py +381 -0
  2393. executorch/exir/capture/_config.py +119 -0
  2394. executorch/exir/capture/_unlift.py +159 -0
  2395. executorch/exir/common.py +140 -0
  2396. executorch/exir/control_flow.py +204 -0
  2397. executorch/exir/debug_handle_utils.py +29 -0
  2398. executorch/exir/delegate.py +171 -0
  2399. executorch/exir/delegate.pyi +21 -0
  2400. executorch/exir/dialects/__init__.py +0 -0
  2401. executorch/exir/dialects/_ops.py +166 -0
  2402. executorch/exir/dialects/backend/_ops.py +123 -0
  2403. executorch/exir/dialects/backend/test/test_backend_ops.py +88 -0
  2404. executorch/exir/dialects/edge/_ops.py +405 -0
  2405. executorch/exir/dialects/edge/arg/model.py +238 -0
  2406. executorch/exir/dialects/edge/arg/type.py +46 -0
  2407. executorch/exir/dialects/edge/dtype/runner.py +122 -0
  2408. executorch/exir/dialects/edge/dtype/supported.py +47 -0
  2409. executorch/exir/dialects/edge/dtype/utils.py +36 -0
  2410. executorch/exir/dialects/edge/edge.yaml +8388 -0
  2411. executorch/exir/dialects/edge/op/api.py +86 -0
  2412. executorch/exir/dialects/edge/op/sample_input.py +1283 -0
  2413. executorch/exir/dialects/edge/op/test/test_api.py +51 -0
  2414. executorch/exir/dialects/edge/spec/gen.py +523 -0
  2415. executorch/exir/dialects/edge/spec/utils.py +328 -0
  2416. executorch/exir/dialects/edge/test/test_edge_ops.py +443 -0
  2417. executorch/exir/dialects/edge/test/test_edge_yaml.py +225 -0
  2418. executorch/exir/dialects/test/test_exir_dialect_ops.py +22 -0
  2419. executorch/exir/dim_order_utils.py +85 -0
  2420. executorch/exir/dynamic_shape.py +12 -0
  2421. executorch/exir/emit/__init__.py +11 -0
  2422. executorch/exir/emit/_emit_program.py +216 -0
  2423. executorch/exir/emit/_emitter.py +2071 -0
  2424. executorch/exir/emit/test/test_emit.py +2405 -0
  2425. executorch/exir/error.py +55 -0
  2426. executorch/exir/graph.py +86 -0
  2427. executorch/exir/graph_module.py +153 -0
  2428. executorch/exir/lowered_backend_module.py +966 -0
  2429. executorch/exir/memory.py +50 -0
  2430. executorch/exir/memory_planning.py +1250 -0
  2431. executorch/exir/operator/convert.py +307 -0
  2432. executorch/exir/operator/manip.py +89 -0
  2433. executorch/exir/operator/test/test_operator.py +84 -0
  2434. executorch/exir/operator/util.py +68 -0
  2435. executorch/exir/pass_base.py +808 -0
  2436. executorch/exir/pass_manager.py +78 -0
  2437. executorch/exir/passes/__init__.py +528 -0
  2438. executorch/exir/passes/_quant_patterns_and_replacements.py +1563 -0
  2439. executorch/exir/passes/const_prop_pass.py +84 -0
  2440. executorch/exir/passes/constant_prop_pass.py +402 -0
  2441. executorch/exir/passes/debug_handle_generator_pass.py +81 -0
  2442. executorch/exir/passes/dim_order_ops_registry.py +90 -0
  2443. executorch/exir/passes/dynamic_shape_prop_pass.py +301 -0
  2444. executorch/exir/passes/executorch_prim_ops_registry.py +166 -0
  2445. executorch/exir/passes/external_constants_pass.py +113 -0
  2446. executorch/exir/passes/init_mutable_pass.py +32 -0
  2447. executorch/exir/passes/insert_write_back_for_buffers_pass.py +185 -0
  2448. executorch/exir/passes/memory_format_ops_pass.py +119 -0
  2449. executorch/exir/passes/memory_planning_pass.py +315 -0
  2450. executorch/exir/passes/normalize_transpose_pass.py +24 -0
  2451. executorch/exir/passes/normalize_view_copy_base_pass.py +62 -0
  2452. executorch/exir/passes/pass_registry.py +89 -0
  2453. executorch/exir/passes/prune_empty_tensors_pass.py +67 -0
  2454. executorch/exir/passes/quant_fusion_pass.py +174 -0
  2455. executorch/exir/passes/quantize_io_pass.py +414 -0
  2456. executorch/exir/passes/reinplace.py +103 -0
  2457. executorch/exir/passes/remove_graph_asserts_pass.py +62 -0
  2458. executorch/exir/passes/remove_mixed_type_operators.py +95 -0
  2459. executorch/exir/passes/remove_noop_pass.py +123 -0
  2460. executorch/exir/passes/remove_unused_parameters_pass.py +55 -0
  2461. executorch/exir/passes/replace_aten_with_edge_pass.py +59 -0
  2462. executorch/exir/passes/replace_broken_ops_with_function_ops_pass.py +42 -0
  2463. executorch/exir/passes/replace_edge_with_backend_pass.py +56 -0
  2464. executorch/exir/passes/replace_sym_size_op_pass.py +35 -0
  2465. executorch/exir/passes/replace_view_copy_with_view_pass.py +325 -0
  2466. executorch/exir/passes/scalar_to_tensor_pass.py +32 -0
  2467. executorch/exir/passes/spec_prop_pass.py +123 -0
  2468. executorch/exir/passes/sym_shape_eval_pass.py +289 -0
  2469. executorch/exir/passes/sym_to_tensor_pass.py +64 -0
  2470. executorch/exir/passes/weights_to_outputs_pass.py +88 -0
  2471. executorch/exir/print_program.py +420 -0
  2472. executorch/exir/program/__init__.py +32 -0
  2473. executorch/exir/program/_fake_program.py +67 -0
  2474. executorch/exir/program/_program.py +1995 -0
  2475. executorch/exir/program/test/__init__.py +0 -0
  2476. executorch/exir/program/test/test_fake_program.py +78 -0
  2477. executorch/exir/program/test/test_program.py +922 -0
  2478. executorch/exir/scalar_type.py +38 -0
  2479. executorch/exir/schema.py +308 -0
  2480. executorch/exir/serde/__init__.py +0 -0
  2481. executorch/exir/serde/export_serialize.py +2872 -0
  2482. executorch/exir/serde/schema.py +406 -0
  2483. executorch/exir/serde/schema_check.py +293 -0
  2484. executorch/exir/serde/serialize.py +838 -0
  2485. executorch/exir/serde/union.py +77 -0
  2486. executorch/exir/sym_util.py +95 -0
  2487. executorch/exir/tensor.py +392 -0
  2488. executorch/exir/tensor_layout.py +39 -0
  2489. executorch/exir/tests/asr_joiner.py +82 -0
  2490. executorch/exir/tests/common.py +96 -0
  2491. executorch/exir/tests/control_flow_models.py +105 -0
  2492. executorch/exir/tests/dynamic_shape_models.py +51 -0
  2493. executorch/exir/tests/models.py +576 -0
  2494. executorch/exir/tests/test_arg_validator.py +72 -0
  2495. executorch/exir/tests/test_capture.py +29 -0
  2496. executorch/exir/tests/test_common.py +81 -0
  2497. executorch/exir/tests/test_delegate.py +308 -0
  2498. executorch/exir/tests/test_dim_order_utils.py +49 -0
  2499. executorch/exir/tests/test_dynamic_shape_propagation.py +174 -0
  2500. executorch/exir/tests/test_error.py +19 -0
  2501. executorch/exir/tests/test_extract_io_quant_params.py +93 -0
  2502. executorch/exir/tests/test_joint_graph.py +124 -0
  2503. executorch/exir/tests/test_memory_format_ops_pass.py +443 -0
  2504. executorch/exir/tests/test_memory_format_ops_pass_aten.py +142 -0
  2505. executorch/exir/tests/test_memory_format_ops_pass_utils.py +266 -0
  2506. executorch/exir/tests/test_memory_planning.py +1135 -0
  2507. executorch/exir/tests/test_op_convert.py +88 -0
  2508. executorch/exir/tests/test_pass_infra.py +179 -0
  2509. executorch/exir/tests/test_passes.py +2332 -0
  2510. executorch/exir/tests/test_print_program.py +54 -0
  2511. executorch/exir/tests/test_prune_empty_tensors_pass.py +77 -0
  2512. executorch/exir/tests/test_quant_fusion_pass.py +528 -0
  2513. executorch/exir/tests/test_quantization.py +120 -0
  2514. executorch/exir/tests/test_quantize_io_pass.py +156 -0
  2515. executorch/exir/tests/test_reinplace_pass.py +124 -0
  2516. executorch/exir/tests/test_remove_unused_parameters_pass.py +205 -0
  2517. executorch/exir/tests/test_remove_view_copy.py +234 -0
  2518. executorch/exir/tests/test_serde.py +352 -0
  2519. executorch/exir/tests/test_tensor.py +341 -0
  2520. executorch/exir/tests/test_tracer.py +497 -0
  2521. executorch/exir/tests/test_verification.py +275 -0
  2522. executorch/exir/tests/test_warnings.py +169 -0
  2523. executorch/exir/tests/transformer.py +122 -0
  2524. executorch/exir/tracer.py +803 -0
  2525. executorch/exir/types.py +18 -0
  2526. executorch/exir/verification/arg_validator.py +140 -0
  2527. executorch/exir/verification/dev_html.py +68 -0
  2528. executorch/exir/verification/interpreter.py +425 -0
  2529. executorch/exir/verification/test/test_verifier.py +177 -0
  2530. executorch/exir/verification/verifier.py +352 -0
  2531. executorch/exir/version.py +9 -0
  2532. executorch/exir/wrap.py +32 -0
  2533. executorch/export/__init__.py +40 -0
  2534. executorch/export/export.py +696 -0
  2535. executorch/export/recipe.py +328 -0
  2536. executorch/export/recipe_provider.py +60 -0
  2537. executorch/export/recipe_registry.py +86 -0
  2538. executorch/export/stages.py +686 -0
  2539. executorch/export/target_recipes.py +185 -0
  2540. executorch/export/tests/test_executorch_export.py +34 -0
  2541. executorch/export/tests/test_export_recipe.py +131 -0
  2542. executorch/export/tests/test_export_session.py +973 -0
  2543. executorch/export/tests/test_export_stages.py +534 -0
  2544. executorch/export/tests/test_recipe_provider.py +98 -0
  2545. executorch/export/tests/test_recipe_registry.py +139 -0
  2546. executorch/export/tests/test_target_recipes.py +539 -0
  2547. executorch/export/types.py +22 -0
  2548. executorch/export/utils.py +51 -0
  2549. executorch/extension/audio/mel_spectrogram.py +279 -0
  2550. executorch/extension/export_util/__init__.py +13 -0
  2551. executorch/extension/export_util/utils.py +147 -0
  2552. executorch/extension/flat_tensor/__init__.py +0 -0
  2553. executorch/extension/flat_tensor/serialize/__init__.py +0 -0
  2554. executorch/extension/flat_tensor/serialize/flat_tensor.fbs +73 -0
  2555. executorch/extension/flat_tensor/serialize/flat_tensor_schema.py +34 -0
  2556. executorch/extension/flat_tensor/serialize/scalar_type.fbs +38 -0
  2557. executorch/extension/flat_tensor/serialize/serialize.py +446 -0
  2558. executorch/extension/flat_tensor/test/test_serialize.py +326 -0
  2559. executorch/extension/gguf_util/convert_main.py +53 -0
  2560. executorch/extension/gguf_util/converter.py +27 -0
  2561. executorch/extension/gguf_util/converters/llama_converter.py +123 -0
  2562. executorch/extension/gguf_util/load_gguf.py +103 -0
  2563. executorch/extension/llm/custom_ops/__init__.py +0 -0
  2564. executorch/extension/llm/custom_ops/custom_ops.py +495 -0
  2565. executorch/extension/llm/custom_ops/custom_ops_aot_lib.dll +0 -0
  2566. executorch/extension/llm/custom_ops/model_sharding.py +117 -0
  2567. executorch/extension/llm/custom_ops/op_tile_crop_aot.py +38 -0
  2568. executorch/extension/llm/custom_ops/preprocess_custom_ops.py +69 -0
  2569. executorch/extension/llm/custom_ops/spinquant/special_hadamard_code_gen.py +279 -0
  2570. executorch/extension/llm/custom_ops/spinquant/third-party/FFHT/example.py +20 -0
  2571. executorch/extension/llm/custom_ops/spinquant/third-party/FFHT/gen.py +869 -0
  2572. executorch/extension/llm/custom_ops/test_preprocess_custom_ops.py +34 -0
  2573. executorch/extension/llm/custom_ops/test_quantized_sdpa.py +550 -0
  2574. executorch/extension/llm/custom_ops/test_sdpa_with_kv_cache.py +651 -0
  2575. executorch/extension/llm/custom_ops/test_update_cache.py +433 -0
  2576. executorch/extension/llm/custom_ops/test_update_cross_attn_cache.py +284 -0
  2577. executorch/extension/llm/export/__init__.py +11 -0
  2578. executorch/extension/llm/export/builder.py +535 -0
  2579. executorch/extension/llm/export/config/llm_config.py +727 -0
  2580. executorch/extension/llm/export/export_llm.py +106 -0
  2581. executorch/extension/llm/export/export_passes.py +202 -0
  2582. executorch/extension/llm/export/partitioner_lib.py +238 -0
  2583. executorch/extension/llm/export/quantizer_lib.py +322 -0
  2584. executorch/extension/llm/export/test/__init__.py +0 -0
  2585. executorch/extension/llm/export/test/test_builder.py +118 -0
  2586. executorch/extension/llm/export/test/test_export_llm.py +155 -0
  2587. executorch/extension/llm/export/test_export_passes.py +209 -0
  2588. executorch/extension/llm/modules/__init__.py +24 -0
  2589. executorch/extension/llm/modules/_position_embeddings.py +729 -0
  2590. executorch/extension/llm/modules/attention.py +415 -0
  2591. executorch/extension/llm/modules/kv_cache.py +151 -0
  2592. executorch/extension/llm/modules/test/__init__.py +0 -0
  2593. executorch/extension/llm/modules/test/test_attention.py +353 -0
  2594. executorch/extension/llm/modules/test/test_kv_cache.py +218 -0
  2595. executorch/extension/llm/modules/test/test_position_embeddings.py +230 -0
  2596. executorch/extension/llm/runner/__init__.py +235 -0
  2597. executorch/extension/llm/runner/_llm_runner.pyi +523 -0
  2598. executorch/extension/llm/runner/test/test_runner_pybindings.py +258 -0
  2599. executorch/extension/llm/tokenizers/pytorch_tokenizers/__init__.py +63 -0
  2600. executorch/extension/llm/tokenizers/pytorch_tokenizers/constants.py +31 -0
  2601. executorch/extension/llm/tokenizers/pytorch_tokenizers/hf_tokenizer.py +57 -0
  2602. executorch/extension/llm/tokenizers/pytorch_tokenizers/llama2c.py +111 -0
  2603. executorch/extension/llm/tokenizers/pytorch_tokenizers/tiktoken.py +198 -0
  2604. executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/__init__.py +0 -0
  2605. executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/llama2c/__init__.py +0 -0
  2606. executorch/extension/llm/tokenizers/pytorch_tokenizers/tools/llama2c/convert.py +49 -0
  2607. executorch/extension/llm/tokenizers/setup.py +199 -0
  2608. executorch/extension/llm/tokenizers/test/test_hf_tokenizer.py +83 -0
  2609. executorch/extension/llm/tokenizers/test/test_python_bindings.py +131 -0
  2610. executorch/extension/llm/tokenizers/test/test_tekken_python.py +453 -0
  2611. executorch/extension/llm/tokenizers/test/test_tiktoken.py +49 -0
  2612. executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/abseil.podspec.gen.py +243 -0
  2613. executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/copts/copts.py +194 -0
  2614. executorch/extension/llm/tokenizers/third-party/abseil-cpp/absl/copts/generate_copts.py +109 -0
  2615. executorch/extension/llm/tokenizers/third-party/abseil-cpp/conanfile.py +51 -0
  2616. executorch/extension/llm/tokenizers/third-party/abseil-cpp/create_lts.py +139 -0
  2617. executorch/extension/llm/tokenizers/third-party/json/docs/mkdocs/scripts/check_structure.py +179 -0
  2618. executorch/extension/llm/tokenizers/third-party/json/tests/thirdparty/imapdl/filterbr.py +109 -0
  2619. executorch/extension/llm/tokenizers/third-party/json/tools/amalgamate/amalgamate.py +299 -0
  2620. executorch/extension/llm/tokenizers/third-party/json/tools/gdb_pretty_printer/nlohmann-json.py +32 -0
  2621. executorch/extension/llm/tokenizers/third-party/json/tools/generate_natvis/generate_natvis.py +41 -0
  2622. executorch/extension/llm/tokenizers/third-party/json/tools/serve_header/serve_header.py +410 -0
  2623. executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateCommon.py +354 -0
  2624. executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateTest.py +186 -0
  2625. executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcd.py +999 -0
  2626. executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcpHeader.py +98 -0
  2627. executorch/extension/llm/tokenizers/third-party/pcre2/maint/GenerateUcpTables.py +203 -0
  2628. executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateCommon.py +31 -0
  2629. executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateDates.py +59 -0
  2630. executorch/extension/llm/tokenizers/third-party/pcre2/maint/UpdateRelease.py +29 -0
  2631. executorch/extension/llm/tokenizers/third-party/re2/benchlog/benchplot.py +98 -0
  2632. executorch/extension/llm/tokenizers/third-party/re2/python/re2.py +583 -0
  2633. executorch/extension/llm/tokenizers/third-party/re2/python/re2_test.py +489 -0
  2634. executorch/extension/llm/tokenizers/third-party/re2/python/setup.py +158 -0
  2635. executorch/extension/llm/tokenizers/third-party/re2/python/toolchains/generate.py +98 -0
  2636. executorch/extension/llm/tokenizers/third-party/re2/re2/make_unicode_casefold.py +151 -0
  2637. executorch/extension/llm/tokenizers/third-party/re2/re2/make_unicode_groups.py +117 -0
  2638. executorch/extension/llm/tokenizers/third-party/re2/re2/unicode.py +284 -0
  2639. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/setup.py +215 -0
  2640. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/__init__.py +1224 -0
  2641. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/_version.py +1 -0
  2642. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/sentencepiece_model_pb2.py +44 -0
  2643. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/src/sentencepiece/sentencepiece_pb2.py +30 -0
  2644. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/test/__init__.py +0 -0
  2645. executorch/extension/llm/tokenizers/third-party/sentencepiece/python/test/sentencepiece_test.py +937 -0
  2646. executorch/extension/module/test/resources/gen_bundled_program.py +99 -0
  2647. executorch/extension/pybindings/_portable_lib.cp313-win_amd64.pyd +0 -0
  2648. executorch/extension/pybindings/portable_lib.py +82 -0
  2649. executorch/extension/pybindings/pybindings.pyi +299 -0
  2650. executorch/extension/pybindings/test/make_test.py +186 -0
  2651. executorch/extension/pybindings/test/test_backend_pybinding.py +27 -0
  2652. executorch/extension/pybindings/test/test_pybindings.py +735 -0
  2653. executorch/extension/pytree/__init__.py +54 -0
  2654. executorch/extension/pytree/test/test.py +331 -0
  2655. executorch/extension/training/__init__.py +22 -0
  2656. executorch/extension/training/examples/CIFAR/data_utils.py +389 -0
  2657. executorch/extension/training/examples/CIFAR/export.py +220 -0
  2658. executorch/extension/training/examples/CIFAR/main.py +188 -0
  2659. executorch/extension/training/examples/CIFAR/model.py +73 -0
  2660. executorch/extension/training/examples/CIFAR/train_utils.py +622 -0
  2661. executorch/extension/training/examples/XOR/export_model.py +74 -0
  2662. executorch/extension/training/examples/XOR/model.py +34 -0
  2663. executorch/extension/training/examples/XOR/test/test_export.py +19 -0
  2664. executorch/extension/training/pybindings/_training_lib.pyi +45 -0
  2665. executorch/extension/training/pybindings/_training_module.py +86 -0
  2666. executorch/extension/training/pybindings/test/test.py +67 -0
  2667. executorch/extension/wasm/test/test_model.py +34 -0
  2668. executorch/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +260 -0
  2669. executorch/include/executorch/extension/kernel_util/meta_programming.h +119 -0
  2670. executorch/include/executorch/extension/kernel_util/type_list.h +145 -0
  2671. executorch/include/executorch/extension/tensor/tensor.h +14 -0
  2672. executorch/include/executorch/extension/tensor/tensor_accessor.h +218 -0
  2673. executorch/include/executorch/extension/tensor/tensor_ptr.h +485 -0
  2674. executorch/include/executorch/extension/tensor/tensor_ptr_maker.h +687 -0
  2675. executorch/include/executorch/extension/threadpool/cpuinfo_utils.h +24 -0
  2676. executorch/include/executorch/extension/threadpool/threadpool.h +124 -0
  2677. executorch/include/executorch/extension/threadpool/threadpool_guard.h +37 -0
  2678. executorch/include/executorch/runtime/core/array_ref.h +262 -0
  2679. executorch/include/executorch/runtime/core/data_loader.h +141 -0
  2680. executorch/include/executorch/runtime/core/defines.h +20 -0
  2681. executorch/include/executorch/runtime/core/error.h +257 -0
  2682. executorch/include/executorch/runtime/core/evalue.h +608 -0
  2683. executorch/include/executorch/runtime/core/event_tracer.h +592 -0
  2684. executorch/include/executorch/runtime/core/event_tracer_hooks.h +340 -0
  2685. executorch/include/executorch/runtime/core/event_tracer_hooks_delegate.h +204 -0
  2686. executorch/include/executorch/runtime/core/exec_aten/exec_aten.h +175 -0
  2687. executorch/include/executorch/runtime/core/exec_aten/testing_util/tensor_factory.h +1133 -0
  2688. executorch/include/executorch/runtime/core/exec_aten/testing_util/tensor_util.h +378 -0
  2689. executorch/include/executorch/runtime/core/exec_aten/util/dim_order_util.h +278 -0
  2690. executorch/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +1430 -0
  2691. executorch/include/executorch/runtime/core/exec_aten/util/tensor_dimension_limit.h +21 -0
  2692. executorch/include/executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h +68 -0
  2693. executorch/include/executorch/runtime/core/exec_aten/util/tensor_util.h +1415 -0
  2694. executorch/include/executorch/runtime/core/freeable_buffer.h +218 -0
  2695. executorch/include/executorch/runtime/core/function_ref.h +108 -0
  2696. executorch/include/executorch/runtime/core/hierarchical_allocator.h +125 -0
  2697. executorch/include/executorch/runtime/core/memory_allocator.h +233 -0
  2698. executorch/include/executorch/runtime/core/named_data_map.h +77 -0
  2699. executorch/include/executorch/runtime/core/portable_type/bfloat16.h +27 -0
  2700. executorch/include/executorch/runtime/core/portable_type/bfloat16_math.h +14 -0
  2701. executorch/include/executorch/runtime/core/portable_type/bits_types.h +83 -0
  2702. executorch/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +1 -0
  2703. executorch/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +1 -0
  2704. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -0
  2705. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-math.h +299 -0
  2706. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +1 -0
  2707. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +1 -0
  2708. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +8 -0
  2709. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +1 -0
  2710. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -0
  2711. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +78 -0
  2712. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/complex_math.h +406 -0
  2713. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/complex_utils.h +46 -0
  2714. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +1 -0
  2715. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +123 -0
  2716. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +905 -0
  2717. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/overflows.h +100 -0
  2718. executorch/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +114 -0
  2719. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +153 -0
  2720. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h +694 -0
  2721. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h +480 -0
  2722. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/Half.h +788 -0
  2723. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h +148 -0
  2724. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h +50 -0
  2725. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex.h +616 -0
  2726. executorch/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h +38 -0
  2727. executorch/include/executorch/runtime/core/portable_type/complex.h +21 -0
  2728. executorch/include/executorch/runtime/core/portable_type/device.h +74 -0
  2729. executorch/include/executorch/runtime/core/portable_type/half.h +27 -0
  2730. executorch/include/executorch/runtime/core/portable_type/optional.h +36 -0
  2731. executorch/include/executorch/runtime/core/portable_type/qint_types.h +83 -0
  2732. executorch/include/executorch/runtime/core/portable_type/scalar.h +123 -0
  2733. executorch/include/executorch/runtime/core/portable_type/scalar_type.h +154 -0
  2734. executorch/include/executorch/runtime/core/portable_type/string_view.h +29 -0
  2735. executorch/include/executorch/runtime/core/portable_type/tensor.h +175 -0
  2736. executorch/include/executorch/runtime/core/portable_type/tensor_impl.h +304 -0
  2737. executorch/include/executorch/runtime/core/portable_type/tensor_options.h +60 -0
  2738. executorch/include/executorch/runtime/core/result.h +268 -0
  2739. executorch/include/executorch/runtime/core/span.h +110 -0
  2740. executorch/include/executorch/runtime/core/tag.h +90 -0
  2741. executorch/include/executorch/runtime/core/tensor_layout.h +93 -0
  2742. executorch/include/executorch/runtime/core/tensor_shape_dynamism.h +39 -0
  2743. executorch/include/executorch/runtime/core/testing_util/error_matchers.h +303 -0
  2744. executorch/include/executorch/runtime/kernel/kernel_includes.h +23 -0
  2745. executorch/include/executorch/runtime/kernel/kernel_runtime_context.h +131 -0
  2746. executorch/include/executorch/runtime/kernel/operator_registry.h +298 -0
  2747. executorch/include/executorch/runtime/kernel/test/test_util.h +40 -0
  2748. executorch/include/executorch/runtime/kernel/thread_parallel_interface.h +107 -0
  2749. executorch/include/executorch/runtime/platform/abort.h +36 -0
  2750. executorch/include/executorch/runtime/platform/assert.h +124 -0
  2751. executorch/include/executorch/runtime/platform/clock.h +43 -0
  2752. executorch/include/executorch/runtime/platform/compat_unistd.h +75 -0
  2753. executorch/include/executorch/runtime/platform/compiler.h +214 -0
  2754. executorch/include/executorch/runtime/platform/log.h +216 -0
  2755. executorch/include/executorch/runtime/platform/platform.h +276 -0
  2756. executorch/include/executorch/runtime/platform/profiler.h +289 -0
  2757. executorch/include/executorch/runtime/platform/runtime.h +35 -0
  2758. executorch/include/executorch/runtime/platform/system.h +49 -0
  2759. executorch/include/executorch/runtime/platform/test/pal_spy.h +86 -0
  2760. executorch/include/executorch/runtime/platform/test/stub_platform.h +76 -0
  2761. executorch/include/executorch/runtime/platform/types.h +24 -0
  2762. executorch/kernels/quantized/__init__.py +21 -0
  2763. executorch/kernels/quantized/quantized.yaml +113 -0
  2764. executorch/kernels/quantized/quantized_ops_aot_lib.dll +0 -0
  2765. executorch/kernels/quantized/test/supported_features_def.yaml +1 -0
  2766. executorch/kernels/quantized/test/test_out_variants.py +100 -0
  2767. executorch/kernels/quantized/test/test_quant_dequant_per_token.py +149 -0
  2768. executorch/runtime/__init__.py +334 -0
  2769. executorch/runtime/kernel/test/functions.yaml +13 -0
  2770. executorch/runtime/test/test_runtime.py +106 -0
  2771. executorch/runtime/test/test_runtime_etdump_gen.py +163 -0
  2772. executorch/schema/program.fbs +489 -0
  2773. executorch/schema/scalar_type.fbs +43 -0
  2774. executorch/share/cmake/executorch-config.cmake +77 -0
  2775. executorch/util/activation_memory_profiler.py +177 -0
  2776. executorch/util/collect_env.py +748 -0
  2777. executorch/util/python_profiler.py +96 -0
  2778. executorch/version.py +4 -0
  2779. executorch-1.1.0.dist-info/METADATA +87 -0
  2780. executorch-1.1.0.dist-info/RECORD +2784 -0
  2781. executorch-1.1.0.dist-info/WHEEL +5 -0
  2782. executorch-1.1.0.dist-info/entry_points.txt +2 -0
  2783. executorch-1.1.0.dist-info/licenses/LICENSE +37 -0
  2784. executorch-1.1.0.dist-info/top_level.txt +7 -0
@@ -0,0 +1,2405 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # pyre-unsafe
8
+
9
+ import typing
10
+ import unittest
11
+ from contextlib import contextmanager
12
+ from copy import deepcopy
13
+ from typing import List, Optional, Tuple
14
+
15
+ import executorch.exir as exir
16
+
17
+ import executorch.exir.schema as schema
18
+ import executorch.exir.tests.models as models
19
+ import pytest
20
+ import torch
21
+ from executorch.exir import (
22
+ EdgeCompileConfig,
23
+ ExecutorchBackendConfig,
24
+ ExecutorchProgramManager,
25
+ to_edge,
26
+ )
27
+ from executorch.exir._serialize._program import deserialize_pte_binary
28
+ from executorch.exir.backend.backend_api import to_backend
29
+ from executorch.exir.backend.backend_details import BackendDetails, PreprocessResult
30
+ from executorch.exir.backend.test.demos.rpc.executor_backend_partitioner import (
31
+ ExecutorBackendPartitioner,
32
+ )
33
+ from executorch.exir.dialects._ops import ops as exir_ops
34
+ from executorch.exir.emit import emit_program # noqa
35
+ from executorch.exir.error import InternalError
36
+ from executorch.exir.passes import MemoryPlanningPass
37
+ from executorch.exir.passes.constant_prop_pass import constant_prop_pass
38
+ from executorch.exir.passes.init_mutable_pass import InitializedMutableBufferPass
39
+ from executorch.exir.passes.sym_shape_eval_pass import ConstraintBasedSymShapeEvalPass
40
+ from executorch.exir.print_program import pretty_print, print_program # noqa
41
+ from executorch.exir.schema import (
42
+ Bool,
43
+ DelegateCall,
44
+ Double,
45
+ EValue,
46
+ ExecutionPlan,
47
+ Int,
48
+ IntList,
49
+ JumpFalseCall,
50
+ KernelCall,
51
+ KernelTypes,
52
+ MoveCall,
53
+ Null,
54
+ OptionalTensorList,
55
+ Program,
56
+ String,
57
+ Tensor,
58
+ )
59
+ from executorch.exir.tests.common import register_additional_test_aten_ops
60
+ from executorch.exir.tests.models import Mul
61
+ from executorch.extension.pybindings.portable_lib import (
62
+ _load_for_executorch_from_buffer,
63
+ )
64
+ from executorch.runtime import Runtime
65
+ from torch import nn
66
+
67
+ from torch._higher_order_ops import cond as torch_cond, map as torch_map
68
+
69
+ from torch.export import Dim, export
70
+ from torch.export.experimental import _export_forward_backward
71
+
72
+
73
+ class WrapperModule(torch.nn.Module):
74
+ def __init__(self, fn):
75
+ super().__init__()
76
+ self.fn = fn
77
+
78
+ def forward(self, *args, **kwargs):
79
+ return self.fn(*args, **kwargs)
80
+
81
+
82
+ @contextmanager
83
+ def patch_forward(obj: torch.nn.Module, new_method):
84
+ """Helper method to make it easier to cleanly torch.export() a method on a
85
+ module that is not `forward`.
86
+
87
+ TODO(suo): upstream this to torch.export.wrapper.
88
+ """
89
+ # Save the original method
90
+ original_method = obj.forward
91
+
92
+ # Patch the method
93
+ obj.forward = new_method.__get__(obj, obj.__class__)
94
+
95
+ try:
96
+ yield
97
+ finally:
98
+ # Restore the original method
99
+ obj.forward = original_method
100
+
101
+
102
+ class TestEmit(unittest.TestCase):
103
+ @classmethod
104
+ def setUpClass(cls) -> None:
105
+ register_additional_test_aten_ops()
106
+
107
+ def setUp(self) -> None:
108
+ self.compile_config = EdgeCompileConfig(_check_ir_validity=False)
109
+
110
+ def check_tensor_buffer_loc(
111
+ self,
112
+ value_index: int,
113
+ values: List[EValue],
114
+ exp_buffer_idx: int,
115
+ exp_mem_id: Optional[int],
116
+ exp_mem_offset: Optional[int],
117
+ ) -> None:
118
+ value = typing.cast(schema.Tensor, values[value_index].val)
119
+ self.assertIsInstance(value, schema.Tensor)
120
+
121
+ self.assertEqual(value.data_buffer_idx, exp_buffer_idx)
122
+
123
+ if not value.allocation_info:
124
+ self.assertIsNone(exp_mem_id)
125
+ self.assertIsNone(exp_mem_offset)
126
+ else:
127
+ self.assertEqual(value.allocation_info.memory_id, exp_mem_id)
128
+ assert value.allocation_info
129
+ self.assertEqual(value.allocation_info.memory_offset, exp_mem_offset)
130
+
131
+ def count_node(self, graph_module: torch.fx.GraphModule, opname: str) -> int:
132
+ return [
133
+ node.target._overloadpacket._qualified_op_name
134
+ for node in graph_module.graph.nodes
135
+ if node.op == "call_function"
136
+ ].count(opname)
137
+
138
+ def run_dce(self, graph_module: torch.fx.GraphModule) -> None:
139
+ for submodule in graph_module.modules():
140
+ self.assertIsInstance(submodule, torch.fx.GraphModule)
141
+ typing.cast(torch.fx.GraphModule, submodule).graph.eliminate_dead_code()
142
+
143
+ def check_value_types(self, values: List[EValue]) -> None:
144
+ for value in values:
145
+ self.assertTrue(type(value.val) in KernelTypes.__args__)
146
+
147
+ def count_move_instructions(self, program: Program) -> int:
148
+ instructions = program.execution_plan[0].chains[0].instructions
149
+ assert instructions is not None
150
+ res = 0
151
+ for instr in instructions:
152
+ if isinstance(instr.instr_args, MoveCall):
153
+ res += 1
154
+ return res
155
+
156
+ def test_basic_api(self) -> None:
157
+ class Foo(torch.nn.Module):
158
+ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
159
+ return x * y + x
160
+
161
+ f = Foo()
162
+
163
+ program = (
164
+ to_edge(export(f, (torch.ones(3, 2), torch.zeros(3, 2)), strict=True))
165
+ .to_executorch()
166
+ .executorch_program
167
+ )
168
+ exec_plan = program.execution_plan[0]
169
+ ops = exec_plan.operators
170
+ for op in ops:
171
+ self.assertEqual(op.overload, "out")
172
+
173
+ self.assertEqual(ops[0].name, "aten::mul")
174
+ self.assertEqual(ops[1].name, "aten::add")
175
+
176
+ self.assertEqual(len(exec_plan.inputs), 2)
177
+ self.assertEqual(len(exec_plan.outputs), 1)
178
+
179
+ self.assertEqual(exec_plan.inputs[0], 0)
180
+ self.assertEqual(exec_plan.outputs[0], 3)
181
+
182
+ def test_basic_end_to_end(self) -> None:
183
+ f = models.BasicSinMax()
184
+ program = (
185
+ to_edge(export(f, f.get_random_inputs(), strict=True))
186
+ .to_executorch()
187
+ .executorch_program
188
+ )
189
+ exec_plan = program.execution_plan[0]
190
+ ops = exec_plan.operators
191
+ for op in ops:
192
+ self.assertIn(op.overload, {"out", "unary_out"})
193
+
194
+ self.assertEqual(ops[0].name, "aten::sin")
195
+
196
+ self.assertEqual(len(exec_plan.inputs), 1)
197
+ self.assertEqual(len(exec_plan.outputs), 1)
198
+
199
+ self.assertEqual(exec_plan.inputs[0], 0)
200
+ self.assertEqual(exec_plan.outputs[0], 1)
201
+
202
+ @pytest.mark.skip(reason="Test not working on OSS")
203
+ def test_nested_return(self) -> None:
204
+ class Foo(torch.nn.Module):
205
+ def forward(
206
+ self, x: torch.Tensor
207
+ ) -> Tuple[torch.Tensor, torch.Tensor, List[torch.Tensor]]:
208
+ return (
209
+ torch.tensor(1),
210
+ torch.tensor(2),
211
+ [torch.sin(x).max(), torch.cos(x).max()],
212
+ )
213
+
214
+ f = Foo()
215
+
216
+ x = (torch.randn(100),)
217
+ program = to_edge(export(f, x, strict=True)).to_executorch().executorch_program
218
+ exec_plan = program.execution_plan[0]
219
+ self.assertEqual(len(exec_plan.outputs), 4)
220
+ self.assertEqual(len(exec_plan.inputs), 1)
221
+
222
+ self.assertEqual(
223
+ program.execution_plan[0].container_meta_type.encoded_out_str,
224
+ "T3#1#1#2($,$,L2#1#1($,$))",
225
+ )
226
+
227
+ self.assertEqual(
228
+ program.execution_plan[0].container_meta_type.encoded_inp_str,
229
+ "T2#1#0(T1#1($),D0())",
230
+ )
231
+
232
+ def test_constant_output(self):
233
+ class M(torch.nn.Module):
234
+ def forward(self, x):
235
+ return [((1, 3, 1.2), True, [x + x, x * x], None)]
236
+
237
+ ep = torch.export.export(M(), (torch.ones(2, 3),), strict=True)
238
+ res = ep.module()(torch.ones(2, 3))
239
+ self.assertEqual(res[0][0], (1, 3, 1.2))
240
+ program = to_edge(ep).to_executorch().executorch_program
241
+ outputs = program.execution_plan[0].outputs
242
+ self.assertEqual(len(outputs), 7)
243
+ self.assertEqual(program.execution_plan[0].values[outputs[0]].val.int_val, 1)
244
+ self.assertEqual(program.execution_plan[0].values[outputs[1]].val.int_val, 3)
245
+ self.assertEqual(
246
+ program.execution_plan[0].values[outputs[2]].val.double_val, 1.2
247
+ )
248
+ self.assertEqual(
249
+ program.execution_plan[0].values[outputs[3]].val.bool_val, True
250
+ )
251
+ self.assertIsInstance(program.execution_plan[0].values[outputs[6]].val, Null)
252
+
253
+ def test_initialized_mutable_buffer(self):
254
+ """Test that mutable buffers can hold meaningful initialized state."""
255
+
256
+ class TestModule(torch.nn.Module):
257
+ def __init__(self):
258
+ super().__init__()
259
+ # Mutable buffer with non-empty initial state.
260
+ self.register_buffer("cache_pos", torch.arange(0, 10))
261
+
262
+ def forward(self, x):
263
+ self.cache_pos.add_(1)
264
+ return self.cache_pos
265
+
266
+ m = TestModule()
267
+ example_inputs = (torch.ones(10),)
268
+ ep = torch.export.export(m, example_inputs, strict=True)
269
+ edge = to_edge(
270
+ ep,
271
+ compile_config=EdgeCompileConfig(
272
+ _check_ir_validity=False,
273
+ ),
274
+ )
275
+
276
+ # Save a copy of the edge program since to_executorch is
277
+ # stateful to some degree.
278
+ edge_copy = deepcopy(edge)
279
+ et_config = ExecutorchBackendConfig(
280
+ passes=[InitializedMutableBufferPass(["cache_pos"])],
281
+ )
282
+ et_program_init_pass = edge.to_executorch(config=et_config)
283
+ et_program_regular = edge_copy.to_executorch()
284
+
285
+ runtime = Runtime.get()
286
+ program_init_pass = runtime.load_program(et_program_init_pass.buffer)
287
+ method_init_pass = program_init_pass.load_method("forward")
288
+
289
+ program_regular = runtime.load_program(et_program_regular.buffer)
290
+ method_regular = program_regular.load_method("forward")
291
+
292
+ # Test that the mutable buffer is initialized.
293
+ torch.allclose(
294
+ method_init_pass.execute((example_inputs))[0], torch.arange(1, 11)
295
+ )
296
+ # Test that the mutable buffer is uninitialized and starts with default zeros,
297
+ # we test equality with torch.ones because of the mutation += 1 in the model forward.
298
+ torch.allclose(
299
+ method_regular.execute((example_inputs))[0],
300
+ torch.ones(10, dtype=torch.int64),
301
+ )
302
+
303
+ def test_int_list_input(self):
304
+ class M(torch.nn.Module):
305
+ def forward(self, x, y, z):
306
+ return x + y, x + x, x + y + z
307
+
308
+ ep = torch.export.export(M(), (torch.ones(2, 3), 2, True), strict=True)
309
+ ep.module()(torch.ones(2, 3), 2, True)
310
+ program = to_edge(ep).to_executorch().executorch_program
311
+ inputs = program.execution_plan[0].inputs
312
+ self.assertEqual(len(inputs), 3)
313
+ self.assertEqual(program.execution_plan[0].values[inputs[1]].val.int_val, 2)
314
+ self.assertEqual(program.execution_plan[0].values[inputs[2]].val.bool_val, True)
315
+
316
+ def test_inplace_ops(self) -> None:
317
+ class Foo(torch.nn.Module):
318
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
319
+ y = torch.sin(x)
320
+ z = y.view(100)
321
+ torch.relu_(z)
322
+ return z.max()
323
+
324
+ f = Foo()
325
+
326
+ inputs = (torch.ones((10, 10)),)
327
+ edge = to_edge(export(f, inputs, strict=True))
328
+
329
+ removed_ops = ["aten::relu_", "aten::view"]
330
+ expected_ops = [
331
+ "aten::sin",
332
+ "aten::relu",
333
+ "aten::max",
334
+ ]
335
+
336
+ def expected_view_ops(config):
337
+ if config.remove_view_copy:
338
+ return []
339
+ else:
340
+ return ["aten::view_copy"]
341
+
342
+ for opname in removed_ops:
343
+ self.assertEqual(
344
+ self.count_node(edge.exported_program().graph_module, opname), 0
345
+ )
346
+ for opname in expected_ops:
347
+ self.assertTrue(
348
+ self.count_node(edge.exported_program().graph_module, opname) >= 1
349
+ )
350
+
351
+ for remove_view_copy in [True, False]:
352
+ config = exir.ExecutorchBackendConfig(remove_view_copy=remove_view_copy)
353
+ edge_copy = deepcopy(edge)
354
+ program = edge_copy.to_executorch(config=config).executorch_program
355
+ for opname in removed_ops:
356
+ self.assertTrue(
357
+ all(op.name != opname for op in program.execution_plan[0].operators)
358
+ )
359
+ for opname in expected_ops + expected_view_ops(config):
360
+ self.assertTrue(
361
+ any(op.name == opname for op in program.execution_plan[0].operators)
362
+ )
363
+ self.assertTrue(
364
+ len(program.execution_plan[0].operators)
365
+ == len(expected_ops + expected_view_ops(config))
366
+ )
367
+
368
+ def test_operators_unique(self) -> None:
369
+ class OpRepeatedModule(torch.nn.Module):
370
+ def __init__(self) -> None:
371
+ super().__init__()
372
+ self.a = torch.ones(2, 2)
373
+ self.b = 2 * torch.ones(2, 2)
374
+
375
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
376
+ for _ in range(10):
377
+ z = self.a * x
378
+ y = z + self.b
379
+ return y
380
+
381
+ model = OpRepeatedModule()
382
+
383
+ inputs = (torch.ones(2, 2),)
384
+
385
+ program = (
386
+ to_edge(export(model, inputs, strict=True))
387
+ .to_executorch()
388
+ .executorch_program
389
+ )
390
+
391
+ self.assertEqual(len(program.execution_plan[0].operators), 2)
392
+
393
+ def test_list_type(self) -> None:
394
+ """Tests that the types of lists are correctly found"""
395
+
396
+ class Foo(torch.nn.Module):
397
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
398
+ return torch.permute(x, (2, 0, 1))
399
+
400
+ f = Foo()
401
+
402
+ program = (
403
+ to_edge(export(f, (torch.randn(2, 3, 5),), strict=True))
404
+ .to_executorch()
405
+ .executorch_program
406
+ )
407
+ exir.print_program.pretty_print(program)
408
+
409
+ deboxed_int_list = []
410
+ for item in program.execution_plan[0].values[5].val.items:
411
+ deboxed_int_list.append(program.execution_plan[0].values[item].val.int_val)
412
+
413
+ self.assertEqual(IntList(deboxed_int_list), IntList([2, 0, 1]))
414
+
415
+ def test_kwargs1(self) -> None:
416
+ """Tests that the kwargs are placed in the order specified by
417
+ native_functions.yaml
418
+ """
419
+
420
+ class Foo(torch.nn.Module):
421
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
422
+ batch1 = torch.randn(10, 3, 4)
423
+ batch2 = torch.randn(10, 4, 5)
424
+ return torch.addbmm(x, batch1, batch2, alpha=2, beta=3)
425
+
426
+ f = Foo()
427
+
428
+ program = (
429
+ to_edge(export(f, (torch.randn(3, 5),), strict=True))
430
+ .to_executorch()
431
+ .executorch_program
432
+ )
433
+ # The value for beta should appear before alpha
434
+ self.assertEqual(program.execution_plan[0].values[12].val, Int(3))
435
+ self.assertEqual(program.execution_plan[0].values[13].val, Int(2))
436
+
437
+ def test_kwargs2(self) -> None:
438
+ """Tests that the kwargs are placed in the order specified by
439
+ native_functions.yaml
440
+ """
441
+
442
+ class Foo(torch.nn.Module):
443
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
444
+ values = torch.randn(3, 2)
445
+ return torch.searchsorted(x, values, side="right", right=True)
446
+
447
+ f = Foo()
448
+
449
+ x, _ = torch.sort(torch.randn(3, 4))
450
+ program = (
451
+ to_edge(export(f, (x,), strict=True)).to_executorch().executorch_program
452
+ )
453
+ # The value for right should appear before side
454
+ self.assertEqual(program.execution_plan[0].values[6].val, Bool(False))
455
+ self.assertEqual(program.execution_plan[0].values[7].val, Bool(True))
456
+ self.assertEqual(program.execution_plan[0].values[8].val, String("right"))
457
+ self.assertEqual(program.execution_plan[0].values[9].val, Null())
458
+
459
+ def _assertCallLength(self, program: Program, idx: int, expected_len: int) -> None:
460
+ instr_args = program.execution_plan[0].chains[0].instructions[idx].instr_args
461
+
462
+ if isinstance(instr_args, KernelCall) or isinstance(instr_args, DelegateCall):
463
+ self.assertEqual(len(instr_args.args), expected_len)
464
+ else:
465
+ self.assertTrue(False)
466
+
467
+ def test_out(self) -> None:
468
+ class Foo(torch.nn.Module):
469
+ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
470
+ z = y.clone()
471
+ return torch.mul(x, y, out=z)
472
+
473
+ f = Foo()
474
+
475
+ program = (
476
+ to_edge(export(f, (torch.ones(3), torch.ones(3)), strict=True))
477
+ .to_executorch()
478
+ .executorch_program
479
+ )
480
+
481
+ self.assertEqual(len(program.execution_plan[0].chains[0].instructions), 1)
482
+ self._assertCallLength(program, 0, 4)
483
+
484
+ def test_model_out(self) -> None:
485
+ class Module_out(torch.nn.Module):
486
+ def __init__(self) -> None:
487
+ super().__init__()
488
+ self.a = 3 * torch.ones(2, 2, dtype=torch.int32)
489
+ self.b = 2 * torch.ones(2, 2, dtype=torch.int32)
490
+
491
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
492
+ z = x.clone()
493
+ torch.mul(self.a, x, out=z)
494
+ y = x.clone()
495
+ torch.add(z, self.b, alpha=2, out=y)
496
+ return y
497
+
498
+ model_out = Module_out()
499
+
500
+ inputs = (torch.ones(2, 2, dtype=torch.int32),)
501
+
502
+ # Trace to FX Graph.
503
+ program = (
504
+ to_edge(export(model_out, inputs, strict=True))
505
+ .to_executorch()
506
+ .executorch_program
507
+ )
508
+
509
+ self.assertEqual(len(program.execution_plan[0].chains[0].instructions), 2)
510
+ self._assertCallLength(program, 0, 4)
511
+ self._assertCallLength(program, 1, 5)
512
+
513
+ def test_stacktrace(self) -> None:
514
+ def f(x: torch.Tensor) -> torch.Tensor:
515
+ return torch.mul(x, torch.randn(3, 2))
516
+
517
+ def g(x: torch.Tensor) -> torch.Tensor:
518
+ return torch.sin(f(x))
519
+
520
+ class Foo(torch.nn.Module):
521
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
522
+ return torch.add(g(x), torch.randn(3, 2))
523
+
524
+ h = Foo()
525
+
526
+ x = (torch.randn(3, 2),)
527
+ exec_prog = to_edge(export(h, x, strict=True)).to_executorch(
528
+ exir.ExecutorchBackendConfig(emit_stacktrace=True)
529
+ )
530
+ program = exec_prog.executorch_program
531
+
532
+ # Check the mul operator's stack trace contains f -> g -> h
533
+ self.assertTrue(
534
+ "return torch.mul(x, torch.randn(3, 2))"
535
+ in program.execution_plan[0].chains[0].stacktrace[1].items[-1].context
536
+ )
537
+ self.assertEqual(
538
+ program.execution_plan[0].chains[0].stacktrace[1].items[-1].name, "f"
539
+ )
540
+ self.assertEqual(
541
+ program.execution_plan[0].chains[0].stacktrace[1].items[-2].name, "g"
542
+ )
543
+ self.assertEqual(
544
+ program.execution_plan[0].chains[0].stacktrace[1].items[-3].name, "forward"
545
+ )
546
+
547
+ # Check the sin operator's stack trace contains g -> h
548
+ self.assertEqual(
549
+ program.execution_plan[0].chains[0].stacktrace[2].items[-1].name, "g"
550
+ )
551
+ self.assertEqual(
552
+ program.execution_plan[0].chains[0].stacktrace[2].items[-2].name, "forward"
553
+ )
554
+
555
+ def test_stacktrace_off(self) -> None:
556
+ class Foo(torch.nn.Module):
557
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
558
+ return torch.mul(x, torch.randn(3, 2))
559
+
560
+ f = Foo()
561
+
562
+ class Goo(torch.nn.Module):
563
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
564
+ return torch.sin(f(x))
565
+
566
+ g = Goo()
567
+
568
+ class Hoo(torch.nn.Module):
569
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
570
+ return torch.add(g(x), torch.randn(3, 2))
571
+
572
+ h = Hoo()
573
+
574
+ x = (torch.randn(3, 2),)
575
+ program = to_edge(export(h, x, strict=True)).to_executorch().executorch_program
576
+
577
+ # Check the stacktrace is None since we did not specify to get the stacktrace
578
+ self.assertTrue(program.execution_plan[0].chains[0].stacktrace is None)
579
+
580
+ def test_positional_argument_default_value(self) -> None:
581
+ class Foo(torch.nn.Module):
582
+ def forward(self, x: torch.Tensor, n: torch.Tensor) -> torch.Tensor:
583
+ z = torch.ones(6, 2)
584
+ return torch.ops.aten.cat.out((x, n), out=z)
585
+
586
+ f = Foo()
587
+
588
+ x = torch.randn(3, 2)
589
+ program = (
590
+ to_edge(export(f, (x, x), strict=True))
591
+ # .to_edge(self.compile_config) # TODO(larryliu): fix cat
592
+ .to_executorch().executorch_program
593
+ )
594
+
595
+ self.assertEqual(len(program.execution_plan[0].chains[0].instructions), 1)
596
+ self._assertCallLength(program, 0, 4)
597
+
598
+ @pytest.mark.skip(reason="Test not working on OSS")
599
+ def test_emit_multiple_out(self) -> None:
600
+ class Foo(torch.nn.Module):
601
+ def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
602
+ return torch.topk(x, 5)
603
+
604
+ f = Foo()
605
+
606
+ x = (torch.randn(10),)
607
+ program = to_edge(export(f, x, strict=True)).to_executorch().executorch_program
608
+ self._assertCallLength(program, 0, 8)
609
+
610
+ def test_emit_layout(self) -> None:
611
+ class Foo(torch.nn.Module):
612
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
613
+ return torch.ones_like(x)
614
+
615
+ f = Foo()
616
+
617
+ x = (torch.randn(3, 2),)
618
+ program = to_edge(export(f, x, strict=True)).to_executorch().executorch_program
619
+
620
+ vals = program.execution_plan[0].values
621
+ for val in vals:
622
+ v = val.val
623
+ if isinstance(v, Tensor):
624
+ self.assertEqual(v.layout, 0)
625
+
626
+ def test_optional_tensor_list(self) -> None:
627
+ class Foo(torch.nn.Module):
628
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
629
+ a = torch.nonzero(x)
630
+ torch._constrain_as_size(a.shape[0], min=1)
631
+ b = torch.ops.aten.index.Tensor(x, [a])
632
+ return b
633
+
634
+ f = Foo()
635
+ x = (torch.triu(torch.ones(2, 2)),)
636
+ program = (
637
+ to_edge(
638
+ export(f, x, strict=True),
639
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
640
+ )
641
+ .to_executorch()
642
+ .executorch_program
643
+ )
644
+ self.assertTrue(
645
+ isinstance(program.execution_plan[0].values[3].val, OptionalTensorList)
646
+ )
647
+ self._assertCallLength(program, 0, 3)
648
+ self._assertCallLength(program, 1, 4)
649
+
650
+ def test_optional_float_list(self) -> None:
651
+ class M(torch.nn.Module):
652
+ def forward(self, x):
653
+ return torch.nn.functional.interpolate(x, scale_factor=2)
654
+
655
+ x = (torch.randn(1, 1, 2, 2, 2),)
656
+ program = (
657
+ to_edge(export(M(), x, strict=True)).to_executorch().executorch_program
658
+ )
659
+ self.assertIsInstance(
660
+ program.execution_plan[0].values[-1].val, schema.OptionalTensorList
661
+ )
662
+
663
+ def test_emit_cond(self) -> None:
664
+ class M(torch.nn.Module):
665
+ def __init__(self):
666
+ super().__init__()
667
+
668
+ def forward(self, pred, x):
669
+ def true_fn(y: torch.Tensor) -> torch.Tensor:
670
+ y = y + y
671
+ y = torch.mm(y, y)
672
+ return y
673
+
674
+ def false_fn(y: torch.Tensor) -> torch.Tensor:
675
+ return torch.mm(y, y)
676
+
677
+ ret = torch_cond(pred, true_fn, false_fn, [x])
678
+ return ret
679
+
680
+ module = to_edge(
681
+ export(M(), (torch.tensor(True), torch.ones(2, 2)), strict=True)
682
+ )
683
+ program = module.to_executorch().executorch_program
684
+
685
+ num_mm = 0
686
+ num_add = 0
687
+ num_other = 0
688
+ for inst in program.execution_plan[0].chains[0].instructions:
689
+ if not isinstance(inst.instr_args, KernelCall):
690
+ continue
691
+
692
+ op = program.execution_plan[0].operators[inst.instr_args.op_index].name
693
+
694
+ if "mm" in op:
695
+ num_mm += 1
696
+ elif "add" in op:
697
+ num_add += 1
698
+ else:
699
+ num_other += 1
700
+
701
+ self.assertEqual(num_mm, 2)
702
+ self.assertEqual(num_add, 1)
703
+ self.assertEqual(num_other, 0)
704
+
705
+ def test_emit_map(self) -> None:
706
+ class Foo(torch.nn.Module):
707
+ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
708
+ def map_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
709
+ return x + y
710
+
711
+ return torch_map(map_fn, x, y)
712
+
713
+ f = Foo()
714
+
715
+ inputs = (torch.ones(4, 4), torch.ones(4))
716
+ module = to_edge(
717
+ export(f, inputs, strict=True),
718
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
719
+ )
720
+ program = module.to_executorch().executorch_program
721
+
722
+ op_table = program.execution_plan[0].operators
723
+ # The first two operators at the beginning of a map program should be sym_size
724
+ # and select_copy, which is what we verify here. The first operator is to generate
725
+ # the number of iterations and the second operator is to slice the input tensor to
726
+ # generate the tensor on which this iteration will operate on.
727
+ self.assertEqual(
728
+ op_table[
729
+ program.execution_plan[0].chains[0].instructions[0].instr_args.op_index
730
+ ].name,
731
+ "aten::sym_size",
732
+ )
733
+ self.assertEqual(
734
+ op_table[
735
+ program.execution_plan[0].chains[0].instructions[1].instr_args.op_index
736
+ ].name,
737
+ "aten::select_copy",
738
+ )
739
+
740
+ # The last three instructions in the map sub-program are:
741
+ # - Calling the custom op to append the output of this iteration to the accumulator tensor
742
+ # - Increment the iteration count.
743
+ # - Then checking if we've completed all the iterations.
744
+ # We check here that both of these have been generated.
745
+ self.assertEqual(
746
+ op_table[
747
+ program.execution_plan[0].chains[0].instructions[-5].instr_args.op_index
748
+ ].name,
749
+ "executorch_prim::et_copy_index",
750
+ )
751
+ self.assertEqual(
752
+ op_table[
753
+ program.execution_plan[0].chains[0].instructions[-4].instr_args.op_index
754
+ ].name,
755
+ "executorch_prim::add",
756
+ )
757
+ self.assertEqual(
758
+ op_table[
759
+ program.execution_plan[0].chains[0].instructions[-3].instr_args.op_index
760
+ ].name,
761
+ "executorch_prim::eq",
762
+ )
763
+ # The last two instructions in the overall program check if we should jump back to the
764
+ # beginning of the loop and then resets the iteration counter if we fall through.
765
+ self.assertTrue(
766
+ isinstance(
767
+ program.execution_plan[0].chains[0].instructions[-2].instr_args,
768
+ JumpFalseCall,
769
+ )
770
+ )
771
+ self.assertEqual(
772
+ op_table[
773
+ program.execution_plan[0].chains[0].instructions[-1].instr_args.op_index
774
+ ].name,
775
+ "executorch_prim::sub",
776
+ )
777
+
778
+ def test_load_emit_map(self) -> None:
779
+ class Foo(torch.nn.Module):
780
+ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
781
+ def map_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
782
+ return x + y
783
+
784
+ return torch_map(map_fn, x, y)
785
+
786
+ f = Foo()
787
+
788
+ inputs = (torch.ones(4, 4), torch.ones(4))
789
+ module = to_edge(
790
+ export(f, inputs, strict=True),
791
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
792
+ )
793
+ _load_for_executorch_from_buffer(module.to_executorch().buffer)
794
+
795
+ def test_run_emit_map(self) -> None:
796
+ class Foo(torch.nn.Module):
797
+ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
798
+ def map_fn(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
799
+ return x + y
800
+
801
+ return torch_map(map_fn, x, y)
802
+
803
+ f = Foo()
804
+
805
+ inputs = (torch.ones(4, 4), torch.ones(4))
806
+ module = to_edge(
807
+ export(f, inputs, strict=True),
808
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
809
+ )
810
+ buffer = module.to_executorch().buffer
811
+ loaded_model = _load_for_executorch_from_buffer(buffer)
812
+ outputs = loaded_model(inputs)[0]
813
+ torch.allclose(outputs, f(*inputs))
814
+
815
+ def test_emit_scan_basic(self) -> None:
816
+ """Test basic scan emission: verifies instruction structure for cumulative sum."""
817
+ from torch._higher_order_ops.scan import scan
818
+
819
+ class ScanCumSum(torch.nn.Module):
820
+ def forward(self, xs: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
821
+ def combine_fn(carry, x):
822
+ new_carry = carry + x
823
+ return new_carry, new_carry.clone()
824
+
825
+ init = torch.zeros_like(xs[0])
826
+ return scan(combine_fn, init, xs)
827
+
828
+ f = ScanCumSum()
829
+ # Use contiguous tensor to avoid stride=0 issue
830
+ inputs = (torch.arange(15).float().reshape(5, 3),)
831
+
832
+ module = to_edge(
833
+ export(f, inputs, strict=True),
834
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
835
+ )
836
+ program = module.to_executorch().executorch_program
837
+
838
+ op_table = program.execution_plan[0].operators
839
+ instructions = program.execution_plan[0].chains[0].instructions
840
+
841
+ # Collect all operator names in the program
842
+ op_names = [op.name for op in op_table]
843
+
844
+ # Verify the key operators are present for scan:
845
+ # 1. sym_size - to get scan length
846
+ self.assertIn(
847
+ "aten::sym_size", op_names, "Should have sym_size for scan length"
848
+ )
849
+
850
+ # 2. copy_ - for carry initialization and carry updates
851
+ self.assertIn("aten::copy_", op_names, "Should have copy_ for carry handling")
852
+
853
+ # 3. select_copy - to slice xs
854
+ self.assertIn(
855
+ "aten::select_copy", op_names, "Should have select_copy for xs slicing"
856
+ )
857
+
858
+ # 4. et_copy_index - to accumulate y outputs
859
+ self.assertIn(
860
+ "executorch_prim::et_copy_index",
861
+ op_names,
862
+ "Should have et_copy_index for y accumulation",
863
+ )
864
+
865
+ # 5. Loop control: add, eq for iteration control
866
+ self.assertIn(
867
+ "executorch_prim::add", op_names, "Should have add for iter increment"
868
+ )
869
+ self.assertIn(
870
+ "executorch_prim::eq", op_names, "Should have eq for completion check"
871
+ )
872
+
873
+ # 6. sub - to reset iter_idx for re-runs
874
+ self.assertIn(
875
+ "executorch_prim::sub", op_names, "Should have sub to reset iterator"
876
+ )
877
+
878
+ # 7. Should have JumpFalseCall for loop back
879
+ jump_false_found = False
880
+ for instr in instructions:
881
+ if isinstance(instr.instr_args, JumpFalseCall):
882
+ jump_false_found = True
883
+ break
884
+ self.assertTrue(jump_false_found, "Should have JumpFalseCall for loop control")
885
+
886
+ # 8. Verify we have the body operations (add from combine_fn)
887
+ self.assertIn("aten::add", op_names, "Should have add from combine_fn body")
888
+
889
+ def test_run_emit_scan_cumsum(self) -> None:
890
+ """Test scan execution correctness: cumulative sum."""
891
+ from torch._higher_order_ops.scan import scan
892
+
893
+ class ScanCumSum(torch.nn.Module):
894
+ def forward(self, xs: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
895
+ def combine_fn(carry, x):
896
+ new_carry = carry + x
897
+ return new_carry, new_carry.clone()
898
+
899
+ init = torch.zeros_like(xs[0])
900
+ return scan(combine_fn, init, xs)
901
+
902
+ f = ScanCumSum()
903
+ # Use contiguous tensor to avoid stride=0 issue
904
+ inputs = (torch.arange(15).float().reshape(5, 3),)
905
+
906
+ module = to_edge(
907
+ export(f, inputs, strict=True),
908
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
909
+ )
910
+ et = module.to_executorch()
911
+ et.dump_executorch_program(False)
912
+ buffer = et.buffer
913
+ loaded_model = _load_for_executorch_from_buffer(buffer)
914
+
915
+ # Run through executorch
916
+ et_outputs = loaded_model(inputs)
917
+
918
+ # Run through eager PyTorch
919
+ eager_outputs = f(*inputs)
920
+
921
+ # Compare final carry
922
+ self.assertTrue(
923
+ torch.allclose(et_outputs[0], eager_outputs[0]),
924
+ f"Final carry mismatch: {et_outputs[0]} vs {eager_outputs[0]}",
925
+ )
926
+
927
+ # Compare stacked outputs
928
+ self.assertTrue(
929
+ torch.allclose(et_outputs[1], eager_outputs[1]),
930
+ f"Stacked outputs mismatch: {et_outputs[1]} vs {eager_outputs[1]}",
931
+ )
932
+
933
+ def test_emit_scan_add_mul(self) -> None:
934
+ """Test scan with add operation in combine_fn."""
935
+ from torch._higher_order_ops.scan import scan
936
+
937
+ class ScanAddMul(torch.nn.Module):
938
+ def forward(
939
+ self, xs: torch.Tensor, y: torch.Tensor
940
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
941
+ def combine_fn(carry, x):
942
+ # Multiply carry by 2 and add x
943
+ new_carry = carry * 2 + x
944
+ return new_carry, new_carry.clone()
945
+
946
+ init = torch.zeros_like(xs[0])
947
+ return scan(combine_fn, init, xs)
948
+
949
+ f = ScanAddMul()
950
+ inputs = (torch.ones(4, 3), torch.ones(3))
951
+
952
+ module = to_edge(
953
+ export(f, inputs, strict=True),
954
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
955
+ )
956
+ program = module.to_executorch().executorch_program
957
+
958
+ # Verify we have the expected operators
959
+ op_names = [op.name for op in program.execution_plan[0].operators]
960
+
961
+ # Should have mul and add operations from the combine_fn body
962
+ self.assertIn("aten::mul", op_names)
963
+ self.assertIn("aten::add", op_names)
964
+
965
+ # Should have scan control flow operators
966
+ self.assertIn("aten::sym_size", op_names)
967
+ self.assertIn("aten::select_copy", op_names)
968
+ self.assertIn("executorch_prim::et_copy_index", op_names)
969
+
970
+ def test_emit_scan_gru(self) -> None:
971
+ """Test scan with a simple GRU-like computation."""
972
+ from torch._higher_order_ops.scan import scan
973
+
974
+ class SimpleGRU(torch.nn.Module):
975
+ """Simple single-layer unidirectional GRU using scan."""
976
+
977
+ def __init__(self, input_size: int, hidden_size: int):
978
+ super().__init__()
979
+ self.input_size = input_size
980
+ self.hidden_size = hidden_size
981
+
982
+ # GRU gates: reset, update, new
983
+ self.weight_ih = torch.nn.Parameter(
984
+ torch.randn(3 * hidden_size, input_size), requires_grad=False
985
+ )
986
+ self.weight_hh = torch.nn.Parameter(
987
+ torch.randn(3 * hidden_size, hidden_size), requires_grad=False
988
+ )
989
+ self.bias_ih = torch.nn.Parameter(
990
+ torch.randn(3 * hidden_size), requires_grad=False
991
+ )
992
+ self.bias_hh = torch.nn.Parameter(
993
+ torch.randn(3 * hidden_size), requires_grad=False
994
+ )
995
+
996
+ def forward(
997
+ self, x: torch.Tensor, h0: torch.Tensor
998
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
999
+ """
1000
+ Args:
1001
+ x: Input tensor of shape [seq_len, batch, input_size]
1002
+ h0: Initial hidden state of shape [batch, hidden_size]
1003
+ Returns:
1004
+ output: Output tensor of shape [seq_len, batch, hidden_size]
1005
+ h_n: Final hidden state of shape [batch, hidden_size]
1006
+ """
1007
+ weight_ih = self.weight_ih
1008
+ weight_hh = self.weight_hh
1009
+ bias_ih = self.bias_ih
1010
+ bias_hh = self.bias_hh
1011
+
1012
+ def gru_cell(
1013
+ h: torch.Tensor, x_t: torch.Tensor
1014
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
1015
+ # Compute gates
1016
+ gates_ih = torch.nn.functional.linear(x_t, weight_ih, bias_ih)
1017
+ gates_hh = torch.nn.functional.linear(h, weight_hh, bias_hh)
1018
+
1019
+ # Split into reset, update, new gates
1020
+ r_ih, z_ih, n_ih = gates_ih.chunk(3, dim=-1)
1021
+ r_hh, z_hh, n_hh = gates_hh.chunk(3, dim=-1)
1022
+
1023
+ r = torch.sigmoid(r_ih + r_hh)
1024
+ z = torch.sigmoid(z_ih + z_hh)
1025
+ n = torch.tanh(n_ih + r * n_hh)
1026
+
1027
+ h_new = (1 - z) * n + z * h
1028
+ return h_new, h_new.clone()
1029
+
1030
+ final_h, outputs = scan(gru_cell, h0, x)
1031
+ return outputs, final_h
1032
+
1033
+ # Create model and inputs
1034
+ input_size = 4
1035
+ hidden_size = 8
1036
+ seq_len = 5
1037
+ batch_size = 2
1038
+
1039
+ model = SimpleGRU(input_size, hidden_size)
1040
+ x = torch.randn(seq_len, batch_size, input_size)
1041
+ h0 = torch.randn(batch_size, hidden_size)
1042
+ inputs = (x, h0)
1043
+
1044
+ # Run through eager PyTorch
1045
+ eager_outputs = model(*inputs)
1046
+
1047
+ # Export and convert to edge
1048
+ module = to_edge(
1049
+ export(model, inputs, strict=True),
1050
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1051
+ )
1052
+ et = module.to_executorch()
1053
+ program = et.executorch_program
1054
+
1055
+ # Verify the program has expected operators
1056
+ op_names = [op.name for op in program.execution_plan[0].operators]
1057
+
1058
+ # Should have scan control flow operators
1059
+ self.assertIn("aten::sym_size", op_names)
1060
+ self.assertIn("aten::select_copy", op_names)
1061
+ self.assertIn("executorch_prim::et_copy_index", op_names)
1062
+
1063
+ # Verify we can load the program
1064
+ buffer = et.buffer
1065
+ loaded_model = _load_for_executorch_from_buffer(buffer)
1066
+
1067
+ # Run through executorch
1068
+ et_outputs = loaded_model(inputs)
1069
+
1070
+ # Compare outputs (with tolerance for floating point)
1071
+ self.assertTrue(
1072
+ torch.allclose(et_outputs[0], eager_outputs[0], atol=1e-5),
1073
+ f"Output mismatch: {et_outputs[0]} vs {eager_outputs[0]}",
1074
+ )
1075
+ self.assertTrue(
1076
+ torch.allclose(et_outputs[1], eager_outputs[1], atol=1e-5),
1077
+ f"Final hidden state mismatch: {et_outputs[1]} vs {eager_outputs[1]}",
1078
+ )
1079
+
1080
+ def test_run_emit_scan_dynamic_shape(self) -> None:
1081
+ """Test scan execution with dynamic sequence length."""
1082
+ from torch._higher_order_ops.scan import scan
1083
+
1084
+ class ScanCumSum(torch.nn.Module):
1085
+ def forward(self, xs: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
1086
+ def combine_fn(carry, x):
1087
+ new_carry = carry + x
1088
+ return new_carry, new_carry.clone()
1089
+
1090
+ init = torch.zeros_like(xs[0])
1091
+ return scan(combine_fn, init, xs)
1092
+
1093
+ f = ScanCumSum()
1094
+
1095
+ upper_bound_inputs = (torch.arange(24).float().reshape(8, 3),)
1096
+
1097
+ seq_dim = Dim("seq", max=8)
1098
+ dynamic_shapes = {"xs": {0: seq_dim}}
1099
+
1100
+ module = to_edge(
1101
+ export(f, upper_bound_inputs, dynamic_shapes=dynamic_shapes, strict=True),
1102
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1103
+ )
1104
+ et = module.to_executorch(
1105
+ config=exir.ExecutorchBackendConfig(
1106
+ sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
1107
+ )
1108
+ )
1109
+ et.dump_executorch_program(True)
1110
+ buffer = et.buffer
1111
+ loaded_model = _load_for_executorch_from_buffer(buffer)
1112
+
1113
+ test_cases = [
1114
+ (torch.arange(15).float().reshape(5, 3),), # seq_len=5
1115
+ (torch.arange(9).float().reshape(3, 3),), # seq_len=3
1116
+ (torch.arange(21).float().reshape(7, 3),), # seq_len=7
1117
+ ]
1118
+
1119
+ for test_inputs in test_cases:
1120
+ et_outputs = loaded_model(test_inputs)
1121
+ eager_outputs = f(*test_inputs)
1122
+
1123
+ self.assertTrue(
1124
+ torch.allclose(et_outputs[0], eager_outputs[0]),
1125
+ f"Final carry mismatch for shape {test_inputs[0].shape}: {et_outputs[0]} vs {eager_outputs[0]}",
1126
+ )
1127
+ self.assertTrue(
1128
+ torch.allclose(et_outputs[1], eager_outputs[1]),
1129
+ f"Stacked outputs mismatch for shape {test_inputs[0].shape}: {et_outputs[1]} vs {eager_outputs[1]}",
1130
+ )
1131
+
1132
+ def test_dim_order(self) -> None:
1133
+ class SimpleLinear(torch.nn.Module):
1134
+ def __init__(self) -> None:
1135
+ super().__init__()
1136
+ self.linear = torch.nn.Linear(5, 5)
1137
+
1138
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1139
+ return torch.nn.functional.relu(self.linear(x))
1140
+
1141
+ model = SimpleLinear()
1142
+ inputs = (torch.ones(10, 5),)
1143
+ program = (
1144
+ to_edge(
1145
+ export(model, inputs, strict=True),
1146
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1147
+ )
1148
+ .to_executorch()
1149
+ .executorch_program
1150
+ )
1151
+
1152
+ addmm_found = False
1153
+ for inst in program.execution_plan[0].chains[0].instructions:
1154
+ kernel = inst.instr_args
1155
+ if isinstance(kernel, KernelCall):
1156
+ op_id = kernel.op_index
1157
+ op = program.execution_plan[0].operators[op_id]
1158
+ if op.name == "aten::addmm":
1159
+ addmm_found = True
1160
+ args = kernel.args
1161
+ bias_id = args[0]
1162
+ act_id = args[1]
1163
+ weight_id = args[2]
1164
+ bias_dim_order = [0]
1165
+ act_dim_order = [0, 1]
1166
+ weight_dim_order = [0, 1]
1167
+ bias_tensor = typing.cast(
1168
+ schema.Tensor, program.execution_plan[0].values[bias_id].val
1169
+ )
1170
+ act_tensor = typing.cast(
1171
+ schema.Tensor, program.execution_plan[0].values[act_id].val
1172
+ )
1173
+ weight_tensor = typing.cast(
1174
+ schema.Tensor, program.execution_plan[0].values[weight_id].val
1175
+ )
1176
+ self.assertTrue(bias_tensor.dim_order == bias_dim_order)
1177
+ self.assertTrue(act_tensor.dim_order == act_dim_order)
1178
+ self.assertTrue(weight_tensor.dim_order == weight_dim_order)
1179
+ self.assertTrue(addmm_found)
1180
+
1181
+ def test_non_const_buffer_sizes(self) -> None:
1182
+ class Add(torch.nn.Module):
1183
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1184
+ b = 3 + 1
1185
+ return x + torch.tensor(b)
1186
+
1187
+ f = Add()
1188
+
1189
+ edge_program_manager = to_edge(export(f, (torch.ones(3, 2),), strict=True))
1190
+ edge_program_manager._edge_programs["forward"] = constant_prop_pass(
1191
+ edge_program_manager.exported_program()
1192
+ )
1193
+ non_const_buffer_size_with_const_prop_pass = (
1194
+ edge_program_manager.to_executorch()
1195
+ .executorch_program.execution_plan[0]
1196
+ .non_const_buffer_sizes
1197
+ )
1198
+
1199
+ edge_program_manager = to_edge(export(f, (torch.ones(3, 2),), strict=True))
1200
+ non_const_buffer_size_without_const_prop_pass = (
1201
+ edge_program_manager.to_executorch()
1202
+ .executorch_program.execution_plan[0]
1203
+ .non_const_buffer_sizes
1204
+ )
1205
+ self.assertTrue(
1206
+ non_const_buffer_size_with_const_prop_pass[1]
1207
+ < non_const_buffer_size_without_const_prop_pass[1]
1208
+ )
1209
+
1210
+ # cant compare plans directly with __eq__ because of the plan names, and data_buffer_idx in tensor values
1211
+ def _compare_execution_plans(
1212
+ self, plan_single: ExecutionPlan, plan_merged: ExecutionPlan
1213
+ ) -> None:
1214
+ self.assertEqual(
1215
+ plan_single.container_meta_type,
1216
+ plan_merged.container_meta_type,
1217
+ )
1218
+ self.assertEqual(
1219
+ plan_single.inputs,
1220
+ plan_merged.inputs,
1221
+ )
1222
+ self.assertEqual(
1223
+ plan_single.outputs,
1224
+ plan_merged.outputs,
1225
+ )
1226
+ self.assertEqual(
1227
+ plan_single.chains,
1228
+ plan_merged.chains,
1229
+ )
1230
+ self.assertEqual(
1231
+ plan_single.operators,
1232
+ plan_merged.operators,
1233
+ )
1234
+ self.assertEqual(
1235
+ plan_single.non_const_buffer_sizes,
1236
+ plan_merged.non_const_buffer_sizes,
1237
+ )
1238
+ self.assertEqual(
1239
+ len(plan_single.values),
1240
+ len(plan_merged.values),
1241
+ )
1242
+ for i in range(0, len(plan_single.values)):
1243
+ single_val = plan_single.values[i].val
1244
+ merged_val = plan_merged.values[i].val
1245
+ if isinstance(single_val, Tensor):
1246
+ # constant buffer index might be different as the constant buffer is shared between plans
1247
+ self.assertTrue(isinstance(merged_val, Tensor))
1248
+ self.assertEqual(single_val.storage_offset, merged_val.storage_offset)
1249
+ self.assertEqual(single_val.scalar_type, merged_val.scalar_type)
1250
+ self.assertEqual(single_val.sizes, merged_val.sizes)
1251
+ self.assertEqual(single_val.dim_order, merged_val.dim_order)
1252
+ self.assertEqual(single_val.requires_grad, merged_val.requires_grad)
1253
+ self.assertEqual(single_val.layout, merged_val.layout)
1254
+ self.assertEqual(single_val.allocation_info, merged_val.allocation_info)
1255
+ self.assertEqual(single_val.shape_dynamism, merged_val.shape_dynamism)
1256
+ else:
1257
+ self.assertEqual(single_val, merged_val)
1258
+
1259
+ def test_emit_memory_format_valid(self) -> None:
1260
+ class SimpleLinear(torch.nn.Module):
1261
+ def __init__(self) -> None:
1262
+ super().__init__()
1263
+
1264
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1265
+ contiguous = x.to(
1266
+ dtype=torch.float32, memory_format=torch.contiguous_format
1267
+ )
1268
+ preserve = x.to(
1269
+ dtype=torch.float32, memory_format=torch.preserve_format
1270
+ )
1271
+ return contiguous + preserve
1272
+
1273
+ # Should succeed at exporting model with legal memory format (contiguous, preserve)
1274
+ model = SimpleLinear()
1275
+ inputs = (torch.ones(10, 5),)
1276
+ try:
1277
+ to_edge(
1278
+ export(model, inputs, strict=True),
1279
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1280
+ ).to_executorch()
1281
+ except:
1282
+ self.fail("Failed to export model with legal memory format")
1283
+
1284
+ def test_emit_memory_format_invalid(self) -> None:
1285
+ class SimpleLinear(torch.nn.Module):
1286
+ def __init__(self) -> None:
1287
+ super().__init__()
1288
+
1289
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1290
+ return x.to(dtype=torch.float32, memory_format=torch.channels_last)
1291
+
1292
+ # Failure expected when exporting model with illegal memory format (channels_last) when not using dim_order
1293
+ model = SimpleLinear()
1294
+ inputs = (torch.ones(10, 5, 2, 1),)
1295
+ with self.assertRaises(InternalError):
1296
+ to_edge(
1297
+ export(model, inputs, strict=True),
1298
+ compile_config=exir.EdgeCompileConfig(
1299
+ _check_ir_validity=False, _skip_dim_order=True
1300
+ ),
1301
+ ).to_executorch()
1302
+
1303
+ # Success if you use dim_order
1304
+ to_edge(
1305
+ export(model, inputs, strict=True),
1306
+ compile_config=exir.EdgeCompileConfig(
1307
+ _check_ir_validity=False, _skip_dim_order=False
1308
+ ),
1309
+ ).to_executorch()
1310
+
1311
+ def test_emit_multiple_entry_points(self) -> None:
1312
+ class SimpleLinear(torch.nn.Module):
1313
+ def __init__(self) -> None:
1314
+ super().__init__()
1315
+ self.linear = torch.nn.Linear(5, 5)
1316
+ self.linear2 = torch.nn.Linear(5, 5)
1317
+
1318
+ def forward_relu(self, x: torch.Tensor) -> torch.Tensor:
1319
+ return torch.nn.functional.relu(self.linear(x))
1320
+
1321
+ def forward_sigmoid(self, x: torch.Tensor) -> torch.Tensor:
1322
+ return torch.nn.functional.sigmoid(self.linear2(x))
1323
+
1324
+ model = SimpleLinear()
1325
+ inputs = (torch.ones(10, 5),)
1326
+ with patch_forward(model, model.forward_relu):
1327
+ program_relu = to_edge(
1328
+ export(model, inputs, strict=True),
1329
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1330
+ ).to_executorch()
1331
+ with patch_forward(model, model.forward_sigmoid):
1332
+ program_sigmoid = to_edge(
1333
+ export(model, inputs, strict=True),
1334
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1335
+ ).to_executorch()
1336
+ exir_input = {
1337
+ "forward_relu": program_relu.exported_program(),
1338
+ "forward_sigmoid": program_sigmoid.exported_program(),
1339
+ }
1340
+ merged_program = emit_program(exir_input, False).program
1341
+ self.assertEqual(len(merged_program.execution_plan), 2)
1342
+
1343
+ self.assertEqual(
1344
+ merged_program.execution_plan[0].name,
1345
+ "forward_relu",
1346
+ )
1347
+ self.assertEqual(
1348
+ merged_program.execution_plan[1].name,
1349
+ "forward_sigmoid",
1350
+ )
1351
+ # reserved spot, weight, bias
1352
+ self.assertEqual(
1353
+ len(program_sigmoid._emitter_output.program.constant_buffer),
1354
+ 3,
1355
+ )
1356
+ self.assertEqual(
1357
+ len(program_relu._emitter_output.program.constant_buffer),
1358
+ 3,
1359
+ )
1360
+ # sum of the entry points minus 1 because we only have one reserved spot still
1361
+ self.assertEqual(
1362
+ len(merged_program.constant_buffer),
1363
+ len(program_sigmoid._emitter_output.program.constant_buffer)
1364
+ + len(program_relu._emitter_output.program.constant_buffer)
1365
+ - 1,
1366
+ )
1367
+
1368
+ self._compare_execution_plans(
1369
+ merged_program.execution_plan[0],
1370
+ program_relu._emitter_output.program.execution_plan[0],
1371
+ )
1372
+ self._compare_execution_plans(
1373
+ merged_program.execution_plan[1],
1374
+ program_sigmoid._emitter_output.program.execution_plan[0],
1375
+ )
1376
+
1377
+ def test_emit_weight_deduplication(self) -> None:
1378
+ class SimpleLinear(torch.nn.Module):
1379
+ def __init__(self) -> None:
1380
+ super().__init__()
1381
+ self.linear = torch.nn.Linear(5, 5)
1382
+
1383
+ def forward_relu(self, x: torch.Tensor) -> torch.Tensor:
1384
+ return torch.nn.functional.relu(self.linear(x))
1385
+
1386
+ def forward_sigmoid(self, x: torch.Tensor) -> torch.Tensor:
1387
+ return torch.nn.functional.sigmoid(self.linear(x))
1388
+
1389
+ model = SimpleLinear()
1390
+ inputs = (torch.ones(10, 5),)
1391
+ with patch_forward(model, model.forward_relu):
1392
+ program_relu = to_edge(export(model, inputs, strict=True)).to_executorch()
1393
+ with patch_forward(model, model.forward_sigmoid):
1394
+ program_sigmoid = to_edge(
1395
+ export(model, inputs, strict=True)
1396
+ ).to_executorch()
1397
+ exir_input = {
1398
+ "forward_relu": program_relu.exported_program(),
1399
+ "forward_sigmoid": program_sigmoid.exported_program(),
1400
+ }
1401
+ merged_program = emit_program(exir_input, False).program
1402
+ self.assertEqual(len(merged_program.execution_plan), 2)
1403
+
1404
+ # reserved spot, weight, bias
1405
+ self.assertEqual(
1406
+ len(program_sigmoid._emitter_output.program.constant_buffer),
1407
+ 3,
1408
+ )
1409
+ self.assertEqual(
1410
+ len(program_relu._emitter_output.program.constant_buffer),
1411
+ 3,
1412
+ )
1413
+ # weights are shared between entry points so the merged one should deduplicate everything
1414
+ self.assertEqual(len(merged_program.constant_buffer), 3)
1415
+
1416
+ self._compare_execution_plans(
1417
+ merged_program.execution_plan[0],
1418
+ program_relu._emitter_output.program.execution_plan[0],
1419
+ )
1420
+ self._compare_execution_plans(
1421
+ merged_program.execution_plan[1],
1422
+ program_sigmoid._emitter_output.program.execution_plan[0],
1423
+ )
1424
+
1425
+ def test_emit_execution_plans_sorted(self) -> None:
1426
+ class Simple(torch.nn.Module):
1427
+ def __init__(self) -> None:
1428
+ super().__init__()
1429
+
1430
+ def a(self, x: torch.Tensor) -> torch.Tensor:
1431
+ return x
1432
+
1433
+ def b(self, x: torch.Tensor) -> torch.Tensor:
1434
+ return x
1435
+
1436
+ def c(self, x: torch.Tensor) -> torch.Tensor:
1437
+ return x
1438
+
1439
+ model = Simple()
1440
+ inputs = (torch.ones(10, 5),)
1441
+
1442
+ def make_program(
1443
+ fn,
1444
+ inputs,
1445
+ ) -> "ExecutorchProgramManager":
1446
+ return to_edge(
1447
+ export(WrapperModule(fn), inputs, strict=True)
1448
+ ).to_executorch()
1449
+
1450
+ program_a = make_program(model.a, inputs)
1451
+ program_b = make_program(model.b, inputs)
1452
+ program_c = make_program(model.c, inputs)
1453
+
1454
+ exir_input = {
1455
+ "b": program_b.exported_program(),
1456
+ "c": program_c.exported_program(),
1457
+ "a": program_a.exported_program(),
1458
+ }
1459
+ merged_program = emit_program(exir_input, False).program
1460
+ self.assertEqual(len(merged_program.execution_plan), 3)
1461
+ self.assertEqual(merged_program.execution_plan[0].name, "a")
1462
+ self.assertEqual(merged_program.execution_plan[1].name, "b")
1463
+ self.assertEqual(merged_program.execution_plan[2].name, "c")
1464
+
1465
+ # Create a second program equivalent to the first, but the input is in a different order.
1466
+ # python dicts are instertion ordered
1467
+ exir_input2 = {
1468
+ "a": program_b.exported_program(),
1469
+ "b": program_c.exported_program(),
1470
+ "c": program_a.exported_program(),
1471
+ }
1472
+ merged_program2 = emit_program(exir_input2, False).program
1473
+ self.assertEqual(
1474
+ merged_program2.execution_plan[0], merged_program.execution_plan[0]
1475
+ )
1476
+ self.assertEqual(
1477
+ merged_program2.execution_plan[1], merged_program.execution_plan[1]
1478
+ )
1479
+ self.assertEqual(
1480
+ merged_program2.execution_plan[2], merged_program.execution_plan[2]
1481
+ )
1482
+
1483
+ def test_upper_bound_memory_planning_respect_input_constraints(self) -> None:
1484
+ class Foo(torch.nn.Module):
1485
+ def forward(self, k: torch.Tensor) -> torch.Tensor:
1486
+ k = torch.cat((k, torch.ones(1, 4)))
1487
+ return k
1488
+
1489
+ func = Foo()
1490
+
1491
+ k = torch.rand(2, 4)
1492
+ dim0_k = Dim("dim0_k", max=3)
1493
+ dynamic_shapes = {"k": {0: dim0_k}}
1494
+ captured = export(func, (k,), dynamic_shapes=dynamic_shapes, strict=True)
1495
+ edge = to_edge(captured)
1496
+ from executorch.exir.passes import MemoryPlanningPass
1497
+
1498
+ config = exir.ExecutorchBackendConfig(
1499
+ sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
1500
+ memory_planning_pass=MemoryPlanningPass(
1501
+ # allow_lifetime_and_storage_overlap: bool = False,
1502
+ alloc_graph_input=True,
1503
+ alloc_graph_output=False,
1504
+ ),
1505
+ )
1506
+
1507
+ exe_prog = edge.to_executorch(config)
1508
+ program = exe_prog._emitter_output.program
1509
+ exir.print_program.pretty_print(exe_prog._emitter_output.program.execution_plan)
1510
+ execution_plan = program.execution_plan[0]
1511
+ self.check_tensor_buffer_loc(0, execution_plan.values, 0, 1, 0)
1512
+ self.check_tensor_buffer_loc(1, execution_plan.values, 0, 1, 48)
1513
+
1514
+ def test_emit_prims(self) -> None:
1515
+ tensor_output = torch.rand(1, 4)
1516
+ tensor_list_output = [torch.rand(1, 4), torch.rand(1, 4)]
1517
+
1518
+ class Simple(torch.nn.Module):
1519
+ def __init__(self) -> None:
1520
+ super().__init__()
1521
+ self.linear = torch.nn.Linear(5, 5)
1522
+ self.x: int = 3
1523
+ self.y = 2
1524
+
1525
+ def get_ints(self) -> Tuple[int]:
1526
+ return (self.x, self.y)
1527
+
1528
+ def get_str(self) -> str:
1529
+ return "foo"
1530
+
1531
+ def get_tensor(self) -> torch.Tensor:
1532
+ return tensor_output
1533
+
1534
+ def get_tensor_list(self) -> List[torch.Tensor]:
1535
+ return tensor_list_output
1536
+
1537
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1538
+ return torch.nn.functional.sigmoid(self.linear(x))
1539
+
1540
+ model = Simple()
1541
+ inputs = (torch.ones(10, 5),)
1542
+ program = to_edge(export(model, inputs, strict=True)).to_executorch()
1543
+ exir_input = {
1544
+ "forward": program.exported_program(),
1545
+ }
1546
+ getters = {}
1547
+ getters["get_ints"] = model.get_ints()
1548
+ getters["get_str"] = model.get_str()
1549
+ getters["get_tensor"] = model.get_tensor()
1550
+ getters["get_tensor_list"] = model.get_tensor_list()
1551
+
1552
+ merged_program = emit_program(exir_input, False, getters).program
1553
+
1554
+ self.assertEqual(len(merged_program.execution_plan), 5)
1555
+
1556
+ self.assertEqual(
1557
+ merged_program.execution_plan[0].name,
1558
+ "forward",
1559
+ )
1560
+ self.assertEqual(
1561
+ merged_program.execution_plan[1].name,
1562
+ "get_ints",
1563
+ )
1564
+ self.assertEqual(
1565
+ merged_program.execution_plan[2].name,
1566
+ "get_str",
1567
+ )
1568
+ self.assertEqual(
1569
+ merged_program.execution_plan[3].name,
1570
+ "get_tensor",
1571
+ )
1572
+ self.assertEqual(
1573
+ merged_program.execution_plan[4].name,
1574
+ "get_tensor_list",
1575
+ )
1576
+
1577
+ # no instructions in a getter
1578
+ self.assertEqual(
1579
+ len(merged_program.execution_plan[1].chains[0].instructions),
1580
+ 0,
1581
+ )
1582
+ # 2 outputs for the flattened tuple
1583
+ self.assertEqual(
1584
+ len(merged_program.execution_plan[1].outputs),
1585
+ 2,
1586
+ )
1587
+ # outputs are 0 and 1 in the values table
1588
+ self.assertEqual(
1589
+ merged_program.execution_plan[1].outputs,
1590
+ [0, 1],
1591
+ )
1592
+ # value 0 is 3
1593
+ self.assertEqual(
1594
+ # pyre-ignore
1595
+ merged_program.execution_plan[1].values[0].val.int_val,
1596
+ 3,
1597
+ )
1598
+ self.assertEqual(
1599
+ # pyre-ignore
1600
+ merged_program.execution_plan[1].values[1].val.int_val,
1601
+ 2,
1602
+ )
1603
+ self.assertEqual(
1604
+ len(merged_program.execution_plan[2].outputs),
1605
+ 1,
1606
+ )
1607
+ self.assertEqual(
1608
+ # pyre-ignore
1609
+ merged_program.execution_plan[2].values[0].val.string_val,
1610
+ "foo",
1611
+ )
1612
+ self.assertEqual(len(merged_program.execution_plan[3].outputs), 1)
1613
+ self.assertEqual(len(merged_program.execution_plan[4].outputs), 2)
1614
+
1615
+ merged_program = to_edge(
1616
+ export(model, inputs, strict=True), constant_methods=getters
1617
+ ).to_executorch()
1618
+ executorch_module = _load_for_executorch_from_buffer(merged_program.buffer)
1619
+ torch.allclose(executorch_module.run_method("get_tensor", [])[0], tensor_output)
1620
+ model_output = executorch_module.run_method("get_tensor_list", [])
1621
+ for i in range(len(tensor_list_output)):
1622
+ torch.allclose(model_output[i], tensor_list_output[i])
1623
+
1624
+ def test_emit_debug_handle_map(self) -> None:
1625
+ mul_model = Mul()
1626
+ program_mul = to_edge(
1627
+ export(mul_model, mul_model.get_random_inputs(), strict=True)
1628
+ ).to_executorch()
1629
+ # this triggers the actual emission of the graph
1630
+ program_mul._emitter_output.program
1631
+ self.assertIsNotNone(program_mul.debug_handle_map)
1632
+
1633
+ def test_final_graph_module_update_debug_handle(self) -> None:
1634
+ class SimpleAddMul(torch.nn.Module):
1635
+ def __init__(self) -> None:
1636
+ super().__init__()
1637
+
1638
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
1639
+ a = x + 1
1640
+ return a * 2
1641
+
1642
+ mul_model = SimpleAddMul()
1643
+ program_mul = to_edge(
1644
+ export(mul_model, (torch.ones(2, 2),), strict=True)
1645
+ ).to_executorch()
1646
+
1647
+ # this triggers the actual emission of the graph
1648
+ program = program_mul._emitter_output.program
1649
+ node = None
1650
+ program.execution_plan[0].chains[0].instructions[0].instr_args.op_index
1651
+
1652
+ # Find the multiplication node in the graph that was emitted.
1653
+ for node in program_mul.exported_program().graph.nodes:
1654
+ if (
1655
+ node.target == torch.ops.aten.mul.out
1656
+ or node.target == torch.ops.aten.mul.Scalar_out
1657
+ ):
1658
+ break
1659
+ self.assertIsNotNone(node)
1660
+
1661
+ idx = 0
1662
+ # Find the multiplication instruction in the program that was emitted.
1663
+ for idx in range(len(program.execution_plan[0].chains[0].instructions)):
1664
+ instruction = program.execution_plan[0].chains[0].instructions[idx]
1665
+ op_index = instruction.instr_args.op_index
1666
+ if "mul" in program.execution_plan[0].operators[op_index].name:
1667
+ break
1668
+
1669
+ # The instruction id of the multiplication instruction and the debug handle of the
1670
+ # multiplication node in the graph module (which was updated in the emitter to be
1671
+ # the same as the instruction id) must be the same.
1672
+ self.assertEqual(
1673
+ idx,
1674
+ node.meta.get("debug_handle"),
1675
+ )
1676
+
1677
+ def test_delegate_with_input_list(self) -> None:
1678
+ class BackendWithCompilerExample(BackendDetails):
1679
+ @staticmethod
1680
+ def preprocess(
1681
+ edge_program,
1682
+ compile_specs,
1683
+ ) -> bytes:
1684
+ return PreprocessResult(
1685
+ processed_bytes=bytes(str("test"), encoding="utf8"),
1686
+ debug_handle_map=None,
1687
+ )
1688
+
1689
+ class TestModel(nn.Module):
1690
+ def __init__(self):
1691
+ super(TestModel, self).__init__()
1692
+
1693
+ def forward(self, x):
1694
+ return torch.cat(x)
1695
+
1696
+ inputs = ([torch.ones(2, 2), torch.ones(2, 2)],)
1697
+ model = TestModel()
1698
+ edgeir_m = to_edge(export(model, inputs, strict=True))
1699
+ lowered_module = to_backend(
1700
+ "BackendWithCompilerExample", edgeir_m.exported_program(), []
1701
+ )
1702
+
1703
+ class CompositeModule(torch.nn.Module):
1704
+ def __init__(self):
1705
+ super().__init__()
1706
+ self.lowered_module = lowered_module
1707
+
1708
+ def forward(self, list_a):
1709
+ return self.lowered_module(list_a)
1710
+
1711
+ composite_model = CompositeModule()
1712
+ exec_prog = to_edge(
1713
+ export(composite_model, inputs, strict=True),
1714
+ ).to_executorch()
1715
+ exec_prog.buffer
1716
+
1717
+ def test_delegate_with_input_tuple(self) -> None:
1718
+ class BackendWithCompilerExample(BackendDetails):
1719
+ @staticmethod
1720
+ def preprocess(
1721
+ edge_program,
1722
+ compile_specs,
1723
+ ) -> bytes:
1724
+ return PreprocessResult(
1725
+ processed_bytes=bytes(str("test"), encoding="utf8"),
1726
+ debug_handle_map=None,
1727
+ )
1728
+
1729
+ class AddMulModule(torch.nn.Module):
1730
+ def __init__(self):
1731
+ super().__init__()
1732
+
1733
+ def forward(self, input): # a, x, b):
1734
+ y = torch.mm(input[0], input[1])
1735
+ z = torch.add(y, input[2])
1736
+ return z
1737
+
1738
+ model_inputs = ((torch.ones(2, 2), 2 * torch.ones(2, 2), 3 * torch.ones(2, 2)),)
1739
+ model = AddMulModule()
1740
+ edgeir_m = to_edge(export(model, model_inputs, strict=True))
1741
+ lowered_module = to_backend(
1742
+ "BackendWithCompilerExample", edgeir_m.exported_program(), []
1743
+ )
1744
+
1745
+ class CompositeModule(torch.nn.Module):
1746
+ def __init__(self):
1747
+ super().__init__()
1748
+ self.lowered_module = lowered_module
1749
+
1750
+ def forward(self, list_a):
1751
+ return self.lowered_module(list_a)
1752
+
1753
+ composite_model = CompositeModule()
1754
+ exec_prog = to_edge(
1755
+ export(composite_model, model_inputs, strict=True),
1756
+ ).to_executorch()
1757
+ exec_prog.buffer
1758
+
1759
+ def test_delegate_mapping(self) -> None:
1760
+ debug_handle_map = {1: [1, 2]}
1761
+
1762
+ class BackendWithCompilerExample(BackendDetails):
1763
+ @staticmethod
1764
+ def preprocess(
1765
+ edge_program,
1766
+ compile_specs,
1767
+ ) -> bytes:
1768
+ return PreprocessResult(
1769
+ processed_bytes=bytes(str("test"), encoding="utf8"),
1770
+ debug_handle_map=debug_handle_map,
1771
+ )
1772
+
1773
+ class TestModel(nn.Module):
1774
+ def __init__(self):
1775
+ super(TestModel, self).__init__()
1776
+
1777
+ def forward(self, x, y):
1778
+ return torch.add(x, y)
1779
+
1780
+ inputs = (torch.ones(2, 2), torch.ones(2, 2))
1781
+ model = TestModel()
1782
+ edgeir_m = to_edge(export(model, inputs, strict=True))
1783
+ lowered_module = to_backend(
1784
+ "BackendWithCompilerExample", edgeir_m.exported_program(), []
1785
+ )
1786
+
1787
+ class CompositeModule(torch.nn.Module):
1788
+ def __init__(self):
1789
+ super().__init__()
1790
+ self.lowered_module = lowered_module
1791
+
1792
+ def forward(self, x, y):
1793
+ return self.lowered_module(x, y)
1794
+
1795
+ composite_model = CompositeModule()
1796
+ exec_prog = to_edge(
1797
+ export(composite_model, inputs, strict=True),
1798
+ ).to_executorch()
1799
+ # Reading the program triggers the call to emit_program underneath which
1800
+ # we need to be done for our test to succeed.
1801
+ exec_prog._emitter_output.program
1802
+ self.assertIsNotNone(exec_prog.delegate_map)
1803
+ self.assertIsNotNone(exec_prog.delegate_map.get("forward"))
1804
+ self.assertIsNotNone(exec_prog.delegate_map.get("forward").get(0))
1805
+ self.assertEqual(
1806
+ exec_prog.delegate_map.get("forward").get(0).get("name"),
1807
+ "BackendWithCompilerExample",
1808
+ )
1809
+ self.assertTrue(
1810
+ len(exec_prog.delegate_map.get("forward").get(0).get("delegate_map")) != 0
1811
+ )
1812
+
1813
+ def test_emit_weight_view(self) -> None:
1814
+ class ModWithWeightViews(nn.Module):
1815
+ def __init__(self):
1816
+ super(ModWithWeightViews, self).__init__()
1817
+ self.W = torch.nn.Parameter(torch.randn(2))
1818
+ self.W1 = self.W[:1]
1819
+ self.W2 = self.W[1:]
1820
+
1821
+ def forward(self, x):
1822
+ return self.W1 + self.W2 + x
1823
+
1824
+ model = ModWithWeightViews()
1825
+ # each weight is a view of the same storage
1826
+ self.assertEqual(model.W1.nbytes, 4)
1827
+ self.assertEqual(model.W1.untyped_storage().nbytes(), 8)
1828
+ self.assertEqual(model.W2.nbytes, 4)
1829
+ self.assertEqual(model.W2.untyped_storage().nbytes(), 8)
1830
+ program = to_edge(export(model, (torch.ones(1),), strict=True)).to_executorch()
1831
+
1832
+ program = program._emitter_output.program
1833
+ # each emitted weight is not a view
1834
+ self.assertEqual(len(program.constant_buffer[1].storage), 4)
1835
+ self.assertEqual(len(program.constant_buffer[2].storage), 4)
1836
+
1837
+ def test_non_persistent_buffer(self) -> None:
1838
+ class NonPersistentBuffer(nn.Module):
1839
+ def __init__(self):
1840
+ super(NonPersistentBuffer, self).__init__()
1841
+ self.register_buffer("buf", torch.tensor([1]), persistent=False)
1842
+
1843
+ def forward(self, x):
1844
+ return x + self.buf
1845
+
1846
+ model = NonPersistentBuffer()
1847
+ program = to_edge(export(model, (torch.ones(1),), strict=True)).to_executorch()
1848
+ program = program._emitter_output.program
1849
+ # confirm that the buffer was emitted
1850
+ self.assertEqual(len(program.constant_buffer), 2)
1851
+ self.assertEqual(len(program.constant_buffer[1].storage), 8)
1852
+
1853
+ def test_emit_lifted_tensor_constant(self) -> None:
1854
+ class LiftedTensorConstants(nn.Module):
1855
+ def __init__(self):
1856
+ super().__init__()
1857
+
1858
+ def forward(self, x):
1859
+ x = x * torch.tensor([[4, 3], [1, 2], [5, 6]], dtype=torch.float)
1860
+ return x
1861
+
1862
+ model = LiftedTensorConstants()
1863
+ # Specify that we want to move non-lifted constants to external file
1864
+ et_cfg = ExecutorchBackendConfig(external_constants=True)
1865
+ program = to_edge(
1866
+ export(model, (torch.ones(3, 2),), strict=True)
1867
+ ).to_executorch(et_cfg)
1868
+ program = program._emitter_output.program
1869
+ exec_plan = program.execution_plan[0]
1870
+ # There should only be 1 input to this model.
1871
+ self.assertEqual(len(exec_plan.inputs), 1)
1872
+ self.assertEqual(len(program.constant_buffer), 2)
1873
+ self.assertEqual(len(program.constant_buffer[1].storage), 24)
1874
+
1875
+ def test_emit_lifted_constant(self) -> None:
1876
+ class LiftedConstants(nn.Module):
1877
+ def __init__(self):
1878
+ super().__init__()
1879
+
1880
+ def forward(self, x):
1881
+ x = x + 1
1882
+ return x
1883
+
1884
+ model = LiftedConstants()
1885
+ # Specify that we want to move non-lifted constants to external file
1886
+ et_cfg = ExecutorchBackendConfig(external_constants=True)
1887
+ program = to_edge(
1888
+ export(model, (torch.ones(3, 2),), strict=True)
1889
+ ).to_executorch(et_cfg)
1890
+
1891
+ program = program._emitter_output.program
1892
+ exec_plan = program.execution_plan[0]
1893
+ # There should only be 1 input to this model.
1894
+ self.assertEqual(len(exec_plan.inputs), 1)
1895
+ self.assertEqual(len(program.constant_buffer), 2)
1896
+ self.assertEqual(len(program.constant_buffer[1].storage), 8)
1897
+
1898
+ def test_mutable_buffers(self) -> None:
1899
+ def count_copies(gm: torch.fx.GraphModule) -> int:
1900
+ return sum(
1901
+ (
1902
+ node.target == torch.ops.aten.copy_
1903
+ or node.target == exir_ops.edge.aten.copy_.default
1904
+ )
1905
+ for node in gm.graph.nodes
1906
+ )
1907
+
1908
+ class MutableStateModule(torch.nn.Module):
1909
+ def __init__(self):
1910
+ super().__init__()
1911
+ self.register_buffer("state", torch.zeros(1))
1912
+
1913
+ def forward(self, x):
1914
+ y = x + self.state
1915
+ self.state.add_(1)
1916
+ return y
1917
+
1918
+ model = to_edge(export(MutableStateModule(), (torch.zeros(1),), strict=True))
1919
+ model = model.to_executorch()
1920
+ self.assertTrue(
1921
+ model.executorch_program.execution_plan[0].values[0].val.allocation_info
1922
+ is not None
1923
+ )
1924
+ executorch_module = _load_for_executorch_from_buffer(model.buffer)
1925
+ self.assertEqual(executorch_module(torch.zeros(1))[0], torch.zeros(1))
1926
+ self.assertEqual(executorch_module(torch.zeros(1))[0], torch.zeros(1) + 1)
1927
+
1928
+ def test_mutable_buffers_without_memplanned_inputs(self) -> None:
1929
+ def count_copies(gm: torch.fx.GraphModule) -> int:
1930
+ return sum(
1931
+ (
1932
+ node.target == torch.ops.aten.copy_
1933
+ or node.target == exir_ops.edge.aten.copy_.default
1934
+ )
1935
+ for node in gm.graph.nodes
1936
+ )
1937
+
1938
+ class MutableStateModule(torch.nn.Module):
1939
+ def __init__(self):
1940
+ super().__init__()
1941
+ self.register_buffer("state", torch.zeros(1))
1942
+
1943
+ def forward(self, x):
1944
+ y = x + self.state
1945
+ self.state.add_(1)
1946
+ return y
1947
+
1948
+ model = to_edge(export(MutableStateModule(), (torch.zeros(1),), strict=True))
1949
+ model = model.to_executorch(
1950
+ config=ExecutorchBackendConfig(
1951
+ memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False),
1952
+ sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
1953
+ )
1954
+ )
1955
+ model.dump_executorch_program(True)
1956
+ self.assertTrue(
1957
+ model.executorch_program.execution_plan[0].values[0].val.allocation_info
1958
+ is not None
1959
+ )
1960
+ executorch_module = _load_for_executorch_from_buffer(model.buffer)
1961
+ self.assertEqual(executorch_module(torch.zeros(1))[0], torch.zeros(1))
1962
+ self.assertEqual(executorch_module(torch.zeros(1))[0], torch.zeros(1) + 1)
1963
+
1964
+ def test_infinity_in_model(self) -> None:
1965
+ class InfinityMaskModel(nn.Module):
1966
+ def __init__(self):
1967
+ super().__init__()
1968
+ self.mask = torch.tensor([[1, 0], [0, 1]], dtype=torch.float32)
1969
+
1970
+ def forward(self, x):
1971
+ masked_weights = x.masked_fill(self.mask == 0, float("-inf"))
1972
+ return masked_weights
1973
+
1974
+ model = to_edge(export(InfinityMaskModel(), (torch.randn(2, 2),), strict=True))
1975
+
1976
+ # Confirm that we can serialize the model with infinity in it.
1977
+ model = model.to_executorch()
1978
+
1979
+ # Assert that the infinity is stored as a string "-inf".
1980
+ values = model.executorch_program.execution_plan[0].values
1981
+ self.assertEqual(values[5].val, Double(double_val=float("-inf")))
1982
+
1983
+ # Confirm that we can also deserialize the model with infinity in it.
1984
+ deserialize = deserialize_pte_binary(model.buffer)
1985
+ self.assertEqual(
1986
+ deserialize.program.execution_plan,
1987
+ model.executorch_program.execution_plan,
1988
+ )
1989
+
1990
+ def test_mutate_input_tensor(self) -> None:
1991
+ class MutateInputTensorModule(torch.nn.Module):
1992
+ def __init__(self):
1993
+ super().__init__()
1994
+
1995
+ def forward(self, x):
1996
+ x.add_(1)
1997
+
1998
+ model = to_edge(
1999
+ export(MutateInputTensorModule(), (torch.zeros(1),), strict=True)
2000
+ ).to_executorch(
2001
+ config=ExecutorchBackendConfig(
2002
+ memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False)
2003
+ )
2004
+ )
2005
+ executorch_model = _load_for_executorch_from_buffer(model.buffer)
2006
+ input = torch.zeros(1)
2007
+ executorch_model(input)
2008
+ self.assertEqual(input, torch.ones(1))
2009
+
2010
+ def test_constant_tagged_tensors(self) -> None:
2011
+ class LinearModule(torch.nn.Module):
2012
+ def __init__(self):
2013
+ super().__init__()
2014
+ self.linear = torch.nn.Linear(5, 5)
2015
+
2016
+ def forward(self, x):
2017
+ return self.linear(x)
2018
+
2019
+ model = to_edge(
2020
+ export(LinearModule(), (torch.ones(5, 5),), strict=True)
2021
+ ).to_executorch(
2022
+ config=ExecutorchBackendConfig(
2023
+ external_constants=True,
2024
+ )
2025
+ )
2026
+ emitter_output = model._emitter_output
2027
+ # Check that constant_buffer is empty besides the non-constant placeholder 0.
2028
+ self.assertEqual(len(emitter_output.program.constant_buffer), 1)
2029
+ # Check that constant weights are in the external constant buffer.
2030
+ self.assertEqual(len(emitter_output.external_constant_buffer), 2)
2031
+ # Setting external_constants=True, saves all constants to the key
2032
+ # '_default_external_constant'.
2033
+ external_map = emitter_output.external_constant_map[
2034
+ "_default_external_constant"
2035
+ ]
2036
+ self.assertEqual(len(external_map), 2)
2037
+ self.assertEqual(external_map["linear.weight"], 0)
2038
+ self.assertEqual(external_map["linear.bias"], 1)
2039
+
2040
+ def test_constant_tagged_tensors_custom(self) -> None:
2041
+ class LinearModule(torch.nn.Module):
2042
+ def __init__(self):
2043
+ super().__init__()
2044
+ self.linear = torch.nn.Linear(5, 5)
2045
+
2046
+ def forward(self, x):
2047
+ return self.linear(x)
2048
+
2049
+ model = to_edge(
2050
+ export(LinearModule(), (torch.ones(5, 5),), strict=True)
2051
+ ).to_executorch(
2052
+ config=ExecutorchBackendConfig(
2053
+ external_constants=lambda x: (
2054
+ "linear_weight" if "weight" in x.name else None
2055
+ ),
2056
+ )
2057
+ )
2058
+ emitter_output = model._emitter_output
2059
+ # constant_buffer contains placeholder and linear bias.
2060
+ self.assertEqual(len(emitter_output.program.constant_buffer), 2)
2061
+ # external constant buffer contains linear weight.
2062
+ self.assertEqual(len(emitter_output.external_constant_buffer), 1)
2063
+ # The lambda saves all constants to the key 'linear_weight'.
2064
+ external_map = emitter_output.external_constant_map["linear_weight"]
2065
+ self.assertEqual(len(external_map), 1)
2066
+ self.assertEqual(external_map["linear.weight"], 0)
2067
+
2068
+ def test_constant_tagged_tensor_dedup(self) -> None:
2069
+ class ConstantModule(nn.Module):
2070
+ def __init__(self):
2071
+ super().__init__()
2072
+ constant = torch.tensor([1.0, 2.0, 3.0])
2073
+
2074
+ # Register the same value with two different names as persistent buffers
2075
+ self.register_buffer("c0", constant.clone(), persistent=True)
2076
+ self.register_buffer("c1", constant.clone(), persistent=True)
2077
+
2078
+ def forward(self, x):
2079
+ return x + self.c0 + self.c1
2080
+
2081
+ model = to_edge(
2082
+ export(ConstantModule(), (torch.ones(1, 3),), strict=True)
2083
+ ).to_executorch(
2084
+ config=ExecutorchBackendConfig(
2085
+ external_constants=True,
2086
+ )
2087
+ )
2088
+ emitter_output = model._emitter_output
2089
+ # constant_buffer is empty besides the non-constant placeholder 0.
2090
+ self.assertEqual(len(emitter_output.program.constant_buffer), 1)
2091
+ # only one item in the external constant buffer.
2092
+ self.assertEqual(len(emitter_output.external_constant_buffer), 1)
2093
+ # Setting external_constants=True, saves all constants to the key
2094
+ # '_default_external_constant'.
2095
+ external_map = emitter_output.external_constant_map[
2096
+ "_default_external_constant"
2097
+ ]
2098
+ self.assertEqual(len(external_map), 2)
2099
+ self.assertEqual(external_map["c0"], 0)
2100
+ self.assertEqual(external_map["c1"], 0)
2101
+
2102
+ def test_constant_tagged_tensor_dedup_2(self) -> None:
2103
+ class ConstantModule(nn.Module):
2104
+ def __init__(self):
2105
+ super().__init__()
2106
+ constant0_4 = torch.tensor([1.0, 2.0, 3.0])
2107
+ constant4_5 = torch.tensor([2.0, 3.0, 4.0])
2108
+
2109
+ # Register the same value with two different names as persistent buffers
2110
+ self.register_buffer("c0", constant0_4.clone(), persistent=True)
2111
+ self.register_buffer("c1", constant0_4.clone(), persistent=True)
2112
+ self.register_buffer("c2", constant0_4.clone(), persistent=True)
2113
+ self.register_buffer("c3", constant0_4.clone(), persistent=True)
2114
+ self.register_buffer("c4", constant4_5.clone(), persistent=True)
2115
+ self.register_buffer("c5", constant4_5.clone(), persistent=True)
2116
+
2117
+ def forward(self, x):
2118
+ return x + self.c0 + self.c1 + self.c2 + self.c3 + self.c4 + self.c5
2119
+
2120
+ model = to_edge(
2121
+ export(ConstantModule(), (torch.ones(1, 3),), strict=True)
2122
+ ).to_executorch(
2123
+ config=ExecutorchBackendConfig(
2124
+ external_constants=True,
2125
+ )
2126
+ )
2127
+ emitter_output = model._emitter_output
2128
+ # constant_buffer is empty besides the non-constant placeholder 0.
2129
+ self.assertEqual(len(emitter_output.program.constant_buffer), 1)
2130
+ # Two items in the external constant buffer.
2131
+ self.assertEqual(len(emitter_output.external_constant_buffer), 2)
2132
+ # Setting external_constants=True, saves all constants to the key
2133
+ # '_default_external_constant'.
2134
+ external_map = emitter_output.external_constant_map[
2135
+ "_default_external_constant"
2136
+ ]
2137
+ self.assertEqual(len(external_map), 6)
2138
+ self.assertEqual(external_map["c0"], 0)
2139
+ self.assertEqual(external_map["c1"], 0)
2140
+ self.assertEqual(external_map["c2"], 0)
2141
+ self.assertEqual(external_map["c3"], 0)
2142
+ self.assertEqual(external_map["c4"], 1)
2143
+ self.assertEqual(external_map["c5"], 1)
2144
+
2145
+ def test_delegate_deduplicate(self) -> None:
2146
+ class SharedModule(torch.nn.Module):
2147
+ def __init__(self):
2148
+ super().__init__()
2149
+ self.linear = torch.nn.Linear(2, 2)
2150
+
2151
+ def forward(self, x):
2152
+ return self.linear(x)
2153
+
2154
+ class Module1(torch.nn.Module):
2155
+ def __init__(self, shared_module):
2156
+ super().__init__()
2157
+ self.shared_module = shared_module
2158
+
2159
+ def forward(self, x):
2160
+ return self.shared_module(x)
2161
+
2162
+ class Module2(torch.nn.Module):
2163
+ def __init__(self, shared_module):
2164
+ super().__init__()
2165
+ self.shared_module = shared_module
2166
+
2167
+ def forward(self, x):
2168
+ return self.shared_module(x)
2169
+
2170
+ shared_module = SharedModule()
2171
+ module_1 = Module1(shared_module)
2172
+ module_2 = Module2(shared_module)
2173
+ example_inputs = (torch.randn(2, 2),)
2174
+ module_1(*example_inputs)
2175
+ module_2(*example_inputs)
2176
+
2177
+ ep1 = export(module_1, example_inputs, strict=True)
2178
+ ep2 = export(module_2, example_inputs, strict=True)
2179
+
2180
+ edge_program_manager = exir.to_edge(
2181
+ {"forward1": ep1, "forward2": ep2},
2182
+ compile_config=exir.EdgeCompileConfig(
2183
+ _check_ir_validity=False, _use_edge_ops=True
2184
+ ),
2185
+ )
2186
+
2187
+ edge_program_manager = edge_program_manager.to_backend(
2188
+ ExecutorBackendPartitioner()
2189
+ ).to_executorch()
2190
+
2191
+ # Check that there is only one delegate because two methods are exactly the same
2192
+ self.assertEqual(
2193
+ len(edge_program_manager.executorch_program.backend_delegate_data), 1
2194
+ )
2195
+
2196
+ def test_delegate_deduplicate_with_different_compile_specs(self) -> None:
2197
+ class LowerableSubModel(torch.nn.Module):
2198
+ def __init__(self):
2199
+ super().__init__()
2200
+
2201
+ def forward(self, x):
2202
+ return torch.sin(x)
2203
+
2204
+ lowered = LowerableSubModel()
2205
+ example_input = (torch.ones(1),)
2206
+
2207
+ lowered_edge = to_edge(export(lowered, example_input))
2208
+
2209
+ from executorch.exir.backend.compile_spec_schema import CompileSpec
2210
+
2211
+ compile_specs1 = [CompileSpec("config", b"fast")]
2212
+ compile_specs2 = [CompileSpec("config", b"small")]
2213
+ lowered_module1 = to_backend(
2214
+ "BackendWithCompilerDemo", lowered_edge.exported_program(), compile_specs1
2215
+ )
2216
+ lowered_module2 = to_backend(
2217
+ "BackendWithCompilerDemo", lowered_edge.exported_program(), compile_specs2
2218
+ )
2219
+
2220
+ class CompositeModel(torch.nn.Module):
2221
+ def __init__(self):
2222
+ super().__init__()
2223
+ self.lowerable1 = lowered_module1
2224
+ self.lowerable2 = lowered_module2
2225
+
2226
+ def forward(self, x):
2227
+ a = self.lowerable1(x)
2228
+ b = self.lowerable2(a)
2229
+ return a, b
2230
+
2231
+ composite_model = CompositeModel()
2232
+ model_inputs = (torch.ones(1),)
2233
+ edge_prog = to_edge(export(composite_model, model_inputs)).to_executorch()
2234
+
2235
+ exported_program = edge_prog.exported_program()
2236
+ program = emit_program({"method1": exported_program}, False).program
2237
+ self.assertEqual(len(program.execution_plan), 1)
2238
+
2239
+ plan = program.execution_plan[0]
2240
+ # Two delegates that point to the same blob.
2241
+ self.assertEqual(len(plan.delegates), 2)
2242
+ self.assertEqual(plan.delegates[0].processed.index, 0)
2243
+ self.assertEqual(plan.delegates[1].processed.index, 0)
2244
+ # Compile specs are different.
2245
+ self.assertEqual(plan.delegates[0].compile_specs, compile_specs1)
2246
+ self.assertEqual(plan.delegates[1].compile_specs, compile_specs2)
2247
+ # Only one delegate blob in the backend_delegate_data.
2248
+ self.assertEqual(len(program.backend_delegate_data), 1)
2249
+
2250
+ def test_constant_tagged_mutable_tensors(self) -> None:
2251
+ class Net(nn.Module):
2252
+ def __init__(self):
2253
+ super().__init__()
2254
+ self.linear = nn.Linear(2, 2)
2255
+
2256
+ def forward(self, x):
2257
+ return self.linear(x)
2258
+
2259
+ # On device training requires the loss to be embedded in the model (and be the first output).
2260
+ # We wrap the original model here and add the loss calculation. This will be the model we export.
2261
+ class TrainingNet(nn.Module):
2262
+ def __init__(self, net):
2263
+ super().__init__()
2264
+ self.net = net
2265
+ self.loss = nn.CrossEntropyLoss()
2266
+
2267
+ def forward(self, input, label):
2268
+ pred = self.net(input)
2269
+ return self.loss(pred, label), pred.detach().argmax(dim=1)
2270
+
2271
+ net = TrainingNet(Net())
2272
+
2273
+ # Captures the forward graph. The graph will look similar to the model definition now.
2274
+ ep = export(
2275
+ net, (torch.randn(1, 2), torch.ones(1, dtype=torch.int64)), strict=True
2276
+ )
2277
+ # Captures the backward graph. The exported_program now contains the joint forward and backward graph.
2278
+ ep = _export_forward_backward(ep)
2279
+ # Lower the graph to edge dialect.
2280
+ ep = to_edge(ep)
2281
+ # Lower the graph to executorch.
2282
+ ep = ep.to_executorch(
2283
+ config=ExecutorchBackendConfig(external_mutable_weights=True)
2284
+ )
2285
+
2286
+ emitter_output = ep._emitter_output
2287
+ # Check that constant_buffer is empty besides the non-constant placeholder 0.
2288
+ self.assertEqual(len(emitter_output.program.constant_buffer), 1)
2289
+ # Check that constant weights are in the external constant buffer.
2290
+ self.assertEqual(len(emitter_output.external_constant_buffer), 2)
2291
+ # Setting external_mutable_weights=True, saves all constants with an associated gradient to the key
2292
+ # '_default_external_constant'.
2293
+ external_map = emitter_output.external_constant_map[
2294
+ "_default_external_constant"
2295
+ ]
2296
+ self.assertEqual(external_map["net.linear.weight"], 0)
2297
+ self.assertEqual(external_map["net.linear.bias"], 1)
2298
+
2299
+ def test_emit_mutable_buffer_names(self) -> None:
2300
+ class Net(nn.Module):
2301
+ def __init__(self):
2302
+ super().__init__()
2303
+ self.linear = nn.Linear(2, 2)
2304
+ self.register_buffer("buffer", torch.zeros(1, 2))
2305
+
2306
+ def forward(self, x):
2307
+ self.buffer.add_(1)
2308
+ return self.linear(x) + self.buffer
2309
+
2310
+ net = Net()
2311
+
2312
+ ep = export(net, (torch.randn(1, 2),), strict=True)
2313
+ # Lower the graph to edge dialect.
2314
+ ep = to_edge(ep)
2315
+ # Lower the graph to executorch.
2316
+ ep = ep.to_executorch(
2317
+ config=ExecutorchBackendConfig(
2318
+ emit_mutable_buffer_names=True,
2319
+ memory_planning_pass=MemoryPlanningPass(alloc_mutable_buffers=False),
2320
+ )
2321
+ )
2322
+ for val in ep.executorch_program.execution_plan[0].values:
2323
+ if isinstance(val, Tensor) and val.extra_tensor_info:
2324
+ self.assertEqual(val.extra_tensor_info.fully_qualified_name, "buffer")
2325
+ self.assertEqual(val.allocation_info, None)
2326
+
2327
+ def test_emit_mutable_buffer_names_fails(self) -> None:
2328
+ class Net(nn.Module):
2329
+ def __init__(self):
2330
+ super().__init__()
2331
+ self.linear = nn.Linear(2, 2)
2332
+ self.register_buffer("buffer", torch.zeros(1, 2))
2333
+
2334
+ def forward(self, x):
2335
+ self.buffer.add_(1)
2336
+ return self.linear(x) + self.buffer
2337
+
2338
+ net = Net()
2339
+
2340
+ ep = export(net, (torch.randn(1, 2),), strict=True)
2341
+ # Lower the graph to edge dialect.
2342
+ ep = to_edge(ep)
2343
+ # Lower the graph to executorch.
2344
+ # Must emit mutable buffer names if we don't allocate mutable buffers
2345
+ with self.assertRaises(InternalError):
2346
+ ep.to_executorch(
2347
+ config=ExecutorchBackendConfig(
2348
+ emit_mutable_buffer_names=False,
2349
+ memory_planning_pass=MemoryPlanningPass(
2350
+ alloc_mutable_buffers=False
2351
+ ),
2352
+ )
2353
+ )
2354
+
2355
+ def test_emit_sym_min_max(self) -> None:
2356
+ class SymMaxModel(nn.Module):
2357
+ def __init__(self, test_min=False):
2358
+ super().__init__()
2359
+ self.test_min = test_min
2360
+
2361
+ def forward(self, x):
2362
+ # Get size of 0th dimension - this creates sym_size op
2363
+ batch_size = x.shape[0]
2364
+ # Compute max of batch_size and 10 - this should create sym_max op
2365
+ if self.test_min:
2366
+ out_size = min(batch_size, 10)
2367
+ else:
2368
+ out_size = max(batch_size, 10)
2369
+ # Create a 1D tensor of zeros with the computed size
2370
+ result = torch.zeros(out_size, dtype=x.dtype, device=x.device)
2371
+ return result
2372
+
2373
+ for validate_min in [True, False]:
2374
+ model = SymMaxModel(test_min=validate_min)
2375
+ test_inputs = [
2376
+ torch.randn(5, 3), # should output zeros(10) for max zeros(5) for min
2377
+ torch.randn(15, 3), # should output zeros(15) for max zeros(10) for min
2378
+ torch.randn(10, 3), # should output zeros(10) for max zeros(10) for min
2379
+ ]
2380
+ model.eval()
2381
+ reference_outputs = []
2382
+ with torch.no_grad():
2383
+ for _, inp in enumerate(test_inputs):
2384
+ output = model(inp)
2385
+ reference_outputs.append(output)
2386
+
2387
+ batch_dim = Dim("batch", min=1, max=20)
2388
+ dynamic_shapes = {"x": {0: batch_dim}} # 0th dimension is dynamic
2389
+ exported_program = torch.export.export(
2390
+ model, (test_inputs[0],), dynamic_shapes=dynamic_shapes
2391
+ )
2392
+ edge_program = to_edge(
2393
+ exported_program,
2394
+ compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
2395
+ )
2396
+ et_program = edge_program.to_executorch()
2397
+ program_buffer = et_program.buffer
2398
+ et_module = _load_for_executorch_from_buffer(program_buffer)
2399
+ for _, (inp, expected) in enumerate(zip(test_inputs, reference_outputs)):
2400
+ # Execute with ExecuTorch
2401
+ et_output = et_module.forward([inp])
2402
+ et_result = et_output[0] # Get first output
2403
+ # Compare results
2404
+ self.assertTrue(expected.shape == et_result.shape)
2405
+ self.assertTrue(torch.allclose(expected, et_result))