KEMBAR78
Support for as_nested_tensor() with jagged layout + fixed nested_tensor() semantics by jbschlosser · Pull Request #112304 · pytorch/pytorch · GitHub
Skip to content

Conversation

@jbschlosser
Copy link
Contributor

@jbschlosser jbschlosser commented Oct 27, 2023

Stack from ghstack (oldest at bottom):

This PR:

  • Adds support for the layout kwarg to torch.nested.as_nested_tensor()
  • Fixes torch.nested.nested_tensor()
    • It should accept a list of lists of scalars
    • It should not preserve autograd history
  • Adds extensive testing for these two functions

Semantics for the two functions follow those of the strided layout:

  • torch.nested.nested_tensor(tensor_list, layout=torch.jagged): Creates a new jagged layout NT with no autograd history
    • tensor_list can be a list of Tensors or list of lists of scalars
  • torch.nested.as_nested_tensor(tensor_list, layout=torch.jagged): Creates a new jagged layout NT preserving autograd history of tensor_list
    • tensor_list must be a list of Tensors

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 27, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112304

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 58f0798 with merge base 128f4db (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

jbschlosser added a commit that referenced this pull request Oct 27, 2023
…or() semantics

ghstack-source-id: 61b633c
Pull Request resolved: #112304
@jbschlosser jbschlosser added topic: improvements topic category release notes: nested tensor Changes that have a direct impact on nested tensors labels Oct 27, 2023
@jbschlosser
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 27, 2023
@cpuhrsch
Copy link
Contributor

cpuhrsch commented Oct 27, 2023

Thanks for sending this! I think it looks good.

Good follow up work for as_nested_tensor could include supporting regular Tensor input (instead of list of Tensors). That means simply a type conversion from a 3D Tensor to a 3D NestedTensor.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@facebook-github-bot facebook-github-bot deleted the gh/jbschlosser/96/head branch October 31, 2023 14:24
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Nov 7, 2023
…or() semantics (pytorch#112304)

This PR:
* Adds support for the `layout` kwarg to `torch.nested.as_nested_tensor()`
* Fixes `torch.nested.nested_tensor()`
    * It should accept a list of lists of scalars
    * It should not preserve autograd history
* Adds extensive testing for these two functions

Semantics for the two functions follow those of the strided layout:
* `torch.nested.nested_tensor(tensor_list, layout=torch.jagged)`: Creates a new jagged layout NT **with no autograd history**
    * `tensor_list` can be a list of Tensors or list of lists of scalars
* `torch.nested.as_nested_tensor(tensor_list, layout=torch.jagged)`: Creates a new jagged layout NT **preserving autograd history of `tensor_list`**
    * `tensor_list` must be a list of Tensors
Pull Request resolved: pytorch#112304
Approved by: https://github.com/cpuhrsch, https://github.com/soulitzer
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
…or() semantics (pytorch#112304)

This PR:
* Adds support for the `layout` kwarg to `torch.nested.as_nested_tensor()`
* Fixes `torch.nested.nested_tensor()`
    * It should accept a list of lists of scalars
    * It should not preserve autograd history
* Adds extensive testing for these two functions

Semantics for the two functions follow those of the strided layout:
* `torch.nested.nested_tensor(tensor_list, layout=torch.jagged)`: Creates a new jagged layout NT **with no autograd history**
    * `tensor_list` can be a list of Tensors or list of lists of scalars
* `torch.nested.as_nested_tensor(tensor_list, layout=torch.jagged)`: Creates a new jagged layout NT **preserving autograd history of `tensor_list`**
    * `tensor_list` must be a list of Tensors
Pull Request resolved: pytorch#112304
Approved by: https://github.com/cpuhrsch, https://github.com/soulitzer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: nested tensor Changes that have a direct impact on nested tensors topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants