Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack bug for 129inputs #8927

Merged
merged 7 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions oneflow/core/functional/impl/array_functor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ class StackFunctor {
int64_t ndims = inputs[0]->ndim();
int64_t stack_dim = dim;
stack_dim = JUST(maybe_wrap_dim(stack_dim, ndims + 1));
if (ninput == 1) { return ExpandDims(inputs[0], dim); }
const std::shared_ptr<const Shape>& first_in_shape = inputs[0]->shape();
for (const auto& input : inputs) {
for (int i = 0; i < ndims; ++i) {
Expand All @@ -615,8 +614,13 @@ class StackFunctor {
size_t size = (i + kMaxInputCount) < ninput ? kMaxInputCount : ninput - i;
TensorTuple partial_inputs(size);
for (int j = 0; j < size; ++j) { partial_inputs[j] = inputs[i + j]; }
outputs.emplace_back(
JUST(OpInterpUtil::Dispatch<Tensor>(*ops_.at(size - 1), partial_inputs, attrs)));
if (partial_inputs.size() == 1) {
// Use ExpandDims functor for only one input
outputs.emplace_back(JUST(functional::ExpandDims(partial_inputs[0], dim)));
} else {
outputs.emplace_back(
JUST(OpInterpUtil::Dispatch<Tensor>(*ops_.at(size - 1), partial_inputs, attrs)));
}
}
if (outputs.size() == 1) { return outputs.at(0); }
return Concat(outputs, stack_dim);
Expand Down
9 changes: 9 additions & 0 deletions python/oneflow/test/modules/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def test_stack_bool_with_random_data(test_case):
out = torch.stack((x, y), dim=random(low=1, high=4).to(int))
return out

@autotest(auto_backward=True, check_graph=True)
def test_stack_kMaxInputCount_inputs(test_case):
kMaxInputCount = 128 + 1
stack_list = [
random_tensor(ndim=2, dim0=3, dim1=4) for _ in range(kMaxInputCount)
]
out = torch.stack(stack_list, 0)
return out


if __name__ == "__main__":
unittest.main()