Skip to content

mount neuron devices for local_docker/aws_batch scheduler #920

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

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 15 additions & 4 deletions torchx/schedulers/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@

# pyre-strict
import warnings
from functools import partial
from typing import Callable, Dict, List, Mapping

from torchx.specs.api import DeviceMount
from torchx.specs.named_resources_aws import EFA_DEVICE, NEURON_DEVICE


def efa_to_devicemounts(num_devices: int) -> List[DeviceMount]:
def to_devicemounts(num_devices: int, device_type: str) -> List[DeviceMount]:
device_mounts = []
for device_index in range(0, num_devices):
device_mounts.append(
DeviceMount(
src_path="/dev/infiniband/uverbs" + str(device_index),
dst_path="/dev/infiniband/uverbs" + str(device_index),
src_path=device_type + str(device_index),
dst_path=device_type + str(device_index),
)
)
return device_mounts


neuron_to_devicemounts: Callable[[int], List[DeviceMount]] = partial(
to_devicemounts, device_type="/dev/neuron"
)
efa_to_devicemounts: Callable[[int], List[DeviceMount]] = partial(
to_devicemounts, device_type="/dev/infiniband/uverbs"
)


DEVICES: Mapping[str, Callable[[int], List[DeviceMount]]] = {
"vpc.amazonaws.com/efa": efa_to_devicemounts,
EFA_DEVICE: efa_to_devicemounts,
NEURON_DEVICE: neuron_to_devicemounts,
}


Expand Down
10 changes: 9 additions & 1 deletion torchx/schedulers/test/aws_batch_scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ def test_resource_devices(self) -> None:
image="",
mounts=[],
resource=specs.Resource(
cpu=1, memMB=1000, gpu=0, devices={"vpc.amazonaws.com/efa": 2}
cpu=1,
memMB=1000,
gpu=0,
devices={"vpc.amazonaws.com/efa": 2, "aws.amazon.com/neurondevice": 1},
),
)
props = _role_to_node_properties(role, 0)
Expand All @@ -379,6 +382,11 @@ def test_resource_devices(self) -> None:
"containerPath": "/dev/infiniband/uverbs1",
"permissions": ["READ", "WRITE", "MKNOD"],
},
{
"hostPath": "/dev/neuron0",
"containerPath": "/dev/neuron0",
"permissions": ["READ", "WRITE", "MKNOD"],
},
],
)

Expand Down
3 changes: 2 additions & 1 deletion torchx/schedulers/test/devices_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class DevicesTest(unittest.TestCase):
def test_get_efa(self) -> None:
devices = {"vpc.amazonaws.com/efa": 2}
devices = {"vpc.amazonaws.com/efa": 2, "aws.amazon.com/neurondevice": 1}
self.assertEqual(
get_device_mounts(devices),
[
Expand All @@ -28,6 +28,7 @@ def test_get_efa(self) -> None:
src_path="/dev/infiniband/uverbs1",
dst_path="/dev/infiniband/uverbs1",
),
DeviceMount(src_path="/dev/neuron0", dst_path="/dev/neuron0"),
],
)

Expand Down
11 changes: 9 additions & 2 deletions torchx/schedulers/test/docker_scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,19 @@ def test_device_mounts(self) -> None:
def test_resource_devices(self) -> None:
app = _test_app()
app.roles[0].mounts = []
app.roles[0].resource.devices = {"vpc.amazonaws.com/efa": 1}
app.roles[0].resource.devices = {
"vpc.amazonaws.com/efa": 1,
"aws.amazon.com/neurondevice": 2,
}

info = self.scheduler.submit_dryrun(app, cfg={})
self.assertEqual(
info.request.containers[0].kwargs["devices"],
["/dev/infiniband/uverbs0:/dev/infiniband/uverbs0:rwm"],
[
"/dev/infiniband/uverbs0:/dev/infiniband/uverbs0:rwm",
"/dev/neuron0:/dev/neuron0:rwm",
"/dev/neuron1:/dev/neuron1:rwm",
],
)

@patch("os.environ", {"FOO_1": "f1", "BAR_1": "b1", "FOOBAR_1": "fb1"})
Expand Down
9 changes: 7 additions & 2 deletions torchx/specs/named_resources_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from torchx.specs.api import Resource

EFA_DEVICE = "vpc.amazonaws.com/efa"
NEURON_DEVICE = "aws.amazon.com/neurondevice"

# ecs and ec2 have memtax and currently AWS Batch uses hard memory limits
# so we have to account for mem tax when registering these resources for AWS
Expand Down Expand Up @@ -255,7 +256,11 @@ def aws_g5_48xlarge() -> Resource:

def aws_trn1_2xlarge() -> Resource:
return Resource(
cpu=8, gpu=0, memMB=32 * GiB, capabilities={K8S_ITYPE: "trn1.2xlarge"}
cpu=8,
gpu=0,
memMB=32 * GiB,
capabilities={K8S_ITYPE: "trn1.2xlarge"},
devices={NEURON_DEVICE: 1},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How were these being used before without these device mounts? Was there a init script/host config that handled this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a optional package aws-neuronx-oci-hook which allows for setting “AWS_NEURON_VISIBLE_DEVICES”
https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/tutorials/build-run-neuron-container.html#container-devices

Which is similar to the nvidia container setting CUDA_VISIBLE_DEVICES
And for kubernetes, there is a plugin which uses aws.amazon.com/neurondevice

)


Expand All @@ -265,7 +270,7 @@ def aws_trn1_32xlarge() -> Resource:
gpu=0,
memMB=512 * GiB,
capabilities={K8S_ITYPE: "trn1.32xlarge"},
devices={EFA_DEVICE: 8},
devices={EFA_DEVICE: 8, NEURON_DEVICE: 16},
)


Expand Down
3 changes: 3 additions & 0 deletions torchx/specs/test/named_resources_aws_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
GiB,
K8S_ITYPE,
NAMED_RESOURCES,
NEURON_DEVICE,
)


Expand Down Expand Up @@ -170,11 +171,13 @@ def test_aws_trn1(self) -> None:
self.assertEqual(8, trn1_2.cpu)
self.assertEqual(0, trn1_2.gpu)
self.assertEqual(32 * GiB, trn1_2.memMB)
self.assertEqual({NEURON_DEVICE: 1}, trn1_2.devices)

trn1_32 = aws_trn1_32xlarge()
self.assertEqual(trn1_32.cpu, trn1_2.cpu * 16)
self.assertEqual(trn1_32.gpu, trn1_2.gpu)
self.assertEqual(trn1_32.memMB, trn1_2.memMB * 16)
self.assertEqual({EFA_DEVICE: 8, NEURON_DEVICE: 16}, trn1_32.devices)

def test_aws_m5_2xlarge(self) -> None:
resource = aws_m5_2xlarge()
Expand Down
Loading