{"record":{"id":"fd2f80957225c758","repo":"huggingface/transformers","slug":"skip-must-contain-only-strings","errorCode":null,"errorMessage":"`skip` must contain only strings.","messagePattern":"`skip` must contain only strings\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/heterogeneity/configuration_utils.py","lineNumber":56,"sourceCode":"\n@dataclass\nclass _HeterogeneitySpec:\n    per_layer_overrides: dict[int, dict[str, Any]]\n    per_layer_attributes: set[str]\n    explicit_per_layer_attributes: set[str]\n\n\ndef _normalize_layer_overrides(layer_overrides: dict[str, Any]) -> dict[str, Any]:\n    normalized = copy.deepcopy(layer_overrides)\n\n    if \"skip\" in normalized:\n        skip = normalized.pop(\"skip\")\n        if isinstance(skip, str) or not isinstance(skip, Iterable):\n            raise TypeError(\"`skip` must be an iterable of strings.\")\n\n        skip = set(skip)\n        if not all(isinstance(item, str) for item in skip):\n            raise TypeError(\"`skip` must contain only strings.\")\n\n        if skip:\n            normalized[\"skip\"] = sorted(skip)\n\n    return normalized\n\n\ndef _validate_layer_indices(config: PreTrainedConfig, per_layer_overrides: dict[int, dict[str, Any]]) -> None:\n    if not per_layer_overrides:\n        return\n\n    num_hidden_layers = config.num_hidden_layers\n    invalid_layer_indices = [\n        layer_idx for layer_idx in per_layer_overrides if layer_idx < 0 or layer_idx >= num_hidden_layers\n    ]\n    if invalid_layer_indices:\n        raise ValueError(\n            f\"`per_layer_config` keys must be integer layer indices in the range [0, {num_hidden_layers}); \"","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/heterogeneity/configuration_utils.py#L38-L74","documentation":"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.\".","triggerScenarios":"per_layer_config with skip=[\"mlp\", 3] or skip=[None, \"attn\"] — any iterable containing at least one non-string element.","commonSituations":"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.","solutions":["Make every skip entry a string: skip=[\"mlp\", \"attn\"]","Coerce programmatically built lists: [str(s) for s in skip]"],"exampleFix":"# before\nconfig.per_layer_config = {0: {\"skip\": [\"mlp\", 2]}}\n\n# after\nconfig.per_layer_config = {0: {\"skip\": [\"mlp\", \"2\"]}}  # all strings","handlingStrategy":"type-guard","validationCode":"assert all(isinstance(x, str) for x in skip_list), \"every skip entry must be a string\"","typeGuard":"def skip_entries_all_strings(skip) -> bool:\n    return all(isinstance(item, str) for item in skip)","tryCatchPattern":null,"preventionTips":["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"],"tags":["heterogeneity","config","type-validation","per-layer"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}