lllyasviel/ControlNet · error · ValueError
inverted_residual_setting should be non-empty or a 4-element
Error message
inverted_residual_setting should be non-empty or a 4-element list, got {} What it means
MobileNetV2-based MLSd large model constructor validates inverted_residual_setting: it must be a non-empty list whose (first) entries are 4-element tuples (t, c, n, s) describing each inverted residual block. Empty lists or wrong-length tuples raise this ValueError.
Source
Thrown at annotator/mlsd/models/mbv2_mlsd_large.py:186
input_channel = 32
last_channel = 1280
width_mult = 1.0
round_nearest = 8
inverted_residual_setting = [
# t, c, n, s
[1, 16, 1, 1],
[6, 24, 2, 2],
[6, 32, 3, 2],
[6, 64, 4, 2],
[6, 96, 3, 1],
#[6, 160, 3, 2],
#[6, 320, 1, 1],
]
# only check the first element, assuming user knows t,c,n,s are required
if len(inverted_residual_setting) == 0 or len(inverted_residual_setting[0]) != 4:
raise ValueError("inverted_residual_setting should be non-empty "
"or a 4-element list, got {}".format(inverted_residual_setting))
# building first layer
input_channel = _make_divisible(input_channel * width_mult, round_nearest)
self.last_channel = _make_divisible(last_channel * max(1.0, width_mult), round_nearest)
features = [ConvBNReLU(4, input_channel, stride=2)]
# building inverted residual blocks
for t, c, n, s in inverted_residual_setting:
output_channel = _make_divisible(c * width_mult, round_nearest)
for i in range(n):
stride = s if i == 0 else 1
features.append(block(input_channel, output_channel, stride, expand_ratio=t))
input_channel = output_channel
self.features = nn.Sequential(*features)
self.fpn_selected = [1, 3, 6, 10, 13]
# weight initialization
for m in self.modules():View on GitHub (pinned to ed85cd1e25)
Solutions
- Keep at least one full [t, c, n, s] entry in inverted_residual_setting
- Revert to the file's default inverted_residual_setting if you modified it
- Validate the setting length programmatically before constructing the model
Example fix
# before setting = [] # all rows commented out # after setting = [[1, 16, 1, 1], [6, 24, 2, 2]] # proper [t,c,n,s] rows
Defensive patterns
Strategy: validation
Validate before calling
assert len(inverted_residual_setting) > 0 and all(len(r) == 4 for r in inverted_residual_setting), 'need non-empty list of [t,c,n,s] rows'
Type guard
def is_valid_setting(s) -> bool:
return isinstance(s, (list, tuple)) and len(s) > 0 and all(len(r) == 4 for r in s) Prevention
- Keep a unit test asserting the default setting parses
- Diff config tables before/after pruning experiments
When it happens
Trigger: Constructing the MLSd large network with an overridden inverted_residual_setting that is [] or whose first element has more/fewer than 4 values (e.g. commented-out rows left in a modified copy of the default settings list).
Common situations: Editing the default layer table to trim layers and accidentally removing all entries; passing a config dict value that deserializes to an empty list.
Related errors
- inverted_residual_setting should be non-empty or a 4-element
- resize_method {self.__resize_method} not implemented
- provide num_res_blocks either as an int (globally constant)
- 'order' must be '1' or '2' or '3'.
- 'solver_type' must be either 'dpm_solver' or 'taylor', got {
AI-assisted analysis of lllyasviel/ControlNet@ed85cd1e25 (2026-08-27).
Data as JSON: /api/errors/caaeacc8629e1d9b.
Report an issue: GitHub.