Engines

Multi-GPU data parallel

create_multigpu_supervised_evaluator(net, metrics=None, devices=None, non_blocking=False, prepare_batch=<function _prepare_batch>, output_transform=<function _default_eval_transform>)[source]

Derived from create_supervised_evaluator in Ignite.

Factory function for creating an evaluator for supervised models.

Parameters
  • net (torch.nn.Module) – the model to train.

  • metrics (dict of str - Metric) – a map of metric names to Metrics.

  • devices (list, optional) – device(s) type specification (default: None). Applies to both model and batches. None is all devices used, empty list is CPU only.

  • non_blocking (bool, optional) – if True and this copy is between CPU and GPU, the copy may occur asynchronously with respect to the host. For other cases, this argument has no effect.

  • prepare_batch (callable, optional) – function that receives batch, device, non_blocking and outputs tuple of tensors (batch_x, batch_y).

  • output_transform (callable, optional) – function that receives ‘x’, ‘y’, ‘y_pred’ and returns value to be assigned to engine’s state.output after each iteration. Default is returning (y_pred, y,) which fits output expected by metrics. If you change it you should use output_transform in metrics.

Note

engine.state.output for this engine is defined by output_transform parameter and is a tuple of (batch_pred, batch_y) by default.

Returns

an evaluator engine with supervised inference function.

Return type

Engine

create_multigpu_supervised_trainer(net, optimizer, loss_fn, devices=None, non_blocking=False, prepare_batch=<function _prepare_batch>, output_transform=<function _default_transform>)[source]

Derived from create_supervised_trainer in Ignite.

Factory function for creating a trainer for supervised models.

Parameters
  • net (torch.nn.Module) – the network to train.

  • optimizer (torch.optim.Optimizer) – the optimizer to use.

  • loss_fn (torch.nn loss function) – the loss function to use.

  • devices (list, optional) – device(s) type specification (default: None). Applies to both model and batches. None is all devices used, empty list is CPU only.

  • non_blocking (bool, optional) – if True and this copy is between CPU and GPU, the copy may occur asynchronously with respect to the host. For other cases, this argument has no effect.

  • prepare_batch (callable, optional) – function that receives batch, device, non_blocking and outputs tuple of tensors (batch_x, batch_y).

  • output_transform (callable, optional) – function that receives ‘x’, ‘y’, ‘y_pred’, ‘loss’ and returns value to be assigned to engine’s state.output after each iteration. Default is returning loss.item().

Returns

a trainer engine with supervised update function.

Return type

Engine

Note

engine.state.output for this engine is defined by output_transform parameter and is the loss of the processed batch by default.

get_devices_spec(devices=None)[source]

Get a valid specification for one or more devices. If devices is None get devices for all CUDA devices available. If devices is and zero-length structure a single CPU compute device is returned. In any other cases devices is returned unchanged.

Parameters

devices (list, optional) – list of devices to request, None for all GPU devices, [] for CPU.

Returns

list of devices.

Return type

list of torch.device