pytorch/test
Jason Ansel a66851a2ad [FX] torch.fx.symbolic_trace patching improvements and math.* support (#50793)
Summary:
This contains some improvements and refactoring to how patching is done in `torch.fx.symbolic_trace`.

1) Functions from `math.*` are now supported without needing to call `torch.fx.wrap()`.  `wrap()` actually errors on some of these function because they are written in C and don't have `__code__` requiring use of the string version.  `math` usage is relatively common, for example [BERT uses math.sqrt here](6f79061bd1/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/attention/single.py (L16)).  Both `math.sqrt()` and `from math import sqrt` (copying to module namespace) are supported.  When modules are called FX now searches the module's global scope to find methods to patch.

2) [Guarded behind `env FX_PATCH_GETITEM=1`] Fixes a failed trace of [PositionalEmbedding from BERT](6f79061bd1/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/embedding/position.py (L24)), which failed to trace with the error `TypeError: slice indices must be integers or None or have an __index__ method` (a Proxy() is getting passed into `Tensor.__getitem__`).  See https://github.com/pytorch/pytorch/issues/50710 for why this is disabled by default.

3) Support for automatically wrapping methods that may have been copied to a different module scope via an import like `from foo import wrapped_function`.  This also isn't exposed in `torch.fx.wrap`, but is used to implement `math.*` support.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/50793

Test Plan: Added unittests to check each feature

Reviewed By: jamesr66a

Differential Revision: D25999788

Pulled By: jansel

