Skip to content

Commit 0ef84b9

Browse files
authored
Support OCI spot instances (#2337)
Migrate to v2 `gpuhunt` catalogs and enable the `oci-spot` flag to see OCI spot offers. The actual support for provisioning spot instances was implemented earlier. Also handle out of capacity errors. Spot capacity does not always match the capacity returned in OCI capacity reports, so handle out of capacity errors gracefully. OCI returns these errors with the `InternalError` code, so we'll need to rely on error messages to detect them.
1 parent 672418a commit 0ef84b9

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

contributing/GPUHUNT.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,18 @@ Some providers offer extreme flexibility in possible configurations, but not all
9595
The offline catalog is built in GitHub Actions every night. Every offline provider produces a CSV file with offers. Later, those files get compressed into a zip archive and uploaded to the public S3 bucket.
9696

9797
To ensure data quality, there is a catalog integrity testing step. It uses some simple heuristics to avoid empty catalog files, zero prices, or missing regions.
98+
99+
### Backward compatibility
100+
101+
The same `gpuhunt` version can be used by different `dstack` versions.
102+
Additionally, offline catalogs are produced by the latest `gpuhunt` version, but used by all `dstack` versions.
103+
104+
These mechanisms are used to preserve backward compatibility:
105+
106+
- **`gpuhunt` version**: The interfaces in the `gpuhunt` package preserve backward compatibility
107+
within a minor version (`X` in `0.X.Y`).
108+
- **Offer flags**: If an offer breaks older `dstack` versions, it is marked with a flag in `RawCatalogItem.flags`
109+
and the flag is added to the list of supported flags in `dstack`.
110+
Older `dstack` versions that don't support this flag will not see the respective offers.
111+
- **Offline catalog versions**: If a breaking change in the structure or content of an offline catalog is unavoidable,
112+
a new version of the catalog can be introduced. Catalog versions are published at `s3://dstack-gpu-pricing/v{N}`.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_long_description():
4848
"python-multipart>=0.0.16",
4949
"filelock",
5050
"psutil",
51-
"gpuhunt>=0.0.19,<0.1.0",
51+
"gpuhunt>=0.1.0,<0.2.0",
5252
"argcomplete>=3.5.0",
5353
]
5454

src/dstack/_internal/core/backends/base/offers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
from dstack._internal.core.models.resources import DEFAULT_DISK, Memory, Range
1515
from dstack._internal.core.models.runs import Requirements
1616

17+
# Offers not supported by all dstack versions are hidden behind one or more flags.
18+
# This list enables the flags that are currently supported.
19+
SUPPORTED_GPUHUNT_FLAGS = [
20+
"oci-spot",
21+
]
22+
1723

1824
def get_catalog_offers(
1925
backend: BackendType,
@@ -110,7 +116,7 @@ def offer_to_catalog_item(offer: InstanceOffer) -> gpuhunt.CatalogItem:
110116

111117

112118
def requirements_to_query_filter(req: Optional[Requirements]) -> gpuhunt.QueryFilter:
113-
q = gpuhunt.QueryFilter()
119+
q = gpuhunt.QueryFilter(allowed_flags=SUPPORTED_GPUHUNT_FLAGS)
114120
if req is None:
115121
return q
116122

src/dstack/_internal/core/backends/oci/compute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def create_instance(
163163
image_id=package.image_id,
164164
)
165165
except oci.exceptions.ServiceError as e:
166-
if e.code in ("LimitExceeded", "QuotaExceeded"):
166+
if e.code in ("LimitExceeded", "QuotaExceeded") or "Out of host capacity" in e.message:
167167
raise NoCapacityError(e.message)
168168
raise
169169

0 commit comments

Comments
 (0)