invoke-ai/InvokeAI · error · ValueError
size {size} has to be smaller or equal to {dim}.
Error message
size {size} has to be smaller or equal to {dim}. What it means
Each per-layer attention slice size must not exceed that layer's head dimension (sliceable_head_dims[i]). This guard rejects any slice entry larger than the corresponding layer's dim, since slicing above the dimension size is meaningless and would misconfigure chunked attention.
Source
Thrown at invokeai/backend/util/hotfixes.py:550
# speed and memory
slice_size = [dim // 2 for dim in sliceable_head_dims]
elif slice_size == "max":
# make smallest slice possible
slice_size = num_sliceable_layers * [1]
slice_size = num_sliceable_layers * [slice_size] if not isinstance(slice_size, list) else slice_size
if len(slice_size) != len(sliceable_head_dims):
raise ValueError(
f"You have provided {len(slice_size)}, but {self.config} has {len(sliceable_head_dims)} different"
f" attention layers. Make sure to match `len(slice_size)` to be {len(sliceable_head_dims)}."
)
for i in range(len(slice_size)):
size = slice_size[i]
dim = sliceable_head_dims[i]
if size is not None and size > dim:
raise ValueError(f"size {size} has to be smaller or equal to {dim}.")
# Recursively walk through all the children.
# Any children which exposes the set_attention_slice method
# gets the message
def fn_recursive_set_attention_slice(module: torch.nn.Module, slice_size: List[int]):
if hasattr(module, "set_attention_slice"):
module.set_attention_slice(slice_size.pop())
for child in module.children():
fn_recursive_set_attention_slice(child, slice_size)
reversed_slice_size = list(reversed(slice_size))
for module in self.children():
fn_recursive_set_attention_slice(module, reversed_slice_size)
def _set_gradient_checkpointing(self, module, value=False):
if isinstance(module, (CrossAttnDownBlock2D, DownBlock2D)):
module.gradient_checkpointing = valueView on GitHub (pinned to 0b6a024f2f)
Solutions
- Lower each slice_size entry so it is <= the corresponding layer's dim
- Use 'auto' or a small power-of-two int (e.g. 2, 4, 8) instead of a custom list
- Verify sliceable_head_dims in the model config and size the list to it
Example fix
// before model.set_attention_slice([128, 128]) // after model.set_attention_slice([64, 64]) # each <= matching layer dim, or use "auto"
Defensive patterns
Strategy: validation
Validate before calling
dims = model.config.attention_head_dim # list of per-layer dims
if isinstance(slice_size, list):
slice_size = [min(s, d) if s is not None else None for s, d in zip(slice_size, dims)] Type guard
def slice_sizes_in_range(slice_size, dims):
return all(s is None or s <= d for s, d in zip(slice_size, dims)) Try / catch
try:
model.set_attention_slice(slice_size)
except ValueError:
model.set_attention_slice("auto") Prevention
- Clamp each slice entry to its layer dim before applying
- Use 'auto' slicing unless you have profiled per-layer dims
- Test new slice configs on the target checkpoint before production use
When it happens
Trigger: Calling set_attention_slice with a list containing an entry greater than the matching layer's dim, e.g. set_attention_slice([128]) on a layer with dim 64, or reusing a slice list tuned for a different model.
Common situations: Copy-pasting slice sizes between SD 1.x/2.x/SDXL models whose attention head dims differ; hand-tuning VRAM-saving slice values; config drift after model or library upgrades.
Related errors
- You have provided {len(slice_size)}, but {self.config} has {
- Invalid or expired token
- User not found or inactive
- Missing authentication credentials
- Invalid or expired authentication token
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/d2d577379d0a9d1b.
Report an issue: GitHub.