pytorch/test
Blaine Burton Rister a1bfb39a31 [Inductor] Expand Identity ops prior to block pattern matching (#146000)
# Feature

Inductor sometimes uses `Identity` functions to group various terms of an expression. While this is convenient in some scenarios, it can frustrate pattern matching. For example, when we're matching an indexing expression to tell if it can be represented as a block pointer, that analysis should be invariant to `Identity`'s.

This PR adds a few features to achieve this invariance.
 - Create a new expansion mode `expr.expand(identity=True)`, which removes all `Identity` functions from the expression.
 -  Preprocess the expression with this expansion prior to pattern matching.
 - Bonus: create a new test utility function called `dummy_graph()`, which creates a simple `GraphLowering`. This is useful for testing the pattern matcher, as we need to initialize `V.graph` before we can access `V.graph.sizevars`.

# Test plan
This PR adds a few new unit tests:
 - Added a unit test specifically for `expr.expand(identity=True)`.
 - Added a new unit test module for the block pattern matcher. Tested that we can correctly match some example patterns containing Identity ops.

I originally intended to add an end to end test compiling pointwise cat, and mapping the corresponding memory accesses to block pointers. However, it looks like that will take more work, since the [relevant code path](https://github.com/pytorch/pytorch/blob/main/torch/_inductor/codegen/triton.py#L1306) disables block pointer analysis. It might be better to defer that to a future PR.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146000
Approved by: https://github.com/eellison, https://github.com/jansel
2025-02-08 18:11:53 +00:00
..
ao/sparsity
autograd
backends/xeon
benchmark_utils PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
bottleneck_test
cpp Introduce cache clearing APIs for the lazy graph executor (#144489) 2025-01-29 17:38:01 +00:00
cpp_api_parity
cpp_extensions Set -DPy_LIMITED_API flag for py_limited_api=True extensions (#145764) 2025-01-28 20:11:05 +00:00
custom_backend
custom_operator PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
distributed distributed/serialization: add experimental streaming torch.save/load methods (#146555) 2025-02-07 18:08:11 +00:00
distributions Temp disable MKL in DistributionKernels.cpp (#146174) 2025-02-01 18:53:11 +00:00
dynamo [dynamo][fullgraph] Do not skip frame with fullgraph=True (#146527) 2025-02-06 18:56:07 +00:00
dynamo_expected_failures [dynamo] Properly model torch profiler context objects (#145537) 2025-01-28 00:03:36 +00:00
dynamo_skips Move Dynamo test to skip from expected_failures (#145390) 2025-01-22 19:06:39 +00:00
edge Use std::string_view in tests (#146120) 2025-02-04 09:51:36 +00:00
error_messages
expect Revert "Add generator parameter to rand*_like functions (#136780)" 2025-01-24 19:00:21 +00:00
export move and fix logic to update unbacked bindings (#146115) 2025-02-07 22:41:19 +00:00
forward_backward_compatibility Clean up op BC check list (#146577) 2025-02-07 22:40:49 +00:00
functorch Add torch.func.debug_unwrap (#146528) 2025-02-06 18:48:09 +00:00
fx [Codemod][AddExplicitStrictExportArg] caffe2/torch (#146439) 2025-02-05 22:56:54 +00:00
higher_order_ops PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
inductor [Inductor] Expand Identity ops prior to block pattern matching (#146000) 2025-02-08 18:11:53 +00:00
inductor_expected_failures Check meta strides for expanded dims in effn_attn_bias (#146054) 2025-02-07 06:35:57 +00:00
inductor_skips [BE] Remove test_ops from FIXME_inductor_dont_reset_dynamo (#145307) 2025-01-27 18:12:39 +00:00
jit [torch] fix exception types in custom class magic setattr/getattr (#146516) 2025-02-06 02:14:11 +00:00
jit_hooks
lazy
mobile PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
nn [ROCm] miopen benchmark behavior now better aligns with cudnn (#145294) 2025-02-05 17:19:53 +00:00
onnx [ONNX] Create deprecation warning on dynamo_export (#146425) 2025-02-07 04:20:46 +00:00
optim
package Remove outdated test skipif conditions for Python3.9 (#146144) 2025-01-31 19:01:04 +00:00
profiler Enable CUPTI on Windows (#141454) 2025-02-06 15:58:20 +00:00
quantization PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
scripts
test_img
torch_np [BE]: Enable ruff SLOT checks (#146276) 2025-02-04 19:18:23 +00:00
typing PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
xpu fix incorrect literal strings / accidental tuples (#146037) 2025-02-03 15:08:11 +00:00
_test_bazel.py
allowlist_for_publicAPI.json Improve typing in torch/types.py (#145237) 2025-01-28 05:29:12 +00:00
conftest.py Apply ruff fixes to tests (#146140) 2025-02-04 05:41:01 +00:00
create_dummy_torchscript_model.py
delete.py
hi.py
HowToWriteTestsUsingFileCheck.md
linear.py
load_torchscript_model.py
minioptest_failures_dict.json
mkl_verbose.py
mkldnn_verbose.py
pytest_shard_custom.py
run_doctests.sh
run_test.py s390x: disable test_model_exports_to_core_aten.py test (#145835) 2025-01-31 17:45:10 +00:00
simulate_nccl_errors.py
slow_tests.json Update slow tests (#146301) 2025-02-03 11:37:16 +00:00
test_accelerator.py Generalize pin memory logic for accelerator when non blocking copy happened (#143783) 2025-01-23 03:43:05 +00:00
test_ao_sparsity.py
test_autocast.py Enable TemporaryFileName tests on Windows (#146311) 2025-02-07 06:06:18 +00:00
test_autograd.py [BE][Ez]: ISC001 Auto concatenate implicit one line strings (#146408) 2025-02-04 19:07:04 +00:00
test_autograd_fallback.py
test_autoload.py
test_binary_ufuncs.py Fix lerp weight type promotion (#141117) 2025-01-24 01:18:20 +00:00
test_bundled_images.py
test_bundled_inputs.py
test_ci_sanity_check_fail.py
test_comparison_utils.py
test_compile_benchmark_util.py
test_complex.py
test_content_store.py Enable TemporaryFileName tests on Windows (#146311) 2025-02-07 06:06:18 +00:00
test_cpp_api_parity.py Enable C++ API parity tests on AArch64 (#145370) 2025-01-30 22:42:49 +00:00
test_cpp_extensions_aot.py
test_cpp_extensions_jit.py [CI][CUDA][Blackwell] sm_\d\d no longer matches sm_100. (#145641) 2025-01-24 23:20:22 +00:00
test_cpp_extensions_mtia_backend.py
test_cpp_extensions_open_device_registration.py Update pin memory related APIs to not pass 'device' argument (#131858) 2025-01-15 17:23:35 +00:00
test_cpp_extensions_stream_and_event.py
test_cuda.py [CUDA][cuBLAS] Add fp16 accumulate option to cuBLAS/cuBLASLt (#144441) 2025-02-06 19:04:50 +00:00
test_cuda_expandable_segments.py
test_cuda_multigpu.py
test_cuda_nvml_based_avail.py
test_cuda_primary_ctx.py
test_cuda_sanitizer.py
test_cuda_trace.py
test_custom_ops.py [opcheck] Improve error reporting; allow atol/rtol overrides (#146488) 2025-02-05 21:25:06 +00:00
test_dataloader.py Enable some tests on MacOS (#146268) 2025-02-03 05:04:24 +00:00
test_datapipe.py Remove unactivated test (#146233) 2025-02-04 05:26:04 +00:00
test_decomp.py
test_deploy.py
test_determination.py
test_dispatch.py
test_dlpack.py
test_dynamic_shapes.py Bail on checking internal overlap when dealing with unbacked symints (#145385) 2025-01-23 22:31:31 +00:00
test_expanded_weights.py
test_extension_utils.py Move privateuse1 test out of test_utils and make them serial (#145380) 2025-01-23 00:31:39 +00:00
test_fake_tensor.py Output of nonzero is transposed, fix fake tensor (#144695) 2025-01-26 01:07:22 +00:00
test_file_check.py
test_flop_counter.py Build RowwiseScaledMM.cu for SM89 (#145676) 2025-02-01 11:44:58 +00:00
test_foreach.py
test_function_schema.py
test_functional_autograd_benchmark.py Enable Windows tests (#146666) 2025-02-08 00:55:20 +00:00
test_functional_optim.py
test_functionalization.py
test_functionalization_of_rng_ops.py
test_futures.py
test_fx.py [Codemod][AddExplicitStrictExportArg] caffe2/torch (#146439) 2025-02-05 22:56:54 +00:00
test_fx_experimental.py Apply ruff fixes to tests (#146140) 2025-02-04 05:41:01 +00:00
test_fx_passes.py
test_fx_reinplace_pass.py
test_hop_infra.py Require that all HOPs be imported at import torch time (#145939) 2025-01-29 22:27:52 +00:00
test_hub.py
test_import_stats.py
test_indexing.py
test_itt.py
test_jit.py Enable TemporaryFileName tests on Windows (#146311) 2025-02-07 06:06:18 +00:00
test_jit_autocast.py PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
test_jit_disabled.py
test_jit_fuser.py
test_jit_fuser_legacy.py
test_jit_fuser_te.py [BE][Ez]: FURB148 - remove useless enumerate calls (#145619) 2025-01-24 23:37:15 +00:00
test_jit_legacy.py
test_jit_llga_fuser.py
test_jit_profiling.py
test_jit_simple.py
test_jit_string.py PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
test_jiterator.py
test_kernel_launch_checks.py
test_legacy_vmap.py
test_license.py
test_linalg.py [ROCm][TunableOp] Future proof TunableOp unit test. (#146548) 2025-02-06 20:26:02 +00:00
test_logging.py
test_masked.py
test_maskedtensor.py
test_matmul_cuda.py [CUDA][cuBLAS] Add fp16 accumulate option to cuBLAS/cuBLASLt (#144441) 2025-02-06 19:04:50 +00:00
test_meta.py [inductor] fix index.Tensor fallback (#144736) 2025-01-16 09:38:29 +00:00
test_metal.py
test_mkl_verbose.py
test_mkldnn.py
test_mkldnn_fusion.py
test_mkldnn_verbose.py
test_mobile_optimizer.py
test_model_exports_to_core_aten.py
test_module_tracker.py
test_modules.py Disable slow gradcheck for nn.Transformer ModuleInfo (#145531) 2025-01-25 00:58:03 +00:00
test_monitor.py
test_mps.py [MPS] lu unpack (#146681) 2025-02-08 00:16:17 +00:00
test_multiprocessing.py [dynamo] Re-enable test_fs family for dynamo (#145302) 2025-01-22 17:50:05 +00:00
test_multiprocessing_spawn.py
test_namedtensor.py
test_namedtuple_return_api.py
test_native_functions.py
test_native_mha.py
test_nestedtensor.py Support remaining *_like factory functions for NJT (#144889) 2025-01-27 21:33:51 +00:00
test_nn.py Add determinmistic kernel for reflection2d (#136241) 2025-01-29 20:34:03 +00:00
test_nnapi.py
test_numba_integration.py
test_numpy_interop.py
test_openmp.py
test_ops.py [inductor] add size-asserts for fallback ops (#145904) 2025-02-07 18:44:32 +00:00
test_ops_fwd_gradients.py
test_ops_gradients.py
test_ops_jit.py
test_optim.py Fix loading older state_dict into AdamW after refactor (#144972) 2025-01-16 19:50:31 +00:00
test_out_dtype_op.py
test_overrides.py Use std::string_view in tests (#146120) 2025-02-04 09:51:36 +00:00
test_package.py
test_per_overload_api.py
test_prims.py
test_proxy_tensor.py Add fake_impl for unique_consecutive (#145649) 2025-01-29 22:33:16 +00:00
test_pruning_op.py
test_public_bindings.py Remove public_allowlist from TestPublicBindings.test_correct_module_names and ensure private_allowlist-ed things are actually private (#145620) 2025-01-27 17:30:02 +00:00
test_python_dispatch.py Delete torch._library.register_functional_op (#145110) 2025-01-18 00:58:25 +00:00
test_pytree.py Barebones flat_apply HOP (#146060) 2025-02-01 16:17:48 +00:00
test_quantization.py
test_reductions.py
test_scatter_gather_ops.py
test_schema_check.py
test_segment_reductions.py
test_serialization.py Enable TemporaryFileName tests on Windows (#146311) 2025-02-07 06:06:18 +00:00
test_set_default_mobile_cpu_allocator.py
test_shape_ops.py
test_show_pickle.py
test_sort_and_select.py Fix linter F821 error (#146665) 2025-02-08 07:19:37 +00:00
test_sparse.py
test_sparse_csr.py [CUDA][SDPA] Compute reference in test_triton_scaled_dot_product_attention_block_size_16_cuda_float32 in float64 (#146461) 2025-02-06 23:28:56 +00:00
test_sparse_semi_structured.py [TEST][Sparse] Force CUTLASS backend in TestSparseSemiStructuredCUTLASS (#146398) 2025-02-04 22:07:12 +00:00
test_spectral_ops.py Re-add stft option to align window for center = false (#146379) 2025-02-06 14:07:13 +00:00
test_stateless.py
test_static_runtime.py
test_subclass.py
test_sympy_utils.py [Inductor] Expand Identity ops prior to block pattern matching (#146000) 2025-02-08 18:11:53 +00:00
test_tensor_creation_ops.py Let tensor_a.new_tensor() be on tensor_a.device by default (#144958) 2025-01-24 22:12:31 +00:00
test_tensorboard.py
test_tensorexpr.py
test_tensorexpr_pybind.py
test_testing.py Enable some tests on Windows (#146243) 2025-02-05 03:54:28 +00:00
test_throughput_benchmark.py Fix Throughputbenchmark issue (#144669) 2025-01-26 03:37:20 +00:00
test_torch.py Enable some tests on Windows (#146243) 2025-02-05 03:54:28 +00:00
test_transformers.py Fix linter F821 error (#146665) 2025-02-08 07:19:37 +00:00
test_type_hints.py
test_type_info.py
test_type_promotion.py
test_typing.py
test_unary_ufuncs.py Enable some tests on Windows (#146243) 2025-02-05 03:54:28 +00:00
test_utils.py [utils] add try_import method for importing optional modules (#145528) 2025-01-25 00:14:07 +00:00
test_utils_config_module.py Add check that envvar configs are boolean (#145454) 2025-02-05 19:40:10 +00:00
test_utils_filelock.py
test_view_ops.py
test_vulkan.py
test_weak.py
test_xnnpack_integration.py [BE][Ez]: ISC001 Auto concatenate implicit one line strings (#146408) 2025-02-04 19:07:04 +00:00
test_xpu.py