Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure direct parameters are properly set on device #1043

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/accelerate/big_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def dispatch_model(
execution_device = {
name: main_device if device in ["cpu", "disk"] else device for name, device in device_map.items()
}
execution_device[""] = main_device
offloaded_devices = ["disk"] if main_device == "cpu" else ["cpu", "disk"]
offload = {name: device in offloaded_devices for name, device in device_map.items()}
save_folder = offload_dir if len(disk_modules) > 0 else None
Expand Down
6 changes: 3 additions & 3 deletions src/accelerate/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def attach_align_device_hook_on_blocks(
if not isinstance(offload, Mapping):
offload = {key: offload for key in execution_device.keys()}

if module_name in execution_device and not offload[module_name]:
if module_name in execution_device and module_name in offload and not offload[module_name]:
hook = AlignDevicesHook(
execution_device=execution_device[module_name],
offload_buffers=offload_buffers,
Expand All @@ -463,7 +463,7 @@ def attach_align_device_hook_on_blocks(
)
add_hook_to_module(module, hook)
attach_execution_device_hook(module, execution_device[module_name])
elif module_name in execution_device:
elif module_name in execution_device and module_name in offload:
attach_align_device_hook(
module,
execution_device=execution_device[module_name],
Expand All @@ -480,7 +480,7 @@ def attach_align_device_hook_on_blocks(
module, execution_device[module_name], preload_module_classes=preload_module_classes
)
elif module_name == "":
hook = AlignDevicesHook(io_same_device=True)
hook = AlignDevicesHook(execution_device=execution_device.get(""), io_same_device=True)
add_hook_to_module(module, hook)

for child_name, child in module.named_children():
Expand Down