Skip to content

Commit

Permalink
Don't remap auto device_map and raise RuntimeError
Browse files Browse the repository at this point in the history
If device_map=auto and modules are selected for disk offload, don't attempt to map them to any other device. Raise a runtime error when a GGUF model is configured to map any modules to disk.
  • Loading branch information
dmlap committed Feb 10, 2025
1 parent 136c2a5 commit b7f3496
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
15 changes: 1 addition & 14 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4241,27 +4241,14 @@ def from_pretrained(
if hf_quantizer is not None:
hf_quantizer.validate_environment(device_map=device_map)

if gguf_path:
remapped_devices = set()
for name, device in device_map.items():
if device == "disk":
device_map[name] = "cpu"
remapped_devices.add(name)
if len(remapped_devices) > 0:
logger.warning(
"Accelerate has auto-mapped modules to disk but disk offload is not supported for "
"models loaded from GGUF files. Remapping modules to the cpu: "
", ".join(remapped_devices)
)

elif device_map is not None:
model.tie_weights()
tied_params = find_tied_parameters(model)
# check if we don't have tied param in different devices
check_tied_parameters_on_same_device(tied_params, device_map)

if gguf_path and device_map is not None and "disk" in device_map.values():
raise NotImplementedError(
raise RuntimeError(
"One or more modules is configured to be mapped to disk. Disk offload is not supported for models "
"loaded from GGUF files."
)
Expand Down
2 changes: 1 addition & 1 deletion tests/quantization/ggml/test_ggml.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_gguf_errors_disk_offload(self):
from collections import OrderedDict

q2_k_gguf_model_id = self.gguf_filename.format(quant_type=QuantType.Q2_K.name)
with self.assertRaises(NotImplementedError):
with self.assertRaises(RuntimeError):
AutoModelForCausalLM.from_pretrained(
self.gguf_model_id,
device_map=OrderedDict(
Expand Down

0 comments on commit b7f3496

Please sign in to comment.