pytorch/test
Boyuan Feng 2fd26925c4 improve noop elimination for view (#151095)
This PR improves noop elimination.

### View Noop

```python
>>> torch.Size([1,2,3]) == [1,2,3]
False
>>> torch.Size([1,2,3]) == (1,2,3)
True
```
So we add `tuple(size)` in `view_noop`.

Example:
```python
import torch

@torch.compile()
def f(x):
    batch_size = x.shape[0]
    x = x.transpose(1, 2) # (batch_size, 2, 3)
    x = x.reshape(batch_size, 2, 3) # noop
    return x

x = torch.randn((2,3,2))
f(x)

x = torch.randn((4,3,2))
f(x)
```

Before:
![image](https://github.com/user-attachments/assets/be488881-6c99-43a9-b088-fa481f675775)

After:
![image](https://github.com/user-attachments/assets/6d93be3d-128b-44d4-ad6a-d3d18e272329)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/151095
Approved by: https://github.com/eellison
2025-04-16 23:55:32 +00:00
..
ao/sparsity Skip ao_sparsity TestComposability for missing FBGEMM (#144146) 2025-03-11 13:02:18 +00:00
autograd
backends/xeon
benchmark_utils PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
bottleneck_test
cpp [c10d] Add _allgather_base , reduce_scatter , and _reduce_scatter_base into ProcessGroupMPI to enable FSDP with MPI backend (#150162) 2025-04-14 19:31:38 +00:00
cpp_api_parity
cpp_extensions Revert "[Openreg][PrivateUse1] Enable CI for openreg (#151007)" 2025-04-16 21:05:17 +00:00
custom_backend [Cmake] Make PyTorch buildable by CMake-4.x (#150203) 2025-03-29 01:39:13 +00:00
custom_operator [Cmake] Make PyTorch buildable by CMake-4.x (#150203) 2025-03-29 01:39:13 +00:00
distributed improve noop elimination for view (#151095) 2025-04-16 23:55:32 +00:00
distributions Temp disable MKL in DistributionKernels.cpp (#146174) 2025-02-01 18:53:11 +00:00
dynamo Revert "[ez] Make relaxed constraint error message more user friendly (#151407)" 2025-04-16 20:40:22 +00:00
dynamo_expected_failures Revert "[dynamo] context manager/decorator for dynamo config patching during tracing (#150586)" 2025-04-16 16:13:47 +00:00
dynamo_skips Revert "[dynamo] context manager/decorator for dynamo config patching during tracing (#150586)" 2025-04-16 16:13:47 +00:00
edge [Cmake] Make PyTorch buildable by CMake-4.x (#150203) 2025-03-29 01:39:13 +00:00
error_messages
expect Facilitate at::_weight_int4pack_mm_with_scale_and_zeros related registration (#147962) 2025-04-08 15:36:07 +00:00
export Revert "[ez] Make relaxed constraint error message more user friendly (#151407)" 2025-04-16 20:40:22 +00:00
forward_backward_compatibility [Reland] Launch kernel on current stream & remove record_stream entirely (#150398) 2025-04-01 16:46:07 +00:00
functorch Revert "[map] always turn on dynamo for map (#150962)" 2025-04-14 21:09:22 +00:00
fx [Codemod][AddExplicitStrictExportForTrainingInferenceArg] caffe2/ (#149595) 2025-04-03 23:50:13 +00:00
higher_order_ops [dynamo][invoke_subgraph] Use FxGraphModule comparison instead of hashing (#150911) 2025-04-14 23:34:26 +00:00
inductor improve noop elimination for view (#151095) 2025-04-16 23:55:32 +00:00
inductor_expected_failures [dynamo] Support Tensor subclass that has dynamic attributes or calls Parameter.__torch_function__ (#149482) 2025-04-02 20:56:43 +00:00
inductor_skips [BE] Remove test_ops from FIXME_inductor_dont_reset_dynamo (#145307) 2025-01-27 18:12:39 +00:00
jit Consistently use load_torchbind_test_lib in tests (#148082) 2025-03-03 19:37:28 +00:00
jit_hooks [Cmake] Make PyTorch buildable by CMake-4.x (#150203) 2025-03-29 01:39:13 +00:00
lazy [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
mobile [Cmake] Make PyTorch buildable by CMake-4.x (#150203) 2025-03-29 01:39:13 +00:00
nn Fix broken LazyLinear init (#149693) 2025-03-25 23:49:49 +00:00
onnx [ONNX] Produce correct dtypes for bf16/f8 in IR TorchTensor (#151259) 2025-04-15 23:21:04 +00:00
optim Remove deprecate method and attirbute in LRScheduler (#147301) 2025-03-05 05:30:19 +00:00
package Remove outdated test skipif conditions for Python3.9 (#146144) 2025-01-31 19:01:04 +00:00
profiler [dynamo] Always trace into tensor subclass __torch_function__ (#149792) 2025-04-02 20:57:00 +00:00
quantization [Quant][PT2E][X86] enable qconv1d-relu fusion (#150751) 2025-04-09 14:42:02 +00:00
scripts
strobelight/examples Enable strobelight profiling specific compile frame ids using COMPILE_STROBELIGHT_FRAME_FILTER (#147549) 2025-02-22 03:44:53 +00:00
test_img
torch_np Code Clean: Remove python3.8 specific code because PyTorch now need Python3.9 and later (#150834) 2025-04-08 18:53:55 +00:00
typing Revert "Fix non-bitwise type annotations for Tensor operators (see #145838) (#146845)" 2025-02-18 19:01:27 +00:00
xpu Facilitate at::_weight_int4pack_mm_with_scale_and_zeros related registration (#147962) 2025-04-08 15:36:07 +00:00
_test_bazel.py
allowlist_for_publicAPI.json Introduce guard_or_true, guard_or_false (#148430) 2025-03-27 09:34:05 +00:00
bench_mps_ops.py [MPS][Testing] Benchmark reduction ops (#150452) 2025-04-02 01:06:27 +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 Revert "[Openreg][PrivateUse1] Enable CI for openreg (#151007)" 2025-04-16 21:05:17 +00:00
simulate_nccl_errors.py
slow_tests.json Update slow tests (#150283) 2025-04-07 11:49:59 +00:00
test_accelerator.py [CI] Disable some tests that are failing in periodic (#150059) 2025-03-28 20:31:32 +00:00
test_ao_sparsity.py
test_appending_byte_serializer.py Add AppendingByteSerializer class (#148226) 2025-03-02 08:20:58 +00:00
test_autocast.py Enable TemporaryFileName tests on Windows (#146311) 2025-02-07 06:06:18 +00:00
test_autograd_fallback.py
test_autograd.py Add some autograd producer consumer stream sync tests (#150952) 2025-04-12 02:44:09 +00:00
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 [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_ci_sanity_check_fail.py
test_comparison_utils.py
test_compile_benchmark_util.py
test_complex.py
test_content_store.py torch.utils._content_store: fix error in hash_storage on XPU (#147785) 2025-02-26 23:57:59 +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 [BE] simplify test_cpp_extensions_aot and .gitignore (#149231) 2025-03-20 18:17:19 +00:00
test_cpp_extensions_jit.py op should NOT be static in aoti_torch_call_dispatcher (#149208) 2025-03-15 01:47:11 +00:00
test_cpp_extensions_mtia_backend.py Revert "Generalize poison fork logic for each device backend (#144664)" 2025-04-10 21:02:14 +00:00
test_cpp_extensions_open_device_registration.py [Openreg][PrivateUse1] Improve openreg module capabilities (#151000) 2025-04-12 17:21:35 +00:00
test_cpp_extensions_stream_and_event.py
test_cuda_expandable_segments.py Revert "Use absolute path path.resolve() -> path.absolute() (#129409)" 2025-01-04 14:17:20 +00:00
test_cuda_multigpu.py [CUDA] try to abate some flakiness in test_stream_event_nogil (#148796) 2025-03-12 19:12:50 +00:00
test_cuda_nvml_based_avail.py
test_cuda_primary_ctx.py Remove outdated skipIfRocmVersionLessThan decorations (#148941) 2025-03-11 18:37:40 +00:00
test_cuda_sanitizer.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_cuda_trace.py
test_cuda.py add unit test for preferred_blas_library settings (#150581) 2025-04-06 01:44:07 +00:00
test_custom_ops.py Generate meta kernel with operator profiles (#150807) 2025-04-14 19:28:54 +00:00
test_dataloader.py Enable more nightly tests on s390x (#148452) 2025-03-18 16:09:39 +00:00
test_datapipe.py Remove unactivated test (#146233) 2025-02-04 05:26:04 +00:00
test_decomp.py Update ruff linter for PEP585 (#147540) 2025-02-22 04:45:17 +00:00
test_deploy.py
test_determination.py
test_dispatch.py [BE][CI] bump ruff to 0.9.0: string quote styles (#144569) 2025-02-24 19:56:09 +00:00
test_dlpack.py
test_dynamic_shapes.py Fix: missing () in generated runtime assert c++ code (#151171) 2025-04-16 08:10:17 +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 Fix aten.div type promotion for FakeTensor (#150874) 2025-04-09 18:52:01 +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 added fake tensor support for foreach_copy (#149127) 2025-03-27 09:26:23 +00:00
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 [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_functionalization_of_rng_ops.py
test_functionalization.py
test_futures.py
test_fx_experimental.py PEP585: Add noqa to necessary tests (#146391) 2025-02-12 15:29:50 +00:00
test_fx_passes.py
test_fx_reinplace_pass.py
test_fx.py Fix codegen, change str comparison opeator to == for proper equality … (#150611) 2025-04-04 09:59:59 +00:00
test_hop_infra.py Support torch.compile rng selective activation checkpointing with cudagraph (#146878) 2025-02-28 00:47:03 +00:00
test_hub.py
test_import_stats.py
test_indexing.py [ROCm] Improve backwards indexing when stride is not one (#147630) 2025-03-11 19:02:48 +00:00
test_itt.py
test_jit_autocast.py PEP585 update - test (#145176) 2025-01-22 04:48:28 +00:00
test_jit_disabled.py
test_jit_fuser_legacy.py
test_jit_fuser_te.py [BE][CI] bump ruff to 0.9.0: string quote styles (#144569) 2025-02-24 19:56:09 +00:00
test_jit_fuser.py
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_jit.py [BE]: Apply ruff PERF403 to use dict comprehensions more often (#149257) 2025-03-18 00:46:07 +00:00
test_jiterator.py
test_kernel_launch_checks.py
test_legacy_vmap.py
test_license.py Fix license check for setuptools>=77 (#151158) 2025-04-12 13:41:12 +00:00
test_linalg.py Fix setUpClass() / tearDownClass() for device-specific tests (#151129) 2025-04-16 02:18:42 +00:00
test_logging.py
test_masked.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_maskedtensor.py
test_matmul_cuda.py Fix setUpClass() / tearDownClass() for device-specific tests (#151129) 2025-04-16 02:18:42 +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_fusion.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_mkldnn_verbose.py
test_mkldnn.py torch.backends.mkldnn.flags() CM should not warn (#150358) 2025-04-01 01:33:40 +00:00
test_mobile_optimizer.py
test_model_exports_to_core_aten.py [Codemod][AddExplicitStrictExportForTrainingInferenceArg] caffe2/ (#149595) 2025-04-03 23:50:13 +00:00
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] Migrate bitwise_not to unary operator (#151460) 2025-04-16 21:34:45 +00:00
test_multiprocessing_spawn.py Remove NO_MULTIPROCESSING_SPAWN checks (#146705) 2025-02-28 05:53:19 +00:00
test_multiprocessing.py Remove NO_MULTIPROCESSING_SPAWN checks (#146705) 2025-02-28 05:53:19 +00:00
test_namedtensor.py
test_namedtuple_return_api.py
test_native_functions.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_native_mha.py
test_nestedtensor.py Introduce UserDefinedExceptionClassVariable (#146504) 2025-03-11 18:55:45 +00:00
test_nn.py Add check for ctc_loss targets param (#150981) 2025-04-14 07:24:30 +00:00
test_nnapi.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_numba_integration.py
test_numpy_interop.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_openmp.py
test_ops_fwd_gradients.py
test_ops_gradients.py Enable more nightly tests on s390x (#148452) 2025-03-18 16:09:39 +00:00
test_ops_jit.py
test_ops.py Fix addbmm & addmv & baddbmm out dtype check (#148176) 2025-04-09 07:02:56 +00:00
test_optim.py Enable more nightly tests on s390x (#148452) 2025-03-18 16:09:39 +00:00
test_out_dtype_op.py [Codemod][AddExplicitStrictExportArg] caffe2/test (#143688) 2024-12-27 07:58:44 +00:00
test_overrides.py [dynamo] Remove traceable_tensor_subclasses-related code (#151062) 2025-04-15 03:55:35 +00:00
test_package.py
test_per_overload_api.py
test_prims.py
test_proxy_tensor.py Use source hashing to generate consistent symbolic ids (#149665) 2025-03-28 05:36:32 +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 [pytree] Register normal class to register_dataclass (#147752) 2025-04-01 23:28:20 +00:00
test_quantization.py add torch.float4_e2m1fn_x2 to PyTorch (#148791) 2025-03-27 17:32:20 +00:00
test_reductions.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_scatter_gather_ops.py
test_schema_check.py
test_segment_reductions.py
test_serialization.py Make torch.serialization.skip_data work with torch.load (#148018) 2025-03-06 12:04:46 +00:00
test_set_default_mobile_cpu_allocator.py
test_shape_ops.py [Quant] flip: throw runtime error for QUInt4x2 and QUInt2x4 input (#147430) 2025-02-25 03:47:40 +00:00
test_show_pickle.py
test_sort_and_select.py Fix linter F821 error (#146665) 2025-02-08 07:19:37 +00:00
test_sparse_csr.py [cuSPARSE][B200] Bump tolerances for test_sparse_csr matvec (#148721) 2025-04-16 18:44:18 +00:00
test_sparse_semi_structured.py Fix setUpClass() / tearDownClass() for device-specific tests (#151129) 2025-04-16 02:18:42 +00:00
test_sparse.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +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 [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
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 [Inductor] Add input value checking to randint meta function (#147191) 2025-02-25 02:18:16 +00:00
test_tensorboard.py
test_tensorexpr_pybind.py
test_tensorexpr.py
test_testing.py Fix setUpClass() / tearDownClass() for device-specific tests (#151129) 2025-04-16 02:18:42 +00:00
test_throughput_benchmark.py Fix Throughputbenchmark issue (#144669) 2025-01-26 03:37:20 +00:00
test_torch.py Add a warning when a tensor with requires_grad=True is converted to a scalar (#143261) 2025-04-01 00:42:46 +00:00
test_transformers_privateuse1.py Split test_transformers.py (#147441) 2025-02-26 11:54:24 +00:00
test_transformers.py [cuDNN][SDPA] Loosen constraints for GQA for cuDNN Attention (#150337) 2025-04-06 20:31:11 +00:00
test_type_hints.py Revert "Use absolute path path.resolve() -> path.absolute() (#129409)" 2025-01-04 14:17:20 +00:00
test_type_info.py
test_type_promotion.py
test_typing.py [4/N] Apply py39 ruff and pyupgrade fixes (#143257) 2025-01-04 10:47:51 +00:00
test_unary_ufuncs.py Enable some tests on Windows (#146243) 2025-02-05 03:54:28 +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_utils.py [utils] add try_import method for importing optional modules (#145528) 2025-01-25 00:14:07 +00:00
test_view_ops.py Fix overflow in checkInBoundsForStorage (#147352) 2025-02-27 15:48:50 +00:00
test_vulkan.py
test_weak.py Consistently use load_torchbind_test_lib in tests (#148082) 2025-03-03 19:37:28 +00:00
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 [XPU] Fix XPU unit test on Windows (#150520) 2025-04-08 07:02:40 +00:00