-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Dense <-> bsc conversions #80781
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
Dense <-> bsc conversions #80781
Conversation
[ghstack-poisoned]
🔗 Helpful links
✅ No Failures (3 Pending)As of commit 925ca12 (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
An issue that will probably need some discussion. It appears that SciPy does not implement the BSC format, so the existing testing framework is not going to work out of the box. We could do some combination of checking indices with a compatible CSC tensor and manually checking block-by-block value equality, but I'm all for a better solution if there is one on offer. |
@amjames - I'm am wondering whether support for transpose(BSR) -> BSC and transpose(BSC) -> BSR could help the tests. |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
auto batched_out = | ||
at::zeros({n_batch, n_compressed_per_batch + 1}, compressed_in.options()); |
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.
need to change to compressed_in.options().dtype(out_type)
, then we can remove to
right before return from the function.
auto offsets = compressed_in.index({Slice(0, -1, n_compressed_per_batch)}) | ||
.reshape({n_batch, -1}); |
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.
same here, we can use slice
and reduce dependency on at::indexing
.
[ghstack-poisoned]
auto offsets = compressed_in.slice(0, 0, -1, n_compressed_per_batch) | ||
.reshape({n_batch, -1}); | ||
batched_out.narrow(-1, 1, n_compressed_per_batch) | ||
.copy_(trailing_slice - offsets); |
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.
@nikitaved I sort of minced your suggestions together with what was already here.
Yes, it could go in a single statement, but it is very difficult to parse and the two intermediate variables trailing_slice
and offsets
make it much clearer.
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.
And you decided against in-placeness, right? I like these variables. Maybe we could also sprinkle some comments here and there...
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, yes. The copy_
is fine however we can't do the subtraction in place as both factors are views on the same storage, and that sub does in fact broadcast (n_batch x n_compressed_per_batch)
- (n_batch x 1)
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.
Yeah, missed that. Good catch!
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.
Alternatively, we could probably copy first, then do an in-place diff ?
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.
Thank you, @amjames , this looks great!
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@pytorchbot merge |
@pytorchbot successfully started a merge job. Check the current status here. |
Pull Request resolved: #80781 Approved by: https://github.com/bhosmer, https://github.com/nikitaved
Hey @amjames. |
Summary: Pull Request resolved: #80781 Approved by: https://github.com/bhosmer, https://github.com/nikitaved Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/8778f337442ab7ad512d20c3a9028df59380c6f0 Reviewed By: mehtanirav Differential Revision: D39213811 fbshipit-source-id: 90a50de4bf00fc7294e3490c34d75264a036a364
Stack from ghstack (oldest at bottom):