Skip to content

Commit 43cae96

Browse files
authored
Update gpuhunt contributing guide (#4143)
1 parent e364738 commit 43cae96

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

contributing/BACKENDS.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ git clone https://github.com/dstackai/gpuhunt.git
3131
- **Online providers** offer dynamic machine configurations that are available at the very moment
3232
when you fetch configurations (e.g., GPU marketplaces).
3333
`gpuhunt` collects online providers' instance offers each time a `dstack` user provisions a new instance.
34-
Examples: `tensordock`, `vastai`, etc.
34+
Examples: `vastai`, `hotaisle`, etc.
3535

3636
### 1.3. Create the provider class
3737

3838
Create the provider class file under `src/gpuhunt/providers`.
3939

40-
Make sure your class extends the [`AbstractProvider`](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/__init__.py)
41-
base class. See its docstrings for descriptions of the methods that your class should implement.
40+
Make sure your class extends either `OnlineProvider` or `OfflineProvider` from
41+
[base.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/base.py),
42+
matching the choice you made above.
43+
44+
Both kinds implement `get`, returning `CatalogItem`s with `provider` set to your provider's `NAME`.
45+
Additionally:
46+
47+
- Online providers implement the `from_env` classmethod, which reads credentials from the
48+
environment with `get_creds_env` and raises `MissingCredsError` if one is missing. Providers that
49+
raise it are skipped by `default_catalog()` rather than failing the whole catalog.
50+
- Offline providers may override `filter` to omit some offers from the published catalog.
4251

4352
Refer to examples:
4453
- Offline providers:
@@ -47,8 +56,8 @@ Refer to examples:
4756
[azure.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/azure.py),
4857
[lambdalabs.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/lambdalabs.py).
4958
- Online providers:
50-
[vultr.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/vultr.py)
51-
[tensordock.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/tensordock.py),
59+
[vultr.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/vultr.py),
60+
[hotaisle.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/hotaisle.py),
5261
[vastai.py](https://github.com/dstackai/gpuhunt/blob/main/src/gpuhunt/providers/vastai.py).
5362

5463
### 1.4. Register the provider with the catalog
@@ -57,7 +66,8 @@ Add your provider in the following places:
5766
- Either `OFFLINE_PROVIDERS` or `ONLINE_PROVIDERS` in `src/gpuhunt/_internal/catalog.py`.
5867
- The `python -m gpuhunt` command in `src/gpuhunt/__main__.py`.
5968
- (offline providers) The CI workflow in `.github/workflows/catalogs.yml`.
60-
- (online providers) The default catalog in `src/gpuhunt/_internal/default.py`.
69+
- (online providers) `ONLINE_PROVIDER_MODULES` in `src/gpuhunt/_internal/default.py`, which is what
70+
`default_catalog()` loads.
6171

6272
### 1.5. Add data quality tests
6373

contributing/GPUHUNT.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44

55
An offer is a possible configuration. It consists of:
66
- Provider (or backend in dstack)
7+
- CPU architecture
78
- CPU count
89
- RAM size
910
- Disk size
1011
- GPU count
12+
- GPU vendor (if any)
1113
- GPU model name (if any)
1214
- GPU VRAM size (if any)
1315
- Is interruptible (or spot)
1416
- Region (provider-specific)
1517
- Instance name or ID (provider-specific)
1618
- Price per hour
1719

20+
Offers are represented by `CatalogItem`. Providers construct them directly, setting `provider` to
21+
their own `NAME`, and `gpu_vendor` whenever `gpu_count` is non-zero.
22+
1823
## Catalog
1924

2025
Some providers don't have a suitable API for querying all offers in real-time. That's why gpuhunt has two types of providers:
2126

22-
- Online — offers can be queried in real-time
27+
- Online — offers can be queried quickly in real-time
2328
- Offline — offers must be loaded from a precomputed catalog file
2429

2530
The `Catalog` class hides those details from the user, reading offers from the file for offline providers or querying online providers.
@@ -28,7 +33,16 @@ The `Catalog` class pulls the latest catalog from the S3 bucket and caches it fo
2833

2934
## Provider implementation
3035

31-
Providers must implement a single method `get`. It has the same name for both online and offline providers but works differently.
36+
Providers subclass either `OnlineProvider` or `OfflineProvider` from `src/gpuhunt/providers/base.py`.
37+
38+
Both implement `get`. It has the same name for both online and offline providers but works differently.
39+
40+
In addition:
41+
42+
- Online providers implement the `from_env` classmethod, since `default_catalog()` constructs them
43+
in the user's process.
44+
- Offline providers may override `filter` to omit some offers from the published catalog.
45+
Credentials are passed in by the caller, so a missing one is an error rather than a skip.
3246

3347
### Offers sorting
3448

@@ -100,7 +114,7 @@ These mechanisms are used to preserve backward compatibility:
100114

101115
- **`gpuhunt` version**: The interfaces in the `gpuhunt` package preserve backward compatibility
102116
within a minor version (`X` in `0.X.Y`).
103-
- **Offer flags**: If an offer breaks older `dstack` versions, it is marked with a flag in `RawCatalogItem.flags`
117+
- **Offer flags**: If an offer breaks older `dstack` versions, it is marked with a flag in `CatalogItem.flags`
104118
and the flag is added to the list of supported flags in `dstack`.
105119
Older `dstack` versions that don't support this flag will not see the respective offers.
106120
- **Offline catalog versions**: If a breaking change in the structure or content of an offline catalog is unavoidable,

0 commit comments

Comments
 (0)