-
Notifications
You must be signed in to change notification settings - Fork 205
Introduce ComputeWith classes to detect compute features #2392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
420bb92
Introduce ComputeWith classes to detect compute features
r4victor da4a169
Filter out offers based on offer.backend instead of backend.TYPE
r4victor 1dbeafb
Check backend type availability for volume and gateway configurations
r4victor 1290743
Mention ComputeWith* classes in backends guide
r4victor 0f9417b
Fixes after review
r4victor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,59 @@ | ||
| from dstack._internal.core.backends.base.compute import ( | ||
| ComputeWithCreateInstanceSupport, | ||
| ComputeWithGatewaySupport, | ||
| ComputeWithMultinodeSupport, | ||
| ComputeWithPlacementGroupSupport, | ||
| ComputeWithPrivateGatewaySupport, | ||
| ComputeWithReservationSupport, | ||
| ComputeWithVolumeSupport, | ||
| ) | ||
| from dstack._internal.core.backends.base.configurator import Configurator | ||
| from dstack._internal.core.backends.configurators import list_available_configurator_classes | ||
| from dstack._internal.core.models.backends.base import BackendType | ||
|
|
||
| BACKENDS_WITH_MULTINODE_SUPPORT = [ | ||
| BackendType.AWS, | ||
| BackendType.AZURE, | ||
| BackendType.GCP, | ||
| BackendType.REMOTE, | ||
| BackendType.OCI, | ||
| BackendType.VULTR, | ||
| ] | ||
| BACKENDS_WITH_CREATE_INSTANCE_SUPPORT = [ | ||
| BackendType.AWS, | ||
| BackendType.DSTACK, | ||
| BackendType.AZURE, | ||
| BackendType.CUDO, | ||
| BackendType.DATACRUNCH, | ||
| BackendType.GCP, | ||
| BackendType.LAMBDA, | ||
| BackendType.OCI, | ||
| BackendType.TENSORDOCK, | ||
| BackendType.VULTR, | ||
| ] | ||
| BACKENDS_WITH_PLACEMENT_GROUPS_SUPPORT = [ | ||
| BackendType.AWS, | ||
| ] | ||
| BACKENDS_WITH_RESERVATION_SUPPORT = [ | ||
| BackendType.AWS, | ||
| ] | ||
|
|
||
| BACKENDS_WITH_GATEWAY_SUPPORT = [ | ||
| BackendType.AWS, | ||
| BackendType.AZURE, | ||
| BackendType.GCP, | ||
| BackendType.KUBERNETES, | ||
| ] | ||
| BACKENDS_WITH_PRIVATE_GATEWAY_SUPPORT = [BackendType.AWS] | ||
| BACKENDS_WITH_VOLUMES_SUPPORT = [ | ||
| BackendType.AWS, | ||
| BackendType.GCP, | ||
| BackendType.LOCAL, | ||
| BackendType.RUNPOD, | ||
| ] | ||
| def _get_backends_with_compute_feature( | ||
| configurator_classes: list[type[Configurator]], | ||
| compute_feature_class: type, | ||
| ) -> list[BackendType]: | ||
| backend_types = [] | ||
| for configurator_class in configurator_classes: | ||
| compute_class = configurator_class.BACKEND_CLASS.COMPUTE_CLASS | ||
| if issubclass(compute_class, compute_feature_class): | ||
| backend_types.append(configurator_class.TYPE) | ||
| return backend_types | ||
|
|
||
|
|
||
| _configurator_classes = list_available_configurator_classes() | ||
|
|
||
|
|
||
| # The following backend lists do not include unavailable backends (i.e. backends missing deps). | ||
| # TODO: Add LocalBackend to lists if it's enabled | ||
| BACKENDS_WITH_CREATE_INSTANCE_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithCreateInstanceSupport, | ||
| ) | ||
| BACKENDS_WITH_MULTINODE_SUPPORT = [BackendType.REMOTE] + _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithMultinodeSupport, | ||
| ) | ||
| BACKENDS_WITH_PLACEMENT_GROUPS_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithPlacementGroupSupport, | ||
| ) | ||
| BACKENDS_WITH_RESERVATION_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithReservationSupport, | ||
| ) | ||
| BACKENDS_WITH_GATEWAY_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithGatewaySupport, | ||
| ) | ||
| BACKENDS_WITH_PRIVATE_GATEWAY_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithPrivateGatewaySupport, | ||
| ) | ||
| BACKENDS_WITH_VOLUMES_SUPPORT = _get_backends_with_compute_feature( | ||
| configurator_classes=_configurator_classes, | ||
| compute_feature_class=ComputeWithVolumeSupport, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| from abc import ABC, abstractmethod | ||
| from typing import ClassVar | ||
|
|
||
| from dstack._internal.core.backends.base.compute import Compute | ||
| from dstack._internal.core.models.backends.base import BackendType | ||
|
|
||
|
|
||
| class Backend(ABC): | ||
| TYPE: BackendType | ||
| TYPE: ClassVar[BackendType] | ||
| # `COMPUTE_CLASS` is used to introspect compute features without initializing it. | ||
| COMPUTE_CLASS: ClassVar[type[Compute]] | ||
|
|
||
| @abstractmethod | ||
| def compute(self) -> Compute: | ||
| """ | ||
| Returns Compute instance. | ||
| """ | ||
| pass |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.