hpcaitech/Open-Sora · error · TypeError
Only support dict and nn.Module, but got {type(module)}.
Error message
Only support dict and nn.Module, but got {type(module)}. What it means
opensora.registry.build_module accepts either a config dict (with a 'type' key resolved through the Registry, e.g. MODELS/VAE/SCHEDULERS) or an already-constructed nn.Module instance; passing None returns None. Anything else — a string, list, dataclass, or partially built object — raises TypeError.
Source
Thrown at opensora/registry.py:30
builder (Registry): The registry to build module.
*args, **kwargs: Arguments passed to build function.
Returns:
(None | nn.Module): The created model.
"""
if module is None:
return None
if isinstance(module, dict):
cfg = deepcopy(module)
for k, v in kwargs.items():
cfg[k] = v
return builder.build(cfg)
elif isinstance(module, nn.Module):
return module
elif module is None:
return None
else:
raise TypeError(f"Only support dict and nn.Module, but got {type(module)}.")
MODELS = Registry(
"model",
locations=["opensora.models"],
)
DATASETS = Registry(
"dataset",
locations=["opensora.datasets"],
)
View on GitHub (pinned to 7ad6a96a13)
Solutions
- Make the value a dict with a 'type' key registered in the target registry, e.g. {type: 'STDiT3-XL/2', ...args}
- Or pass the constructed nn.Module itself if you already built it
- If it may legitimately be absent, use None (explicitly) or omit the key
Example fix
# before
model = build_module(MODELS, "STDiT3-XL/2")
# after
model = build_module(MODELS, {"type": "STDiT3-XL/2", "input_size": ...}) Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(cfg, (dict, nn.Module)) or cfg is None, f"config must be dict/nn.Module/None, got {type(cfg)}"
if isinstance(cfg, dict):
assert "type" in cfg, "config dict needs a 'type' key registered in the target registry" Type guard
def is_buildable_cfg(cfg) -> bool:
return cfg is None or isinstance(cfg, (dict, nn.Module)) Try / catch
try:
module = build_module(MODELS, cfg)
except TypeError as e:
raise TypeError(f"bad config entry {cfg!r}: use {{'type': ...}} dict or an nn.Module") from e Prevention
- Validate top-level config structure before build_module
- Never put bare model-name strings where registry configs belong
- Add schema checks for YAML pipeline configs
When it happens
Trigger: Calling build_module(registry, cfg) where cfg is e.g. a model name string ('latte-t2v'), a list of configs, or an arbitrary object. Reached from build_models/prepare_models/main during pipeline construction from a config file.
Common situations: Hand-written or migrated configs that put a plain model-name string where a {type: ..., ...} mapping is expected; YAML anchors producing lists instead of dicts; passing a half-initialized module wrapped in another type.
Related errors
- block_type {block_type} is not supported
- ConvPixelUnshuffle downsample is not supported for video
- block_type {block_type} is not supported for downsampling
- shortcut {shortcut} is not supported for downsample
- ConvPixelShuffle upsample is not supported for video
AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28).
Data as JSON: /api/errors/4163c23042f6c333.
Report an issue: GitHub.