feat: warn when SLURM ranks double count a node - #1390
davidberenstein1957 wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1390 +/- ##
==========================================
+ Coverage 91.43% 91.71% +0.28%
==========================================
Files 49 50 +1
Lines 5057 5169 +112
==========================================
+ Hits 4624 4741 +117
+ Misses 433 428 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
10815c4 to
cfd15f4
Compare
cfd15f4 to
89b00c5
Compare
With several ranks per node and tracking_mode="machine", every rank measures the whole node, so the job's reported footprint is silently multiplied by the rank count. Read SLURM_NTASKS_PER_NODE at tracker init and say so, since a docs warning does not catch anyone. Split out of #1366, where it was unrelated scope. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
89b00c5 to
dae06ff
Compare
Verdict: 🔧 Request changesThe hazard is real. Must fix:
Low: Tests:
|
…node Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Description
On SLURM,
srun --ntasks-per-node=4starts four ranks on one node. Withtracking_mode="machine"(the default), each of those four trackers measures the whole node, so the job's reported total is silently 4x the true value and nothing in the output flags it. This PR addscodecarbon/core/slurm.py, which runs at tracker init and, inmachinemode on a non-zeroSLURM_LOCALID, logs a warning naming two ways out: start the tracker only onSLURM_LOCALID == 0, or switch totracking_mode="process". The message includes the step's tasks-per-node (SLURM_STEP_TASKS_PER_NODE, falling back toSLURM_TASKS_PER_NODE). Local rank 0, and the batch step whereSLURM_LOCALIDis unset, never warn. Split out of #1366, which mixed this in with unrelated job-metadata-column work.Related Issue
N/A
Motivation and Context
Multi-rank SLURM jobs using the default machine-tracking mode silently overcount emissions by the rank count, and nothing in the current output tells the user this is happening. A warning at init lets users catch and correct the setup before trusting the numbers.
How Has This Been Tested?
tests/test_slurm.py: warns on non-zero local rank (step and job tasks-per-node vars,4(x2)); silent for local rank 0, the batch step, no SLURM env, andtracking_mode="process"; one test throughOfflineEmissionsTracker.__init__.Screenshots (if appropriate):
N/A
Types of changes
AI Usage Disclosure
Checklist:
Not in this PR
Automatic rank election (e.g. suppressing extra trackers) is deferred; it is the same problem as
LOCAL_RANK == 0in distributed training and deserves one generic solution, not a SLURM-specific one. This PR is the warning only.