Commit b413425
(torchx-fb/named_resources) implement @named_resource decorator to autogenerate aliases and fractionals, migrate zion_4s_80g to use it. (#1121)
Summary:
Context: D82556202
```
named_resource(aliases=["zion4s_80g"], fractionals=powers_of_two_gpus)
def zion_4s_80g(fractional: float = 1.0) -> Resource:
...
```
Registers the named resources:
1. `zion_4s_80g` and the alias `zion4s_80g`
1. `zion_4s_80g_1 == zion_4s_80g(fractional=EIGHTH)`
1. `zion_4s_80g_2 == zion_4s_80g(fractional=QUARTER)`
1. `zion_4s_80g_4 == zion_4s_80g(fractional=HALF)`
1. `zion_4s_80g_8 == zion_4s_80g(fractional=WHOLE)`
so that we don't have to manually do this.
The auto-generated fractionals will return `True` when:
```
from torchx.specs.fb.resource import is_fractional
from torchx.specs import get_named_resource
assert is_fractional(get_named_resource("zion_4s_80g_1")) == True
assert is_fractional(get_named_resource("zion_4s_80g_2")) == True
assert is_fractional(get_named_resource("zion_4s_80g_4")) == True
assert is_fractional(get_named_resource("zion_4s_80g_8")) == True
assert is_fractional(get_named_resource("zion_4s_80g")) == False
```
NOTE: each of the fractional types (including WHOLE) will have `resource.capabilities[IS_FRACTIONAL] == True` so that we can use it as a way to determine whether a resource originates from a fractional named resource.
Reviewed By: ajauhri, highker
Differential Revision: D825943251 parent 99e8d5e commit b413425
2 files changed
+14
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | | - | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
62 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
| 85 | + | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| |||
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
| |||
0 commit comments