mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Remove `torch.nested_tensor` which has erroneous behavior wrt gradients (could be either leaf or not leaf). Introduce `torch.nested.nested_tensor` and `torch.nested.as_nested_tensor` in the vein of `torch.tensor` and `torch.as_tensor`. Done in nested `__init__.py` for now but can move to pybind in future (when we want to load from numpy/nested lists ). Discussed offline with @cpuhrsch and pybind constructor (https://github.com/pytorch/pytorch/pull/85536) was more gnarly than expected, so we can move to that when we do need loading from numpy etc. Differential Revision: [D39806622](https://our.internmc.facebook.com/intern/diff/D39806622) Pull Request resolved: https://github.com/pytorch/pytorch/pull/85593 Approved by: https://github.com/drisspg, https://github.com/cpuhrsch
16 lines
394 B
C++
16 lines
394 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <torch/nested.h>
|
|
#include <torch/torch.h>
|
|
|
|
#include <test/cpp/api/support.h>
|
|
|
|
// Simple test that verifies the nested namespace is registered properly
|
|
// properly in C++
|
|
TEST(NestedTest, Nested) {
|
|
auto a = torch::randn({2, 3});
|
|
auto b = torch::randn({4, 5});
|
|
auto nt = torch::nested::nested_tensor({a, b});
|
|
torch::nested::to_padded_tensor(nt, 0);
|
|
}
|