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

Improved Reshape #1634

Merged
merged 3 commits into from
Jan 10, 2020
Merged

Improved Reshape #1634

merged 3 commits into from
Jan 10, 2020

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Jan 9, 2020

  • Add relative extents
  • Add "remaining volume" extent (-1) support

Signed-off-by: Michal Zientkiewicz michalz@nvidia.com

Why we need this PR?

Pick one, remove the rest

  • It adds new feature needed for RNN-t feature frame splicing

What happened in this PR?

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

  • What solution was applied:
    • Add rel_shape to Reshape parameter which accepts (floating point) relative shapes
    • Interpret negative extent as "all remaining volume" - it's calculated as a ratio of source tensor volume to the product of explicitly defined extents
  • Affected modules and functionalities:
    • Reshape operator
  • Key points relevant for the review:
    • reshape.cc
  • Validation and testing:
    • Python test
  • Documentation (including examples):
    • Parameter docstrings

JIRA TASK: N/A

* Add relative extents
* Add "remaining volume" extent (-1) support

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient mzient requested a review from a team January 9, 2020 14:53
@mzient
Copy link
Contributor Author

mzient commented Jan 9, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1064365]: BUILD STARTED

"is preserved if number of dimension matches existing layout "
"or reset to empty otherwise",
"");
.AddOptionalArg<float>("rel_shape", "The relative shape of the output. Number of dimensions "
Copy link
Contributor

Choose a reason for hiding this comment

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

you should point out that "shape" and "rel_shape" are mutually exclusive

bool has_rel_shape_arg = spec.HasArgument("rel_shape") || spec.HasTensorArgument("rel_shape");
DALI_ENFORCE(has_shape_input + has_shape_arg + has_rel_shape_arg == 1,
"Reshape: shape input, `shape` argument and `rel_shape` argument are mutually exclusive");
DALI_ENFORCE(has_shape_input || has_shape_arg || has_rel_shape_arg || has_layout_arg,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: you are already checking that at least one shape argument is provided, you don't need to check that again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a bug - it should be <= 1.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1064365]: BUILD FAILED

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient
Copy link
Contributor Author

mzient commented Jan 9, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1064465]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1064465]: BUILD PASSED

TYPE_SWITCH(tl.type().id(), type2id, type,
(int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t),
(this->ShapeFromInput(view<const type>(tl));),
(DALI_FAIL("Reshape: shape input must have integral type; got: " + tl.type().name() +
Copy link
Contributor

Choose a reason for hiding this comment

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

must have integral type unless it's the if above and we handle float.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shape input is only for absolute shape. Relative shape is specified as an argument input.
The regular input is only here for historical reasons (from before CPU/support unification).

@@ -28,34 +29,75 @@ DALI_SCHEMA(Reshape)
.AllowSequences()
.SupportVolumetric()
.AddOptionalArg<int>("shape", "The desired shape of the output. Number of elements in "
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to provide the information, that Reshape can also take optional input with shapes. Now there is no such information.

break;
case ShapeSource::Input:
ShapeFromInput(ws.template InputRef<CPUBackend>(1));
ShapeFromInput(ws.template InputRef<CPUBackend>(1), use_rel_shape_);
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't ever work with relative shapes provided as inputs, as even if we get second input with float values, we won't set use_rel_shape_=true.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, does it actually work on GPU to receive the shapes as CPU input? (It's not like it will be widely used due to it's limitations).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. It will always be false.
  2. It does work and is actually tested.

Comment on lines 207 to 210
if (use_rel_shape_)
ShapeFromInput(ws.ArgumentInput("shape"), false);
else
ShapeFromInput(ws.ArgumentInput("rel_shape"), false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

...lol, bug.

@mzient mzient requested a review from klecki January 10, 2020 12:57
@mzient
Copy link
Contributor Author

mzient commented Jan 10, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1066198]: BUILD STARTED

for test in test_reshape_arg():
test[0](*test[1:])
for test in test_reshape_input():
#for test in test_reshape_arg():
Copy link
Contributor

Choose a reason for hiding this comment

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

??

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient
Copy link
Contributor Author

mzient commented Jan 10, 2020

!build

@mzient mzient requested a review from klecki January 10, 2020 13:57
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1066265]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1066198]: BUILD PASSED


rng = ops.Uniform(range=[100,128])
cast = ops.Cast(dtype=types.INT32)
widths = cast(rng()) * 2.0
Copy link
Contributor Author

@mzient mzient Jan 10, 2020

Choose a reason for hiding this comment

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

This makes sure we always get even width - we're halving it, so it must not be odd or the volume will not match.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1066265]: BUILD PASSED

@mzient mzient merged commit 6b7683c into NVIDIA:master Jan 10, 2020
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