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

Add warnings and fallback for unassigned devices in infer_auto_device_map #3066

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/accelerate/utils/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ def infer_auto_device_map(
current_memory_used = 0
device_memory_used = {}
device_buffer_sizes = {}
device_minimum_assignment_memory = {}

# Direct submodules and parameters
modules_to_treat = (
Expand Down Expand Up @@ -1318,7 +1319,8 @@ def infer_auto_device_map(
# -> no split, we go to the next device
if verbose:
print("This module cannot be split, going to the next device.")

if current_memory_used == 0:
device_minimum_assignment_memory[device] = module_size + current_memory_reserved
device_memory_used[device] = current_memory_used + current_memory_reserved
current_device += 1
modules_to_treat = [(name, module)] + modules_to_treat
Expand Down Expand Up @@ -1417,6 +1419,8 @@ def infer_auto_device_map(
# If the tied module is not split, we go to the next device
if verbose:
print("None of the tied module can be split, going to the next device.")
if current_memory_used == 0:
device_minimum_assignment_memory[device] = module_size_with_ties + current_memory_reserved

device_memory_used[device] = current_memory_used + current_memory_reserved
current_device += 1
Expand Down Expand Up @@ -1465,6 +1469,13 @@ def infer_auto_device_map(
f"offload_buffers=True."
)

for device, mem in device_minimum_assignment_memory.items():
Nech-C marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
f"No modules could be assigned to {device} as the minimum memory required is {mem} "
f"for the current calculation, which is higher than the available memory {max_memory[device]}."
f"Consider increasing the memory available."
)

return device_map


Expand Down