Skip to content
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

Add BSR subclass +torch.compile and clean up superblock #680

Merged
merged 14 commits into from
Aug 15, 2024

Conversation

jcaip
Copy link
Contributor

@jcaip jcaip commented Aug 14, 2024

This PR adds in torch.compile support for block sparsity.

In a custom op, we create the sprase_bsr_tensor from the explicit crow_indices, col_indices, values tensors that are passed in to the custom op.

I also created a tensor subclass which holds these same values.

At dispatch, when we see a torch.nn.functional.linear call, we dispatch into our custom op torch.ops.blocksparse.linear, using the tensors stored in the subclass.

This will allow us to add a public API similar to semi_sparse_weight(), which I plan to do in a future PR.

This PR also cleans up the superblock prototype implementation, as there was a lot of repeated code, and also adds in kernel tuning for BSR.

For bfloat16 I see the following numbers, for a 1.23x gain:

New compile baseline: 63.431 ms
New compile + bsr: 53.514 ms 
New compile + bsr + tuning: 51.485 ms 

Copy link

pytorch-bot bot commented Aug 14, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/680

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d14e320 with merge base accbdba (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 14, 2024
@jcaip jcaip changed the title [wip] add bsr compile support Add BSR subclass and clean up superblock Aug 15, 2024
@jcaip jcaip changed the title Add BSR subclass and clean up superblock Add BSR subclass +torch.compile and clean up superblock Aug 15, 2024
@@ -12,6 +12,25 @@
import torch
import torch.distributed as dist

### IMAGENET UTILS
@torch.inference_mode
def benchmark_inference(warmup, iters, f, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use

def benchmark_model(model, num_runs, args=(), kwargs=None, device_type=None):
? we can add a warmup as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was giving me different timings from my function. I'll try and debug the delta later, if I can find out whats causes it I'll switch over.

@jcaip jcaip merged commit b16f0dc into main Aug 15, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants