{"record":{"id":"1446d09aac25d8dd","repo":"huggingface/transformers","slug":"module-name-r-does-not-have-the-expected-child-m","errorCode":null,"errorMessage":"Module {name!r} does not have the expected child modules {child_names} required for the fused kernel {kernel_cls.__name__!r}","messagePattern":"Module (.+?) does not have the expected child modules (.+?) required for the fused kernel (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/hub_kernels.py","lineNumber":973,"sourceCode":"\n            if len(set(parent_patterns)) != 1:\n                raise ValueError(\n                    f\"All patterns for a fused kernel must share the same parent module, got {glob_patterns}\"\n                )\n\n            parent_pattern = parent_patterns[0].replace(\"*\", r\"\\w+\")\n            child_names = [p.rsplit(\".\", 1)[1] for p in glob_patterns]\n\n            if meta_model is None:\n                with torch.device(\"meta\"):\n                    meta_model = cls(config)\n\n            matched_any = False\n            for name, module in meta_model.named_modules():\n                if not re.fullmatch(parent_pattern, name):\n                    continue\n                if not all(hasattr(module, child) for child in child_names):\n                    raise ValueError(\n                        f\"Module {name!r} does not have the expected child modules {child_names} required for \"\n                        f\"the fused kernel {kernel_cls.__name__!r}\"\n                    )\n                matched_any = True\n                module_cls = type(module)\n                patch_mapping[module_cls.__name__] = make_parent_class_for_kernel_fusion(\n                    module_cls, child_names, layout_cls\n                )\n\n            if not matched_any:\n                raise ValueError(\n                    f\"No module matched pattern {parent_pattern!r} for fused kernel {kernel_cls.__name__!r}. \"\n                    f\"Provide the full dotted path from the model root.\"\n                )\n\n        register_patch_mapping(patch_mapping, overwrite=True)\n\n        if hasattr(layout_cls, \"conversion_mapping\"):","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/hub_kernels.py#L955-L991","documentation":"During fusion registration, transformers instantiates the model on the meta device, walks named_modules(), and fullmatch()es each name against the parent pattern; when a module matches the parent pattern but lacks even one of the expected child attributes (child_names from the pattern suffixes), this ValueError is raised. It signals the pattern matched a structurally different module.","triggerScenarios":"Thrown at src/transformers/integrations/hub_kernels.py:973 when the library encounters an invalid state.","commonSituations":"Wildcard too broad (e.g. 'model.*' matching decoder layers plus embeddings/rotary modules); using a kernel catalog written for a different model variant (Llama-2 vs Llama-3, Mistral vs Llama) whose inner module names differ; MoE models where 'mlp' matches both dense and expert blocks.","solutions":["Tighten the glob pattern so it only matches modules that actually contain all listed children (e.g. 'model.layers.*.mlp' instead of 'model.*').","Use the pattern names matching your exact model architecture — print [n for n, _ in model.named_modules()] to see real names.","Drop the kernel entry for structures your model does not have."],"exampleFix":"// before\n\"parent_pattern\": \"model.*\"\n\n// after\n\"parent_pattern\": \"model.layers.*.mlp\"","handlingStrategy":"validation","validationCode":"import re, torch\n\ndef pattern_modules_have_children(model, parent_pattern: str, children: list[str]) -> bool:\n    pat = parent_pattern.replace(\"*\", r\"\\w+\")\n    for name, module in model.named_modules():\n        if re.fullmatch(pat, name) and not all(hasattr(module, c) for c in children):\n            return False\n    return True\n\n# with torch.device(\"meta\"): probe = AutoModel.from_config(config)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate fusion patterns against a meta-device instantiation of your exact model before deployment.","Prefer precise patterns ('model.layers.*.mlp') over broad ones ('model.*')."],"tags":["hub-kernels","fusion","pattern-matching"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}