{"record":{"id":"2937be9bf262e16b","repo":"huggingface/transformers","slug":"using-a-device-map-tp-plan-torch-device-co","errorCode":null,"errorMessage":"Using a `device_map`, `tp_plan`, `torch.device` context manager or setting `torch.set_default_device(device)` requires `accelerate`. You can install it with `pip install accelerate`","messagePattern":"Using a `device_map`, `tp_plan`, `torch\\.device` context manager or setting `torch\\.set_default_device\\(device\\)` requires `accelerate`\\. You can install it with `pip install accelerate`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/accelerate.py","lineNumber":135,"sourceCode":"            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`\"\n            )\n    return device_map\n\n\ndef compute_module_sizes(\n    model: \"PreTrainedModel\",\n    hf_quantizer: \"HfQuantizer | None\" = None,\n    buffers_only: bool = False,\n    only_modules: bool = True,\n) -> tuple[dict[str, int], dict[str, int]]:\n    \"\"\"\n    Compute the size of each submodule of a given model (in bytes).\n    Returns a tuple of 2 dicts, the first one containing a mapping of all the modules and the corresponding size\n    in bytes, and the 2nd one containing a mapping from all leaf modules (modules containing parameters, the end of\n    the model graph) and the corresponding sizes.\n    If `only_modules` is set to False, the first mapping will not only contain the size of all modules, but also","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/accelerate.py#L117-L153","documentation":"Error \"Using a `device_map`, `tp_plan`, `torch.device` context manager or setting `torch.set_default_device(device)` requires `accelerate`. You can install it with `pip install accelerate`\" thrown in huggingface/transformers.","triggerScenarios":"Raised when device_map/tp_plan/torch.device context is requested but the accelerate package is not installed.","commonSituations":"Using device_map='auto' or tp_plan on a minimal environment without accelerate installed.","solutions":["Install accelerate: `pip install accelerate`.","Remove device_map/tp_plan/device context usage."],"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"}