-
Notifications
You must be signed in to change notification settings - Fork 0
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
use nanobind ndarray to make use of bfloat16 weights possible (without coping the data) #5
use nanobind ndarray to make use of bfloat16 weights possible (without coping the data) #5
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ac06f9b
to
a50d3b0
Compare
First iteration, can compile and run with float16 and bfloat16. AFAIU we have now just one object which gets deleted at the end |
a50d3b0
to
8519a35
Compare
How do we add a test for bfloat16 (currently we creat numby objects). Maybe we create the dlpack object directly. Or simply import torch, but this is then a further dependency. Will upstream accept? EDIT: has been clarified by now |
8519a35
to
96aa072
Compare
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 think we need to make sure ownership of the tensor is handled.
c34f357
to
f49e81e
Compare
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 think we need to verify this change works.
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.
Just looking into this a little more, the DLPack does not define semantics for transfer of ownership, so for now this ndarray function will have to assume the lifetime of the data is tied to the python interpreter. nanobinds should ensure that condition.
42c3cad
to
893acad
Compare
893acad
to
e0ad43b
Compare
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.
Looks good to me. @devtbi can you give your opinion?
up to the caller to ensure that the buffer meets the characteristics | ||
implied by the shape. | ||
|
||
The backing buffer and any user objects will be retained for the lifetime |
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 don't think this statement is true. NDArray is designed as a view of the memory. Ownership is not transferred AFAIK. Can you change the wording to reflect that?
And I believe this is also true for the original buffer constructor. AFAIK for numpy at least we can't transfer ownership of the memory.
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.
Regarding numpy: We transfer a memory view which 'Create a new memoryview object which references the given object.'
self.dlpack_capsule = array.__dlpack__() | ||
|
||
def __del__(self): | ||
print("BACKING MEMORY DELETED") |
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.
print("BACKING MEMORY DELETED") | |
print("DLPACK MEMORY DELETED") |
we actually don't own the memory just the metadata about the tensor (dlpack).
e0ad43b
to
35d0d56
Compare
can't find anything to complain about since my last review... looks good :) |
coping the data)