{"record":{"id":"4163c23042f6c333","repo":"hpcaitech/Open-Sora","slug":"only-support-dict-and-nn-module-but-got-type-mod","errorCode":null,"errorMessage":"Only support dict and nn.Module, but got {type(module)}.","messagePattern":"Only support dict and nn\\.Module, but got (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"opensora/registry.py","lineNumber":30,"sourceCode":"        builder (Registry): The registry to build module.\n        *args, **kwargs: Arguments passed to build function.\n\n    Returns:\n        (None | nn.Module): The created model.\n    \"\"\"\n    if module is None:\n        return None\n    if isinstance(module, dict):\n        cfg = deepcopy(module)\n        for k, v in kwargs.items():\n            cfg[k] = v\n        return builder.build(cfg)\n    elif isinstance(module, nn.Module):\n        return module\n    elif module is None:\n        return None\n    else:\n        raise TypeError(f\"Only support dict and nn.Module, but got {type(module)}.\")\n\n\nMODELS = Registry(\n    \"model\",\n    locations=[\"opensora.models\"],\n)\n\nDATASETS = Registry(\n    \"dataset\",\n    locations=[\"opensora.datasets\"],\n)\n","sourceCodeStart":12,"sourceCodeEnd":42,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/registry.py#L12-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nmodel = build_module(MODELS, \"STDiT3-XL/2\")\n# after\nmodel = build_module(MODELS, {\"type\": \"STDiT3-XL/2\", \"input_size\": ...})","handlingStrategy":"type-guard","validationCode":"assert isinstance(cfg, (dict, nn.Module)) or cfg is None, f\"config must be dict/nn.Module/None, got {type(cfg)}\"\nif isinstance(cfg, dict):\n    assert \"type\" in cfg, \"config dict needs a 'type' key registered in the target registry\"","typeGuard":"def is_buildable_cfg(cfg) -> bool:\n    return cfg is None or isinstance(cfg, (dict, nn.Module))","tryCatchPattern":"try:\n    module = build_module(MODELS, cfg)\nexcept TypeError as e:\n    raise TypeError(f\"bad config entry {cfg!r}: use {{'type': ...}} dict or an nn.Module\") from e","preventionTips":["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"],"tags":["registry","config","factory","type-error"],"backgroundTag":"invalid-config-type","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}