This application discloses a
data processing method and apparatus, relating to the field of
computer technology, for improving the
throughput of large language models. The method is applied to edge devices or
cloud testing devices, and includes: prefetching key KV cache for at least one future generation step at a first time, and calculating the attention
score for the (T+N)th generation step based on the key KV cache. The first time is any time of the Tth generation step, which is used to generate token T. The scheme provided in this application prefetches key KV cache for one or more future steps during the
inference process of the generation step. Since the prefetching of key KV cache and
model inference can be executed in parallel, the
transmission latency of the key KV cache can be effectively reduced. In this way, the scheme of this application can significantly improve the
throughput of large models, i.e., more tokens can be generated per second.