-
Notifications
You must be signed in to change notification settings - Fork 54
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
Bug fix / Enhancement array initialization different devices #678
Conversation
Codecov Report
@@ Coverage Diff @@
## release/0.5.x #678 +/- ##
=================================================
- Coverage 97.46% 97.43% -0.03%
=================================================
Files 87 87
Lines 17101 17110 +9
=================================================
+ Hits 16667 16671 +4
- Misses 434 439 +5
Continue to review full report at Codecov.
|
Bugfix remove implicit tests when wrong device is given to DNDarray.
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.
Well done, thanks a lot for this. Was this all the device inconsistencies? I'm surprised we haven't got more.
I only have a few comments.
|
||
# change device if it do not match | ||
if str(obj.device) != device.torch_device: | ||
obj = obj.to(device.torch_device) |
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 is the implicit data transfer ok here? 🤔
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.
It's analogous to dtype in factories.array(). The user explicitly wants to use a specific device here.
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.
On internal functions, however, it still can obfuscate some wrong devices if the device parameter is overused. I add a warning.
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.
OK, yes I can see why we want to transfer data here. On internal functions, we have to keep an eye on it during review and testing I guess.
CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
# v0.5.1 | |||
|
|||
- [#678](https://github.com/helmholtz-analytics/heat/pull/678) Bugfix: Many implicit array transfers on DNDarray initialization |
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.
Can you be more descriptive? If I get it right, we are avoiding implicit array transfers or replacing them with ...
(Apologies for this comment, having spent so much time trying to figure out what our Pending additions
for 0.5.0 meant, I'm a bit traumatized 😅 )
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.
Possible change for clarity
Bugfix: Internal functions now use explicit device parametes for DNDarray
and torch.Tensor
initializations.
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'm fine with this, thanks Michael!
But I'm not satisfied anymore 😃 |
run tests |
heat/core/factories.py
Outdated
assert str(obj.device) == device.torch_device | ||
|
||
if str(obj.device) != device.torch_device: | ||
warnings.warn( | ||
"Array 'obj' is not on device '{}'. It will be copied to it.".format(device), | ||
UserWarning, | ||
) |
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.
Should I keep the assertion or the warning here?
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 deleted the assertion as there are some rare cases where it is allowed. However the unittest results must be reviewed for possible wrong devices.
CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
# v0.5.1 | |||
|
|||
- [#678](https://github.com/helmholtz-analytics/heat/pull/678) Bugfix: Many implicit array transfers on DNDarray initialization |
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.
Possible change for clarity
Bugfix: Internal functions now use explicit device parametes for DNDarray
and torch.Tensor
initializations.
Description
Refines the same device check on array initialization and also fixes the calling functions that it will not be called any longer. Kept as an assertion instead.
Lowers coverage
Issue/s resolved: #675
Changes proposed:
devices.cpu.torch_device
to be akin to str(torch.device)torch.device.type
todevices.sanitize.device
Type of change
Bug fix
Due Diligence
Does this change modify the behaviour of other functions? If so, which?
no