Skip to content

Commit fc914c3

Browse files
authored
Do not filter by fleet in filter_instances() (#3674)
Motivation: - Simplify the implementation and improve the performance of the upcoming `<project>/<fleet>` syntax in the `fleets` property. Filtering by fleet in `filter_instance()` would require loading the project from the database for each fleet in order to support filtering by `<project>/<fleet>`. - Make the behavior of `dstack offer --fleet` consistent for idle instances and backend offers, by ignoring `--fleet` for both. At least as a temporary solution, until we support filtering backend offers by `--fleet`. Apart from `dstack offer`, there is no other impact of this change for end users. In all other cases when `filter_instances()` is called, filtering by fleet is actually redundant — either because the instances are already pre-filtered by `select_run_candidate_fleet_models_with_filters`, or because `profile.fleets` is guaranteed to be `None` (the case for autocreated fleets).
1 parent 8657913 commit fc914c3

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/dstack/_internal/cli/commands/offer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
from dstack._internal.core.models.configurations import ApplyConfigurationType, TaskConfiguration
1616
from dstack._internal.core.models.gpus import GpuGroup
1717
from dstack._internal.core.models.runs import RunSpec
18+
from dstack._internal.utils.logging import get_logger
1819
from dstack.api.utils import load_profile
1920

21+
logger = get_logger(__name__)
22+
2023

2124
class OfferConfigurator(BaseRunConfigurator):
2225
TYPE = ApplyConfigurationType.TASK
@@ -74,6 +77,11 @@ def _register(self):
7477

7578
def _command(self, args: argparse.Namespace):
7679
super()._command(args)
80+
if args.fleets:
81+
logger.warning(
82+
"Specifying `--fleet` in `dstack offer` has no defined effect"
83+
" and may be disallowed in a future release"
84+
)
7785
# Set image and user so that the server (a) does not default gpu.vendor
7886
# to nvidia — `dstack offer` should show all vendors, and (b) does not
7987
# attempt to pull image config from the Docker registry.

src/dstack/_internal/server/services/instances.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ def filter_instances(
363363
*,
364364
requirements: Optional[Requirements] = None,
365365
status: Optional[InstanceStatus] = None,
366-
fleet_model: Optional[FleetModel] = None,
367366
multinode: bool = False,
368367
master_job_provisioning_data: Optional[JobProvisioningData] = None,
369368
volumes: Optional[List[List[Volume]]] = None,
@@ -417,12 +416,6 @@ def filter_instances(
417416
continue
418417
if instance.health.is_failure():
419418
continue
420-
if profile.fleets is not None:
421-
fleet_name = fleet_model.name if fleet_model is not None else None
422-
if fleet_name is None and instance.fleet is not None:
423-
fleet_name = instance.fleet.name
424-
if fleet_name is None or fleet_name not in profile.fleets:
425-
continue
426419
if status is not None and instance.status != status:
427420
continue
428421
jpd = get_instance_provisioning_data(instance)
@@ -467,7 +460,6 @@ def get_shared_instances_with_offers(
467460
requirements: Requirements,
468461
*,
469462
idle_only: bool = False,
470-
fleet_model: Optional[FleetModel] = None,
471463
multinode: bool = False,
472464
volumes: Optional[List[List[Volume]]] = None,
473465
) -> list[tuple[InstanceModel, InstanceOfferWithAvailability]]:
@@ -476,7 +468,6 @@ def get_shared_instances_with_offers(
476468
filtered_instances = filter_instances(
477469
instances=instances,
478470
profile=profile,
479-
fleet_model=fleet_model,
480471
multinode=multinode,
481472
volumes=volumes,
482473
shared=True,

src/dstack/_internal/server/services/runs/plan.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ def get_instance_offers_in_fleet(
484484
instances=fleet_model.instances,
485485
profile=profile,
486486
requirements=job.job_spec.requirements,
487-
fleet_model=fleet_model,
488487
multinode=multinode,
489488
master_job_provisioning_data=master_job_provisioning_data,
490489
volumes=volumes,
@@ -495,7 +494,6 @@ def get_instance_offers_in_fleet(
495494
instances=fleet_model.instances,
496495
profile=profile,
497496
requirements=job.job_spec.requirements,
498-
fleet_model=fleet_model,
499497
multinode=multinode,
500498
volumes=volumes,
501499
)

0 commit comments

Comments
 (0)