[core][aDAG] suppress numpy is_writable warning #47776
Open
+74
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
When we do cpu tensor -> gpu transfer, we change tensor to numpy -> and numpy -> tensor to utilize ray's zero copy serialization/deserialization. However, when it happens, ray sets nd_array.is_writable = False.
This is intentional design to make object immutable. Ray object being immutable is important for data integrity. However, when we convert such numpy array to tensor, tensor raises a warning loudly;
which means that tensor doesn't respect is_writable.
However, we use this mechanism (converting zero copy numpy array inside shared memory that has is_writable=False) only when we convert numpy array to gpu object. We know it is safe to do that because the cpu data is anyway copied to gpu (so no one can write to shared memory anyway). Since we know it is safe, there's no meaning of this warning, but confusion. So we suppress it. To avoid having high overhead suppress warning, we use a global variable to make checking as cheap as possible.
Q: Why not just setting flags.is_writable = True? I tried, but it somehow didn't work. I assume there's some kind of mechanism to block this in Ray?
Related issue number
Closes #47597
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.