From 09c883db90a230e8f0fb5cf099680666ae479427 Mon Sep 17 00:00:00 2001 From: "Alexander Nicholson 4584443+DragonStuff@users.noreply.github.com" <4584443+DragonStuff@users.noreply.github.com> Date: Wed, 15 Oct 2025 13:51:25 +0900 Subject: [PATCH 1/3] feat(VastAICompute): add support for region --- src/dstack/_internal/core/backends/vastai/compute.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dstack/_internal/core/backends/vastai/compute.py b/src/dstack/_internal/core/backends/vastai/compute.py index b019fbb9b..ed350cfe7 100644 --- a/src/dstack/_internal/core/backends/vastai/compute.py +++ b/src/dstack/_internal/core/backends/vastai/compute.py @@ -58,6 +58,7 @@ def get_offers_by_requirements( ) -> List[InstanceOfferWithAvailability]: offers = get_catalog_offers( backend=BackendType.VASTAI, + locations=self.config.regions or None, requirements=requirements, # TODO(egor-s): spots currently not supported extra_filter=lambda offer: not offer.instance.resources.spot, From 0ba98a292a5ca166e0c980612268a062bb09e7c0 Mon Sep 17 00:00:00 2001 From: "Alexander Nicholson 4584443+DragonStuff@users.noreply.github.com" <4584443+DragonStuff@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:10:45 +0900 Subject: [PATCH 2/3] fix(VastAICompute): use iso country code in offer --- .../_internal/core/backends/vastai/compute.py | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/dstack/_internal/core/backends/vastai/compute.py b/src/dstack/_internal/core/backends/vastai/compute.py index ed350cfe7..ff5c98049 100644 --- a/src/dstack/_internal/core/backends/vastai/compute.py +++ b/src/dstack/_internal/core/backends/vastai/compute.py @@ -56,12 +56,46 @@ def __init__(self, config: VastAIConfig): def get_offers_by_requirements( self, requirements: Requirements ) -> List[InstanceOfferWithAvailability]: + def spot_filter(offer): + return not offer.instance.resources.spot + + extra_filter = spot_filter + + configured_regions = self.config.regions or [] + if configured_regions: + normalized_exact_regions = { + r.strip() for r in configured_regions if isinstance(r, str) and r.strip() + } + iso_country_codes = { + r.strip().upper() + for r in configured_regions + if isinstance(r, str) and len(r.strip()) == 2 and r.strip().isalpha() + } + + def region_accepts(offer): + region_value = (offer.region or "").strip() + if not region_value: + return False + if region_value in normalized_exact_regions: + return True + if "," in region_value: + trailing_code = region_value.split(",")[-1].strip().upper() + if trailing_code in iso_country_codes: + return True + if len(region_value) == 2 and region_value.isalpha() and region_value.upper() in iso_country_codes: + return True + return False + + def combined_filter(offer): + return spot_filter(offer) and region_accepts(offer) + + extra_filter = combined_filter + offers = get_catalog_offers( backend=BackendType.VASTAI, - locations=self.config.regions or None, requirements=requirements, # TODO(egor-s): spots currently not supported - extra_filter=lambda offer: not offer.instance.resources.spot, + extra_filter=extra_filter, catalog=self.catalog, ) offers = [ From 0c9ac39403deb596fbc25dba301c34144562e7de Mon Sep 17 00:00:00 2001 From: "Alexander Nicholson 4584443+DragonStuff@users.noreply.github.com" <4584443+DragonStuff@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:27:40 +0900 Subject: [PATCH 3/3] Revert "fix(VastAICompute): use iso country code in offer" This reverts commit 0ba98a292a5ca166e0c980612268a062bb09e7c0. --- .../_internal/core/backends/vastai/compute.py | 38 +------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/dstack/_internal/core/backends/vastai/compute.py b/src/dstack/_internal/core/backends/vastai/compute.py index ff5c98049..ed350cfe7 100644 --- a/src/dstack/_internal/core/backends/vastai/compute.py +++ b/src/dstack/_internal/core/backends/vastai/compute.py @@ -56,46 +56,12 @@ def __init__(self, config: VastAIConfig): def get_offers_by_requirements( self, requirements: Requirements ) -> List[InstanceOfferWithAvailability]: - def spot_filter(offer): - return not offer.instance.resources.spot - - extra_filter = spot_filter - - configured_regions = self.config.regions or [] - if configured_regions: - normalized_exact_regions = { - r.strip() for r in configured_regions if isinstance(r, str) and r.strip() - } - iso_country_codes = { - r.strip().upper() - for r in configured_regions - if isinstance(r, str) and len(r.strip()) == 2 and r.strip().isalpha() - } - - def region_accepts(offer): - region_value = (offer.region or "").strip() - if not region_value: - return False - if region_value in normalized_exact_regions: - return True - if "," in region_value: - trailing_code = region_value.split(",")[-1].strip().upper() - if trailing_code in iso_country_codes: - return True - if len(region_value) == 2 and region_value.isalpha() and region_value.upper() in iso_country_codes: - return True - return False - - def combined_filter(offer): - return spot_filter(offer) and region_accepts(offer) - - extra_filter = combined_filter - offers = get_catalog_offers( backend=BackendType.VASTAI, + locations=self.config.regions or None, requirements=requirements, # TODO(egor-s): spots currently not supported - extra_filter=extra_filter, + extra_filter=lambda offer: not offer.instance.resources.spot, catalog=self.catalog, ) offers = [