unilab.algos.torch.common.stability.safe_tensor

unilab.algos.torch.common.stability.safe_tensor(tensor, nan_value=0.0, clamp_range=(-10.0, 10.0))[source]

Make tensor numerically safe by clamping and replacing NaN values.

Parameters:
  • tensor (Tensor) – Input tensor

  • nan_value (float) – Value to replace NaN with

  • clamp_range (tuple) – (min, max) range to clamp values

Return type:

Tensor

Returns:

Safe tensor