Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ pub struct Resources {
pub cpus: u32,
pub mem: String,
pub time: String,
/// `--nodes`. Defaults to 1 when unset, which emits no directive at all.
pub nodes: Option<u32>,
pub partition: Option<String>,
pub qos: Option<String>,
pub account: Option<String>,
Expand All @@ -469,8 +471,8 @@ pub struct Resources {
/// waiting for SLURM's drain detection.
pub exclude_nodes: Option<String>,
/// Escape hatch for sbatch directives the typed schema doesn't cover
/// (e.g. `--array`, `--nodes`, `--mail-type`, `--gpu-bind`). Each entry
/// is rendered verbatim as a separate `#SBATCH` line, *after* the
/// (e.g. `--array`, `--mail-type`, `--gpu-bind`). Each entry is
/// rendered verbatim as a separate `#SBATCH` line, *after* the
/// typed directives. Use this only for things labctl can't model —
/// don't override `--cpus-per-task` or `--time` here, those have
/// dedicated fields and overriding them confuses the dispatcher.
Expand Down Expand Up @@ -518,6 +520,7 @@ impl Default for Resources {
cpus: 1,
mem: "4GB".to_string(),
time: "00:10:00".to_string(),
nodes: None,
partition: None,
qos: None,
account: None,
Expand Down
38 changes: 38 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,9 @@ fn render_script(
if let Some(qos) = recipe.resources.qos.as_ref().or(cluster.slurm.qos.as_ref()) {
script.push_str(&format!("#SBATCH --qos={qos}\n"));
}
if let Some(nodes) = recipe.resources.nodes {
script.push_str(&format!("#SBATCH --nodes={nodes}\n"));
}
if let Some(exclude) = recipe.resources.exclude_nodes.as_ref() {
script.push_str(&format!("#SBATCH --exclude={exclude}\n"));
}
Expand Down Expand Up @@ -2115,6 +2118,41 @@ time = "12:00:00"
);
}

#[test]
fn base_resources_nodes_is_typed() {
let script = render(&format!("{BASE}nodes = 2\n"));
assert!(
script.contains("#SBATCH --nodes=2"),
"base nodes missing:\n{script}"
);
// Unset stays unset, so existing recipes render unchanged.
let plain = render(BASE);
assert!(
!plain.contains("#SBATCH --nodes"),
"unset nodes must not emit a directive:\n{plain}"
);
}

#[test]
fn base_and_component_nodes_are_independent() {
let script = render(&format!(
"{BASE}nodes = 2\n\n[[resources.components]]\ngpus = 4\ncpus = 16\nmem = \"128GB\"\nnodes = 1\n"
));
assert!(
script.contains("#SBATCH --nodes=2"),
"fleet nodes:\n{script}"
);
assert!(
script.contains("#SBATCH --nodes=1"),
"trainer nodes:\n{script}"
);
assert_eq!(
script.matches("#SBATCH --nodes=").count(),
2,
"one per component:\n{script}"
);
}

#[test]
fn components_emit_one_separator_and_own_directives() {
let script = render(&format!(
Expand Down
Loading