Skip to content

Commit 19f69e4

Browse files
authored
Fix case where remote server has GPU but local machine does not (#806)
* Fix case where remote server has GPU but local machine does not * remove unused import
1 parent dcb86b4 commit 19f69e4

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

model_analyzer/config/input/config_command_profile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,9 @@ def _autofill_values(self):
13911391
config values.
13921392
"""
13931393
cpu_only = False
1394-
if len(self.gpus) == 0 or not numba.cuda.is_available():
1394+
if self.triton_launch_mode != "remote" and (
1395+
len(self.gpus) == 0 or not numba.cuda.is_available()
1396+
):
13951397
cpu_only = True
13961398

13971399
# Set global constraints if latency budget is specified

model_analyzer/record/metrics_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def _print_run_config_info(self, run_config):
791791
cpu_only = run_config.cpu_only()
792792

793793
# Inform user CPU metric(s) are not being collected under CPU mode
794-
collect_cpu_metrics_expect = cpu_only or len(self._gpus) == 0
794+
collect_cpu_metrics_expect = cpu_only
795795
collect_cpu_metrics_actual = len(self._cpu_metrics) > 0
796796
if collect_cpu_metrics_expect and not collect_cpu_metrics_actual:
797797
if not self._cpu_warning_printed:

tests/mocks/mock_numba.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MockNumba(MockBase):
2525
Mocks numba class
2626
"""
2727

28-
def __init__(self, mock_paths):
28+
def __init__(self, mock_paths, is_available=True):
2929
device = MagicMock()
3030

3131
# Ignore everything after 0
@@ -43,7 +43,10 @@ def __init__(self, mock_paths):
4343
list_devices = MagicMock()
4444
list_devices.return_value = [device]
4545

46-
cuda_attrs = {"list_devices": list_devices}
46+
cuda_attrs = {
47+
"list_devices": list_devices,
48+
"is_available": MagicMock(return_value=is_available),
49+
}
4750
numba_attrs = {"cuda": MagicMock(**cuda_attrs)}
4851
self._mock_paths = mock_paths
4952
self._patchers_numba = {}

tests/test_config.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ def _create_parameters(
6767
"max_token_count": max_token_count,
6868
}
6969

70-
def _evaluate_config(self, args, yaml_content, subcommand="profile"):
70+
def _evaluate_config(
71+
self, args, yaml_content, subcommand="profile", numba_available=True
72+
):
7173
mock_numba = MockNumba(
72-
mock_paths=["model_analyzer.config.input.config_command_profile"]
74+
mock_paths=["model_analyzer.config.input.config_command_profile"],
75+
is_available=numba_available,
7376
)
7477

7578
mock_config = MockConfig(args, yaml_content)
@@ -109,6 +112,7 @@ def _assert_equality_of_model_configs(self, model_configs, expected_model_config
109112
for model_config, expected_model_config in zip(
110113
model_configs, expected_model_configs
111114
):
115+
self.assertEqual(expected_model_config.cpu_only(), model_config.cpu_only())
112116
self.assertEqual(
113117
expected_model_config.model_name(), model_config.model_name()
114118
)
@@ -1384,6 +1388,32 @@ def test_autofill(self):
13841388
]
13851389
self._assert_equality_of_model_configs(model_configs, expected_model_configs)
13861390

1391+
# Test autofill CPU_ONLY. It will only be false if no local gpus are available AND we are not in remote mode
1392+
yaml_content = """
1393+
profile_models:
1394+
- vgg_16_graphdef
1395+
"""
1396+
for launch_mode in ["remote", "c_api", "docker", "local"]:
1397+
for local_gpus_available in [True, False]:
1398+
new_args = args.copy()
1399+
new_args.extend(["--triton-launch-mode", launch_mode])
1400+
config = self._evaluate_config(
1401+
new_args, yaml_content, numba_available=local_gpus_available
1402+
)
1403+
model_configs = config.get_all_config()["profile_models"]
1404+
expected_cpu_only = not local_gpus_available and launch_mode != "remote"
1405+
expected_model_configs = [
1406+
ConfigModelProfileSpec(
1407+
"vgg_16_graphdef",
1408+
cpu_only=expected_cpu_only,
1409+
parameters=self._create_parameters(batch_sizes=[1]),
1410+
objectives={"perf_throughput": 10},
1411+
)
1412+
]
1413+
self._assert_equality_of_model_configs(
1414+
model_configs, expected_model_configs
1415+
)
1416+
13871417
def test_config_shorthands(self):
13881418
"""
13891419
test flags like --latency-budget

0 commit comments

Comments
 (0)