Skip to content

Commit 6ab9f69

Browse files
authored
(torchx-fb/named_resources) semi-automate registration of fractional resources for gpu types
Differential Revision: D82594325 Pull Request resolved: #1121
1 parent 99e8d5e commit 6ab9f69

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

torchx/specs/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Meta Platforms, Inc. and affiliates.
32
# All rights reserved.
43
#
@@ -52,14 +51,19 @@
5251

5352
from torchx.util.modules import import_attr
5453

55-
AWS_NAMED_RESOURCES: Mapping[str, Callable[[], Resource]] = import_attr(
54+
GiB: int = 1024
55+
56+
ResourceFactory = Callable[[], Resource]
57+
58+
AWS_NAMED_RESOURCES: Mapping[str, ResourceFactory] = import_attr(
5659
"torchx.specs.named_resources_aws", "NAMED_RESOURCES", default={}
5760
)
58-
GENERIC_NAMED_RESOURCES: Mapping[str, Callable[[], Resource]] = import_attr(
61+
GENERIC_NAMED_RESOURCES: Mapping[str, ResourceFactory] = import_attr(
5962
"torchx.specs.named_resources_generic", "NAMED_RESOURCES", default={}
6063
)
61-
62-
GiB: int = 1024
64+
FB_NAMED_RESOURCES: Mapping[str, ResourceFactory] = import_attr(
65+
"torchx.specs.fb.named_resources", "NAMED_RESOURCES", default={}
66+
)
6367

6468

6569
def _load_named_resources() -> Dict[str, Callable[[], Resource]]:
@@ -69,6 +73,7 @@ def _load_named_resources() -> Dict[str, Callable[[], Resource]]:
6973
for name, resource in {
7074
**GENERIC_NAMED_RESOURCES,
7175
**AWS_NAMED_RESOURCES,
76+
**FB_NAMED_RESOURCES,
7277
**resource_methods,
7378
}.items():
7479
materialized_resources[name] = resource

torchx/specs/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
# Copyright (c) Meta Platforms, Inc. and affiliates.
32
# All rights reserved.
43
#
@@ -83,6 +82,8 @@ class Resource:
8382
memMB: MB of ram
8483
capabilities: additional hardware specs (interpreted by scheduler)
8584
devices: a list of named devices with their quantities
85+
tags: metadata tags for the resource (not interpreted by schedulers)
86+
used to add non-functional information about resources (e.g. whether it is an alias of another resource)
8687
8788
Note: you should prefer to use named_resources instead of specifying the raw
8889
resource requirement directly.
@@ -93,6 +94,7 @@ class Resource:
9394
memMB: int
9495
capabilities: Dict[str, Any] = field(default_factory=dict)
9596
devices: Dict[str, int] = field(default_factory=dict)
97+
tags: Dict[str, object] = field(default_factory=dict)
9698

9799
@staticmethod
98100
def copy(original: "Resource", **capabilities: Any) -> "Resource":
@@ -101,6 +103,7 @@ def copy(original: "Resource", **capabilities: Any) -> "Resource":
101103
are present in the original resource and as parameter, the one from parameter
102104
will be used.
103105
"""
106+
104107
res_capabilities = dict(original.capabilities)
105108
res_capabilities.update(capabilities)
106109
return Resource(

0 commit comments

Comments
 (0)