You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7bc5e0e
Browse filesBrowse the repository at this point in the historyBrowse files
Fixespytorch#20270
### Summary
Add portable scalar and tensor bucketize operator, based on the PyTorch
implementation.
Key differences from the PyTorch implementation:
- Implemented only bucketize, no searchsorted
- Boundaries tensor size is not checked against output type, as
`SizesType` is an `int32_t` and must be 1D
- In the original implementation the input scalar is wrapped into a
tensor, here two sets of functions are used instead
- Supports both NHWC and NCHW as it is a pointwise kernel and there is
no sorter argument. This avoids creating contiguous tensors
- Stayed as close to the PyTorch version as possible, should a
searchsorted implementation be added in the future
Release notes: ops & kernels
### Test plan
C++ tests are extensive and include failure and edge cases tests.
Python tests compare the output of an exported module to the PyTorch
implementation only for normal and edge cases, similar to pytorch#15893.
cc @larryliu0820@manuelcandales
---------
Signed-off-by: Gallinator <lcgallinator4@gmail.com>
// Performs check which are common to both tensor and scalar implementations:
141
+
// - Boundaries must be 1D
142
+
// - Out type must be consistent with out_int32 parameter
143
+
// - Boundaries type must be realhbf16
144
+
// Boundaries size is not checked against out type as SizesType always fits into
145
+
// an int32_t.
146
+
Error bucketize_common_pre_checks(
147
+
const Tensor& boundaries,
148
+
bool out_int32,
149
+
Tensor& out) {
150
+
ET_CHECK_OR_RETURN_ERROR(
151
+
boundaries.dim() == 1,
152
+
InvalidArgument,
153
+
"boundaries tensor must be 1 dimension, but got dim(%zu)",
154
+
boundaries.dim());
155
+
156
+
ScalarType out_dtype = out.scalar_type();
157
+
ET_CHECK_OR_RETURN_ERROR(
158
+
(out_dtype == ScalarType::Long && !out_int32) ||
159
+
(out_dtype == ScalarType::Int && out_int32),
160
+
InvalidArgument,
161
+
"torch.bucketize(): output tensor's dtype is wrong, it can only be Int(int32) or Long(int64) depending on whether out_int32 flag is True, but we got output tensor dtype %s and out_int32 flag is %s",
0 commit comments