{"record":{"id":"5d71fbd588e568ba","repo":"huggingface/transformers","slug":"you-can-only-update-int-float-bool-or-string-val","errorCode":null,"errorMessage":"You can only update int, float, bool or string values in the config, got {v} for key {k}","messagePattern":"You can only update int, float, bool or string values in the config, got (.+?) for key (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":1202,"sourceCode":"        d = dict(x.split(\"=\") for x in update_str.split(\",\"))\n        for k, v in d.items():\n            if not hasattr(self, k):\n                raise ValueError(f\"key {k} isn't in the original config dict\")\n\n            old_v = getattr(self, k)\n            if isinstance(old_v, bool):\n                if v.lower() in [\"true\", \"1\", \"y\", \"yes\"]:\n                    v = True\n                elif v.lower() in [\"false\", \"0\", \"n\", \"no\"]:\n                    v = False\n                else:\n                    raise ValueError(f\"can't derive true or false from {v} (key {k})\")\n            elif isinstance(old_v, int):\n                v = int(v)\n            elif isinstance(old_v, float):\n                v = float(v)\n            elif not isinstance(old_v, str):\n                raise TypeError(\n                    f\"You can only update int, float, bool or string values in the config, got {v} for key {k}\"\n                )\n\n            setattr(self, k, v)\n\n    def dict_dtype_to_str(self, d: dict[str, Any]) -> None:\n        \"\"\"\n        Checks whether the passed dictionary and its nested dicts have a *dtype* key and if it's not None,\n        converts torch.dtype to a string of just the type. For example, `torch.float32` get converted into *\"float32\"*\n        string, which can then be stored in the json format.\n        \"\"\"\n        if d.get(\"dtype\") is not None:\n            if isinstance(d[\"dtype\"], dict):\n                d[\"dtype\"] = {k: str(v).split(\".\")[-1] for k, v in d[\"dtype\"].items()}\n            # models like Emu3 can have \"dtype\" as token in config's vocabulary map,\n            # so we also exclude int type here to avoid error in this special case.\n            elif not isinstance(d[\"dtype\"], (str, int)):\n                d[\"dtype\"] = str(d[\"dtype\"]).split(\".\")[1]","sourceCodeStart":1184,"sourceCodeEnd":1220,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L1184-L1220","documentation":"TypeError from update_from_string when the existing attribute's type is not int, float, bool, or str (e.g. a list, dict, or None), so the parser cannot convert the string value. The update-string mechanism deliberately supports only scalar types.","triggerScenarios":"config.update_from_string(\"layer_types=[dense, dense]\") where layer_types is a list, or updating a key whose current value is None (e.g. an unset optional field).","commonSituations":"Attempting to tweak list-typed config fields (layer_types, rope scaling dicts, activation lists) through the string API; configs where optional attributes default to None.","solutions":["Set non-scalar attributes directly in Python: config.layer_types = [\"dense\", \"dense\"].","If the attribute is None because it is optional, first assign a typed default, then use update_from_string only for scalars.","Restrict update_from_string usage to int/float/bool/str keys."],"exampleFix":"// before\nconfig.update_from_string(\"layer_types=dense,dense\")  # TypeError\n\n// after\nconfig.layer_types = [\"dense\", \"dense\"]","handlingStrategy":"type-guard","validationCode":"for k, v in updates.items():\n    old = getattr(config, k, None)\n    if not isinstance(old, (bool, int, float, str)) or old is None:\n        raise TypeError(f\"key {k} has non-scalar type {type(old).__name__}; set it directly\")","typeGuard":"def is_scalar_config_value(old) -> bool:\n    return isinstance(old, (bool, int, float, str))","tryCatchPattern":"try:\n    config.update_from_string(s)\nexcept TypeError as e:\n    if \"only update int, float, bool or string\" in str(e):\n        # apply via direct attribute assignment instead\n        raise","preventionTips":["Keep update_from_string limited to scalar hyperparameters; mutate list/dict config fields in Python."],"tags":["config","update-from-string","type-error"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}