fbshipit-source-id: f1ce11a69b7d97f26c9e2741c6acf9c513a84467
2021-01-22 15:05:24 -08:00
..
backward_compatibility refactor profiling optional (#47667) 2021-01-22 14:45:28 -08:00
benchmark_utils
bottleneck_test
cpp Modernize for-loops (#50912) 2021-01-22 10:53:24 -08:00
cpp_api_parity Add PixelUnshuffle (#49334) 2020-12-22 20:14:55 -08:00
cpp_extensions Move generator state APIs to ATen (#49589) 2021-01-06 18:26:56 -08:00
custom_backend
custom_operator
distributed ZeroRedundancyOptimizer: an implementation of a standalone sharded optimizer wrapper (#46750) 2021-01-20 14:36:16 -08:00
distributions Independent constraint (#50547) 2021-01-21 18:42:45 -08:00
error_messages
expect
fx Create subgraph rewriter (#49540) 2021-01-12 16:32:13 -08:00
jit [WIP] JIT Static Hooks: python tests (#49546) 2021-01-20 09:12:53 -08:00
jit_hooks [WIP] JIT Static Hooks: cpp tests (#49547) 2021-01-20 09:12:57 -08:00
mobile [PyTorch] Add missing Dispatcher.h include in quantized_ops.cpp (#50646) 2021-01-15 19:44:46 -08:00
namespace_b
onnx [ONNX] Handle sequence output for models (#50599) 2021-01-21 15:36:41 -08:00
optim
package_a [package] mangle imported module names (#50049) 2021-01-13 16:32:36 -08:00
quantization quantization: Linear + BatchNorm1d fusion (#50748) 2021-01-20 12:59:02 -08:00
scripts
test_img
type_hint_tests Fix mypy type hint for AdaptiveAvgPool2,3d, AdaptiveMaxPool2,3d (#49963) 2021-01-06 09:47:15 -08:00
HowToWriteTestsUsingFileCheck.md
module_a.py
print_test_stats.py only upload s3 stats on master, nightly, and release branch (#49645) 2020-12-22 14:15:18 -08:00
run_test.py ZeroRedundancyOptimizer: an implementation of a standalone sharded optimizer wrapper (#46750) 2021-01-20 14:36:16 -08:00
simulate_nccl_errors.py
test_autograd.py count_nonzero with requires grad (#50866) 2021-01-22 11:19:59 -08:00
test_binary_ufuncs.py Implement NumPy-like function torch.fmax() & torch.fmin() (#49312) 2021-01-20 06:45:25 -08:00
test_bundled_images.py
test_bundled_inputs.py Back out "Revert D25757721: [pytorch][PR] Run mypy on more test files" (#50142) 2021-01-06 11:27:36 -08:00
test_complex.py
test_cpp_api_parity.py
test_cpp_extensions_aot.py
test_cpp_extensions_jit.py
test_cuda.py Add complex support for torch.nn.L1Loss (#49912) 2021-01-15 15:53:15 -08:00
test_cuda_primary_ctx.py
test_dataloader.py Fix persistent_workers + pin_memory (#48543) 2021-01-08 07:04:10 -08:00
test_dataset.py Fix mypy typing check for test_dataset (#50108) 2021-01-05 19:57:22 -08:00
test_determination.py
test_dispatch.py Fix test_dispatch.py when running with TORCH_SHOW_CPP_STACKTRACES=1 (#50509) 2021-01-20 10:15:01 -08:00
test_expecttest.py [BE] replace unittest.main with run_tests (#50451) 2021-01-13 10:33:08 -08:00
test_foreach.py
test_function_schema.py
test_functional_autograd_benchmark.py Skip test_functional_autograd_benchmark during code coverage (#50183) 2021-01-07 11:17:21 -08:00
test_futures.py
test_fx.py [FX] torch.fx.symbolic_trace patching improvements and math.* support (#50793) 2021-01-22 15:05:24 -08:00
test_fx_experimental.py [fx] Add matrix multiplication fusion pass (#50151) 2021-01-06 21:49:37 -08:00
test_indexing.py
test_jit.py Improve complex support in common_nn test machinery (#50593) 2021-01-22 09:44:45 -08:00
test_jit_cuda_fuser.py JIT: guard DifferentiableGraph node (#49433) 2021-01-08 20:01:27 -08:00
test_jit_disabled.py [BE] replace unittest.main with run_tests (#50451) 2021-01-13 10:33:08 -08:00
test_jit_fuser.py Clean up some type annotations in caffe2/test (#49943) 2021-01-13 10:01:55 -08:00
test_jit_fuser_legacy.py
test_jit_fuser_te.py [TensorExpr] Use wider type for scalars (#50774) 2021-01-20 15:12:27 -08:00
test_jit_legacy.py
test_jit_profiling.py Remove redundant code for unsupported Python versions (#49486) 2021-01-06 12:45:46 -08:00
test_jit_py3.py cleaned up ModuleAttributeError (#50298) 2021-01-14 06:58:01 -08:00
test_jit_simple.py Remove redundant code for unsupported Python versions (#49486) 2021-01-06 12:45:46 -08:00
test_jit_string.py Clean up some type annotations in caffe2/test (#49943) 2021-01-13 10:01:55 -08:00
test_kernel_launch_checks.py
test_linalg.py Rename set_deterministic to use_deterministic_algorithms (#49904) 2021-01-22 11:27:07 -08:00
test_logging.py
test_metal.py
test_mkldnn.py
test_mobile_optimizer.py cleaned up ModuleAttributeError (#50298) 2021-01-14 06:58:01 -08:00
test_multiprocessing.py [BE] unified run_process_no_exception code (#49774) 2021-01-04 13:43:09 -08:00
test_multiprocessing_spawn.py
test_namedtensor.py
test_namedtuple_return_api.py Added linalg.slogdet (#49194) 2021-01-19 07:28:12 -08:00
test_native_functions.py
test_nn.py Padding: support complex dtypes (#50594) 2021-01-22 11:57:42 -08:00
test_numba_integration.py Drop unused imports from test (#49973) 2021-01-07 12:09:38 -08:00
test_numpy_interop.py Back out "Revert D25757721: [pytorch][PR] Run mypy on more test files" (#50142) 2021-01-06 11:27:36 -08:00
test_op_aliases.py Implementing NumPy-like function torch.broadcast_to (#48997) 2020-12-21 11:24:50 -08:00
test_openmp.py
test_ops.py OpInfo: Remove promotes_integers_to_float and infer it instead (#50279) 2021-01-22 09:32:37 -08:00
test_optim.py Revert D25976245: [pytorch][PR] Enable Skipped ROCM Tests in common_nn.py 2021-01-21 13:28:37 -08:00
test_overrides.py Fix indexing for overrides. (#49324) 2021-01-20 11:34:02 -08:00
test_package.py [packaging] add support for BytesIO (#50838) 2021-01-22 08:33:39 -08:00
test_profiler.py Enable tests using named temp files on Windows (#49640) 2020-12-29 09:57:35 -08:00
test_pruning_op.py
test_pytree.py
test_quantization.py [quant] Quantizable LSTM (#49671) 2020-12-30 15:21:38 -08:00
test_reductions.py [numpy] torch.{all/any} : output dtype is always bool (#47878) 2021-01-08 11:05:39 -08:00
test_serialization.py Enable tests using named temp files on Windows (#49640) 2020-12-29 09:57:35 -08:00
test_shape_ops.py [testing] Port torch.{repeat, tile} tests to use OpInfo machinery (#50199) 2021-01-19 06:02:27 -08:00
test_show_pickle.py [BE] replace unittest.main with run_tests (#50451) 2021-01-13 10:33:08 -08:00
test_sort_and_select.py Revert "Stable sort for CPU (#50052)" (#50752) 2021-01-19 18:21:25 -08:00
test_sparse.py [ROCm] re-enable test_sparse.py tests (#50557) 2021-01-18 23:36:39 -08:00
test_spectral_ops.py Padding: support complex dtypes (#50594) 2021-01-22 11:57:42 -08:00
test_static_runtime.py Clean up some type annotations in caffe2/test (#49943) 2021-01-13 10:01:55 -08:00
test_tensor_creation_ops.py [testing] Port torch.{repeat, tile} tests to use OpInfo machinery (#50199) 2021-01-19 06:02:27 -08:00
test_tensorboard.py
test_tensorexpr.py [BE] replace unittest.main with run_tests (#50451) 2021-01-13 10:33:08 -08:00
test_tensorexpr_pybind.py [TensorExpr] Add python bindings. (#49698) 2021-01-14 21:02:47 -08:00
test_testing.py Refactor mypy configs list into editor-friendly wrapper (#50826) 2021-01-22 13:35:44 -08:00
test_throughput_benchmark.py Enable tests using named temp files on Windows (#49640) 2020-12-29 09:57:35 -08:00
test_torch.py Migrate masked_scatter_ CPU to ATen (#49732) 2021-01-22 12:05:56 -08:00
test_type_hints.py Refactor mypy configs list into editor-friendly wrapper (#50826) 2021-01-22 13:35:44 -08:00
test_type_info.py
test_type_promotion.py
test_unary_ufuncs.py OpInfo: Remove promotes_integers_to_float and infer it instead (#50279) 2021-01-22 09:32:37 -08:00
test_utils.py Run mypy over test/test_utils.py (#50278) 2021-01-11 08:16:23 -08:00
test_view_ops.py Add tensor.view(dtype) (#47951) 2021-01-08 06:55:21 -08:00
test_vmap.py [vmap] Add batching rules for comparisons ops (#50364) 2021-01-12 13:00:56 -08:00
test_vulkan.py
test_xnnpack_integration.py