-
Notifications
You must be signed in to change notification settings - Fork 312
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
[develop] Introduce InstanceRequirements schema and resource #5419
Draft
NSsirena
wants to merge
5
commits into
aws:develop
Choose a base branch
from
NSsirena:wip/instance-requirements
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7c9269
Add classes for InstanceRequirements definition
NSsirena 5da9262
Add schema classes for InstanceRequirements
NSsirena 070defe
Add tests for InstanceRequirements schema
NSsirena fc97ed6
Update Changelog
NSsirena 2a45dac
Add logic to list instance-types matching Requirement set
NSsirena 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 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 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 |
---|---|---|
|
@@ -487,3 +487,21 @@ def run_instances(self, **kwargs): | |
except ClientError as e: | ||
if e.response.get("Error").get("Code") != "DryRunOperation": | ||
raise | ||
|
||
@AWSExceptionHandler.handle_client_exception | ||
@Cache.cached | ||
def get_instance_types_from_instance_requirements( | ||
self, instance_requirements: str, architecture: str = "x86_64" | ||
) -> List[str]: | ||
"""Get list of instance types matching a set of instance_requirements.""" | ||
config = { | ||
"ArchitectureTypes": [architecture], | ||
"VirtualizationTypes": ["hvm"], | ||
"InstanceRequirements": instance_requirements, | ||
} | ||
|
||
response = self._client.get_instance_types_from_instance_requirements(config) | ||
if "InstanceTypes" in response: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you could write: instance_types = response.get("InstanceTypes", [])
return [res.get("InstanceType") for res in instance_types] or: return [instance_types.get("InstanceType") for instance_types in response.get("InstanceTypes", [])] |
||
return [res["InstanceType"] for res in response["InstanceTypes"]] | ||
else: | ||
return [] |
This file contains 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 |
---|---|---|
|
@@ -2167,6 +2167,133 @@ def max_network_interface_count(self) -> int: | |
return least_max_nics | ||
|
||
|
||
class InstanceRequirementsDefinition(Resource): | ||
"""Collects the attributes required to define a Slurm Compute Resource through Instance Requirements.""" | ||
|
||
def __init__( | ||
self, | ||
min_vcpus, | ||
min_memory_mib, | ||
max_vcpus=0, | ||
max_memory_mib=0, | ||
accelerator_count=0, | ||
max_price_percentage=50, | ||
allowed_instance_types: List[str] = None, | ||
excluded_instance_types: List[str] = None, | ||
accelerator_types: List[str] = None, | ||
accelerator_manufacturers: List[str] = None, | ||
bare_metal: List[str] = None, | ||
instance_generations: List[str] = None, | ||
**kwargs, | ||
): | ||
super().__init__(**kwargs) | ||
self.min_vcpus = Resource.init_param(min_vcpus) | ||
self.max_vcpus = Resource.init_param(max_vcpus) | ||
self.min_memory_mib = Resource.init_param(min_memory_mib) | ||
self.max_memory_mib = Resource.init_param(max_memory_mib) | ||
self.accelerator_count = Resource.init_param(accelerator_count) | ||
self.max_price_percentage = Resource.init_param(max_price_percentage) | ||
self.allowed_instance_types = Resource.init_param(allowed_instance_types) | ||
self.excluded_instance_types = Resource.init_param(excluded_instance_types) | ||
self.bare_metal = bare_metal | ||
self.instance_generations = instance_generations | ||
self.accelerator_types = accelerator_types | ||
self.accelerator_manufacturers = accelerator_manufacturers | ||
# Enforce desired default behavior | ||
if self.accelerator_count > 0: | ||
self.accelerator_types = ["gpu"] | ||
self.accelerator_manufacturers = ["nvidia"] | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you're forcing a specific behaviour you can avoid the set in the previous lines, that is useless: self.accelerator_types = accelerator_types
self.accelerator_manufacturers = accelerator_manufacturers |
||
self.accelerator_types = None | ||
self.accelerator_manufacturers = None | ||
|
||
def _vcpu_config(self): | ||
config = { | ||
"Min": self.min_vcpus, | ||
} | ||
if self.max_vcpus > 0: | ||
config["Max"] = self.max_vcpus | ||
|
||
return config | ||
|
||
def _mem_config(self): | ||
config = { | ||
"Min": self.min_memory_mib, | ||
} | ||
if self.max_memory_mib > 0: | ||
config["Max"] = self.max_memory_mib | ||
|
||
return config | ||
|
||
def config(self): | ||
"""Compiles an InstanceRequirement config to retrieve the list of matching instance-types.""" | ||
config = { | ||
"VCpuCount": self._vcpu_config(), | ||
"MemoryMiB": self._mem_config(), | ||
"InstanceGenerations": self.instance_generations, | ||
"BareMetal": self.bare_metal, | ||
"MaxPricePercentageOverLowestPrice": self.bare_metal, | ||
} | ||
|
||
if self.accelerator_count > 0: | ||
config["AcceleratorCount"] = self.accelerator_count | ||
config["AcceleratorTypes"] = self.accelerator_types | ||
config["AcceleratorManufacturers"] = self.max_price_percentage | ||
|
||
if self.allowed_instance_types: | ||
config["AllowedInstanceTypes"] = self.allowed_instance_types | ||
elif self.excluded_instance_types: | ||
config["AllowedInstanceTypes"] = self.allowed_instance_types | ||
|
||
return config | ||
|
||
|
||
class InstanceRequirementsComputeResource(_BaseSlurmComputeResource): | ||
"""Represents a Slurm Compute Resource defined through Instance Requirements.""" | ||
|
||
def __init__( | ||
self, | ||
instance_requirements: InstanceRequirementsDefinition, | ||
**kwargs, | ||
): | ||
super().__init__(**kwargs) | ||
self.instance_requirements = Resource.init_param(instance_requirements) | ||
self.instance_type_list = None | ||
|
||
@property | ||
def disable_simultaneous_multithreading_manually(self) -> bool: | ||
"""Return true if simultaneous multithreading must be disabled with a cookbook script.""" | ||
return self.disable_simultaneous_multithreading | ||
|
||
@property | ||
def max_network_interface_count(self) -> int: | ||
"""Return max number of NICs for the compute resource. | ||
|
||
Currently customers are not allowed to specify 'NetworkInterfaceCount' as requirement so this method is | ||
a placeholder for future improvements. | ||
An implementation is required since it is an abstract method of the base class. | ||
It is meant to be used in the validators. | ||
For MVP the validator will list the instance types returned by CreateFlet and pick the minimum common value. | ||
""" | ||
return 1 | ||
|
||
def get_matching_instance_type_list(self, architecture): | ||
"""Return the list of instance types matching the Requirements for a given architecture.""" | ||
# TODO add a mechanism to discover the architecture at ComputeResource level | ||
# it should get the HeadNode architecture that wins over the CR config | ||
# Currently we receive if from the outside (Validator) and delegate the burden to it | ||
if self.instance_type_list is None: | ||
self.instance_type_list = AWSApi.instance().ec2.get_instance_types_from_instance_requirements( | ||
self.instance_requirements.config(), architecture | ||
) | ||
return self.instance_type_list | ||
|
||
@property | ||
def instance_types(self) -> List[str]: | ||
"""Should Return list of instance type names in this compute resource.""" | ||
return self.instance_type_list | ||
|
||
|
||
class SlurmComputeResource(_BaseSlurmComputeResource): | ||
"""Represents a Slurm Compute Resource with a Single Instance Type.""" | ||
|
||
|
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
InstanceRequirements