Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit d00fd7c

Browse files
cpuhrschfacebook-github-bot
authored andcommitted
Adopt nestedtensor to structured cumsum
Summary: https://www.internalfb.com/diff/D29939489 broke NT Reviewed By: ezyang Differential Revision: D30110005 fbshipit-source-id: 2fe58d0a7295283483fc7e3b05f97fa55e4b37ca
1 parent 9b6dcbc commit d00fd7c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

nestedtensor/csrc/BinaryOps.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Tensor NestedTensor_add_Tensor(
7272
}
7373
at::Tensor numbers_t = torch::tensor(numbers).to(torch::kInt32);
7474
Tensor nt_sizes_cumsum =
75-
at::native::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
75+
at::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
7676
TORCH_CHECK(nt_sizes_.dim() == 2, "NestedTensor metadata of unexpected dimension.")
7777
Tensor nt_sizes = at::cat({torch::tensor({0}, torch::kInt32), nt_sizes_cumsum});
7878
nt_sizes = nt_sizes.to(torch::kCUDA);
@@ -108,7 +108,7 @@ Tensor NestedTensor_add_Tensor(
108108
}
109109
std::tie(self, other) = _expand_other_as(self_, other_);
110110
return map_nested_tensor(
111-
[&alpha](Tensor s, Tensor o) {
111+
[&alpha](Tensor s, Tensor o) {
112112
return at::add(s, o, alpha); },
113113
self,
114114
other);
@@ -270,7 +270,7 @@ Tensor NestedTensor_mul_Tensor(const Tensor& self_, const Tensor& other_) {
270270
}
271271
at::Tensor numbers_t = torch::tensor(numbers).to(torch::kInt32);
272272
Tensor nt_sizes_cumsum =
273-
at::native::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
273+
at::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
274274
TORCH_CHECK(nt_sizes_.dim() == 2, "NestedTensor metadata of unexpected dimension.")
275275
Tensor nt_sizes = at::cat({torch::tensor({0}, torch::kInt32), nt_sizes_cumsum});
276276
nt_sizes = nt_sizes.to(torch::kCUDA);
@@ -295,7 +295,7 @@ Tensor NestedTensor_mul_Tensor(const Tensor& self_, const Tensor& other_) {
295295
}
296296
std::tie(self, other) = _expand_other_as(self_, other_);
297297
return map_nested_tensor(
298-
[](Tensor s, Tensor o) {
298+
[](Tensor s, Tensor o) {
299299
return at::mul(s, o); }, self, other);
300300
}
301301

@@ -389,7 +389,7 @@ Tensor NestedTensor_sub_Tensor(
389389
}
390390
at::Tensor numbers_t = torch::tensor(numbers).to(torch::kInt32);
391391
Tensor nt_sizes_cumsum =
392-
at::native::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
392+
at::cumsum(numbers_t, 0).to(torch::kInt32).reshape({-1});
393393
TORCH_CHECK(nt_sizes_.dim() == 2, "NestedTensor metadata of unexpected dimension.")
394394
Tensor nt_sizes = at::cat({torch::tensor({0}, torch::kInt32), nt_sizes_cumsum});
395395
nt_sizes = nt_sizes.to(torch::kCUDA);
@@ -414,7 +414,7 @@ Tensor NestedTensor_sub_Tensor(
414414
}
415415
std::tie(self, other) = _expand_other_as(self_, other_);
416416
return map_nested_tensor(
417-
[&alpha](Tensor s, Tensor o) {
417+
[&alpha](Tensor s, Tensor o) {
418418
return at::sub(s, o, alpha); },
419419
self,
420420
other);

nestedtensor/csrc/masking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ std::tuple<Tensor, Tensor> to_tensor_mask(
261261
Tensor nt_sizes = at::native::narrow(nt_sizes_, 1, 0, 1);
262262
int max_size_1 = nt_sizes.max().item<int>();
263263
nt_sizes =
264-
at::native::cumsum(nt_sizes, 0).to(torch::kInt32).reshape({-1});
264+
at::cumsum(nt_sizes, 0).to(torch::kInt32).reshape({-1});
265265
nt_sizes = at::cat({torch::tensor({0}, torch::kInt32), nt_sizes});
266266
Tensor output = torch::zeros(
267267
{*nt_opt_size[0], max_size_1, *nt_opt_size[2]}, nt_buffer.options());
@@ -477,7 +477,7 @@ Tensor from_padded_tensor(Tensor padded, EfficientSizeNode target_size) {
477477
std::vector<at::Tensor> all_sizes = target_size.sizes().unbind();
478478
for (int64_t i = 0; i < all_sizes.size(); i++) {
479479
std::vector<int64_t> sizes_i(
480-
all_sizes[i].data_ptr<int64_t>(),
480+
all_sizes[i].data_ptr<int64_t>(),
481481
all_sizes[i].data_ptr<int64_t>() + all_sizes[i].numel());
482482
at::Tensor mask_i = padded.new_full(
483483
IntArrayRef(sizes_i),

0 commit comments

Comments
 (0)