quickstart.gpu_config#

GPU configuration helpers for quickstart: detection, CUDA_VISIBLE_DEVICES filtering, and string parsing.

Module Contents#

Functions#

apply_cuda_visible_devices_filter

Filter detected GPU IDs by CUDA_VISIBLE_DEVICES (integer indices only).

format_gpu_ids_for_storage

Format a list of GPU IDs as a comma-separated string for config storage.

parse_comma_separated_non_negative_integers

Parse a comma-separated string of non-negative integers (shared helper).

parse_cuda_visible_devices_integers

Parse CUDA_VISIBLE_DEVICES as comma-separated integer device IDs only.

Data#

API#

quickstart.gpu_config.CUDA_VISIBLE_DEVICES_ENV#

‘CUDA_VISIBLE_DEVICES’

quickstart.gpu_config.apply_cuda_visible_devices_filter(
detected_ids: list[int],
*,
log_exclusions: bool = True,
) list[int]#

Filter detected GPU IDs by CUDA_VISIBLE_DEVICES (integer indices only).

Uses the intersection of (parsed CUDA_VISIBLE_DEVICES) and (detected_ids), preserving the order of CUDA_VISIBLE_DEVICES. Logs any IDs from CUDA_VISIBLE_DEVICES that are not in the detected set.

If CUDA_VISIBLE_DEVICES is unset, empty, or contains non-integers, returns detected_ids unchanged.

Parameters:
  • detected_ids – Full list of autodetected GPU device IDs.

  • log_exclusions – Whether to log excluded IDs (default True).

Returns:

Filtered list of GPU IDs (order from CUDA_VISIBLE_DEVICES when applicable).

quickstart.gpu_config.format_gpu_ids_for_storage(gpu_ids: list[int]) str#

Format a list of GPU IDs as a comma-separated string for config storage.

quickstart.gpu_config.logger#

‘getLogger(…)’

quickstart.gpu_config.parse_comma_separated_non_negative_integers(
value: str,
) list[int] | None#

Parse a comma-separated string of non-negative integers (shared helper).

Used by both quickstart config parsing and CUDA_VISIBLE_DEVICES parsing. Returns None if the string is empty/whitespace-only, has no tokens, or any token is not a non-negative integer.

Parameters:

value – Comma-separated string (e.g. “0,2,1” or “0, 2, 1”).

Returns:

List of integer device IDs in order, or None if invalid.

quickstart.gpu_config.parse_cuda_visible_devices_integers(value: str) list[int] | None#

Parse CUDA_VISIBLE_DEVICES as comma-separated integer device IDs only.

Only integer indices are supported. If any token is not a non-negative integer, returns None (caller should use full detected list and optionally log).

Parameters:

value – Raw env value (e.g. “0,2,1” or “0, 2, 1”).

Returns:

List of integer device IDs in order, or None if any token is non-integer.