Skip to content

Commit 76180d4

Browse files
committed
[Executorch] Add quantized kv cache to oss ci
Fixes to make sure quantized kv cache works in oss Differential Revision: [D66269487](https://our.internmc.facebook.com/intern/diff/D66269487/) ghstack-source-id: 254679000 Pull Request resolved: #6997
1 parent 64ca7ab commit 76180d4

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

examples/models/llama/source_transformation/quantized_kv_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import logging
88
from enum import Enum
99

10+
import executorch.extension.llm.custom_ops # noqa: F401
11+
1012
import torch
1113
import torch.nn as nn
1214
from executorch.examples.models.llama.llama_transformer import KVCache

examples/models/llama/source_transformation/sdpa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def forward(
5656

5757
k_cache = self.kv_cache.k_cache
5858
v_cache = self.kv_cache.v_cache
59-
if isinstance(self.kv_cache, QuantizedKVCache):
59+
if hasattr(self.kv_cache, "quantized_cache_dtype"):
6060
# updated quantize cache, scale and zero points
6161
# returns dequantized kv cache
6262
# Not most optimal. Optimizations to follow next

exir/passes/_quant_patterns_and_replacements.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ def embedding_byte_dtype_out_meta(
192192
"int weight_quant_min, int weight_quant_max, Tensor indices, *, ScalarType? dtype=None, Tensor(a!) out) -> Tensor(a!)",
193193
)
194194

195+
# TODO: move these registrations to pytorch core
196+
quantized_decomposed_lib.define(
197+
"quantize_per_token.out(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!)",
198+
)
199+
200+
quantized_decomposed_lib.define(
201+
"dequantize_per_token.out(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, ScalarType output_dtype, *, Tensor(a!) out) -> Tensor(a!)",
202+
)
203+
204+
quantized_decomposed_lib.define(
205+
"choose_qparams_per_token_asymmetric.out(Tensor input, ScalarType dtype, *, Tensor(a!) scale_out, Tensor(b!) zero_point_out) -> (Tensor(a!), Tensor(b!))",
206+
)
207+
195208

196209
@impl(quantized_decomposed_lib, "embedding_2bit", "CompositeExplicitAutograd")
197210
def embedding_2bit(

0 commit comments

Comments
 (0)