Clusterscope Documentation
website·Indexed 30 days ago
https://facebookresearch.github.io/clusterscope/A CLI and Python library designed to extract cluster information and enable cluster-agnostic design. It provides tools to detect cluster capabilities, identify Slurm versions, and manage GPU/CPU resources, including utilities like cscope-job-gen for generating GPU and CPU jobs and functions to retrieve memory, CPU counts, and temporary directories.
What's inside Clusterscope
- Clusterscope provides a cluster-agnostic design that allows users to 'write once, run anywhere' by automatically detecting cluster capabilities. This ensures high portability across heterogeneous computing environments, removing the need for users to manually handle specific HPC cluster operations or write environment-specific job submissions.
Inspect available GPUs using cscope gpus
Thecscope gpuscommand displays information about available GPUs. When executed on a Slurm cluster, it provides details for every partition; otherwise, it defaults to the local node. By default, it outputs the GPU generation, count, vendor, and the associated Slurm partition.$ cscope gpus GPU Gen, GPU Count, GPU Vendor, Slurm Partition: h100, 8, nvidia, h100 h200, 8, nvidia, h200Get local node GPU generation and count
Use theclusterscope.local_node_gpu_generation_and_count()function to retrieve information about the GPUs on the local node. This function returns either a singleGPUInfoinstance or a list ofGPUInfoinstances containing details such as the GPU generation, the number of GPUs, the vendor, and the partition.import clusterscope gpu_info = clusterscope.local_node_gpu_generation_and_count() print(gpu_info) # Example Output: GPUInfo(gpu_gen='H100', gpu_count=8, vendor='nvidia', partition=None)Retrieve system memory information using clusterscope.mem()
The
clusterscope.mem()function provides information about available system memory. Its behavior depends on the environment:- Slurm Cluster: Returns a list of
MemInfoobjects, one for each available partition. - Local Node: Returns a single
MemInfoinstance for the local node (wherepartitionisNone).
The
MemInfoobject contains the following attributes:mem_total_MB: Total memory in Megabytes.mem_total_GB: Total memory in Gigabytes.partition: The name of the Slurm partition, orNoneif not applicable.
import clusterscope # Get memory info for all partitions (if on Slurm) or local node mem_info = clusterscope.mem() print(mem_info)- Slurm Cluster: Returns a list of
Retrieve available CPU core information using cpus()
The
clusterscope.cpus()function returns information about the number of CPU cores available in the system.- On a Slurm Cluster: It returns a list of
CPUInfoobjects, one for each available partition. - On a Local Node (Non-Slurm): It returns a single
CPUInfoinstance where thepartitionattribute isNone.
Note: To find CPUs specifically assigned to a current job rather than total system availability, use
get_job().import clusterscope # Get all available CPU info cpu_info = clusterscope.cpus() print(cpu_info) # Example Slurm output: [CPUInfo(cpu_count=192, partition='cpu'), ...] # Example Local output: CPUInfo(cpu_count=16, partition=None)- On a Slurm Cluster: It returns a list of
Configure pre-commit hooks for ClusterScope
ClusterScope usespre-committo integrate linters, formatters, and typecheckers. These checks are also enforced via GitHub CI. To automate these checks locally before committing code, install the pre-commit hooks.pre-commit installUpdate ClusterScope project dependencies
When adding new dependencies, first add them to the appropriate section in thepyproject.tomlfile. Then, regenerate the requirements files using the provided make targets.# Update the standard requirements file make requirements.txt # Update the development requirements file make dev-requirements.txtGenerate Slurm job requirements using cscope job-gen
Thecscope job-gen task slurmcommand calculates the proportionate amount of CPUs and Memory to allocate for a Slurm job based on the available resources in a specified partition. Users only need to specify either the number of GPUs or CPUs per task; the tool automatically derives the corresponding memory and CPU requirements.# Example: Request 4 GPUs in the h100 partition with slurm_cli output $ cscope job-gen task slurm --partition=h100 --gpus-per-task=4 --format=slurm_cliInstall Clusterscope via pip
Clusterscope is a CLI and Python library used to extract information from HPC Clusters and Jobs. It can be installed using pip.pip install clusterscopeSubmit a Pull Request to ClusterScope
To contribute code to ClusterScope, follow these steps:
- Fork the repository and create a feature branch from
main. - Add suitable tests for any new code.
- Verify that the test suite and linting checks pass.
- Complete the Contributor License Agreement (CLA) at https://code.facebook.com/cla (required once for all Facebook open source projects).
- Fork the repository and create a feature branch from
Retrieve current job metadata using get_job
Useclusterscope.get_job()to obtain a job object that provides methods for querying the current execution environment, such as CPU/GPU counts, job IDs, and distributed training ranks.import clusterscope job = clusterscope.get_job()Set up the ClusterScope development environment
To set up the development environment, install the required dependencies usinguvand install ClusterScope in editable mode from the root of the repository. Once installed, you can activate the environment to access theclusterscopelibrary and thecscopeCLI tool.# Install development requirements and clusterscope in editable mode make install-dev-requirements # Activate the environment source <(make activate)