def forward(x, encoder_hidden_states=None, attention_mask=None, context=None, mask=None):
                """
                The attention is similar to the original implementation of LDM CrossAttention class
                except adding some modifications on the attention
                """
                if encoder_hidden_states is not None:
                    context = encoder_hidden_states
                if attention_mask is not None:
                    mask = attention_mask

                to_out = self.to_out
                if isinstance(to_out, nn.modules.container.ModuleList):
                    to_out = self.to_out[0]
                else:
                    to_out = self.to_out

                h = self.heads
                q = self.to_q(x)
                is_cross = context is not None
                context = context if is_cross else x
                k = self.to_k(context)
                v = self.to_v(context)
                # q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> (b h) n d', h=h), (q, k, v))
                q, k, v = (rearrange(t, "b n (h d) -> (b h) n d", h=h) for t in (q, k, v))

                sim = torch.einsum("b i d, b j d -> b i j", q, k) * self.scale

                if mask is not None:
                    mask = rearrange(mask, "b ... -> b (...)")
                    max_neg_value = -torch.finfo(sim.dtype).max
                    mask = repeat(mask, "b j -> (b h) () j", h=h)
                    mask = mask[:, None, :].repeat(h, 1, 1)
                    sim.masked_fill_(~mask, max_neg_value)

                attn = sim.softmax(dim=-1)
                # the only difference
                out = editor(q, k, v, sim, attn, is_cross, place_in_unet, self.heads, scale=self.scale)

                return to_out(out)

                The attention is similar to the original implementation of LDM CrossAttention class
                except adding some modifications on the attention
                
examples/community/pipeline_stable_diffusion_xl_attentive_eraser.py