Construct a `DeviceSpec` from a string. Args: spec: a string of the form /job: /replica: /task: /device:CPU: or /job: /replica: /task: /device:GPU: as cpu and gpu are mutually exclusive. All entries are optional. Returns:
(cls, spec)
| 122 | |
| 123 | @classmethod |
| 124 | def from_string(cls, spec): |
| 125 | """Construct a `DeviceSpec` from a string. |
| 126 | |
| 127 | Args: |
| 128 | spec: a string of the form |
| 129 | /job:<name>/replica:<id>/task:<id>/device:CPU:<id> |
| 130 | or |
| 131 | /job:<name>/replica:<id>/task:<id>/device:GPU:<id> |
| 132 | as cpu and gpu are mutually exclusive. |
| 133 | All entries are optional. |
| 134 | |
| 135 | Returns: |
| 136 | A DeviceSpec. |
| 137 | """ |
| 138 | return cls(*cls._string_to_components(spec)) |
| 139 | |
| 140 | def parse_from_string(self, spec): |
| 141 | """Parse a `DeviceSpec` name into its components. |