gt4sd.frameworks.torch package

Generic utils for pytorch.

Submodules:

Summary

Reference

claim_device_name()[source]

Claim a device name.

Return type

str

Returns

device name, if on GPU is available returns CPU.

device_claim(device=None)[source]

Satidfy a device claim.

Parameters

device (Union[device, str, None]) – device where the inference is running either as a dedicated class or a string. If not provided is inferred.

Returns

the claimed device or a default one.

Return type

torch.device

get_device()[source]

Get device dynamically.

Return type

device

get_device_from_tensor(tensor)[source]

Get the device from a tensor.

Parameters

tensor (Tensor) – a tensor.

Return type

device

Returns

the device.

get_gpu_device_names()[source]

Get GPU device names as a list.

Return type

List[str]

Returns

names of available GPU devices.

map_tensor_dict(tensor_dict, device)[source]

Maps a dictionary of tensors to a specific device.

Parameters
  • tensor_dict (Dict[str, Tensor]) – A dictionary of tensors.

  • device (device) – The device to map the tensors to.

Return type

Dict[str, Tensor]

Returns

A dictionary of tensors mapped to the device.