Skip to main content

shim

Backend-agnostisc shims.

Classes

BackendTensorShim

class BackendTensorShim():

A shim for handling tensors of a particular type.

An abstract class representing a shim/bridge for tensor handling in a particular backend.

Ancestors

Static methods


clamp_params

def clamp_params(    p: _TensorLike, prime_q: int, precision: int, num_workers: int,)> _TensorLike:

Clamps the parameter of a given tensor.

Constrains the parameters for secure sharing to be within the required range for secure sharing. Used only when steps_between_parameter_updates is 1.

Arguments

  • p: The tensor to be constrained.
  • prime_q: The prime use for secret aggregation.
  • precision: The precision used for secret aggregation.
  • num_workers: The number of workers taking part in the secure aggregation.

Returns The clamped parameters.

is_tensor

def is_tensor(p: Any)> bool:

Checks if the argument is a tensor.

Arguments

  • p: The argument to check.

Returns True if the supplied argument is a tensor according to this model's backend, False otherwise.

to_list

def to_list(p: Union[np.ndarray, _TensorLike])> List[float]:

Converts the supplied tensor or numpy array to a list and returns it.

Arguments

  • p: The tensor or numpy array to convert to a list.

Returns A list.

to_numpy

def to_numpy(t: Union[_TensorLike, List[float]])> np.ndarray:

Converts a tensor into a numpy array and returns it.

Arguments

  • t: The tensor or list to convert.

Returns A numpy array.

to_tensor

def to_tensor(p: Any, **kwargs: Any)> _TensorLike:

Converts the supplied argument to a tensor (if possible) and returns it.

Arguments

  • p: The argument to convert to a tensor.
  • ****kwargs**: Additional keyword arguments to pass to the tensor constructor.

Returns A tensor.