-
Notifications
You must be signed in to change notification settings - Fork 158
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
Make Partition into dedicated dataclass #3563
Open
mr0re1
wants to merge
1
commit into
GoogleCloudPlatform:develop
Choose a base branch
from
mr0re1:partition_class
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.
+89
−66
Open
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions
47
...ity/modules/scheduler/schedmd-slurm-gcp-v6-controller/modules/slurm_files/scripts/base.py
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2024 "Google LLC" | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Any, List, Dict | ||
|
||
from dataclasses import dataclass, field | ||
|
||
@dataclass(frozen=True) | ||
class Partition: | ||
name: str | ||
enable_job_exclusive: bool = False | ||
conf: Dict[str, Any] = field(default_factory=dict) | ||
|
||
nodesets: List[str] = field(default_factory=list) | ||
nodesets_dyn: List[str] = field(default_factory=list) | ||
nodesets_tpu: List[str] = field(default_factory=list) | ||
|
||
@property | ||
def is_tpu(self) -> bool: | ||
return len(self.nodesets_tpu) > 0 | ||
|
||
@property | ||
def any_dynamic(self) -> bool: | ||
return len(self.nodesets_dyn) > 0 | ||
|
||
@classmethod | ||
def from_json(cls, jo: dict) -> "Partition": | ||
return cls( | ||
name=jo["partition_name"], | ||
enable_job_exclusive=jo["enable_job_exclusive"], | ||
conf=jo.get("partition_conf", {}), | ||
|
||
nodesets=jo.get("nodesets", []), | ||
nodesets_dyn=jo.get("nodesets_dyn", []), | ||
nodesets_tpu=jo.get("nodesets_tpu", []), | ||
) |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import util | ||
from util import dirs, slurmdirs | ||
import tpu | ||
from base import Partition | ||
|
||
FILE_PREAMBLE = """ | ||
# Warning: | ||
|
@@ -76,13 +77,9 @@ def get(key, default): | |
for nodeset in lkp.cfg.nodeset.values() | ||
) | ||
|
||
any_tpu = any( | ||
tpu_nodeset is not None | ||
for part in lkp.cfg.partitions.values() | ||
for tpu_nodeset in part.partition_nodeset_tpu | ||
) | ||
any_tpu = any(p.is_tpu for p in lkp.partitions) | ||
any_dynamic = any(p.any_dynamic for p in lkp.partitions) | ||
|
||
any_dynamic = any(bool(p.partition_feature) for p in lkp.cfg.partitions.values()) | ||
comma_params = { | ||
"LaunchParameters": [ | ||
"enable_nss_slurm", | ||
|
@@ -180,7 +177,7 @@ def nodeset_dyn_lines(nodeset): | |
) | ||
|
||
|
||
def partitionlines(partition, lkp: util.Lookup) -> str: | ||
def partitionlines(partition: Partition, lkp: util.Lookup) -> str: | ||
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: Could we change this to |
||
"""Make a partition line for the slurm.conf""" | ||
MIN_MEM_PER_CPU = 100 | ||
|
||
|
@@ -192,32 +189,23 @@ def defmempercpu(nodeset_name: str) -> int: | |
return max(MIN_MEM_PER_CPU, (machine.memory - mem_spec_limit) // machine.cpus) | ||
|
||
defmem = min( | ||
map(defmempercpu, partition.partition_nodeset), default=MIN_MEM_PER_CPU | ||
) | ||
|
||
nodesets = list( | ||
chain( | ||
partition.partition_nodeset, | ||
partition.partition_nodeset_dyn, | ||
partition.partition_nodeset_tpu, | ||
) | ||
map(defmempercpu, partition.nodesets), default=MIN_MEM_PER_CPU | ||
) | ||
|
||
is_tpu = len(partition.partition_nodeset_tpu) > 0 | ||
is_dyn = len(partition.partition_nodeset_dyn) > 0 | ||
nodesets = list(chain(partition.nodesets, partition.nodesets_dyn, partition.nodesets_tpu)) | ||
|
||
oversub_exlusive = partition.enable_job_exclusive or is_tpu | ||
power_down_on_idle = partition.enable_job_exclusive and not is_dyn | ||
oversub_exlusive = partition.enable_job_exclusive or partition.is_tpu | ||
power_down_on_idle = partition.enable_job_exclusive and not partition.any_dynamic | ||
|
||
line_elements = { | ||
"PartitionName": partition.partition_name, | ||
"PartitionName": partition.name, | ||
"Nodes": ",".join(nodesets), | ||
"State": "UP", | ||
"DefMemPerCPU": defmem, | ||
"SuspendTime": 300, | ||
"Oversubscribe": "Exclusive" if oversub_exlusive else None, | ||
"PowerDownOnIdle": "YES" if power_down_on_idle else None, | ||
**partition.partition_conf, | ||
**partition.conf, | ||
} | ||
|
||
return dict_to_conf(line_elements) | ||
|
@@ -231,12 +219,8 @@ def suspend_exc_lines(lkp: util.Lookup) -> Iterable[str]: | |
static_nodelists.append(nodelist) | ||
suspend_exc_nodes = {"SuspendExcNodes": static_nodelists} | ||
|
||
dyn_parts = [ | ||
p.partition_name | ||
for p in lkp.cfg.partitions.values() | ||
if len(p.partition_nodeset_dyn) > 0 | ||
] | ||
suspend_exc_parts = {"SuspendExcParts": [*dyn_parts]} | ||
dyn_parts = [p.name for p in lkp.partitions if p.any_dynamic] | ||
suspend_exc_parts = {"SuspendExcParts": dyn_parts} | ||
|
||
return filter( | ||
None, | ||
|
@@ -255,7 +239,7 @@ def make_cloud_conf(lkp: util.Lookup) -> str: | |
*(nodeset_lines(n, lkp) for n in lkp.cfg.nodeset.values()), | ||
*(nodeset_dyn_lines(n) for n in lkp.cfg.nodeset_dyn.values()), | ||
*(nodeset_tpu_lines(n, lkp) for n in lkp.cfg.nodeset_tpu.values()), | ||
*(partitionlines(p, lkp) for p in lkp.cfg.partitions.values()), | ||
*(partitionlines(p, lkp) for p in lkp.partitions), | ||
*(suspend_exc_lines(lkp)), | ||
] | ||
return "\n\n".join(filter(None, lines)) | ||
|
@@ -341,11 +325,7 @@ def install_cgroup_conf(lkp: util.Lookup) -> None: | |
|
||
def install_jobsubmit_lua(lkp: util.Lookup) -> None: | ||
"""install job_submit.lua if there are tpu nodes in the cluster""" | ||
if not any( | ||
tpu_nodeset is not None | ||
for part in lkp.cfg.partitions.values() | ||
for tpu_nodeset in part.partition_nodeset_tpu | ||
): | ||
if not any(p.is_tpu for p in lkp.partitions): | ||
return # No TPU partitions, no need for job_submit.lua | ||
|
||
scripts_dir = lkp.cfg.slurm_scripts_dir or dirs.scripts | ||
|
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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
import unittest | ||
import tempfile | ||
|
||
from common import TstCfg, TstNodeset, TstPartition, TstTPU # needed to import util | ||
from common import TstCfg, TstNodeset, TstTPU # needed to import util | ||
import util | ||
import resume | ||
from resume import ResumeData, ResumeJobData, BulkChunk, PlacementAndNodes | ||
|
@@ -74,11 +74,11 @@ def test_group_nodes_bulk(mock_create_placements, mock_tpu): | |
"t": TstNodeset(nodeset_name="t"), | ||
}, | ||
partitions={ | ||
"p1": TstPartition( | ||
"p1": dict( | ||
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. Why not use the Partition class? |
||
partition_name="p1", | ||
enable_job_exclusive=True, | ||
), | ||
"p2": TstPartition( | ||
"p2": dict( | ||
partition_name="p2", | ||
partition_nodeset_tpu=["t"], | ||
enable_job_exclusive=True, | ||
|
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: I'd probably name it something like
has_dynamic