TensorDictBase.lerp#
- TensorDictBase.lerp(end: TensorCollection | Tensor, weight: TensorCollection | Tensor | float) Self#
Returns a new tensordict that interpolates linearly from every leaf (the start) to
end.\[\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)\]- Parameters:
end (TensorDictBase or Tensor) – the end points. A tensordict is paired with the tensordict key by key and must have all its keys. A tensor is aligned with the batch dimensions of each leaf and expanded over its feature dimensions.
weight (TensorDictBase, Tensor or float) – the interpolation weight: a number for all the leaves, or a tensordict or a tensor paired like
end. One ofendandweightcan be a tensordict and the other a tensor. Where a lazy stack meets a tensordict that is not one, aweighttensor that does not broadcast with the batch dims broadcasts with each leaf from the right instead, with aFutureWarning. Starting with TensorDict 0.17, the default will change to raising the error of the other tensordicts.
Examples
>>> import torch >>> from tensordict import TensorDict >>> start = TensorDict(x=torch.zeros(2), batch_size=[2]) >>> end = TensorDict(x=torch.full((2,), 10.0), batch_size=[2]) >>> start.lerp(end, 0.25)["x"] tensor([2.5000, 2.5000])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.