huggingface/pytorch-image-models · error · RuntimeError
No node names found matching {names}.
Error message
No node names found matching {names}. What it means
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.
Source
Thrown at timm/utils/attention_extract.py:53
if mode == 'train':
model = model.train()
else:
model = model.eval()
assert method in ('fx', 'hook')
if method == 'fx':
# names are activation node names
from timm.models._features_fx import get_graph_node_names, GraphExtractNet
node_names = get_graph_node_names(model)[0 if mode == 'train' else 1]
names = names or self.default_node_names
if use_regex:
regexes = [re.compile(r) for r in names]
matched = [g for g in node_names if any([r.match(g) for r in regexes])]
else:
matched = [g for g in node_names if any([fnmatch.fnmatch(g, n) for n in names])]
if not matched:
raise RuntimeError(f'No node names found matching {names}.')
self.model = GraphExtractNet(model, matched, return_dict=True)
self.hooks = None
else:
# names are module names
assert hook_type in ('forward', 'forward_pre')
from timm.models._features import FeatureHooks
module_names = [n for n, m in model.named_modules()]
names = names or self.default_module_names
if use_regex:
regexes = [re.compile(r) for r in names]
matched = [m for m in module_names if any([r.match(m) for r in regexes])]
else:
matched = [m for m in module_names if any([fnmatch.fnmatch(m, n) for n in names])]
if not matched:
raise RuntimeError(f'No module names found matching {names}.')
View on GitHub (pinned to 9a5261e31b)
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
Example fix
# before ext = AttentionExtractor(model, names=['attn_drop'], hook_type='graph') # after import torch.fx as fx print([n.name for n in fx.symbolic_trace(model).graph.nodes]) ext = AttentionExtractor(model, names=['.*attn.*'], use_regex=True, hook_type='graph')
Defensive patterns
Strategy: validation
Validate before calling
import torch.fx as fx node_names = [n.name for n in fx.symbolic_trace(model).graph.nodes] assert any(fnmatch.fnmatch(n, pat) for n in node_names for pat in names), 'no graph node matches'
Try / catch
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
Prevention
- Print graph node names before constructing the extractor
- Prefer module-hook mode when names come from named_modules()
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- No module names found matching {names}.
- Input image must have positive dimensions, got H={height}, W
- Invalid class map file, expected a dict ({class_map_path}).
- Dataset length is unknown, please pass `num_samples` explici
- Found 0 images in subfolders of {root}. Supported image exte
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/47ec765cba2bede3.
Report an issue: GitHub.