Giter VIP home page Giter VIP logo

Comments (3)

ShashwatNigam99 avatar ShashwatNigam99 commented on May 25, 2024

I have the same query

The first for loop modifies the following blocks:

 down_blocks.0.attentions.0.transformer_blocks.0
 down_blocks.0.attentions.1.transformer_blocks.0
 down_blocks.1.attentions.0.transformer_blocks.0
 down_blocks.1.attentions.1.transformer_blocks.0
 down_blocks.2.attentions.0.transformer_blocks.0
 down_blocks.2.attentions.1.transformer_blocks.0
 up_blocks.1.attentions.0.transformer_blocks.0
 up_blocks.1.attentions.1.transformer_blocks.0
 up_blocks.1.attentions.2.transformer_blocks.0
 up_blocks.2.attentions.0.transformer_blocks.0
 up_blocks.2.attentions.1.transformer_blocks.0
 up_blocks.2.attentions.2.transformer_blocks.0
 up_blocks.3.attentions.0.transformer_blocks.0
 up_blocks.3.attentions.1.transformer_blocks.0
 up_blocks.3.attentions.2.transformer_blocks.0
 mid_block.attentions.0.transformer_blocks.0

The second for loop modifies:

up_blocks.1.attentions.1.transformer_blocks.0.attn1
up_blocks.1.attentions.2.transformer_blocks.0.attn1
up_blocks.2.attentions.0.transformer_blocks.0.attn1
up_blocks.2.attentions.1.transformer_blocks.0.attn1
up_blocks.2.attentions.2.transformer_blocks.0.attn1
up_blocks.3.attentions.0.transformer_blocks.0.attn1
up_blocks.3.attentions.1.transformer_blocks.0.attn1
up_blocks.3.attentions.2.transformer_blocks.0.attn1

Which is a subset of the first for loop.

according to the comment, the first block of the lowest resolution shouldn't have extended attention registered. the first for loop registers extended attention for that block as well.

from tokenflow.

Zeldalina avatar Zeldalina commented on May 25, 2024

同问

from tokenflow.

edward3862 avatar edward3862 commented on May 25, 2024

I think the valid function should be register_extended_attention_pnp where a list injection_schedule is defined.

for _, module in model.unet.named_modules():
if isinstance_str(module, "BasicTransformerBlock"):
module.attn1.forward = sa_forward(module.attn1)
setattr(module.attn1, 'injection_schedule', [])
res_dict = {1: [1, 2], 2: [0, 1, 2], 3: [0, 1, 2]}
# we are injecting attention in blocks 4 - 11 of the decoder, so not in the first block of the lowest resolution
for res in res_dict:
for block in res_dict[res]:
module = model.unet.up_blocks[res].attentions[block].transformer_blocks[0].attn1
module.forward = sa_forward(module)
setattr(module, 'injection_schedule', injection_schedule)

The injection is activated according to injection_schedule.

if self.injection_schedule is not None and (self.t in self.injection_schedule or self.t == 1000):
# inject unconditional
q[n_frames:2 * n_frames] = q[:n_frames]
k[n_frames:2 * n_frames] = k[:n_frames]
# inject conditional
q[2 * n_frames:] = q[:n_frames]
k[2 * n_frames:] = k[:n_frames]

if self.injection_schedule is not None and (self.t in self.injection_schedule or self.t == 1000):
source_batch_size = int(hidden_states.shape[0] // 3)
# inject unconditional
hidden_states[source_batch_size:2 * source_batch_size] = hidden_states[:source_batch_size]
# inject conditional
hidden_states[2 * source_batch_size:] = hidden_states[:source_batch_size]

BTW, I tried removing the first loop in L203-L206 and found the result was not changed. However, when removing the second loop in L208-L214, the result would get worse.

from tokenflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.