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 for CPU random ops seed narrowing conversion. #1594

Merged
merged 1 commit into from
Aug 12, 2019
Merged
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
55 changes: 35 additions & 20 deletions onnxruntime/core/providers/cpu/generator/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class RandomNormal final : public OpKernel {

// read optional seed attribute and generate if not provided
float seed = 0.f;
if (!info.GetAttr<float>("seed", &seed).IsOK()) {
seed = gsl::narrow_cast<float>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
if (info.GetAttr<float>("seed", &seed).IsOK()) {
generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};
}
else {
generator_ = std::default_random_engine{
gsl::narrow_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count())
};
}

generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};

int64_t dtype;
ORT_ENFORCE(info.GetAttr<int64_t>("dtype", &dtype).IsOK());
Expand Down Expand Up @@ -60,11 +63,14 @@ class RandomNormalLike final : public OpKernel {

// read optional seed attribute and generate if not provided
float seed = 0.f;
if (!info.GetAttr<float>("seed", &seed).IsOK()) {
seed = gsl::narrow_cast<float>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
if (info.GetAttr<float>("seed", &seed).IsOK()) {
generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};
}
else {
generator_ = std::default_random_engine{
gsl::narrow_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count())
};
}

generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};

int64_t dtype;
if (info.GetAttr<int64_t>("dtype", &dtype).IsOK()) {
Expand Down Expand Up @@ -94,11 +100,14 @@ class RandomUniform final : public OpKernel {

// read optional seed attribute and generate if not provided
float seed = 0.f;
if (!info.GetAttr<float>("seed", &seed).IsOK()) {
seed = gsl::narrow_cast<float>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
if (info.GetAttr<float>("seed", &seed).IsOK()) {
generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};
}
else {
generator_ = std::default_random_engine{
gsl::narrow_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count())
};
}

generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};

int64_t dtype;
ORT_ENFORCE(info.GetAttr<int64_t>("dtype", &dtype).IsOK());
Expand Down Expand Up @@ -131,11 +140,14 @@ class RandomUniformLike final : public OpKernel {
ORT_ENFORCE(info.GetAttr<float>("low", &low_).IsOK());
// read optional seed attribute and generate if not provided
float seed = 0.f;
if (!info.GetAttr<float>("seed", &seed).IsOK()) {
seed = gsl::narrow_cast<float>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
if (info.GetAttr<float>("seed", &seed).IsOK()) {
generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};
}
else {
generator_ = std::default_random_engine{
gsl::narrow_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count())
};
}

generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};

int64_t dtype;
if (info.GetAttr<int64_t>("dtype", &dtype).IsOK()) {
Expand Down Expand Up @@ -163,11 +175,14 @@ class Multinomial final : public OpKernel {
ORT_ENFORCE(info.GetAttr<int64_t>("sample_size", &num_samples_).IsOK());

float seed = 0.f;
if (!info.GetAttr<float>("seed", &seed).IsOK()) {
seed = gsl::narrow_cast<float>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
if (info.GetAttr<float>("seed", &seed).IsOK()) {
generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};
}
else {
generator_ = std::default_random_engine{
gsl::narrow_cast<uint32_t>(std::chrono::high_resolution_clock::now().time_since_epoch().count())
};
}

generator_ = std::default_random_engine{gsl::narrow_cast<uint32_t>(seed)};

int64_t output_dtype_tmp;
if (!info.GetAttr<int64_t>("dtype", &output_dtype_tmp).IsOK()) {
Expand Down