IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python function

calculate_virtual_device_count_from_cli

calculate_virtual_device_count_from_cli()

max.driver.calculate_virtual_device_count_from_cli(*device_inputs)

source

Calculates the minimum virtual device count from raw CLI inputs (before parsing).

This helper works with the raw device input strings or lists before they’re parsed into DeviceSpec objects. Used when virtual device mode needs to be enabled before device validation occurs.

Parameters:

*device_inputs (str | list[int]) – One or more raw device inputs, either strings like gpu:0,1,2 or lists of integers like [0, 1, 2].

Returns:

the slot count implied by the highest GPU index in the raw inputs, with a floor of 1. In particular, gpu:all when accelerator_count() is 0 leaves max_gpu_id == -1 and still returns 1 (same as no GPU IDs in the CLI). That floor is for virtual-device setup; actual gpu:all with zero GPUs still fails later when device specs are built.

Return type:

max(1, max_gpu_id + 1)