Skip to content

Commit

Permalink
Extend testing
Browse files Browse the repository at this point in the history
  • Loading branch information
billschereriii committed Oct 12, 2023
1 parent 17e5cf1 commit ad99dfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 10 additions & 7 deletions smartsim/entity/dbobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,24 @@ def _enumerate_devices(self) -> t.List[str]:
def _check_devices(
device: t.Literal["CPU", "GPU"], devices_per_node: int, first_device: int,
) -> None:
if device == "CPU" and devices_per_node > 1:
raise SSUnsupportedError(
"Cannot set devices_per_node>1 if CPU is specified under devices"
)

if device == "CPU" and first_device > 0:
raise SSUnsupportedError(
"Cannot set first_device>0 if CPU is specified under devices"
)

if devices_per_node == 1:
return

if first_device < 0:
raise ValueError("Cannot set first_device to a negative number")

if ":" in device:
msg = "Cannot set devices_per_node>1 if a device numeral is specified, "
msg += f"the device was set to {device} and \
devices_per_node=={devices_per_node}"
raise ValueError(msg)
if device == "CPU":
raise SSUnsupportedError(
"Cannot set devices_per_node>1 if CPU is specified under devices"
)


class DBScript(DBObject):
Expand Down
14 changes: 13 additions & 1 deletion tests/backends/test_dbscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def test_inconsistent_params_db_script(fileutils):

torch_script = fileutils.get_test_conf_path("torchscript.py")
with pytest.raises(SSUnsupportedError) as ex:
db_script = DBScript(
_ = DBScript(
name="test_script_db",
script_path=torch_script,
device="CPU",
Expand All @@ -614,3 +614,15 @@ def test_inconsistent_params_db_script(fileutils):
ex.value.args[0]
== "Cannot set devices_per_node>1 if CPU is specified under devices"
)
with pytest.raises(SSUnsupportedError) as ex:
_ = DBScript(
name="test_script_db",
script_path=torch_script,
device="CPU",
devices_per_node=1,
first_device=5,
)
assert (
ex.value.args[0]
== "Cannot set first_device>0 if CPU is specified under devices"
)

0 comments on commit ad99dfd

Please sign in to comment.