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
Identical validation in the MLSd tiny variant: the constructor requires inverted_residual_setting to be a non-empty list of 4-element (t, c, n, s) tuples. An empty list or malformed first row triggers the error.
Source
Thrown at annotator/mlsd/models/mbv2_mlsd_tiny.py:185
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 = [3, 6, 10]
# weight initialization
for m in self.modules():View on GitHub (pinned to ed85cd1e25)
Solutions
- Supply a valid non-empty list of [t, c, n, s] rows
- Diff your config against the default in mbv2_mlsd_tiny.py
- Guard with an assertion before model construction
Example fix
# before model = MobileNetV2([[6, 24, 2]]) # 3-element row # after model = MobileNetV2([[6, 24, 2, 2]]) # [t,c,n,s]
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
- Reuse the model file's default settings when unsure
- Validate config-derived lists before model construction
When it happens
Trigger: Building mbv2_mlsd_tiny with a custom inverted_residual_setting that is empty or has a first element whose length != 4.
Common situations: Porting layer configs between tiny/large variants; YAML overrides that drop the list; experimental pruning scripts emptying the setting.
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/613bbb420e839430.
Report an issue: GitHub.