{"record":{"id":"577908e749a6e0e0","repo":"huggingface/transformers","slug":"when-passing-device-map-as-a-string-the-value-nee","errorCode":null,"errorMessage":"When passing device_map as a string, the value needs to be a device name (e.g. cpu, cuda:0) or 'auto', 'balanced', 'balanced_low_0', 'sequential' but found {device_map}.","messagePattern":"When passing device_map as a string, the value needs to be a device name \\(e\\.g\\. cpu, cuda:0\\) or 'auto', 'balanced', 'balanced_low_0', 'sequential' but found (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/accelerate.py","lineNumber":119,"sourceCode":"            raise RuntimeError(\n                \"You are using `from_pretrained` with a meta device context manager or `torch.set_default_device('meta')`.\\n\"\n                \"This is an anti-pattern as `from_pretrained` wants to load existing weights.\\nIf you want to initialize an \"\n                \"empty model on the meta device, use the context manager or global device with `from_config`, or `ModelClass(config)`\"\n            )\n        device_map = device_in_context\n\n    # change device_map into a map if we passed an int, a str or a torch.device\n    if isinstance(device_map, torch.device):\n        device_map = {\"\": device_map}\n    elif isinstance(device_map, str) and device_map not in [\"auto\", \"balanced\", \"balanced_low_0\", \"sequential\"]:\n        try:\n            if device_map == \"cuda\":\n                # setting to the local rank\n                local_rank = int(os.environ.get(\"LOCAL_RANK\", 0))\n                device_map = f\"cuda:{local_rank}\"\n            device_map = {\"\": torch.device(device_map)}\n        except RuntimeError:\n            raise ValueError(\n                \"When passing device_map as a string, the value needs to be a device name (e.g. cpu, cuda:0) or \"\n                f\"'auto', 'balanced', 'balanced_low_0', 'sequential' but found {device_map}.\"\n            )\n    elif isinstance(device_map, int):\n        if device_map < 0:\n            raise ValueError(\n                \"You can't pass device_map as a negative int. If you want to put the model on the cpu, pass device_map = 'cpu' \"\n            )\n        else:\n            device_map = {\"\": device_map}\n\n    if device_map is not None:\n        if is_deepspeed_zero3_enabled():\n            raise ValueError(\"DeepSpeed Zero-3 is not compatible with passing a `device_map`.\")\n        if not is_accelerate_available():\n            raise ValueError(\n                \"Using a `device_map`, `tp_plan`, `torch.device` context manager or setting `torch.set_default_device(device)` \"\n                \"requires `accelerate`. You can install it with `pip install accelerate`\"","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/accelerate.py#L101-L137","documentation":"Error \"When passing device_map as a string, the value needs to be a device name (e.g. cpu, cuda:0) or 'auto', 'balanced', 'balanced_low_0', 'sequential' but found {device_map}.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in device_map validation when a string device_map is not a device name or a known strategy ('auto', 'balanced', etc.).","commonSituations":"Typo in device_map string, e.g. device_map='gpu' or 'balance', instead of a valid strategy or device name.","solutions":["Pass device_map as 'auto', 'balanced', 'balanced_low_0', 'sequential', or a device name like 'cpu'/'cuda:0'.","Pass a dict mapping module names to devices for fine-grained placement."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}