API Reference

class gpuparallel.GPUParallel(n_gpu=1, n_workers_per_gpu=1, init_fn: Optional[Callable] = None, progressbar=True, ignore_errors=True)[source]

Bases: object

__init__(n_gpu=1, n_workers_per_gpu=1, init_fn: Optional[Callable] = None, progressbar=True, ignore_errors=True)[source]
Parameters
  • n_gpu – Number of GPUs to use. The library doesn’t check if GPUs really available, it is simply provide consistent worker_id and gpu_id to both init_fn and task functions. n_gpu = 0 turns on synced debug mode.

  • n_workers_per_gpu – Number of workers on every GPU.

  • init_fn – Function which will be called during worker init. Function must have parameters worker_id and gpu_id (or **kwargs). Helpful to init all common stuff (e.g. neural networks) here.

  • progressbar – Allow to use tqdm progressbar.

  • ignore_errors – Either ignore errors inside tasks or raise them.

__del__()[source]

Created pool will be freed only during this destructor. This allows to use __call__ multiple times with the same initialized workers.

__call__(tasks: Iterable)List[source]

Function which submits tasks for pool and collects the results of computations.

Parameters

tasks – List or generator with callable functions to be executed. Functions must have parameters worker_id and gpu_id (or **kwargs).

Returns

List of results

gpuparallel.delayed(func)[source]

Decorator used to capture the arguments of a function. Analogue of joblib’s delayed.

Parameters

func – Function to be captured.

gpuparallel.log_to_stderr(log_level='INFO')[source]

Shortcut allowing to display logs from workers.

Parameters

log_level – Set the logging level of this logger.