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

Fix dtype inference in arange_like operator #15930

Merged
merged 4 commits into from
Aug 25, 2019

Conversation

TaoLv
Copy link
Member

@TaoLv TaoLv commented Aug 16, 2019

Description

Remove the dtype argument from parameter structure and use ElemwiseType instead.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@TaoLv
Copy link
Member Author

TaoLv commented Aug 16, 2019

@eric-haibin-lin @fhieber

Copy link
Member

@eric-haibin-lin eric-haibin-lin left a comment

Choose a reason for hiding this comment

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

Great. This will fix the bug with float16 inputs. Would you mind just adding a simple unit test to check the dtype with float16 inputs?

@TaoLv
Copy link
Member Author

TaoLv commented Aug 17, 2019

@eric-haibin-lin Did you observe any crash with fp16 input? With below code snippet, it doesn't seem to crash but just gives numpy.float32 output:

import mxnet as mx
import numpy as np

x = mx.sym.Variable('x', dtype=np.float16)
y = mx.sym.reshape(x, shape=(0, 0, -1))
z = mx.sym.contrib.arange_like(y, axis=-1)

mod = z.simple_bind(ctx=mx.gpu(0), x=(3, 4, 5, 6), graph_req='null')

mod.arg_arrays[0][:] = np.random.normal(size=mod.arg_arrays[0].shape).astype(np.float16)
out = mod.forward(is_train=False)
print(out[0].dtype)

@eric-haibin-lin
Copy link
Member

No I didn't expect a crash. I expect it copies dtype attribute like other xx_like ops

@TaoLv
Copy link
Member Author

TaoLv commented Aug 20, 2019

@eric-haibin-lin do you think the below code snippet can be used as a test case?

import mxnet as mx
import numpy as np

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

for t in dtypes:
    x = mx.sym.Variable('x', dtype=t)
    y = mx.sym.reshape(x, shape=(0, 0, -1))
    z = mx.sym.contrib.arange_like(y, axis=-1)

    mod = z.simple_bind(ctx=mx.gpu(0), x=(3, 4, 5, 6), graph_req='null')

    mod.arg_arrays[0][:] = np.random.normal(size=mod.arg_arrays[0].shape).astype(t)
    out = mod.forward(is_train=False)
    assert out[0].dtype == np.float32

@eric-haibin-lin
Copy link
Member

eric-haibin-lin commented Aug 20, 2019

Yes. Could you also check the forwward output with [0, 1, 2,.. ] etc?

@wkcn
Copy link
Member

wkcn commented Aug 25, 2019

I hope to reserve the dtype attribution, and there is a default action when dtype is None.

@TaoLv
Copy link
Member Author

TaoLv commented Aug 25, 2019

I hope to reserve the dtype attribution, and there is a default action when dtype is None.

Just want to provide the same user experience for ones_like, zeros_like and arange_like.

@eric-haibin-lin eric-haibin-lin merged commit c7a8a78 into apache:master Aug 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants