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

Commit 87793a3

Browse files
bdhirshfacebook-github-bot
authored andcommitted
Revert D24714803: make duplicate def() calls an error in the dispatcher. Updating all fb operators to use the new dispatcher registration API
Differential Revision: D24714803 Original commit changeset: c809aad8a698 fbshipit-source-id: fb2ada65f9fc00d965708d202bd9d050f13ef467
1 parent 01870a1 commit 87793a3

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

nestedtensor/csrc/mha.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ at::Tensor min_mha(
6262
return attn_output;
6363
}
6464

65-
TORCH_LIBRARY_FRAGMENT(nestedtensor, m) {
66-
m.def("min_mha", min_mha);
67-
}
65+
static auto registry =
66+
torch::RegisterOperators().op("nestedtensor::min_mha", &min_mha);
6867

6968
} // namespace nested_tensor
7069
} // namespace torch

nestedtensor/csrc/py_init.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,34 +145,36 @@ inline std::vector<std::string> split_str(
145145
result.push_back(s);
146146
return result;
147147
}
148-
TORCH_LIBRARY_FRAGMENT(nestedtensor, m) {
149-
m.def("is_nested_tensor_impl",
150-
[](Tensor tensor) { return is_nested_tensor_impl(tensor); });
151-
m.def("nested_dim",
148+
149+
static auto registry =
150+
torch::RegisterOperators()
151+
.op("nestedtensor::is_nested_tensor_impl",
152+
[](Tensor tensor) { return is_nested_tensor_impl(tensor); })
153+
.op("nestedtensor::nested_dim",
152154
[](Tensor tensor) {
153155
return get_nested_tensor_impl(tensor)->nested_dim();
154-
});
155-
m.def("stack",
156+
})
157+
.op("nestedtensor::stack",
156158
[](std::vector<Tensor> tensors, int64_t dim) {
157159
return at::stack(TensorList(tensors), dim);
158-
});
159-
m.def("cat",
160+
})
161+
.op("nestedtensor::cat",
160162
[](std::vector<Tensor> tensors, int64_t dim) {
161163
return at::cat(TensorList(tensors), dim);
162-
});
163-
m.def("to_nested_tensor",
164+
})
165+
.op("nestedtensor::to_nested_tensor",
164166
[](Tensor tensor, c10::optional<int64_t> dim) {
165167
return get_nested_tensor_impl(tensor)->to_nested_tensor(dim);
166-
});
167-
m.def("sizes",
168+
})
169+
.op("nestedtensor::sizes",
168170
[](Tensor tensor) {
169171
return get_nested_tensor_impl(tensor)->opt_sizes();
170-
});
171-
m.def("len",
172+
})
173+
.op("nestedtensor::len",
172174
[](Tensor self) {
173175
return (int64_t)(get_nested_tensor_structure(self).degree());
174-
});
175-
m.def("str", [](Tensor tensor) {
176+
})
177+
.op("nestedtensor::str", [](Tensor tensor) {
176178
auto node = get_nested_tensor_structure(tensor);
177179
return NestedNode___str__(
178180
node,
@@ -201,8 +203,6 @@ TORCH_LIBRARY_FRAGMENT(nestedtensor, m) {
201203
return result;
202204
});
203205
});
204-
}
205-
206206
} // namespace
207207
} // namespace nested_tensor
208208
} // namespace torch

nestedtensor/csrc/totensor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ Tensor NestedTensor_to_tensor(Tensor tensor, c10::optional<int64_t> dim_) {
109109
// return wrap_tensor_node(TensorNode(std::move(result)));
110110
}
111111

112-
TORCH_LIBRARY_FRAGMENT(nestedtensor, m) {
113-
m.def("to_tensor",
112+
static auto registry = torch::RegisterOperators().op(
113+
"nestedtensor::to_tensor",
114114
[](Tensor tensor, c10::optional<int64_t> dim) {
115115
return NestedTensor_to_tensor(tensor, dim);
116116
});
117-
}
118117

119118
} // namespace at

0 commit comments

Comments
 (0)