-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix error message of multinomial op #27946
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
Changes from 4 commits
9128de9
74ed1ee
2144fb6
e6e54ea
1bb315b
8f35154
d5fe719
f616d5b
994713c
01f331d
8250e58
0b7f5cf
9a3b6e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -53,12 +53,18 @@ class MultinomialOp : public framework::OperatorWithKernel { | |||||
|
|
||||||
| auto x_dim = ctx->GetInputDim("X"); | ||||||
| int64_t x_rank = x_dim.size(); | ||||||
| PADDLE_ENFORCE_EQ( | ||||||
| x_rank > 0 && x_rank <= 2, true, | ||||||
| platform::errors::PreconditionNotMet( | ||||||
| "Input probability distribution should be 1 or 2 dimension")); | ||||||
| std::vector<int64_t> out_dims(x_rank); | ||||||
| for (int64_t i = 0; i < x_rank - 1; i++) { | ||||||
| out_dims[i] = x_dim[i]; | ||||||
| } | ||||||
|
|
||||||
| int64_t num_samples = ctx->Attrs().Get<int>("num_samples"); | ||||||
| PADDLE_ENFORCE_GT(num_samples, 0, platform::errors::OutOfRange( | ||||||
| "Number of samples should be > 0")); | ||||||
|
||||||
| "Number of samples should be > 0")); | |
| "The number of samples should be > 0, but got %d.", num_samples )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ limitations under the License. */ | |
| #include "paddle/fluid/framework/op_registry.h" | ||
| #include "paddle/fluid/framework/operator.h" | ||
| #include "paddle/fluid/operators/multinomial_op.h" | ||
| #include "paddle/fluid/platform/enforce.h" | ||
| #include "paddle/fluid/platform/transform.h" | ||
|
|
||
| namespace paddle { | ||
|
|
@@ -31,6 +32,14 @@ __global__ void NormalizeProbability(T* norm_probs, const T* in_data, | |
| T* sum_rows) { | ||
| int id = threadIdx.x + blockIdx.x * blockDim.x + | ||
| blockIdx.y * gridDim.x * blockDim.x; | ||
| PADDLE_ENFORCE(in_data[id] >= 0.0, | ||
| "The input of multinomial distribution should be >= 0"); | ||
|
||
| PADDLE_ENFORCE( | ||
| !std::isinf(static_cast<double>(in_data[id])) && | ||
|
||
| !std::isnan(static_cast<double>(in_data[id])), | ||
| "The input of multinomial distribution shoud not be infinity or NaN"); | ||
| PADDLE_ENFORCE(sum_rows[blockIdx.y] > 0.0, | ||
| "The sum of input should not be 0"); | ||
|
||
| norm_probs[id] = in_data[id] / sum_rows[blockIdx.y]; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use PADDLE_ENFORCE_GT and PADDLE_ENFORCE_LE instead, do not combine two checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done