{"record":{"id":"47ec765cba2bede3","repo":"huggingface/pytorch-image-models","slug":"no-node-names-found-matching-names","errorCode":null,"errorMessage":"No node names found matching {names}.","messagePattern":"No node names found matching (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"timm/utils/attention_extract.py","lineNumber":53,"sourceCode":"        if mode == 'train':\n            model = model.train()\n        else:\n            model = model.eval()\n\n        assert method in ('fx', 'hook')\n        if method == 'fx':\n            # names are activation node names\n            from timm.models._features_fx import get_graph_node_names, GraphExtractNet\n\n            node_names = get_graph_node_names(model)[0 if mode == 'train' else 1]\n            names = names or self.default_node_names\n            if use_regex:\n                regexes = [re.compile(r) for r in names]\n                matched = [g for g in node_names if any([r.match(g) for r in regexes])]\n            else:\n                matched = [g for g in node_names if any([fnmatch.fnmatch(g, n) for n in names])]\n            if not matched:\n                raise RuntimeError(f'No node names found matching {names}.')\n\n            self.model = GraphExtractNet(model, matched, return_dict=True)\n            self.hooks = None\n        else:\n            # names are module names\n            assert hook_type in ('forward', 'forward_pre')\n            from timm.models._features import FeatureHooks\n\n            module_names = [n for n, m in model.named_modules()]\n            names = names or self.default_module_names\n            if use_regex:\n                regexes = [re.compile(r) for r in names]\n                matched = [m for m in module_names if any([r.match(m) for r in regexes])]\n            else:\n                matched = [m for m in module_names if any([fnmatch.fnmatch(m, n) for n in names])]\n            if not matched:\n                raise RuntimeError(f'No module names found matching {names}.')\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/utils/attention_extract.py#L35-L71","documentation":"AttentionExtractor with graph-based extraction (hook_type='graph') matches the provided node names (fnmatch globs or regexes) against the traced FX graph node names. If nothing matches, RuntimeError is raised because extraction would be a no-op — usually the names don't correspond to any module/functional node in the model's graph.","triggerScenarios":"Calling AttentionExtractor(model, names=['attn.softmax'], hook_type='graph') where no graph node has that name; using a wildcard pattern that doesn't match any node; using module-name patterns when graph node names differ (e.g. missing trailing call suffix).","commonSituations":"Porting hook names from one backbone to another; assuming names look like attribute paths when FX graph node names differ; typos in regex patterns; regex mismatch because re.match anchors at start.","solutions":["Inspect node names first: print([n for n in torch.fx.symbolic_trace(model).graph.nodes]) and adjust patterns","Use correct glob/regex (remember re.match anchors at the string start; use '.*' prefix if needed)","Verify hook_type: if names are module names, drop hook_type='graph' so module matching is used","Check the model class actually contains the attention modules you named"],"exampleFix":"# before\next = AttentionExtractor(model, names=['attn_drop'], hook_type='graph')\n# after\nimport torch.fx as fx\nprint([n.name for n in fx.symbolic_trace(model).graph.nodes])\next = AttentionExtractor(model, names=['.*attn.*'], use_regex=True, hook_type='graph')","handlingStrategy":"validation","validationCode":"import torch.fx as fx\nnode_names = [n.name for n in fx.symbolic_trace(model).graph.nodes]\nassert any(fnmatch.fnmatch(n, pat) for n in node_names for pat in names), 'no graph node matches'","typeGuard":null,"tryCatchPattern":"try:\\n    ext = AttentionExtractor(model, names, hook_type='graph')\\nexcept RuntimeError as e:\\n    if 'No node names' in str(e):\\n        print([n for n in node_names])\\n        raise\\n    raise","preventionTips":["Print graph node names before constructing the extractor","Prefer module-hook mode when names come from named_modules()"],"tags":["attention-extraction","fx-graph","name-matching","timm"],"backgroundTag":"name-pattern-no-match","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}