pytorch/torch
William Wen 8c13e96be2 [dynamo] add logging artifact for traced graph tensor sizes (#104672)
Log tensor size information with the `graph_sizes` logging artifact, as part of the model x-ray feature requests. Typically can be combined with `graph_code`.

Sample:
```python
import torch

def fn(a, b, c, d):
    return (a + b) @ (c + d)

opt_fn = torch.compile(fn, backend="eager", dynamic=False)
opt_fn(torch.randn(10, 20), torch.randn(1, 20), torch.randn(20, 15), torch.randn(1, 15))
opt_fn(torch.randn(5, 2), torch.randn(1, 2), torch.randn(2, 4), torch.randn(1, 4))
```

Output:
```shell
$ TORCH_LOGS="graph_sizes,graph_code" python playground8.py
[2023-07-06 01:42:39,093] torch._dynamo.output_graph.__graph_code: [DEBUG] TRACED GRAPH
 ===== __compiled_fn_0 =====
 <eval_with_key>.0 class GraphModule(torch.nn.Module):
    def forward(self, L_a_ : torch.Tensor, L_b_ : torch.Tensor, L_c_ : torch.Tensor, L_d_ : torch.Tensor):
        l_a_ = L_a_
        l_b_ = L_b_
        l_c_ = L_c_
        l_d_ = L_d_

        # File: playground8.py:66, code: return (a + b) @ (c + d)
        add = l_a_ + l_b_;  l_a_ = l_b_ = None
        add_1 = l_c_ + l_d_;  l_c_ = l_d_ = None
        matmul = add @ add_1;  add = add_1 = None
        return (matmul,)

[2023-07-06 01:42:39,093] torch._dynamo.output_graph.__graph_sizes: [DEBUG] TRACED GRAPH TENSOR SIZES
===== __compiled_fn_0 =====
l_a_: (10, 20)
l_b_: (1, 20)
l_c_: (20, 15)
l_d_: (1, 15)
add: (10, 20)
add_1: (20, 15)
matmul: (10, 15)

[2023-07-06 01:42:39,198] torch._dynamo.output_graph.__graph_code: [DEBUG] TRACED GRAPH
 ===== __compiled_fn_1 =====
 <eval_with_key>.1 class GraphModule(torch.nn.Module):
    def forward(self, s0 : torch.SymInt, s1 : torch.SymInt, L_a_ : torch.Tensor, L_b_ : torch.Tensor, s4 : torch.SymInt, L_c_ : torch.Tensor, L_d_ : torch.Tensor):
        l_a_ = L_a_
        l_b_ = L_b_
        l_c_ = L_c_
        l_d_ = L_d_

        # File: playground8.py:66, code: return (a + b) @ (c + d)
        add = l_a_ + l_b_;  l_a_ = l_b_ = None
        add_1 = l_c_ + l_d_;  l_c_ = l_d_ = None
        matmul = add @ add_1;  add = add_1 = None
        return (matmul,)

[2023-07-06 01:42:39,198] torch._dynamo.output_graph.__graph_sizes: [DEBUG] TRACED GRAPH TENSOR SIZES
===== __compiled_fn_1 =====
l_a_: (s0, s1)
l_a_ (concrete): (5, 2)
l_b_: (1, s1)
l_b_ (concrete): (1, 2)
l_c_: (s1, s4)
l_c_ (concrete): (2, 4)
l_d_: (1, s4)
l_d_ (concrete): (1, 4)
add: (s0, s1)
add (concrete): (5, 2)
add_1: (s1, s4)
add_1 (concrete): (2, 4)
matmul: (s0, s4)
matmul (concrete): (5, 4)
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/104672
Approved by: https://github.com/ezyang
2023-07-06 21:44:05 +00:00
..
_awaits
_C DDP + C10D sparse all_reduce changes (#103916) (#104256) 2023-06-28 00:37:52 +00:00
_C_flatbuffer
_custom_op Add API to construct the functional variant of an op (#102293) 2023-06-02 13:36:50 +00:00
_decomp reduce computation of batch_norm when weight or bias is none (#104616) 2023-07-06 00:47:41 +00:00
_dispatch Reland of https://github.com/pytorch/pytorch/pull/101818 (#103888) 2023-06-21 21:00:56 +00:00
_dynamo [dynamo] add logging artifact for traced graph tensor sizes (#104672) 2023-07-06 21:44:05 +00:00
_export [export][serde] Hookup export upgrader with TorchScript upgrader entries (#104227) 2023-07-06 16:57:36 +00:00
_functorch Revert "Re-enable low memory dropout (#103330)" 2023-07-05 19:00:40 +00:00
_higher_order_ops [HigherOrderOp] Remove _deprecated_global_ns from some ops (#104105) 2023-06-28 00:03:29 +00:00
_inductor [hotfix inductor test] disable cpp vectorization codegen in fbcode for inductor (#104560) 2023-07-06 19:00:13 +00:00
_lazy
_logging [dynamo] add logging artifact for traced graph tensor sizes (#104672) 2023-07-06 21:44:05 +00:00
_prims Refactor unwrap_proxy() for proxy tensor tracing. (#104667) 2023-07-06 03:03:13 +00:00
_prims_common [pt2] add metas for max_unpool2d and max_unpool3d (#103821) 2023-07-01 01:33:35 +00:00
_refs [decomp] Add test tracking core ATen operators (#104262) 2023-07-04 16:41:44 +00:00
_subclasses [pt2] grad support (#102264) 2023-06-21 10:13:09 +00:00
amp pre_dispatch tracing: support autocast and no_grad/enable_grad ctx managers, add a pre_dispatch_eager dynamo backend (#103024) 2023-06-29 14:17:42 +00:00
ao [Quant][PT2E] Enable conv2d unary and binary recipe for x86 inductor quantizer (#98826) 2023-07-04 00:01:10 +00:00
autograd Deprecate "Type" and support more devices for save_on_cpu (#103245) 2023-06-09 05:05:01 +00:00
backends [BE] Deprecate has_XYZ attributes (#103279) 2023-06-10 05:17:17 +00:00
compiler torch.compiler public namespace (#102182) 2023-06-13 19:52:17 +00:00
contrib
cpu Quantization oneDNN backend only support VNNI CPU (#103653) 2023-06-19 09:50:07 +00:00
csrc [export][serde] Hookup export upgrader with TorchScript upgrader entries (#104227) 2023-07-06 16:57:36 +00:00
cuda [pt2] grad support (#102264) 2023-06-21 10:13:09 +00:00
distributed [FSDP] Annotate modules for fully_shard (#104363) 2023-07-06 16:56:59 +00:00
distributions Fix Dirichlet.log_prob() when x=0 and alpha=1 (#103605) 2023-06-15 16:16:50 +00:00
fft
func [pt2] grad support (#102264) 2023-06-21 10:13:09 +00:00
futures
fx Refactor unwrap_proxy() for proxy tensor tracing. (#104667) 2023-07-06 03:03:13 +00:00
jit [jit] Fix inspect.get_annotations usage in python >= 3.10 (#104485) 2023-07-06 00:37:47 +00:00
legacy
lib Use size_t in THManagedMapAllocator (#103331) 2023-06-13 04:50:30 +00:00
linalg [Doc] linalg.ldl_factor: render the Shape of tensor A (#99777) 2023-06-28 09:28:45 +00:00
masked Fix autograd issue with identity conversions (#92022) 2023-06-21 21:23:03 +00:00
monitor
mps [doc] Improve mps package description (#104184) 2023-06-27 15:50:36 +00:00
multiprocessing
nested
nn [dynamo] Reland #104317 - Lazy disable_dynamo API out-of-dynamo (#104664) 2023-07-06 00:48:02 +00:00
onnx [ONNX] Export dynamic step size for aten::slice() (#104385) 2023-07-06 21:38:59 +00:00
optim [dynamo] Reland #104317 - Lazy disable_dynamo API out-of-dynamo (#104664) 2023-07-06 00:48:02 +00:00
package Integrating new API usage metadata logger (#101762) 2023-05-26 00:24:26 +00:00
profiler Fix broken torch._inductor.config import (#104477) 2023-07-01 02:23:44 +00:00
quantization
signal
sparse [core][pruning][sparse][feature] SparseSemiStructured tensor subclass (#102135) 2023-06-27 19:21:06 +00:00
special
testing [c10d] Adopt allgather_into_tensor_coalesced for NCCL. (#103086) 2023-07-06 15:05:55 +00:00
utils [dynamo][ac] Reland #104397 - Remove disable monkeypatching of utils.checkpoint (#104665) 2023-07-06 00:48:02 +00:00
__config__.py
__future__.py
__init__.py [dynamo] Reland #104317 - Lazy disable_dynamo API out-of-dynamo (#104664) 2023-07-06 00:48:02 +00:00
_appdirs.py
_classes.py
_compile.py [dynamo] Reland #104317 - Lazy disable_dynamo API out-of-dynamo (#104664) 2023-07-06 00:48:02 +00:00
_deploy.py
_guards.py Lift user defined attributes into inputs for certain cases (user defined types and tensors) (#103386) 2023-06-20 23:45:19 +00:00
_jit_internal.py default should be used as default value in boolean_dispatch (#103463) 2023-06-14 03:16:31 +00:00
_linalg_utils.py
_lobpcg.py
_lowrank.py
_meta_registrations.py [pt2] add metas for multilabel_margin_loss ops (#104388) 2023-07-05 13:42:22 +00:00
_namedtensor_internals.py
_ops.py Raise AttributeError in _OpsNamespace if __self__ attribute is requested (#104096) 2023-06-27 01:42:06 +00:00
_python_dispatcher.py
_sources.py
_storage_docs.py
_tensor_docs.py Added is_xla (#103100) 2023-06-22 23:31:04 +00:00
_tensor_str.py Add torch._utils.render_call, improve printoptions (#102623) 2023-05-31 22:08:04 +00:00
_tensor.py This extra message would have helped with Wav2Vec2 debugging. (#103002) 2023-06-06 04:28:16 +00:00
_torch_docs.py doc: fix fake_quantize_per_tensor_affine docs (#104453) 2023-06-30 22:59:00 +00:00
_utils_internal.py
_utils.py fix hpu storage serialization (#101680) 2023-06-21 21:19:49 +00:00
_VF.py
_vmap_internals.py
_weights_only_unpickler.py
abi-check.cpp
CMakeLists.txt enable more ASAN tests (#101483) 2023-06-15 05:21:15 +00:00
custom_class_detail.h
custom_class.h
extension.h
functional.py [BE] Do not expose torch.functional.opt_einsum (#102004) 2023-05-23 01:52:40 +00:00
hub.py
library.h [PyTorch] Delete c10::guts::if_constexpr (#101991) 2023-05-23 23:19:35 +00:00
library.py [torch.library] Change Library.__del__ into weakref.finalize (#101829) 2023-05-22 19:51:08 +00:00
overrides.py sparse_mask: backward support for sparse lhs (take 2) (#104341) 2023-07-03 14:12:44 +00:00
py.typed
quasirandom.py
random.py Correct warning message info in fork_rng (#104525) 2023-07-04 19:08:16 +00:00
README.txt
return_types.py
script.h
serialization.py Add functions to get and set default endianness in load() functions (#101973) 2023-07-06 20:12:56 +00:00
storage.py fix hpu storage serialization (#101680) 2023-06-21 21:19:49 +00:00
torch_version.py
types.py
version.py.tpl [bazel] add build for functorch (#101475) 2023-05-18 20:29:08 +00:00

Note [TH abstraction violation]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TH/THC provide some hpp headers, which are proper C++ headers rather than
C headers.  These headers serve double duty as *internal implementation
detail* headers, whose contents should largely not be used by external
clients.

Ideally, we would not install these headers at all; instead, you should
use public functions (in headers like `THTensor.h`, NOT `THTensor.hpp`)
to manipulate these structs.  However, there are a few places
in torch/csrc where we violate this abstraction.  They are marked with
a pointer to this note.  Each of those sites will have to be refactored
when we refactor the guts of THTensor and related structures.