pytorch/test
Kimish Patel f4a921600a [PyTorch, Mobile] Serialization format change for source range (#54284)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54284

In order to bring mobile deployment, via lite interpreter, on feature
parity with JIT, with respect model level debug information we must make
model level debug information available to mobile runtime.
At the moment, model level debug information is stored in SourceRange
which associates node's of graph to where the come from in original
python source code.
This information is serialized as part of debug_pkl and deserialized
when JIT loads the model and reads the model code.
On lite interpreter, we do not have access to all the functionality of
JIT and hence we cannot load model in the same way as JIT, by reading
code, constructing module hierarchy and graph corresponding module
methods etc. Instead in, lite interpreter, only bytecode corresonding to
the compiled graph, Code, is saved.
Thus in order to annotate OPs in the bytecode with equivalent
SourceRange information we do the following:
1. During model serialization, we create a unique tag for each source
range of the model.
2. Create a map of <SourceRange, tag>
3. During debug_pkl serialization we save tag along with SourceRange, on
top of byte offset.
4. During bytecode generation, the methods of the top module are
lowered. During this process methods are inlined. In the inlined graph,
when the node of a graph is lowered to bytecode, we query node's source
range and look it up against the map.
5. Resulting source range tag is serialized in module_debug_info.
6. During model deserialization, we read all the debug_pkl records in
the archieve and create a map of <tag, SourceRange>
7. This map can be used to find source code information.

During mobile runtime:
1. We read all the debug_pkl records and create <tag=debug_handle,
SourceRange> map.
   1.1 This map, MobileDebugInfo, is a member of mobile Module.
2. Interpreter catches appropriate exceptions and sets the thread local
debug handle and rethrows the exception.
3. In Function's run method we catch exception and query current debug
handle where the exception happened.
4. Query MobileDebugInfo with debug handle to retrieve source range and
augment error with source range info.

This information is still incomplete as it does not contain entire
callstack.

In the following diffs we will serialize InlinedCallStack directly.

Note that compilation is gated by SYMBOLICATE_MOBILE_DEBUG_HANDLE macro,
so that mobile builds can avoid building MobileDebugInfo, source range
and source range pickler/unpickler. Later we will add path where, if
building without debug support stack trace will contain only debug
handles. They can be symbolicated later.

Test Plan:
Ported bunch of source range tests from test_jit.py. Added on more test
in test_lite_interpreter.py

Imported from OSS

Reviewed By: raziel

Differential Revision: D27174722

fbshipit-source-id: a7b7c6088ce16dec37e823c7fefa4f0b61047e12
2021-05-04 09:19:27 -07:00
..
backward_compatibility Add torch.linalg.cholesky_ex without checking for errors by default (#56724) 2021-05-01 18:48:27 -07:00
benchmark_utils Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
bottleneck_test
cpp [TensorExpr] Add methods for inspecting generated code in TensorExprKernel. (#57074) 2021-05-03 20:02:28 -07:00
cpp_api_parity
cpp_extensions [torch distributed] Implementing all_gather_base (#56315) 2021-04-23 14:16:47 -07:00
custom_backend
custom_operator AutoDispatchBelowAutograd takes no arguments. (#56424) 2021-04-21 14:44:12 -07:00
distributed [23/n] [torch/elastic] Introduce the implementation of DynamicRendezvousHandler (#57151) 2021-05-03 18:32:43 -07:00
distributions
error_messages
expect Eliminate global usage of torch.set_default_dtype in sparse test (#56393) 2021-04-27 15:23:14 -07:00
fx Maintain submodule references during subgraph rewriting (#55463) 2021-04-30 16:46:44 -07:00
jit [JIT] Enable conv-add-relu fusion as a part of frozen graph optimization (#56580) 2021-04-30 15:29:38 -07:00
jit_hooks
mobile [PyTorch, Mobile] Serialization format change for source range (#54284) 2021-05-04 09:19:27 -07:00
onnx torch.clamp with tensor min and max (#52695) 2021-05-03 12:56:16 -07:00
optim
package [package] PackageExporter __import__ logic to not parse dynamic cases (#57283) 2021-04-29 14:21:33 -07:00
quantization [quant][graphmode][fx] Skip observering boolean Tensors (#57375) 2021-05-03 11:20:33 -07:00
scripts
test_img
typing Port NumPy typing testing style to PyTorch (#54234) 2021-04-15 01:25:16 -07:00
HowToWriteTestsUsingFileCheck.md
linear.py
run_test.py Torchelastic: add multiprocessing tests to ci/cd (#56842) 2021-05-02 14:03:47 -07:00
simulate_nccl_errors.py
test_ao_sparse.py [sparsity] Moving the sparsity python files to OSS (#56617) 2021-04-22 14:07:31 -07:00
test_autograd.py Eliminate global usage of torch.set_default_dtype in test_autograd (#56446) 2021-05-02 22:13:33 -07:00
test_binary_ufuncs.py Support auto generation of device check (#56872) 2021-05-01 12:02:09 -07:00
test_bundled_images.py [easy] Rename fb::jpeg_decode_to_NCHW to fb::image_decode_to_NCHW (#55857) 2021-04-15 13:44:13 -07:00
test_bundled_inputs.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_complex.py
test_cpp_api_parity.py
test_cpp_extensions_aot.py
test_cpp_extensions_jit.py Add minidump collection via breakpad (#55647) 2021-04-16 13:05:01 -07:00
test_cuda.py [RELAND] [CUDA graphs] Avoid sync errors when graph capturing cudnn rnn calls that use cudnn dropout (#57373) 2021-05-03 11:41:40 -07:00
test_cuda_primary_ctx.py
test_dataloader.py [DataLoader] Add generate_state for NumPy seeding (#56797) 2021-04-27 08:14:02 -07:00
test_datapipe.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_determination.py
test_dispatch.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
test_expecttest.py
test_foreach.py
test_function_schema.py Add stricter check for function schemas with varargs (#56509) 2021-04-20 20:04:38 -07:00
test_functional_autograd_benchmark.py
test_futures.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_fx.py OpInfo: ravel, view, view_as (#56910) 2021-05-02 22:10:36 -07:00
test_fx_experimental.py OpInfo: ravel, view, view_as (#56910) 2021-05-02 22:10:36 -07:00
test_import_time.py Add a test to measure import torch time (#56041) 2021-04-15 00:53:30 -07:00
test_indexing.py Migrate thrust->cub for index put (#55693) 2021-04-27 12:27:09 -07:00
test_jit.py [PyTorch, Mobile] Serialization format change for source range (#54284) 2021-05-04 09:19:27 -07:00
test_jit_cuda_fuser.py Fixing error in jit cuda on ROCm: non-constant-expression cannot be n… (#55243) 2021-04-21 16:35:27 -07:00
test_jit_disabled.py
test_jit_fuser.py
test_jit_fuser_legacy.py
test_jit_fuser_te.py [nnc] Enable all fuser tests for cpu (#57332) 2021-04-30 10:11:06 -07:00
test_jit_legacy.py
test_jit_profiling.py
test_jit_simple.py
test_jit_string.py
test_kernel_launch_checks.py
test_license.py
test_linalg.py Revert D28143091: [pytorch][PR] Add cross OpInfo 2021-05-03 09:19:41 -07:00
test_logging.py
test_metal.py
test_mkldnn.py [BE] Improve has_bf16_support (#57408) 2021-05-03 09:11:04 -07:00
test_mobile_optimizer.py [Pytorch Edge] Remove methods_to_optimize arg (#57045) 2021-04-27 14:54:13 -07:00
test_model_dump.py model_dump tool for model inspection (#56868) 2021-04-28 07:33:10 -07:00
test_module_init.py Support factory kwargs in torch.nn modules (#54508) 2021-04-22 16:16:53 -07:00
test_multiprocessing.py Fix mp serialization for integer nn.Parameter on CUDA (#56529) 2021-04-22 16:21:04 -07:00
test_multiprocessing_spawn.py
test_namedtensor.py
test_namedtuple_return_api.py Add torch.linalg.cholesky_ex without checking for errors by default (#56724) 2021-05-01 18:48:27 -07:00
test_native_functions.py
test_nn.py Fix a numerical issue of CUDA channels-last SyncBatchNorm (#57077) 2021-04-29 21:38:52 -07:00
test_nnapi.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
test_numba_integration.py
test_numpy_interop.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_op_aliases.py [OpInfo] Add opinfo for transpose and its aliases (#56122) 2021-04-25 21:58:16 -07:00
test_openmp.py
test_ops.py Add supported backward_dtype to OpInfo (#56156) 2021-04-30 08:24:58 -07:00
test_optim.py
test_overrides.py Update test_overrides for gradcheck (#57155) 2021-04-29 07:43:18 -07:00
test_package.py
test_profiler.py Add gzip format support for chrome tracing (#56554) 2021-04-28 12:40:33 -07:00
test_pruning_op.py
test_public_bindings.py
test_pytree.py
test_quantization.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
test_reductions.py Fix min() and max() for empty tensors (#52565) 2021-04-30 15:55:10 -07:00
test_segment_reductions.py [torch][segment_reduce] Add support for initial value (#56923) 2021-04-30 18:01:31 -07:00
test_serialization.py
test_set_default_mobile_cpu_allocator.py
test_shape_ops.py Fix tensor device in test_kthvalue_overlap (#56869) 2021-05-01 12:01:09 -07:00
test_show_pickle.py
test_sort_and_select.py Fix tensor device in test_kthvalue_overlap (#56869) 2021-05-01 12:01:09 -07:00
test_sparse.py Sparse support for division rounding_mode argument (#51989) 2021-05-01 17:37:25 -07:00
test_sparse_csr.py Modernize test-suite in sparse tensor CSR (#56392) 2021-04-27 15:22:17 -07:00
test_spectral_ops.py Remove distutils (#57040) 2021-04-29 12:10:11 -07:00
test_static_runtime.py
test_tensor_creation_ops.py [resubmit] Remove sync for randperm on small tensors. (#54113) (#57364) 2021-05-03 20:48:04 -07:00
test_tensorboard.py Add lint for unqualified noqa (#56272) 2021-04-19 13:16:18 -07:00
test_tensorexpr.py [nnc] Enable all fuser tests for cpu (#57332) 2021-04-30 10:11:06 -07:00
test_tensorexpr_pybind.py [JIT] Add a pass for removing a first (self) argument from a graph if it is unused. (#57169) 2021-05-03 20:02:25 -07:00
test_testing.py add support for complex input to torch.testing.assert_(equal|close) (#57162) 2021-05-02 16:13:12 -07:00
test_throughput_benchmark.py
test_torch.py torch.clamp with tensor min and max (#52695) 2021-05-03 12:56:16 -07:00
test_type_hints.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_type_info.py
test_type_promotion.py Revert D27765618: Initial support for sparse complex tensors constructors for CPU/CUDA 2021-04-27 15:48:51 -07:00
test_typing.py Port NumPy typing testing style to PyTorch (#54234) 2021-04-15 01:25:16 -07:00
test_unary_ufuncs.py OpInfo: mvlgamma (#56907) 2021-05-01 20:51:01 -07:00
test_utils.py Add lint for unqualified type: ignore (#56290) 2021-04-21 08:07:23 -07:00
test_view_ops.py Adding hsplit,vsplit and dsplit methods (#53536) 2021-04-26 09:39:09 -07:00
test_vmap.py
test_vulkan.py
test_xnnpack_integration.py