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

allocate 80% for cpu is unset in max_memory #2219

Open
wants to merge 4 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
9 changes: 8 additions & 1 deletion src/accelerate/utils/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ def get_max_layer_size(

def get_max_memory(max_memory: Optional[Dict[Union[int, str], Union[int, str]]] = None):
"""
Get the maximum memory available if nothing is passed, converts string to int otherwise.
Get the maximum memory available if nothing is passed.
Otherwise, we convert string to int and we allocate 80% of the cpu memory if cpu is not passed in max_memory.
"""
import psutil

Expand Down Expand Up @@ -692,6 +693,12 @@ def get_max_memory(max_memory: Optional[Dict[Union[int, str], Union[int, str]]]
for key in max_memory:
if isinstance(max_memory[key], str):
max_memory[key] = convert_file_size_to_int(max_memory[key])
if "cpu" not in max_memory:
max_memory["cpu"] = psutil.virtual_memory().available * 0.8
logger.info(
"We will use 80% of the memory on cpu for storing the model."
"You can set `max_memory` in to a higher value to use more memory (at your own risk)."
SunMarc marked this conversation as resolved.
Show resolved Hide resolved
)

# Need to sort the device by type to make sure that we allocate the gpu first.
# As gpu/xpu are represented by int, we need to sort them first.
Expand Down
Loading