Skip to content

[KV Cache] support kv cache int8 per channel quant #398

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/compressed_tensors/quantization/lifecycle/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def initialize_module_for_quantization(

if is_attention_module(module):
# quantized actions based on calltime status
_initialize_attn_scales(module)
_initialize_attn_scales(module, scheme.output_activations)

else:

Expand Down Expand Up @@ -220,10 +220,18 @@ def _initialize_scale_zero_point(
register_offload_parameter(module, f"{base_name}_g_idx", init_g_idx)


def _initialize_attn_scales(module: Module) -> None:
def _initialize_attn_scales(module: Module, quantization_args: QuantizationArgs) -> None:
"""Initlaize k_scale, v_scale for self_attn"""

expected_shape = 1 # per tensor
if quantization_args.strategy == QuantizationStrategy.CHANNEL:
expected_shape = module.k_proj.out_features
elif quantization_args.strategy == QuantizationStrategy.TENSOR:
expected_shape = 1
else:
raise ValueError(
f"One of {(QuantizationStrategy.TENSOR, QuantizationStrategy.CHANNEL)} must be specified "
f"for kv cache quantization."
)

param = next(module.parameters())
scale_dtype = param.dtype
Expand Down