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

Float8 dynamic autoquant #946

Merged
merged 14 commits into from
Oct 2, 2024
Merged

Float8 dynamic autoquant #946

merged 14 commits into from
Oct 2, 2024

Conversation

jainapurva
Copy link
Contributor

@jainapurva jainapurva commented Sep 25, 2024

Added support to autoquant for float8 dynamically quantized linear weight, i.e float8 weight and activation.
Added fallback path in safe_int_mm to support float8 with torch.compile

Benchmark:
On llama3.1b - bfloat16 model

For Float8 Dynamic Quant

  • Time for inference: 14.55 sec total
  • Average tokens/sec: 13.67
  • Average Bandwidth: 103.05 GB/s
  • Peak Memory Usage: 13.77 GB
  • Model Size: 7.54 GB

For Float8 weight only

  • Time for inference: 12.02 sec total
  • Average tokens/sec: 16.65
  • Average Bandwidth: 125.47 GB/s
  • Peak Memory Usage: 11.97 GB
  • Model Size: 7.54 GB

Copy link

pytorch-bot bot commented Sep 25, 2024

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit ae18023 with merge base fbe97a0 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 Sep 25, 2024
@jainapurva jainapurva marked this pull request as ready for review September 26, 2024 22:56
torchao/kernel/intmm.py Outdated Show resolved Hide resolved
return weight

@classmethod
def _autoquant_test(cls, act_mat, weight, bias, best_time, mode=["relu", None]):
Copy link
Contributor

Choose a reason for hiding this comment

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

did you test this in practice? we may need different constants for int8 and float8 dynamic, how does it perform in benchmarks and stuff. If you haven't really tested this on 2-3 models it may be better to just remove it and use the default method which will be very conservative under the interpolation mode and will still work reasonably under the relu mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tested it on Llama, the numbers aren't great, but I can push it to next PR, with more benchmarks

@@ -139,13 +139,12 @@ def _get_per_token_block_size(x: torch.Tensor) -> List[int]:
# taken from
# https://github.com/mit-han-lab/smoothquant/blob/2f87951dacfb9238d8d657f52ae83a82a3c9ba0c/smoothquant/fake_quant.py#L26
# and slightly modified
def quantize_activation_per_token_absmax(t):
def quantize_activation_per_token_absmax(t, dtype=torch.int8):
Copy link
Contributor

@HDCharles HDCharles Sep 28, 2024

Choose a reason for hiding this comment

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

does this actually work in practice with non int8 dtypes?, we're still using the same quant min/max as +-128, this seems inadvisable.

I also don't think we should extend this function, should probably just call into whatever quant function is normally used for that dtype, this is a specific instance of function where the mapping types and quant min/max are hard coded to specific values so it shouldn't be extended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need this anymore, I'm reverting the changes to this method, as there's another implementation in float8 that I'll be using.

Copy link
Contributor

@HDCharles HDCharles left a comment

Choose a reason for hiding this comment

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

see comments, i would probably skip the quant test bit unless it gets tested on 2-3 models and the way the activation quantization is implemented seems like its going to cause issues because its only superficially been altered away from its normal int8 quantization.

@@ -492,6 +494,46 @@ def from_float(cls, weight):
block_size = (1, weight.shape[1])
return super(AQFloat8WeightOnlyQuantizedLinearWeight, cls).from_hp_to_floatx(weight, block_size, target_dtype=cls.target_dtype, layout_type=Float8LayoutType())

class AQFloat8DynamicallyQuantizedLinearWeight(AQMixin, LinearActivationQuantizedTensor):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this looks good, lets name this PerRow scaling and lets only import PerRow above

@jainapurva jainapurva merged commit 9229df9 into main Oct 2, 2024
13 checks passed
melvinebenezer pushed a commit to melvinebenezer/ao that referenced this pull request Oct 7, 2024
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.

5 participants