poprox_recommender.pytorch#

Utility functions for implementing POPROX recommender components with PyTorch.

poprox_recommender.pytorch.assert_tensor_size(tensor, *size, label=None, prefix=True)#

Check that a tensor is of the expected size, and fail with an assertion error if it is the incorrect size.

Parameters:
  • tensor (Tensor) – The tensor to check.

  • *size (int) – The expected size of the tensor.

  • label (str | None) – A label for the tensor.

  • prefix (bool) – If True and the tensor has more dimensions than the expected size, only match the common prefix of dimensions.

poprox_recommender.pytorch.torch_inference(func)#

Decorator for functions or methods that use PyTorch for inference (an thus torch.inference_mode() should be set for performance). It wraps the function in the following logic:

with torch.inference_mode():
    func()
Parameters:

func (Callable[[~P], R]) – the function to wrap.

Return type:

Callable[[~P], R]

Modules

datachecks

Data-checking routines.

decorators

Decorators to help with Torch usage.