Skip to content

Commit aabc50e

Browse files
haozha111copybara-github
authored andcommitted
Introduce a helper function to initialize all-zeroed kv cache.
PiperOrigin-RevId: 764438981
1 parent ed3a9cc commit aabc50e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2025 The AI Edge Torch Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Test utils for generative layers."""
16+
from typing import Sequence
17+
from ai_edge_torch.generative.layers import kv_cache as kv_utils
18+
import torch
19+
20+
21+
def initialize_kv_cache_all_zeros(
22+
kv_shape: Sequence[int],
23+
layout: kv_utils.KVLayout = kv_utils.KV_LAYOUT_DEFAULT,
24+
) -> kv_utils.KVCacheEntry:
25+
return kv_utils.KVCacheEntry(
26+
k_cache=torch.zeros(kv_shape, dtype=torch.float32),
27+
v_cache=torch.zeros(kv_shape, dtype=torch.float32),
28+
kv_layout=layout,
29+
)

0 commit comments

Comments
 (0)