-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 backend.copyto
for mismatched dtypes to CuPy ndarray
#8043
Conversation
@@ -65,7 +65,8 @@ def copyto(dst, src): | |||
elif isinstance(dst, cuda.ndarray): | |||
if isinstance(src, chainer.get_cpu_array_types()): | |||
src = numpy.asarray(src) | |||
if dst.flags.c_contiguous or dst.flags.f_contiguous: | |||
if (src.dtype == dst.dtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set
does not accept an array of different dtype, so we choose to fall through if dtypes don't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyto
LGTM. You may split the PR for TestUninitializedParameterWithDevices
.
tests/chainer_tests/test_variable.py
Outdated
x.initialize(a.shape) | ||
assert isinstance(x.data, xp.ndarray) | ||
assert x._has_chainerx_array is (xp is chainerx) | ||
xp.testing.assert_array_equal(x.data, xp.asarray(a)) | ||
xp.testing.assert_array_equal( | ||
x.data.astype(expected_dtype, copy=False), xp.asarray(a)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose
assert x.dtype == expected_dtype
xp.testing.assert_array_equal(x.data, xp.asarray(a, expected_dtype))
tests/chainer_tests/test_variable.py
Outdated
x.initialize(a.shape) | ||
assert isinstance(x.data, xp.ndarray) | ||
assert x._has_chainerx_array is (xp is chainerx) | ||
xp.testing.assert_array_equal(x.data, xp.asarray(a)) | ||
xp.testing.assert_array_equal( | ||
x.data.astype(expected_dtype, copy=False), xp.asarray(a)) | ||
xp.testing.assert_array_equal(x.grad, np.float32('nan')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you keep np.float32
? It could be np.nan
or float('nan')
.
Thanks for the comments. I'll address them in a separate PR. Removed |
Should |
Random ideas:
|
I'm okay with making it strict, not allowing different dtypes. This functions is by no means a hot spot so we can afford some checking. We could also take inspiration from @toslunar do you have concrete cases where stride checking would be beneficial? |
Not really. Loading NHWC-layout parameters, maybe. A low-level |
The PR is no longer a PR-blocker because #8046 is closed. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs. Thank you for your contributions. |
We discussed the status of the PR internally.
|
Jenkins, test this please. |
Jenkins CI test (for commit 0aa2ad7, target branch master) succeeded! |
@toslunar This pull-request is marked as |
Jenkins, test this please. |
Jenkins CI test (for commit 5bbb615, target branch master) succeeded! |
/test |
/test |
Jenkins, test this please |
Jenkins CI test (for commit 5bbb615, target branch master) failed with status FAILURE. |
Jenkins, test this please |
Jenkins CI test (for commit 5bbb615, target branch master) succeeded! |
FlexCI failures: timeout of |
Re-running pfCI still fails on the same tests
Both of them added some extra errors. |
Jenkins, test this please |
Jenkins CI test (for commit 5bbb615, target branch master) succeeded! |
Jenkins, test this please |
Jenkins CI test (for commit 5bbb615, target branch master) succeeded! |
Fixes a parameter initialization bug. See #7965 (comment).