huggingface/transformers · error · TypeError
`skip` must contain only strings.
Error message
`skip` must contain only strings.
What it means
Second-stage validation of the heterogeneity 'skip' entry: after confirming skip is a non-string Iterable, each element must be a string. Mixed lists like ["mlp", 2] or [None] fail the all(isinstance(item, str)) check and raise TypeError with the message "`skip` must contain only strings.".
Source
Thrown at src/transformers/integrations/heterogeneity/configuration_utils.py:56
@dataclass
class _HeterogeneitySpec:
per_layer_overrides: dict[int, dict[str, Any]]
per_layer_attributes: set[str]
explicit_per_layer_attributes: set[str]
def _normalize_layer_overrides(layer_overrides: dict[str, Any]) -> dict[str, Any]:
normalized = copy.deepcopy(layer_overrides)
if "skip" in normalized:
skip = normalized.pop("skip")
if isinstance(skip, str) or not isinstance(skip, Iterable):
raise TypeError("`skip` must be an iterable of strings.")
skip = set(skip)
if not all(isinstance(item, str) for item in skip):
raise TypeError("`skip` must contain only strings.")
if skip:
normalized["skip"] = sorted(skip)
return normalized
def _validate_layer_indices(config: PreTrainedConfig, per_layer_overrides: dict[int, dict[str, Any]]) -> None:
if not per_layer_overrides:
return
num_hidden_layers = config.num_hidden_layers
invalid_layer_indices = [
layer_idx for layer_idx in per_layer_overrides if layer_idx < 0 or layer_idx >= num_hidden_layers
]
if invalid_layer_indices:
raise ValueError(
f"`per_layer_config` keys must be integer layer indices in the range [0, {num_hidden_layers}); "View on GitHub (pinned to a597f97485)
Solutions
- Make every skip entry a string: skip=["mlp", "attn"]
- Coerce programmatically built lists: [str(s) for s in skip]
Example fix
# before
config.per_layer_config = {0: {"skip": ["mlp", 2]}}
# after
config.per_layer_config = {0: {"skip": ["mlp", "2"]}} # all strings Defensive patterns
Strategy: type-guard
Validate before calling
assert all(isinstance(x, str) for x in skip_list), "every skip entry must be a string"
Type guard
def skip_entries_all_strings(skip) -> bool:
return all(isinstance(item, str) for item in skip) Prevention
- Coerce skip entries with str(x) when building them from untyped config sources
- Keep skip lists literal in config files rather than computed from mixed-type data
When it happens
Trigger: per_layer_config with skip=["mlp", 3] or skip=[None, "attn"] — any iterable containing at least one non-string element.
Common situations: Programmatically building skip from config values that include ints/None; YAML/JSON coercion turning intended strings into numbers; copy-pasting a skip list schema from elsewhere.
Related errors
- `skip` must be an iterable of strings.
- `per_layer_config` keys must be integer layer indices in the
- The following attributes are missing: {sorted(missing_requir
- The following layers have the mutually exclusive `sliding_wi
- Layer type '{layer_idx}' requested, but config.layer_types i
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/fd2f80957225c758.
Report an issue: GitHub.