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 discrete distribution #2635

Merged
merged 4 commits into from Jan 26, 2021

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Jan 25, 2021

Signed-off-by: Joaquin Anton janton@nvidia.com

Why we need this PR?

Pick one, remove the rest

  • It fixes a bug in Uniform distribution producing unexpected values

What happened in this PR?

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

  • What solution was applied:
    An extra ArgValue Acquire call every iteration was overriding the values pointer inside ArgValue implementation while the per_sample_values data was kept unmodified due to the assumption that the pointer won't change.
    As a solution, we Acquire the values only once when a non-tensor argument is given
    Using TryGetArgument/TryGetRepeatedArgument to avoid reallocation
  • Affected modules and functionalities:
    Uniform distribution and other operators using ArgValue
  • Key points relevant for the review:
    All
  • Validation and testing:
    Added niter to uniform tests
  • Documentation (including examples):
    N/A

JIRA TASK: [DALI-1824

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@JanuszL JanuszL self-assigned this Jan 25, 2021
@@ -116,7 +116,7 @@ class ArgValue {
DALI_ENFORCE(is_uniform(view_.shape) && expected_shape == view_.shape[0],
make_string("Expected uniform shape for argument \"", arg_name_,
"\" but got shape ", view_.shape));
} else {
} else if (view_.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. It assumes that non-tensor data is constant (and we may change that at some point)
  2. It validates the hidden (and dangerous) assumption that Acquire is no-op - I think that hoisting this logic outside of Acquire violates encapsulation of ArgValue.
  3. It makes clear that the way we obtain non-tensor arguments is inefficient, as it results in reallocation of the internal vector - use TryGetArgument / TryGetRepeatedArgument which will resize and populate an existing vector.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Comment on lines 121 to 122
per_sample_values_.resize(nsamples);
per_sample_nvalues_.resize(nsamples);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
per_sample_values_.resize(nsamples);
per_sample_nvalues_.resize(nsamples);
per_sample_values_.resize(values_.size());
per_sample_nvalues_.resize(values_.size());

Copy link
Contributor

Choose a reason for hiding this comment

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

and similarly in the loops below

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2015068]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2015068]: BUILD FAILED

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@@ -83,17 +83,17 @@ TEST(ArgValue, TensorInput_3D) {

TEST(ArgValueTests, Constant_0D) {
int nsamples = 5;
auto spec = OpSpec("opname").AddArg("argname", 0.123f);
ArgValue<float, 0> arg("argname", spec);
auto spec = OpSpec("Erase").AddArg("shape", 0.123f);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: Using TryGetArgument* required that the spec points to an existing operator.

@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2015569]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2015569]: BUILD PASSED

@jantonguirao jantonguirao merged commit 9b4697b into NVIDIA:master Jan 26, 2021
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.

None yet

4 participants