MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / aggregate_attention

Function aggregate_attention

sample.py:189–200  ·  view source on GitHub ↗
(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int)

Source from the content-addressed store, hash-verified

187 # display(pil_img)
188
189def aggregate_attention(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int):
190 out = []
191 attention_maps = attention_store.get_average_attention()
192 num_pixels = res ** 2
193 for location in from_where:
194 for item in attention_maps[f"{location}_{'cross' if is_cross else 'self'}"]:
195 if item.shape[1] == num_pixels:
196 cross_maps = item.reshape(len(prompts), -1, res, res, item.shape[-1])[select]
197 out.append(cross_maps)
198 out = torch.cat(out, dim=0)
199 out = out.sum(0) / out.shape[0]
200 return out.cpu()
201
202def aggregate_attention_all(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int, len_tokens: int):
203 attention_maps = attention_store.get_average_attention()

Callers

nothing calls this directly

Calls 1

get_average_attentionMethod · 0.80

Tested by

no test coverage detected