Skip to content

Commit 5ce087c

Browse files
Add community_cloud to VastAI backend (default true) (#3635)
1 parent b190ea6 commit 5ce087c

File tree

6 files changed

+99
-2
lines changed

6 files changed

+99
-2
lines changed

docs/docs/concepts/backends.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,4 +1223,23 @@ projects:
12231223

12241224
</div>
12251225

1226+
??? info "Community Cloud"
1227+
By default, `dstack` includes both Server Cloud (datacenter) and Community Cloud offers.
1228+
To restrict offers to Server Cloud only, set `community_cloud: false` in the backend settings.
1229+
1230+
<div editor-title="~/.dstack/server/config.yml">
1231+
1232+
```yaml
1233+
projects:
1234+
- name: main
1235+
backends:
1236+
- type: vastai
1237+
creds:
1238+
type: api_key
1239+
api_key: d75789f22f1908e0527c78a283b523dd73051c8c7d05456516fc91e9d4efd8c5
1240+
community_cloud: false
1241+
```
1242+
1243+
</div>
1244+
12261245
Also, the `vastai` backend supports on-demand instances only. Spot instance support coming soon.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"python-multipart>=0.0.16",
3333
"filelock",
3434
"psutil",
35-
"gpuhunt==0.1.18",
35+
"gpuhunt==0.1.19",
3636
"argcomplete>=3.5.0",
3737
"ignore-python>=0.2.0",
3838
"orjson",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ def __init__(self, config: VastAIConfig):
4343
self.catalog = gpuhunt.Catalog(balance_resources=False, auto_reload=False)
4444
self.catalog.add_provider(
4545
VastAIProvider(
46+
community_cloud=config.allow_community_cloud,
4647
extra_filters={
4748
"direct_port_count": {"gte": 1},
4849
"reliability2": {"gte": 0.9},
4950
"inet_down": {"gt": 128},
5051
"verified": {"eq": True},
5152
"cuda_max_good": {"gte": 12.8},
5253
"compute_cap": {"gte": 600},
53-
}
54+
},
5455
)
5556
)
5657

src/dstack/_internal/core/backends/vastai/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from dstack._internal.core.models.common import CoreModel
66

7+
# TODO: Re-evaluate this default once Vast Server Cloud inventory improves for
8+
# CUDA-sensitive GPU families (e.g. H100 with strict cuda_max_good filtering).
9+
VASTAI_COMMUNITY_CLOUD_DEFAULT = True
10+
711

812
class VastAIAPIKeyCreds(CoreModel):
913
type: Annotated[Literal["api_key"], Field(description="The type of credentials")] = "api_key"
@@ -20,6 +24,15 @@ class VastAIBackendConfig(CoreModel):
2024
Optional[List[str]],
2125
Field(description="The list of VastAI regions. Omit to use all regions"),
2226
] = None
27+
community_cloud: Annotated[
28+
Optional[bool],
29+
Field(
30+
description=(
31+
"Whether Community Cloud offers can be suggested in addition to Server Cloud."
32+
f" Defaults to `{str(VASTAI_COMMUNITY_CLOUD_DEFAULT).lower()}`"
33+
)
34+
),
35+
] = None
2336

2437

2538
class VastAIBackendConfigWithCreds(VastAIBackendConfig):
@@ -35,3 +48,9 @@ class VastAIStoredConfig(VastAIBackendConfig):
3548

3649
class VastAIConfig(VastAIStoredConfig):
3750
creds: AnyVastAICreds
51+
52+
@property
53+
def allow_community_cloud(self) -> bool:
54+
if self.community_cloud is not None:
55+
return self.community_cloud
56+
return VASTAI_COMMUNITY_CLOUD_DEFAULT
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from unittest.mock import patch
2+
3+
from dstack._internal.core.backends.vastai.compute import VastAICompute
4+
from dstack._internal.core.backends.vastai.models import VastAIConfig, VastAICreds
5+
6+
7+
def _config(community_cloud=None) -> VastAIConfig:
8+
return VastAIConfig(creds=VastAICreds(api_key="test"), community_cloud=community_cloud)
9+
10+
11+
def test_vastai_compute_enables_community_cloud_by_default():
12+
with (
13+
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
14+
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
15+
):
16+
catalog_instance = catalog_cls.return_value
17+
VastAICompute(_config())
18+
vast_provider_cls.assert_called_once()
19+
assert vast_provider_cls.call_args.kwargs["community_cloud"] is True
20+
catalog_instance.add_provider.assert_called_once()
21+
22+
23+
def test_vastai_compute_can_enable_community_cloud():
24+
with (
25+
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
26+
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
27+
):
28+
catalog_instance = catalog_cls.return_value
29+
VastAICompute(_config(community_cloud=True))
30+
vast_provider_cls.assert_called_once()
31+
assert vast_provider_cls.call_args.kwargs["community_cloud"] is True
32+
catalog_instance.add_provider.assert_called_once()
33+
34+
35+
def test_vastai_compute_can_disable_community_cloud():
36+
with (
37+
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
38+
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
39+
):
40+
catalog_instance = catalog_cls.return_value
41+
VastAICompute(_config(community_cloud=False))
42+
vast_provider_cls.assert_called_once()
43+
assert vast_provider_cls.call_args.kwargs["community_cloud"] is False
44+
catalog_instance.add_provider.assert_called_once()

src/tests/_internal/core/backends/vastai/test_configurator.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99

1010
class TestVastAIConfigurator:
11+
def test_allow_community_cloud_default(self):
12+
config = VastAIBackendConfigWithCreds(creds=VastAICreds(api_key="valid"))
13+
backend = VastAIConfigurator().create_backend(project_name="main", config=config)
14+
loaded_config = VastAIConfigurator()._get_config(backend)
15+
assert loaded_config.allow_community_cloud is True
16+
17+
def test_allow_community_cloud_enabled(self):
18+
config = VastAIBackendConfigWithCreds(
19+
creds=VastAICreds(api_key="valid"), community_cloud=True
20+
)
21+
backend = VastAIConfigurator().create_backend(project_name="main", config=config)
22+
loaded_config = VastAIConfigurator()._get_config(backend)
23+
assert loaded_config.allow_community_cloud is True
24+
1125
def test_validate_config_valid(self):
1226
config = VastAIBackendConfigWithCreds(
1327
creds=VastAICreds(api_key="valid"),

0 commit comments

Comments
 (0)