{"record":{"id":"38888d2d01dfde77","repo":"huggingface/transformers","slug":"the-current-device-map-had-weights-offloaded-to","errorCode":null,"errorMessage":"The current `device_map` had weights offloaded to the disk, which needed to be re-saved. This is either because the weights are not in `safetensors` format, or because the model uses an internal weight format different than the one saved (i.e. most MoE models). Please provide an `offload_folder` for them in `from_pretrained`.","messagePattern":"The current `device_map` had weights offloaded to the disk, which needed to be re-saved\\. This is either because the weights are not in `safetensors` format, or because the model uses an internal weight format different than the one saved \\(i\\.e\\. most MoE models\\)\\. Please provide an `offload_folder` for them in `from_pretrained`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/integrations/accelerate.py","lineNumber":503,"sourceCode":"        # Tie weights which are both disk offloaded\n        all_tied_weights_keys = getattr(model, \"all_tied_weights_keys\", {})\n        for target_param_name, source_param_name in all_tied_weights_keys.items():\n            if source_param_name in disk_offload_index and target_param_name not in disk_offload_index:\n                disk_offload_index[target_param_name] = disk_offload_index[source_param_name]\n\n    # In this case we will resave every offloaded weight\n    else:\n        disk_offload_index = {}\n\n    return disk_offload_index\n\n\ndef offload_weight(weight: torch.Tensor, weight_name: str, offload_folder: str | None, offload_index: dict) -> dict:\n    \"\"\"Write `weight` to disk inside `offload_folder`, and update `offload_index` accordingly. Everything is\n    saved in `safetensors` format.\"\"\"\n\n    if offload_folder is None:\n        raise ValueError(\n            \"The current `device_map` had weights offloaded to the disk, which needed to be re-saved. This is either \"\n            \"because the weights are not in `safetensors` format, or because the model uses an internal weight format \"\n            \"different than the one saved (i.e. most MoE models). Please provide an `offload_folder` for them in \"\n            \"`from_pretrained`.\"\n        )\n    # Write the weight to disk\n    safetensor_file = os.path.join(offload_folder, f\"{weight_name}.safetensors\")\n    save_file({weight_name: weight}, safetensor_file)\n    # Update the offloading index\n    str_dtype = str(weight.dtype).replace(\"torch.\", \"\")\n    offload_index[weight_name] = {\"safetensors_file\": safetensor_file, \"weight_name\": weight_name, \"dtype\": str_dtype}\n    return offload_index\n\n\ndef load_offloaded_parameter(model: \"PreTrainedModel\", param_name: str) -> torch.Tensor:\n    \"\"\"Load `param_name` from disk, if it was offloaded due to the device_map, and thus lives as a meta parameter\n    inside `model`.\n    This is needed when resaving a model, when some parameters were offloaded (we need to load them from disk, to","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/integrations/accelerate.py#L485-L521","documentation":"Error \"The current `device_map` had weights offloaded to the disk, which needed to be re-saved. This is either because the weights are not in `safetensors` format, or because the model uses an internal weight format different than the one saved (i.e. most MoE models). Please provide an `offload_folder` for them in `from_pretrained`.\" thrown in huggingface/transformers.","triggerScenarios":"Raised during from_pretrained dispatch when some weights must be offloaded to disk but no offload_folder was provided.","commonSituations":"device_map with disk offload on non-safetensors or MoE checkpoints without specifying offload_folder.","solutions":["Pass an `offload_folder` to `from_pretrained` for disk-offloaded weights.","Re-save the checkpoint in safetensors format."],"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"}