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 uniform generator operator #2352

Merged
merged 4 commits into from
Oct 13, 2020
Merged

Conversation

JanuszL
Copy link
Contributor

@JanuszL JanuszL commented Oct 13, 2020

Signed-off-by: Janusz Lisiecki jlisiecki@nvidia.com

Why we need this PR?

Pick one, remove the rest

  • It fixes uniform generator operator

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    so ask the generator to draw samples until they are < b
  • Affected modules and functionalities:
    uniform operator
  • Key points relevant for the review:
    NA
  • Validation and testing:
    CI
  • Documentation (including examples):
    NA

JIRA TASK: [NA]

@JanuszL
Copy link
Contributor Author

JanuszL commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1695888]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1695888]: BUILD FAILED

Copy link
Member

@szalpal szalpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this introduces unwanted behaviour in the test and we shouldn't go this way. I'd be better to fix the operator

@jantonguirao
Copy link
Contributor

If the range is [a,b] we should say so in the documentation.

- for some reason uniform_real_distribution returns [a, b] instead
  of [a, b) so ask the generator to draw samples until they are < b
- see http://open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#2524

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL JanuszL changed the title Fix conditions in test_operator_uniform.py Fix uniform generator operator Oct 13, 2020
@JanuszL
Copy link
Contributor Author

JanuszL commented Oct 13, 2020

!build

Comment on lines 33 to 35
while (sample_data[k] >= range_[1]) {
sample_data[k] = dist(rng_);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while (sample_data[k] >= range_[1]) {
sample_data[k] = dist(rng_);
}
do {
sample_data[k] = dist(rng_);
} while (sample_data[k] >= range_[1]); // Due to GCC and LLVM bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 22 to 27
if (range_[0] >= range_[1]) {
for (int i = 0; i < batch_size_; ++i) {
sample_data[k] = range_[0];
}
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding argument verification in Uniform constructor, sth like:

    if (discrete_mode_) {
      set_ = spec.GetRepeatedArgument<float>("values");
      DALI_ENFORCE(!set_.empty(), "`values` argument cannot be empty");
    } else {
      range_ = spec.GetRepeatedArgument<float>("range");
      DALI_ENFORCE(range_.size() == 2, "`range` argument shall contain precisely 2 values");
      DALI_ENFORCE(range_[0] < range_[1],
                   "Invalid range. It shall be left-closed [a, b), where a < b");
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1696987]: BUILD STARTED

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL
Copy link
Contributor Author

JanuszL commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697021]: BUILD STARTED

Comment on lines 22 to 27
if (range_[0] >= range_[1]) {
for (int i = 0; i < batch_size_; ++i) {
sample_data[k] = range_[0];
}
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no becessary if we enfornce that the range is not empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL
Copy link
Contributor Author

JanuszL commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697032]: BUILD STARTED

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL
Copy link
Contributor Author

JanuszL commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697074]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697074]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697074]: BUILD PASSED

@JanuszL JanuszL merged commit 63f5fce into NVIDIA:master Oct 13, 2020
@JanuszL JanuszL deleted the fix_uniform_test branch October 13, 2020 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants