Skip to content
fn

bloom_model_postprocess_past_key_value

→tuple of tuple of Tensor
bloom_model_postprocess_past_key_value(past_key_values: tuple[Tensor, ...])

Reshape a prefix-tuning prompt into the cache layout of the bloom family.

The bloom family keeps its keys as (batch * heads, head_dim, tokens) and its values as (batch * heads, tokens, head_dim). This joins the prompt's tensors along their first axis, takes the first half of the result for keys and the second half for values, and reshapes each to that layout — the reference's rule, split point included.

Parameters

past_key_valuestuple of Tensor
The prompt's tensors, each of shape (n, batch, heads, tokens, head_dim); the n of all of them add up to an even number of layers' keys and values.

Returns

tuple of tuple of Tensor

One (keys, values) pair per layer.

Examples

>>> import lucid
>>> from lucid.peft import bloom_model_postprocess_past_key_value
>>> prompt = tuple(lucid.zeros(1, 2, 4, 3, 8) for _ in range(4))  # 2 layers: keys, then values
>>> pairs = bloom_model_postprocess_past_key_value(prompt)
>>> len(pairs), pairs[0][0].shape, pairs[0][1].shape
(2, (8, 8, 3), (8, 3, 8))

Used by 1