pytorch/torch/_dynamo/variables
Joel Schlosser 5855c490f0 Proper view support for jagged layout NestedTensor (#113279)
This PR:
* Introduces an ATen op for creating true jagged views from a dense values buffer
    * `_nested_view_from_jagged(values, offsets, lengths, ragged_idx, dummy)`
    * This ops is implemented on the Python side using torch.library so we can return a subclass instance
    * `jagged_from_list()` now uses this instead of the old autograd.Function `NestedViewFromBuffer`
    * The latter op is used for non-contiguous JTs returned via `torch.nested.narrow()`
    * `dummy` is an awful hack to ensure that `NestedTensor.__torch_dispatch__()` is invoked for our view
* Introduces an ATen op for accessing the `values` component of an NT via a view
    * `_nested_get_values(nt)`
* **Removes** the autograd.Functions `ViewNestedFromBuffer` and `ViewBufferFromNested` in favor of `nested_from_values_offsets()` / `nested_from_values_offsets_lengths()` and `nt.values()`, respectively.
* Changes test code to prefer `as_nested_tensor()` over `jagged_from_list()` directly
    * Similarly, avoid `buffer_from_jagged()`, preferring `values()`
* Depends on general subclass view fake-ification on the PT2 side (handled solely in previous PRs in the stack)

With these changes, the semantics of jagged layout NTs are such that they are considered a true view of the underlying `values` buffer. This means views of jagged NTs are views of the underlying buffer as well, simplifying some handling.

Differential Revision: [D54269922](https://our.internmc.facebook.com/intern/diff/D54269922)
Co-authored-by: voznesenskym <voznesenskym@gmail.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/113279
Approved by: https://github.com/ezyang
2024-03-20 23:45:34 +00:00
..
__init__.py Revert "Teach dynamo about torch.func.jvp (#119926)" 2024-03-20 18:34:43 +00:00
base.py [dynamo] Replace VariableTracker.apply with visit/realize_all (#122218) 2024-03-20 07:53:18 +00:00
builder.py Proper view support for jagged layout NestedTensor (#113279) 2024-03-20 23:45:34 +00:00
builtin.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
constant.py [dynamo] Remove VariableTracker.parents_tracker (#122058) 2024-03-19 04:23:24 +00:00
ctx_manager.py Revert "Teach dynamo about torch.func.jvp (#119926)" 2024-03-20 18:34:43 +00:00
dicts.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
distributed.py [dynamo] Tweak naming for module hook bw_state (#121609) 2024-03-12 16:27:56 +00:00
functions.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
higher_order_ops.py [while_loop] disable closure capturing and manually set the inputs. (#122244) 2024-03-20 20:14:35 +00:00
iter.py [dynamo] Optimize SourcelessBuilder (#122063) 2024-03-19 04:23:30 +00:00
lazy.py [dynamo] Replace VariableTracker.apply with visit/realize_all (#122218) 2024-03-20 07:53:18 +00:00
lists.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
misc.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
nn_module.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
optimizer.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
sdpa.py [dynamo] Refactor reconstruct() not to return anything (#120150) 2024-02-17 17:13:41 +00:00
tensor.py [dynamo] Add missing _nonvar_fields annotations (#122219) 2024-03-20 07:53:18 +00:00
torch_function.py [dynamo] Optimize SourcelessBuilder (#122063) 2024-03-19 04:23:30 +00:00
torch.py Revert "Teach dynamo about torch.func.jvp (#119926)" 2024-03-20 18:34:43 +00:00
user_defined.py [dynamo] Optimize SourcelessBuilder (#122063) 2024-03-19 04:23:30 +00:00