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

Temporary solution to remove the unnecessary ar cache during prefill #1115

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion MaxText/layers/attentions.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,18 @@ def _get_ar_cache_vars(self, batch, heads, kv_head_size, model_mode):

dtype = self._get_cached_kv_dtype(self.dtype)
cache_length = self.max_target_length - self.max_prefill_predict_length
cache_logical_shape = (batch, cache_length, heads, kv_head_size)

if model_mode == common_types.MODEL_MODE_PREFILL:
cache_logical_axis_names = self.prefill_cache_logical_axis_names
# TODO: find a better way to not initialize the ar cache during prefill.
# The current Engine insert API implementation requires the prefill result
# cache has the same pytree def as the decode state cache, so we still
# initialize the ar cache in prefill but with length as 1.
cache_length = 1
else:
cache_logical_axis_names = self.cache_logical_axis_names

cache_logical_shape = (batch, cache_length, heads, kv_head_size)
cache_axis_names = self.transpose_tuple(cache_logical_axis_names, self.ar_cache_axis_order)
cache_shape = self.transpose_tuple(cache_logical_shape, self.ar_cache_axis_order)

Expand Down
Loading