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 kMaxInputCount check in GroupedMatmulFunctor #10322

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions oneflow/core/functional/impl/nn_functor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5223,6 +5223,8 @@ class GroupedMatmulFunctor {
Maybe<TensorTuple> operator()(const TensorTuple& xs, const TensorTuple& weights) const {
const int64_t input_size = xs.size();
const int64_t weight_size = weights.size();
CHECK_LT_OR_RETURN(input_size, kMaxInputCount)
<< Error::RuntimeError() << "input_size size should not be greater than 128";
CHECK_GE_OR_RETURN(input_size, 1)
<< Error::RuntimeError() << "The number of xs should be greater equal than 1.";
CHECK_EQ_OR_RETURN(weight_size, input_size)
Expand Down
8 changes: 7 additions & 1 deletion oneflow/user/kernels/grouped_matmul_bias.cu
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ class GroupedMatmulBiasKernel final : public user_op::OpKernel, public user_op::
}
void* workspace = ctx->Tensor4ArgNameAndIndex("tmp_buffer", 0)->mut_dptr();
for (const auto& group : groups) {
ApplyGroup<T>(group.first, group.second, has_biases, workspace, ctx->stream());
for (size_t i = 0; i < group.second.size(); i += kMaxProblemBatch) {
std::vector<Buffer<T>> ptrs(
{group.second.begin() + i,
group.second.begin() + i
+ std::min<size_t>(group.second.size() - i, kMaxProblemBatch)});
ApplyGroup<T>(group.first, ptrs, has_biases, workspace, ctx->stream());
}
}
}
bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; }
Expand Down
Loading