Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Pad Operator Type Support #12035

Merged
merged 7 commits into from
Aug 20, 2018
Merged

Pad Operator Type Support #12035

merged 7 commits into from
Aug 20, 2018

Conversation

sbodenstein
Copy link
Contributor

@sbodenstein sbodenstein commented Aug 5, 2018

This PR allows the pad operator to operate on any type. Fixes Issue #11967.

One potential issue: I've enabled this layer for integer types, for which gradients don't get computed. Is there a standard way of handling this?

@haojin2
Copy link
Contributor

haojin2 commented Aug 6, 2018

I think you can get rid of the change from MSHADOW_REAL_TYPE_SWITCH to MSHADOW_TYPE_SWITCH, that way you still have support for all float types while getting rid of the integer issue.

@sbodenstein
Copy link
Contributor Author

@haojin2: it gets rid of the integer issue by getting rid of integer support (which seems unnecessarily restrictive). But adding integer support could also be a separate PR. What do you think I should do?

@haojin2
Copy link
Contributor

haojin2 commented Aug 7, 2018

@sbodenstein I would say that floating inputs should be the most common use case, so I would suggest that we start with floating types only and if we see needs for integer types later we can address accordingly.

@nswamy nswamy added Feature Operator pr-awaiting-response PR is reviewed and waiting for contributor to respond labels Aug 8, 2018
@sbodenstein
Copy link
Contributor Author

@haojin2: ok, done. Can we merge?

@haojin2
Copy link
Contributor

haojin2 commented Aug 9, 2018

@sbodenstein I cannot decide that as I'm not a committer, I'll ping some committers for you.
@anirudh2290 @eric-haibin-lin @reminisce Can you guys take a look?

Y = mx.symbol.Pad(data=X, mode=mode, pad_width=pad_width)
x = mx.random.uniform(-1, 1, shape, ctx=mx.cpu()).copyto(xpu)
if dtype in real_types:
x = mx.random.uniform(-1, 1, shape, ctx=mx.cpu(), dtype=dtype).copyto(xpu)
Copy link
Member

Choose a reason for hiding this comment

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

what's the purpose of looping over real_types and generate a new x to override the previous one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not looping over real_types and its not overriding anything (X and x are different). This is simply written to be compatible with the integer case one day (happy to remove for now if you want). Unless I'm misunderstanding something?

@sbodenstein
Copy link
Contributor Author

It would be great if I could get some idea of when this can be merged, as we want to make new builds with this feature enabled.

@haojin2
Copy link
Contributor

haojin2 commented Aug 17, 2018

@eric-haibin-lin @anirudh2290 Please take a look when you have time, thanks!

Y = mx.symbol.Pad(data=X, mode=mode, pad_width=pad_width)
x = mx.random.uniform(-1, 1, shape, ctx=mx.cpu()).copyto(xpu)
if dtype in real_types:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you do not really need this if-else branch at this moment as the caller of this function only passes real types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. I had kept it there as I thought that it will be useful when integer support is added. But removed for now.



@with_seed()
def test_pad():
ct = default_context()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ctx is probably a more commonly used name for context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to ctx.

check_pad_with_shape(shape2, default_context(), pad2, 'reflect')
# note: this op doesn't support ints yet. Add tests when supported
test_types = ["float32", "float64", "float16"]
for d in test_types:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: to be consistent with most other tests within this file I would prefer:

dtypes = [np.float16, np.float32, np.float64]
for dtype in dtypes:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@nswamy
Copy link
Member

nswamy commented Aug 19, 2018

LGTM, I triggered the CI again, we can merge once CI passes.

@nswamy
Copy link
Member

nswamy commented Aug 20, 2018

@sbodenstein changes to the test_pad unit test is failing, could you please fix it

======================================================================

ERROR: test_operator.test_pad

----------------------------------------------------------------------

Traceback (most recent call last):

  File "C:\Anaconda3\envs\py2\lib\site-packages\nose\case.py", line 197, in runTest

    self.test(*self.arg)

  File "C:\jenkins_slave\workspace\ut-python-cpu\tests\python\unittest\common.py", line 172, in test_new

    orig_test(*args, **kwargs)

  File "C:\jenkins_slave\workspace\ut-python-cpu\tests\python\unittest\test_operator.py", line 3039, in test_pad

    for dtype in dtypes:

NameError: global name 'dtypes' is not defined

check_pad_with_shape(shape1, default_context(), pad1, 'reflect')
check_pad_with_shape(shape2, default_context(), pad2, 'reflect')
# note: this op doesn't support ints yet. Add tests when supported
test_types = ["float16", "float32", "float64"]
Copy link
Contributor

Choose a reason for hiding this comment

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

should be

dtypes = [np.float16, np.float32, np.float64]

?

@nswamy nswamy merged commit b03227d into apache:master Aug 20, 2018
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
* fix no data type inference for pad

* add support for int types

* add tests for all types

* fix gpu type switch

* remove integer support

* fix python op test style issues

* fix type bug in python tests
anirudh2290 pushed a commit to anirudh2290/mxnet that referenced this pull request Sep 19, 2018
* fix no data type inference for pad

* add support for int types

* add tests for all types

* fix gpu type switch

* remove integer support

* fix python op test style issues

* fix type bug in python tests
@szha szha removed the Feature label Nov 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature request Operator pr-awaiting-response PR is reviewed and waiting for contributor to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants