Skip to content
Open
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
19 changes: 19 additions & 0 deletions clusterscope/job_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from functools import lru_cache

from clusterscope.cluster_info import LocalNodeInfo

MIN_MASTER_PORT, MAX_MASTER_PORT = (20_000, 60_000)


Expand Down Expand Up @@ -40,6 +42,23 @@ def __init__(self):
self.world_size = self.get_world_size()
self.is_rank_zero = self.get_is_rank_zero()

@lru_cache(maxsize=1)
def get_cpus(self) -> int:
if self.is_slurm_job():
return int(os.environ.get("SLURM_CPUS_ON_NODE", 1))
return int(max(os.cpu_count() or 0, 1))

@lru_cache(maxsize=1)
def get_gpus(self) -> int:
if self.is_slurm_job():
return int(os.environ.get("SLURM_GPUS_ON_NODE", 1))
return sum(
Comment on lines +48 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intent of the ask?

Is it to know how many GPUs/CPUs are "present" on the node or "allocated" to this job?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocated to the job if slurm job, otherwise what's present in the node

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I may, I think we should stick to a clear and limited contract for an API - If we want to return GPUs allocated to a job for a given API let's stick to that. I don't see benefits in either allocated or provisioned GPU count coming via the same API.

Copy link
Member Author

@luccabb luccabb Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skalyan I think this is fine for now, it matches how other methods from this class behaves. I'm up to change position here as we see how it gets used

[
int(count)
for gpu, count in LocalNodeInfo().get_gpu_generation_and_count().items()
]
)

@lru_cache(maxsize=1)
def get_job_id(self) -> int:
if self.is_slurm_job():
Expand Down