@@ -404,15 +404,17 @@ def __init__(
404404 self .resnets = nn .ModuleList (resnets )
405405
406406 def set_attention_slice (self , slice_size ):
407- if slice_size is not None and self .attn_num_head_channels % slice_size != 0 :
407+ head_dims = self .attn_num_head_channels
408+ head_dims = [head_dims ] if isinstance (head_dims , int ) else head_dims
409+ if slice_size is not None and any (dim % slice_size != 0 for dim in head_dims ):
408410 raise ValueError (
409- f"Make sure slice_size { slice_size } is a divisor of "
410- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
411+ f"Make sure slice_size { slice_size } is a common divisor of "
412+ f"the number of heads used in cross_attention: { head_dims } "
411413 )
412- if slice_size is not None and slice_size > self . attn_num_head_channels :
414+ if slice_size is not None and slice_size > min ( head_dims ) :
413415 raise ValueError (
414- f"Chunk_size { slice_size } has to be smaller or equal to "
415- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
416+ f"slice_size { slice_size } has to be smaller or equal to "
417+ f"the lowest number of heads used in cross_attention: min( { head_dims } ) = { min ( head_dims ) } "
416418 )
417419
418420 for attn in self .attentions :
@@ -600,15 +602,17 @@ def __init__(
600602 self .gradient_checkpointing = False
601603
602604 def set_attention_slice (self , slice_size ):
603- if slice_size is not None and self .attn_num_head_channels % slice_size != 0 :
605+ head_dims = self .attn_num_head_channels
606+ head_dims = [head_dims ] if isinstance (head_dims , int ) else head_dims
607+ if slice_size is not None and any (dim % slice_size != 0 for dim in head_dims ):
604608 raise ValueError (
605- f"Make sure slice_size { slice_size } is a divisor of "
606- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
609+ f"Make sure slice_size { slice_size } is a common divisor of "
610+ f"the number of heads used in cross_attention: { head_dims } "
607611 )
608- if slice_size is not None and slice_size > self . attn_num_head_channels :
612+ if slice_size is not None and slice_size > min ( head_dims ) :
609613 raise ValueError (
610- f"Chunk_size { slice_size } has to be smaller or equal to "
611- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
614+ f"slice_size { slice_size } has to be smaller or equal to "
615+ f"the lowest number of heads used in cross_attention: min( { head_dims } ) = { min ( head_dims ) } "
612616 )
613617
614618 for attn in self .attentions :
@@ -1197,15 +1201,17 @@ def __init__(
11971201 self .gradient_checkpointing = False
11981202
11991203 def set_attention_slice (self , slice_size ):
1200- if slice_size is not None and self .attn_num_head_channels % slice_size != 0 :
1204+ head_dims = self .attn_num_head_channels
1205+ head_dims = [head_dims ] if isinstance (head_dims , int ) else head_dims
1206+ if slice_size is not None and any (dim % slice_size != 0 for dim in head_dims ):
12011207 raise ValueError (
1202- f"Make sure slice_size { slice_size } is a divisor of "
1203- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
1208+ f"Make sure slice_size { slice_size } is a common divisor of "
1209+ f"the number of heads used in cross_attention: { head_dims } "
12041210 )
1205- if slice_size is not None and slice_size > self . attn_num_head_channels :
1211+ if slice_size is not None and slice_size > min ( head_dims ) :
12061212 raise ValueError (
1207- f"Chunk_size { slice_size } has to be smaller or equal to "
1208- f"the number of heads used in cross_attention { self . attn_num_head_channels } "
1213+ f"slice_size { slice_size } has to be smaller or equal to "
1214+ f"the lowest number of heads used in cross_attention: min( { head_dims } ) = { min ( head_dims ) } "
12091215 )
12101216
12111217 for attn in self .attentions :
0 commit comments