-
Notifications
You must be signed in to change notification settings - Fork 486
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
feat: bitwise-ops-for-tensors #2498
Conversation
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.
Great start! Some minor comments but here is my preliminary review:
I think the bitwise ops should only be added as an int tensor operation, it doesn't make sense for floats.
We could eventually extend the ops to boolean tensors with their logical counterpart (would be applied on a single bit represented by the bool), but this can be left for another PR.
We can leave the candle ops as unimplemented, but for the JIT backends we should wait to merge once it's implemented with cubecl.
The idea behind the whole float implementation was to convert to int before computing and back to float after, you're right, doesn't really make sense, will make the changes. Raised an issue in the cubecl repo for adding the bitwise op support, will look at that first before implementing here |
This PR has been marked as stale because it has not been updated for over a month |
Amazing! This is the PR I was looking for! Is there a way to support bit counting on integer tensors as well? P.S.: Also, what is the status of the PR? Does somebody work on it? Maybe I should pick it up? |
@0x7CFE Yes, this implementation will allow for bit counting. Unless you mean having direct tensor op methods where you can just call and have the bits counted, ex: Also this PR is pending a release in cubecl with this implementation Cubecl |
Just in case, numpy has bitwise_count, wgsl has countOneBits, CUDA has __popc. Apparently, pytorch does not have a ready solution, but there are some tricks to do the counting efficiently given that boolean ops are available. So I believe it would be possible to efficiently implement this at least for some of the backends. P.S.: Since the blocker mentioned above was already resolved, what are the next steps for this PR? |
Possible yes, what bit counting ops exactly are you looking to include? As for if its something the burn team would like to move forward with @laggui would have to comment on that
Waiting on an official release for |
I described my use case in #2641, so essentially I need |
I opened a PR to add the required backend ops to |
Sorry all I didn't access my computer during the holidays 😅 github app is not as great for reviews and long discussions
I think something like
The main branch of burn is actually kept up to date as much as possible with the latest cubecl revision, so your changes are already available 🙂 |
I just need to review the requested changes for the current PR, but this one should land pretty soon. Regarding your request for bit counting, I think once the linked cubecl PR lands (thanks Genna 🙏) we could add 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.
Thanks for addressing the changes 🙂
I have a couple of comments, most of them just pointing out some commented code you forgot to remove.
Also, bitwise tests are failing but that's probably just because you're not using the correct operations (as pointed out in the review below).
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2498 +/- ##
==========================================
- Coverage 83.91% 83.56% -0.36%
==========================================
Files 821 824 +3
Lines 106890 108225 +1335
==========================================
+ Hits 89702 90440 +738
- Misses 17188 17785 +597 ☔ View full report in Codecov by Sentry. |
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.
Thanks for all the additions 🙏
Should be good with one last round of minor changes. See my comments below.
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.
Fixed the remaining dead code and added the ops to the book while I was at it.
Good to go now! 🎉
Haha I was about pushing for the book till I saw you merged it |
Figured for the last minor changes missed I'd do it myself instead of going through the request + change phase again 😄 Thanks again! |
Fair Enough 😆
My pleasure |
Pull Request Template
Checklist
run-checks all
script has been executed.Related Issues/PRs
#2234
Blocked by CubeCL
Changes
Bitwise Operations for Tensors
Testing
The corresponding tests for the ops were included under the
burn_tensor/tensor/tests
directory.Candle seems to not have bitwise operations so as it stands the implementation for the candle backend
is replaced with the todo macro.