huggingface/transformers · error · ValueError

Module {name!r} does not have the expected child modules {ch

Error message

Module {name!r} does not have the expected child modules {child_names} required for the fused kernel {kernel_cls.__name__!r}

What it means

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.

Source

Thrown at src/transformers/integrations/hub_kernels.py:973

            if len(set(parent_patterns)) != 1:
                raise ValueError(
                    f"All patterns for a fused kernel must share the same parent module, got {glob_patterns}"
                )

            parent_pattern = parent_patterns[0].replace("*", r"\w+")
            child_names = [p.rsplit(".", 1)[1] for p in glob_patterns]

            if meta_model is None:
                with torch.device("meta"):
                    meta_model = cls(config)

            matched_any = False
            for name, module in meta_model.named_modules():
                if not re.fullmatch(parent_pattern, name):
                    continue
                if not all(hasattr(module, child) for child in child_names):
                    raise ValueError(
                        f"Module {name!r} does not have the expected child modules {child_names} required for "
                        f"the fused kernel {kernel_cls.__name__!r}"
                    )
                matched_any = True
                module_cls = type(module)
                patch_mapping[module_cls.__name__] = make_parent_class_for_kernel_fusion(
                    module_cls, child_names, layout_cls
                )

            if not matched_any:
                raise ValueError(
                    f"No module matched pattern {parent_pattern!r} for fused kernel {kernel_cls.__name__!r}. "
                    f"Provide the full dotted path from the model root."
                )

        register_patch_mapping(patch_mapping, overwrite=True)

        if hasattr(layout_cls, "conversion_mapping"):

View on GitHub (pinned to a597f97485)

Solutions

  1. Tighten the glob pattern so it only matches modules that actually contain all listed children (e.g. 'model.layers.*.mlp' instead of 'model.*').
  2. Use the pattern names matching your exact model architecture — print [n for n, _ in model.named_modules()] to see real names.
  3. Drop the kernel entry for structures your model does not have.

Example fix

// before
"parent_pattern": "model.*"

// after
"parent_pattern": "model.layers.*.mlp"
Defensive patterns

Strategy: validation

Validate before calling

import re, torch

def pattern_modules_have_children(model, parent_pattern: str, children: list[str]) -> bool:
    pat = parent_pattern.replace("*", r"\w+")
    for name, module in model.named_modules():
        if re.fullmatch(pat, name) and not all(hasattr(module, c) for c in children):
            return False
    return True

# with torch.device("meta"): probe = AutoModel.from_config(config)

Prevention

When it happens

Trigger: Thrown at src/transformers/integrations/hub_kernels.py:973 when the library encounters an invalid state.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/1446d09aac25d8dd. Report an issue: GitHub.