Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/docs/concepts/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -1211,4 +1211,23 @@ projects:

</div>

??? info "Community Cloud"
By default, `dstack` includes both Server Cloud (datacenter) and Community Cloud offers.
To restrict offers to Server Cloud only, set `community_cloud: false` in the backend settings.

<div editor-title="~/.dstack/server/config.yml">

```yaml
projects:
- name: main
backends:
- type: vastai
creds:
type: api_key
api_key: d75789f22f1908e0527c78a283b523dd73051c8c7d05456516fc91e9d4efd8c5
community_cloud: false
```

</div>

Also, the `vastai` backend supports on-demand instances only. Spot instance support coming soon.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ignore-case = true

[tool.uv.sources]
dstack-plugin-server = { path = "examples/plugins/example_plugin_server", editable = true }
gpuhunt = { git = "https://github.com/dstackai/gpuhunt.git", branch = "feat/vastai-community-default" }

[tool.ruff]
target-version = "py39"
Expand Down
3 changes: 2 additions & 1 deletion src/dstack/_internal/core/backends/vastai/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def __init__(self, config: VastAIConfig):
self.catalog = gpuhunt.Catalog(balance_resources=False, auto_reload=False)
self.catalog.add_provider(
VastAIProvider(
community_cloud=config.allow_community_cloud,
extra_filters={
"direct_port_count": {"gte": 1},
"reliability2": {"gte": 0.9},
"inet_down": {"gt": 128},
"verified": {"eq": True},
"cuda_max_good": {"gte": 12.8},
"compute_cap": {"gte": 600},
}
},
)
)

Expand Down
19 changes: 19 additions & 0 deletions src/dstack/_internal/core/backends/vastai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

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


class VastAIAPIKeyCreds(CoreModel):
type: Annotated[Literal["api_key"], Field(description="The type of credentials")] = "api_key"
Expand All @@ -20,6 +24,15 @@ class VastAIBackendConfig(CoreModel):
Optional[List[str]],
Field(description="The list of VastAI regions. Omit to use all regions"),
] = None
community_cloud: Annotated[
Optional[bool],
Field(
description=(
"Whether Community Cloud offers can be suggested in addition to Server Cloud."
f" Defaults to `{str(VASTAI_COMMUNITY_CLOUD_DEFAULT).lower()}`"
)
),
] = None


class VastAIBackendConfigWithCreds(VastAIBackendConfig):
Expand All @@ -35,3 +48,9 @@ class VastAIStoredConfig(VastAIBackendConfig):

class VastAIConfig(VastAIStoredConfig):
creds: AnyVastAICreds

@property
def allow_community_cloud(self) -> bool:
if self.community_cloud is not None:
return self.community_cloud
return VASTAI_COMMUNITY_CLOUD_DEFAULT
44 changes: 44 additions & 0 deletions src/tests/_internal/core/backends/vastai/test_compute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from unittest.mock import patch

from dstack._internal.core.backends.vastai.compute import VastAICompute
from dstack._internal.core.backends.vastai.models import VastAIConfig, VastAICreds


def _config(community_cloud=None) -> VastAIConfig:
return VastAIConfig(creds=VastAICreds(api_key="test"), community_cloud=community_cloud)


def test_vastai_compute_enables_community_cloud_by_default():
with (
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
):
catalog_instance = catalog_cls.return_value
VastAICompute(_config())
vast_provider_cls.assert_called_once()
assert vast_provider_cls.call_args.kwargs["community_cloud"] is True
catalog_instance.add_provider.assert_called_once()


def test_vastai_compute_can_enable_community_cloud():
with (
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
):
catalog_instance = catalog_cls.return_value
VastAICompute(_config(community_cloud=True))
vast_provider_cls.assert_called_once()
assert vast_provider_cls.call_args.kwargs["community_cloud"] is True
catalog_instance.add_provider.assert_called_once()


def test_vastai_compute_can_disable_community_cloud():
with (
patch("dstack._internal.core.backends.vastai.compute.VastAIProvider") as vast_provider_cls,
patch("dstack._internal.core.backends.vastai.compute.gpuhunt.Catalog") as catalog_cls,
):
catalog_instance = catalog_cls.return_value
VastAICompute(_config(community_cloud=False))
vast_provider_cls.assert_called_once()
assert vast_provider_cls.call_args.kwargs["community_cloud"] is False
catalog_instance.add_provider.assert_called_once()
14 changes: 14 additions & 0 deletions src/tests/_internal/core/backends/vastai/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@


class TestVastAIConfigurator:
def test_allow_community_cloud_default(self):
config = VastAIBackendConfigWithCreds(creds=VastAICreds(api_key="valid"))
backend = VastAIConfigurator().create_backend(project_name="main", config=config)
loaded_config = VastAIConfigurator()._get_config(backend)
assert loaded_config.allow_community_cloud is True

def test_allow_community_cloud_enabled(self):
config = VastAIBackendConfigWithCreds(
creds=VastAICreds(api_key="valid"), community_cloud=True
)
backend = VastAIConfigurator().create_backend(project_name="main", config=config)
loaded_config = VastAIConfigurator()._get_config(backend)
assert loaded_config.allow_community_cloud is True

def test_validate_config_valid(self):
config = VastAIBackendConfigWithCreds(
creds=VastAICreds(api_key="valid"),
Expand Down