MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / summarize_chunk

Function summarize_chunk

diffusers/src/diffusers/models/attention_flax.py:31–41  ·  view source on GitHub ↗
(query, key, value)

Source from the content-addressed store, hash-verified

29
30 @functools.partial(jax.checkpoint, prevent_cse=False)
31 def summarize_chunk(query, key, value):
32 attn_weights = jnp.einsum("...qhd,...khd->...qhk", query, key, precision=precision)
33
34 max_score = jnp.max(attn_weights, axis=-1, keepdims=True)
35 max_score = jax.lax.stop_gradient(max_score)
36 exp_weights = jnp.exp(attn_weights - max_score)
37
38 exp_values = jnp.einsum("...vhf,...qhv->...qhf", value, exp_weights, precision=precision)
39 max_score = jnp.einsum("...qhk->...qh", max_score)
40
41 return (exp_values, exp_weights.sum(axis=-1), max_score)
42
43 def chunk_scanner(chunk_idx):
44 # julienne key array

Callers 1

chunk_scannerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected