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

Autoquant v2 initial version #1240

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented Nov 8, 2024

Summary:
We refactored the v1 to do benchmark for subgraphs of (prev_op -> linear -> post_op) in order to get more accurate estimation of timing. One issue here is now we need to care about batch size of the subgraph, so we'd need the batch size dimension to use symbolic shape, seems that it does not have good support on torch.compile right now

More improvements:

  • current batch size adjustment code is hardcoded to work for llama model, need to think of a way to generalize it
  • using canonicalized subgraph as key for the cache to reduce the number of times we need to do benchmarking
  • add accuracy sanity checks

Issues

  • fqn from named_modules does not match extracted fqn (in dynamo tracking stack)

Test Plan:
Testing with torchao/_models/llama/generate.py

python generate.py --checkpoint_path $CHECKPOINT_PATH/$MODEL_REPO/model.pth --compile --compile_prefill --quantization autoquant_v2-int4

Reviewers:

Subscribers:

Tasks:

Tags:

Summary:
We refactored the v1 to do benchmark for subgraphs of (prev_op -> linear -> post_op) in order to get more accurate estimation
of timing. One issue here is now we need to care about batch size of the subgraph, so we'd need the batch size dimension to use symbolic
shape, seems that it does not have good support on torch.compile right now

More improvements:
* current batch size adjustment code is hardcoded to work for llama model, need to think of a way to generalize it
* using canonicalized subgraph as key for the cache to reduce the number of times we need to do benchmarking
* add accuracy sanity checks

Test Plan:
Testing with torchao/_models/llama/generate.py

```
python generate.py --checkpoint_path $CHECKPOINT_PATH/$MODEL_REPO/model.pth --compile --compile_prefill --quantization autoquant_v2-int4
```

Reviewers:

Subscribers:

Tasks:

Tags:
Copy link

pytorch-bot bot commented Nov 8, 2024

🔗 Helpful Links

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

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

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 Nov 8, 2024
torch.nn.Linear(*new_shape, dtype=weight_val.dtype),
).cuda()

else:
Copy link
Contributor

Choose a reason for hiding this comment

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

this file has some complexity for extracting (prev_op -> linear1 -> maybe_linear_2 -> next_ops) because the models we originally studied had back to back linears. If you only care about transformer models, you can simplify this code quite a bit by removing the special logic for extraction of the second linear. Happy to point to the right places in the code if needed.

return True
return False

def debug_single_linear(
Copy link
Contributor

Choose a reason for hiding this comment

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

depending on what you're using this file for, this function also might be deleteable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah will refine more when it's closer to land, right now just experimenting to see if this approach helps improve things over the original approach on models we care about

@jerryzh168 jerryzh168 marked this pull request as draft November 12, 2024 00:35
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