return output, None
def _attention_inputs(self, module, state, positions, partition):
"""Prepare Q/K/V through the selected rotary callback and communication schedule."""
degree = self.plan.cp_degree
rotary_fn = apply_mla_rope if self.rotary_fn is None else self.rotary_fn
rotated_key = rotary_fn(
state.key_rope.unsqueeze(2), positions, interleaved=module.rotary_interleaved,
).squeeze(2)
if self.plan.overlap and degree > 1:
prepare = self._expanded_overlap if self.plan.strategy == "expanded_ulysses" else self._latent_overlap
query, key, value = prepare(module, state, positions, rotated_key, partition, rotary_fn=rotary_fn)
else:
query = _query(module, state.query_latent, positions, self.plan.local_heads, rotary_fn)
if self.plan.strategy == "expanded_ulysses" or degree == 1:
query, key, value = self._expanded(module, state, query, rotated_key, partition)
else:
query, key, value = self._latent(module, state, query, rotated_key, partition)
return query, key, value
def _expanded(self, module, state, query, key_rope, partition=None):
"""Pack unequal-width QKV into one sequence-to-head exchange."""
key, value = _key_value(module, state.kv_latent, key_rope, self.plan.local_heads, None)