-
Notifications
You must be signed in to change notification settings - Fork 223
feat: add from_* style constructor classmethods to StridedMemoryView and make constructor amenable to future from_*-style constructors #1224
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
Conversation
|
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/ok to test |
This comment has been minimized.
This comment has been minimized.
786140a to
f7eef8d
Compare
|
/ok to test |
f7eef8d to
2cd276a
Compare
|
/ok to test |
2cd276a to
35bcd87
Compare
|
/ok to test |
35bcd87 to
6f8ff96
Compare
|
/ok to test |
mdboom
left a comment
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.
LGTM, other than the strides property issue.
6f8ff96 to
28727f8
Compare
|
/ok to test |
28727f8 to
7620fee
Compare
|
/ok to test |
1 similar comment
|
/ok to test |
85a81a9 to
0c267bc
Compare
|
|
||
| @property | ||
| def strides(self) -> Optional[tuple[int]]: | ||
| def strides(self) -> tuple[int, ...]: |
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.
Oops, let me fix the annotation.
…and make constructor amenable to future from_*-style constructors
0c267bc to
08676b1
Compare
|
/ok to test |
mdboom
left a comment
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.
LGTM
|
| def __init__(self, obj=None, stream_ptr=None): | ||
| if obj is not None: | ||
| # populate self's attributes | ||
| if check_has_dlpack(obj): | ||
| view_as_dlpack(obj, stream_ptr, self) | ||
| else: | ||
| view_as_cai(obj, stream_ptr, self) |
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.
@cpcloud This is a breaking change. Can we please restore the old behavior and add a deprecation warning? We need a release note, too.
If we want to push for alternative constructors, we should eventually raise in __init__ following what we do in other objects.
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 point me to downstream breakages so I can understand the impact? Across all of GitHub the only use of StridedMemoryView is in a comment:
I'd strongly prefer not to restore the behavior without evidence that this change causes problems.
Happy to add the release note.
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.
We have real users that cannot be found this way. Examples include issues filed by people outside of the team:
- Lowering
StridedMemoryViewattribues to typed efficient C/C++/Cython accessible values #180 - [BUG]: Segmentation fault with StridedMemoryView.shape #1186
- [BUG]: StridedMemoryView leaks the producer memory #1043
- BUG: StridedMemoryView fails to wrap NumPy array #473
StridedMemoryViewfails with Jax arrays #285 (comment)
We have way too many invisible users at this point (check out the download counts from e.g. pypistats). We have also been slammed by our PM for breaking too often and too much (despite I disagreed in that case; in any case I was the one arguing and taking time in sorting things out, so plz back me up).
We need to make sure major breaking changes like this have a deprecation period, even before GA. In particular, in this case it is absolutely fine that we add extra constructors without breaking anything. I am not sure why we must leap so aggressively.
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.
+1 to @leofang guidance. Breaking existing public facing API should go through our teams standard deprecation flow where we notify users at least a release before to when we remove the code.
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.
Apologies for approving while misunderstanding the backward-compat guarantees of the experimental namespace.
I think this is all a reasonable policy to have, but challenging to follow as long as we are releasing from main. If we had a maintenance branch, we could put the "backward-compatible-with-deprecation-warnings" version of this on the maintenance branch, and the aspirational "where-we-want-to-be" on main. As it stands, we need to do the first now, put a reminder in a calendar to do the second and hope that reviews get it merged in the expected window.
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.
Sorry, I've meant to follow up here and offline with Phillip, but I got distracted (as always) by other things including the pixi stuff that Phillip started playing around with 😛
I did not mean that this PR is bad. I apologize if my earlier comments gave this impression. The alternative constructors are totally fine. They give users finer control if they already have prior knowledge on what protocols a foreign object supports. I meant that we just need to preserve the default constructor's behavior for a little longer, at least for another minor release. We could just revert the change on __init__() and leave everything else as-is, though now that we have an urgent (TBD) patch release in preparation, it is good that it's reverted for now.
We're dealing with an interesting situation. On the one hand we're still beta/experimental software, and we do allow breaking changes in each minor release. On the other hand we are perhaps too successful in telling our CUDA Python story that we have unexpectedly high number of users, and this does increasingly keep me up at night. If we break too often, downstream projects end up pinning too tightly (example), resulting in NVIDIA software unable to be installed in the same environment. This hurts our storytelling.
I suggest that we clearly highlight all PRs that contain breaking changes with the "breaking" label and a rel-note entry under the Breaking Change section. With such marks we can make informed decisions and evaluate all breaking changes on a case-by-case basis. There is also no need to seek short turnaround in merging breaking PRs. We still want to design cuda.core properly in a future-looking fashion to avoid as much breaks as possible, it's been one of the core principles since Day 1, and for that I am fine taking a bit more time thinking through the design.
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 didn't interpret your comments as this PR being bad, just haven't had a chance to re-PR the changes while preserving the current constructor behavior. I will PR that today.
…oryView and make constructor amenable to future from_*-style constructors (NVIDIA#1224) This reverts commit f223c17.
…ridedMemoryView and make constructor amenable to future from_*-style constructors (NVIDIA#1224) (NVIDIA#1232) This reverts commit a87f937.
…ridedMemoryView and make constructor amenable to future from_*-style constructors (NVIDIA#1224) (NVIDIA#1232) This reverts commit a87f937.
…ridedMemoryView and make constructor amenable to future from_*-style constructors (NVIDIA#1224) (NVIDIA#1232) This reverts commit a87f937.
This PR adds three methods to conform better to APIs familiar to Python users and to ease future work on
StridedMemoryViewadding support for constructing them from other objects besides CAI and dlpack objects.
Three methods are added:
from_dlpack(obj, stream_ptr)same functionality as beforefrom_cuda_array_interface(obj, stream_ptr)same functionality as beforefrom_any_interface(obj, stream_ptr)same behavior as the previous constructorThe constructor changes to a simple field initialization, in an effort to make
it easier to add a
from_buffer(naming TBD) method that allows constructionfrom an owned raw buffer (without shape and stride information), which may
require passing in additional information such as shape and stride to the
constructor.