{"record":{"id":"fe613b8f27c8b616","repo":"huggingface/transformers","slug":"key-k-isn-t-in-the-original-config-dict","errorCode":null,"errorMessage":"key {k} isn't in the original config dict","messagePattern":"key (.+?) isn't in the original config dict","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":1187,"sourceCode":"\n    def update_from_string(self, update_str: str):\n        \"\"\"\n        Updates attributes of this class with attributes from `update_str`.\n\n        The expected format is ints, floats and strings as is, and for booleans use `true` or `false`. For example:\n        \"n_embd=10,resid_pdrop=0.2,scale_attn_weights=false,summary_type=cls_index\"\n\n        The keys to change have to already exist in the config object.\n\n        Args:\n            update_str (`str`): String with attributes that should be updated for this class.\n\n        \"\"\"\n\n        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","sourceCodeStart":1169,"sourceCodeEnd":1205,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L1169-L1205","documentation":"ValueError from PreTrainedConfig.update_from_string: the CLI-style update string contains a key that does not already exist as an attribute on the config object. update_from_str only mutates existing attributes; it never creates new ones.","triggerScenarios":"config.update_from_string(\"n_embdd=10\") (typo), or updating a key that belongs to a different model family's config (e.g. num_attention_heads on a config class that does not define it, or a parameter only present on the nested text_config).","commonSituations":"Scripts that build the update string dynamically from a dict of hyperparameters; copy-pasting example strings from a different model's docs; trying to set sub-config attributes at the top level of a composite (vision-language) config.","solutions":["Check hasattr(config, key) for the failing key and fix the typo or use the correct attribute name.","For nested configs, target the sub-config: config.text_config.update_from_string(...).","If you truly need a new attribute, set it directly (config.my_key = value) instead of via update_from_string."],"exampleFix":"// before\nconfig.update_from_string(\"n_embdd=10\")  # ValueError\n\n// after\nconfig.update_from_string(\"n_embd=10\")","handlingStrategy":"validation","validationCode":"updates = {\"n_embd\": \"10\", \"scale_attn_weights\": \"false\"}\nmissing = [k for k in updates if not hasattr(config, k)]\nif missing:\n    raise KeyError(f\"Unknown config keys: {missing}\")\nconfig.update_from_string(\",\".join(f\"{k}={v}\" for k, v in updates.items()))","typeGuard":"def can_update(config, key: str) -> bool:\n    return hasattr(config, key)","tryCatchPattern":"try:\n    config.update_from_string(s)\nexcept ValueError as e:\n    if \"isn't in the original config dict\" in str(e):\n        raise KeyError(f\"bad update string {s!r}: {e}\")","preventionTips":["Build update strings from validated key/value tables, not free-form user input.","Prefer direct attribute assignment in Python code; reserve update_from_string for CLI ergonomics."],"tags":["config","update-from-string","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}