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

[KV-Cache] Make k_scale, v_scale as attributes of self_attn using HFCache #148

Merged
merged 21 commits into from
Sep 25, 2024

Conversation

horheynm
Copy link
Member

@horheynm horheynm commented Aug 31, 2024

FIX #132
Automatically set k/v_scales a part of self_attn module's attribute.

Before:
Compute input, weight, output quantization params, create it as an attribute of the leaf module (ex. self_attn.k_proj.output_scale)
Then, copy the attribute to the self_attn layer (ex. self_attn.k_proj.output_scale -> self_attn.k_scale) and delete the attr from the child.

After
Use HF's cache object, when self_attn forward is called, use the cache to compute the k_scale and v_scale of the kv cache, wrap the forward call to automatically populate the scales to self_attn.

Note:
Previously, the scales were computed from wrap_module_forward_quantized, which does out = output_fq(weight_fq(input_fq(x))where .*_fq is fake quantize

Now the cache computes the k/v_scales of the kv cache, not the output activations

@horheynm horheynm marked this pull request as draft August 31, 2024 03:32
@horheynm horheynm requested review from Satrat and mgoin August 31, 2024 17:33
@horheynm horheynm self-assigned this Aug 31, 2024
@horheynm horheynm marked this pull request as ready for review August 31, 2024 17:33
src/compressed_tensors/quantization/cache.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/cache.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/lifecycle/apply.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/lifecycle/apply.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/lifecycle/forward.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/lifecycle/forward.py Outdated Show resolved Hide resolved
src/compressed_tensors/quantization/lifecycle/forward.py Outdated Show resolved Hide resolved
tests/test_quantization/test_cache.py Show resolved Hide resolved
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

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

I tested on a few different models and it works well for producing checkpoints that work with vLLM, thanks George!

@mgoin mgoin merged commit 74f1aa6 into main Sep 25, 2024
1 check passed
@mgoin mgoin deleted the kv-cache branch September 25, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Change kv_cache_scheme to HF QuantizedCache rather than Linear.output_scale
3 participants