Skip to content

Commit cb387bc

Browse files
committed
Move module level accelerate import to be function level
1 parent cb9aedb commit cb387bc

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/sagemaker/serve/detector/dependency_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def capture_dependencies(dependencies: dict, work_dir: Path, capture_all: bool =
5454

5555
with open(path, "r") as f:
5656
autodetect_depedencies = f.read().splitlines()
57-
autodetect_depedencies.append("sagemaker>=2.199")
57+
autodetect_depedencies.append("sagemaker[huggingface]>=2.199")
5858
else:
59-
autodetect_depedencies = ["sagemaker>=2.199"]
59+
autodetect_depedencies = ["sagemaker[huggingface]>=2.199"]
6060

6161
module_version_dict = _parse_dependency_list(autodetect_depedencies)
6262

src/sagemaker/serve/utils/hardware_detector.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
from botocore.exceptions import ClientError
2020

21-
from accelerate.commands.estimate import estimate_command_parser, gather_data
2221
from sagemaker import Session
23-
from sagemaker.model import Model
2422
from sagemaker import instance_types_gpu_info
2523

2624
logger = logging.getLogger(__name__)
@@ -116,18 +114,23 @@ def _format_instance_type(instance_type: str) -> str:
116114
return ec2_instance
117115

118116

119-
def _total_inference_model_size_mib(model: Model, dtype: str) -> int:
117+
def _total_inference_model_size_mib(model: str, dtype: str) -> int:
120118
"""Calculates the model size from HF accelerate
121119
122120
This function gets the model size from accelerate. It also adds a
123121
padding and converts to size MiB. When performing inference, expect
124122
to add up to an additional 20% to the given model size as found by EleutherAI.
125123
"""
126-
args = estimate_command_parser().parse_args([model, "--dtypes", dtype])
127-
128-
output = gather_data(
129-
args
130-
) # "dtype", "Largest Layer", "Total Size Bytes", "Training using Adam"
124+
try:
125+
from accelerate.commands.estimate import estimate_command_parser, gather_data
126+
args = estimate_command_parser().parse_args([model, "--dtypes", dtype])
127+
128+
output = gather_data(
129+
args
130+
) # "dtype", "Largest Layer", "Total Size Bytes", "Training using Adam"
131+
except ImportError:
132+
logger.error("Install HuggingFace extras dependencies using pip install 'sagemaker["
133+
"huggingface]>=2.212.0'")
131134

132135
if output is None:
133136
raise ValueError(f"Could not get Model size for {model}")

0 commit comments

Comments
 (0)