Fix nasty bug in bisect_percentile_op (#73147)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73147

Code used `reserve` instead of `resize` leading to platform010 test failures:
```
Trying example: test_bisect_percentil_op_large(
    self=<caffe2.caffe2.python.operator_test.bisect_percentile_op_test.TestBisectPercentileOp testMethod=test_bisect_percentil_op_large>,
    N=20,
    lengths=[2, 2],
    max_value=100,
    discrete=False,
    p=0.0,
    gc=,
    dc=[],
)

stderr:
E0219 13:14:52.601948 995877 JustKnobsConfigeratorLoader.cpp:114] Failed to load config justknobs/movefast/knobs after 55000ms timeout
E0219 13:14:52.602150 995877 JustKnobsConfigeratorLoader.cpp:114] Failed to load config justknobs/pytorch/compiler after 55000ms timeout
test_bisect_percentil_op_large (caffe2.caffe2.python.operator_test.bisect_percentile_op_test.TestBisectPercentileOp) ... third-party-buck/platform010/build/libgcc/include/c++/trunk/bits/stl_vector.h:1045: std::vector::reference std::vector<int>::operator[](std::vector::size_type) [_Tp = int, _Alloc = std::allocator<int>]: Assertion '__n < this->size()' failed.
*** Aborted at 1645305292 (Unix time, try 'date -d 1645305292') ***
*** Signal 6 (SIGABRT) (0x8556000f3225) received by PID 995877 (pthread TID 0x7f13a79c51c0) (linux TID 995877) (maybe from PID 995877, UID 34134) (code: -6), stack trace: ***
W0219 13:14:52.682251 995932 RetryingSender.cpp:433] Failed to make rpc. Sender name: pr-scubasing. Reason: apache::thrift::transport::TTransportException: AsyncSocketException: connect failed, type = Socket not open, errno = 111 (Connection refused): Connection refused.
    @ 000000000000431b folly::symbolizer::(anonymous namespace)::signalHandler(int, siginfo_t*, void*)
                       ./folly/experimental/symbolizer/SignalHandler.cpp:449
    @ 0000000000000000 (unknown)
    @ 000000000009c9f3 __GI___pthread_kill
```

Test Plan: Sandcastle

Reviewed By: luciang

Differential Revision: D34365188

fbshipit-source-id: 65dcc23226c59096afd5fb3c338c3bd29c936ec3
(cherry picked from commit a1d18e3e6a)
This commit is contained in:
Richard Barnes 2022-02-20 09:08:13 -08:00 committed by PyTorch MergeBot
parent bf03d93496
commit 24c91e23d3

View File

@ -44,7 +44,7 @@ class BisectPercentileOp final : public Operator<Context> {
pct_upper_.size(),
"Feature (raw) data and upper bound dimension should match.");
n_features = pct_lens_.size();
index.reserve(n_features + 1);
index.resize(n_features + 1);
index[0] = 0;
for (int i = 1; i <= n_features; ++i) {
index[i] = index[i - 1] + pct_lens_[i - 1];