Operations¶
This subpackage contains operations like adding modules, subtracting, grafting, tracking the maximum, etc.
Classes:
-
Abs
–Returns :code:
abs(input)
-
AccumulateMaximum
–Accumulates maximum of all past updates.
-
AccumulateMean
–Accumulates mean of all past updates.
-
AccumulateMinimum
–Accumulates minimum of all past updates.
-
AccumulateProduct
–Accumulates product of all past updates.
-
AccumulateSum
–Accumulates sum of all past updates.
-
Add
–Add :code:
other
to tensors. :code:other
can be a number or a module. -
BinaryOperationBase
–Base class for operations that use update as the first operand. This is an abstract class, subclass it and override
transform
method to use it. -
CenteredEMASquared
–Maintains a centered exponential moving average of squared updates. This also maintains an additional
-
CenteredSqrtEMASquared
–Maintains a centered exponential moving average of squared updates, outputs optionally debiased square root.
-
Clip
–clip tensors to be in :code:
(min, max)
range. :code:min
and :code:`max: can be None, numbers or modules. -
ClipModules
–Calculates :code:
input(tensors).clip(min, max)
. :code:min
and :code:max
can be numbers or modules. -
Clone
–Clones input. May be useful to store some intermediate result and make sure it doesn't get affected by in-place operations
-
CopyMagnitude
–Returns :code:
other(tensors)
with sign copied from tensors. -
CopySign
–Returns tensors with sign copied from :code:
other(tensors)
. -
CustomUnaryOperation
–Applies :code:
getattr(tensor, name)
to each tensor -
Debias
–Multiplies the update by an Adam debiasing term based first and/or second momentum.
-
Debias2
–Multiplies the update by an Adam debiasing term based on the second momentum.
-
Div
–Divide tensors by :code:
other
. :code:other
can be a number or a module. -
DivModules
–Calculates :code:
input / other
. :code:input
and :code:other
can be numbers or modules. -
EMASquared
–Maintains an exponential moving average of squared updates.
-
Exp
–Returns :code:
exp(input)
-
Fill
–Outputs tensors filled with :code:
value
-
Grad
–Outputs the gradient
-
GradToNone
–Sets :code:
grad
attribute to None on :code:var
. -
Graft
–Outputs tensors rescaled to have the same norm as :code:
magnitude(tensors)
. -
GraftModules
–Outputs :code:
direction
output rescaled to have the same norm as :code:magnitude
output. -
GraftToUpdate
–Outputs :code:
magnitude(tensors)
rescaled to have the same norm as tensors -
GramSchimdt
–outputs tensors made orthogonal to
other(tensors)
via Gram-Schmidt. -
Identity
–Identity operator that is argument-insensitive. This also can be used as identity hessian for trust region methods.
-
LerpModules
–Does a linear interpolation of :code:
input(tensors)
and :code:end(tensors)
based on a scalar :code:weight
. -
Maximum
–Outputs :code:
maximum(tensors, other(tensors))
-
MaximumModules
–Outputs elementwise maximum of :code:
inputs
that can be modules or numbers. -
Mean
–Outputs a mean of :code:
inputs
that can be modules or numbers. -
Minimum
–Outputs :code:
minimum(tensors, other(tensors))
-
MinimumModules
–Outputs elementwise minimum of :code:
inputs
that can be modules or numbers. -
Mul
–Multiply tensors by :code:
other
. :code:other
can be a number or a module. -
MultiOperationBase
–Base class for operations that use operands. This is an abstract class, subclass it and override
transform
method to use it. -
NanToNum
–Convert
nan
,inf
and-inf
to numbers. -
Negate
–Returns :code:
- input
-
Noop
–Identity operator that is argument-insensitive. This also can be used as identity hessian for trust region methods.
-
Ones
–Outputs ones
-
Params
–Outputs parameters
-
Pow
–Take tensors to the power of :code:
exponent
. :code:exponent
can be a number or a module. -
PowModules
–Calculates :code:
input ** exponent
. :code:input
and :code:other
can be numbers or modules. -
Prod
–Outputs product of :code:
inputs
that can be modules or numbers. -
RCopySign
–Returns :code:
other(tensors)
with sign copied from tensors. -
RDiv
–Divide :code:
other
by tensors. :code:other
can be a number or a module. -
RGraft
–Outputs :code:
magnitude(tensors)
rescaled to have the same norm as tensors -
RPow
–Take :code:
other
to the power of tensors. :code:other
can be a number or a module. -
RSub
–Subtract tensors from :code:
other
. :code:other
can be a number or a module. -
Randn
–Outputs tensors filled with random numbers from a normal distribution with mean 0 and variance 1.
-
RandomSample
–Outputs tensors filled with random numbers from distribution depending on value of :code:
distribution
. -
Reciprocal
–Returns :code:
1 / input
-
ReduceOperationBase
–Base class for reduction operations like Sum, Prod, Maximum. This is an abstract class, subclass it and override
transform
method to use it. -
Sign
–Returns :code:
sign(input)
-
Sqrt
–Returns :code:
sqrt(input)
-
SqrtEMASquared
–Maintains an exponential moving average of squared updates, outputs optionally debiased square root.
-
Sub
–Subtract :code:
other
from tensors. :code:other
can be a number or a module. -
SubModules
–Calculates :code:
input - other
. :code:input
and :code:other
can be numbers or modules. -
Sum
–Outputs sum of :code:
inputs
that can be modules or numbers. -
Threshold
–Outputs tensors thresholded such that values above :code:
threshold
are set to :code:value
. -
UnaryLambda
–Applies :code:
fn
to input tensors. -
UnaryParameterwiseLambda
–Applies :code:
fn
to each input tensor. -
Uniform
–Outputs tensors filled with random numbers from uniform distribution between :code:
low
and :code:high
. -
UpdateToNone
–Sets :code:
update
attribute to None on :code:var
. -
WeightedMean
–Outputs weighted mean of :code:
inputs
that can be modules or numbers. -
WeightedSum
– -
Zeros
–Outputs zeros
Abs ¶
Bases: torchzero.core.transform.Transform
Returns :code:abs(input)
Source code in torchzero/modules/ops/unary.py
AccumulateMaximum ¶
Bases: torchzero.core.transform.Transform
Accumulates maximum of all past updates.
Parameters:
-
decay
(float
, default:0
) –decays the accumulator. Defaults to 0.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/accumulate.py
AccumulateMean ¶
Bases: torchzero.core.transform.Transform
Accumulates mean of all past updates.
Parameters:
-
decay
(float
, default:0
) –decays the accumulator. Defaults to 0.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/accumulate.py
AccumulateMinimum ¶
Bases: torchzero.core.transform.Transform
Accumulates minimum of all past updates.
Parameters:
-
decay
(float
, default:0
) –decays the accumulator. Defaults to 0.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/accumulate.py
AccumulateProduct ¶
Bases: torchzero.core.transform.Transform
Accumulates product of all past updates.
Parameters:
-
decay
(float
, default:0
) –decays the accumulator. Defaults to 0.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/accumulate.py
AccumulateSum ¶
Bases: torchzero.core.transform.Transform
Accumulates sum of all past updates.
Parameters:
-
decay
(float
, default:0
) –decays the accumulator. Defaults to 0.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/accumulate.py
Add ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Add :code:other
to tensors. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:tensors + other(tensors)
Source code in torchzero/modules/ops/binary.py
BinaryOperationBase ¶
Bases: torchzero.core.module.Module
, abc.ABC
Base class for operations that use update as the first operand. This is an abstract class, subclass it and override transform
method to use it.
Methods:
-
transform
–applies the operation to operands
Source code in torchzero/modules/ops/binary.py
CenteredEMASquared ¶
Bases: torchzero.core.transform.Transform
Maintains a centered exponential moving average of squared updates. This also maintains an additional exponential moving average of un-squared updates, square of which is subtracted from the EMA.
Parameters:
-
beta
(float
, default:0.99
) –momentum value. Defaults to 0.999.
-
amsgrad
(bool
, default:False
) –whether to maintain maximum of the exponential moving average. Defaults to False.
-
pow
(float
, default:2
) –power, absolute value is always used. Defaults to 2.
Source code in torchzero/modules/ops/higher_level.py
CenteredSqrtEMASquared ¶
Bases: torchzero.core.transform.Transform
Maintains a centered exponential moving average of squared updates, outputs optionally debiased square root. This also maintains an additional exponential moving average of un-squared updates, square of which is subtracted from the EMA.
Parameters:
-
beta
(float
, default:0.99
) –momentum value. Defaults to 0.999.
-
amsgrad
(bool
, default:False
) –whether to maintain maximum of the exponential moving average. Defaults to False.
-
debiased
(bool
, default:False
) –whether to multiply the output by a debiasing term from the Adam method. Defaults to False.
-
pow
(float
, default:2
) –power, absolute value is always used. Defaults to 2.
Source code in torchzero/modules/ops/higher_level.py
Clip ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
clip tensors to be in :code:(min, max)
range. :code:min
and :code:`max: can be None, numbers or modules.
If code:min
and :code:max
: are modules, this calculates :code:tensors.clip(min(tensors), max(tensors))
.
Source code in torchzero/modules/ops/binary.py
ClipModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Calculates :code:input(tensors).clip(min, max)
. :code:min
and :code:max
can be numbers or modules.
Source code in torchzero/modules/ops/multi.py
Clone ¶
Bases: torchzero.core.module.Module
Clones input. May be useful to store some intermediate result and make sure it doesn't get affected by in-place operations
Source code in torchzero/modules/ops/utility.py
CopyMagnitude ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Returns :code:other(tensors)
with sign copied from tensors.
Source code in torchzero/modules/ops/binary.py
CopySign ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Returns tensors with sign copied from :code:other(tensors)
.
Source code in torchzero/modules/ops/binary.py
CustomUnaryOperation ¶
Bases: torchzero.core.transform.Transform
Applies :code:getattr(tensor, name)
to each tensor
Source code in torchzero/modules/ops/unary.py
Debias ¶
Bases: torchzero.core.transform.Transform
Multiplies the update by an Adam debiasing term based first and/or second momentum.
Parameters:
-
beta1
(float | None
, default:None
) –first momentum, should be the same as first momentum used in modules before. Defaults to None.
-
beta2
(float | None
, default:None
) –second (squared) momentum, should be the same as second momentum used in modules before. Defaults to None.
-
alpha
(float
, default:1
) –learning rate. Defaults to 1.
-
pow
(float
, default:2
) –power, assumes absolute value is used. Defaults to 2.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/higher_level.py
Debias2 ¶
Bases: torchzero.core.transform.Transform
Multiplies the update by an Adam debiasing term based on the second momentum.
Parameters:
-
beta
(float | None
, default:0.999
) –second (squared) momentum, should be the same as second momentum used in modules before. Defaults to None.
-
pow
(float
, default:2
) –power, assumes absolute value is used. Defaults to 2.
-
target
(Literal
, default:'update'
) –target. Defaults to 'update'.
Source code in torchzero/modules/ops/higher_level.py
Div ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Divide tensors by :code:other
. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:tensors / other(tensors)
Source code in torchzero/modules/ops/binary.py
DivModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Calculates :code:input / other
. :code:input
and :code:other
can be numbers or modules.
Source code in torchzero/modules/ops/multi.py
EMASquared ¶
Bases: torchzero.core.transform.Transform
Maintains an exponential moving average of squared updates.
Parameters:
-
beta
(float
, default:0.999
) –momentum value. Defaults to 0.999.
-
amsgrad
(bool
, default:False
) –whether to maintain maximum of the exponential moving average. Defaults to False.
-
pow
(float
, default:2
) –power, absolute value is always used. Defaults to 2.
Methods:
-
EMA_SQ_FN
–Updates
exp_avg_sq_
with EMA of squaredtensors
, ifmax_exp_avg_sq_
is not None, updates it with maximum of EMA.
Source code in torchzero/modules/ops/higher_level.py
EMA_SQ_FN ¶
EMA_SQ_FN(tensors: TensorList, exp_avg_sq_: TensorList, beta: float | NumberList, max_exp_avg_sq_: TensorList | None, pow: float = 2)
Updates exp_avg_sq_
with EMA of squared tensors
, if max_exp_avg_sq_
is not None, updates it with maximum of EMA.
Returns exp_avg_sq_
or max_exp_avg_sq_
.
Source code in torchzero/modules/functional.py
Exp ¶
Bases: torchzero.core.transform.Transform
Returns :code:exp(input)
Source code in torchzero/modules/ops/unary.py
Fill ¶
Bases: torchzero.core.module.Module
Outputs tensors filled with :code:value
Source code in torchzero/modules/ops/utility.py
Grad ¶
Bases: torchzero.core.module.Module
Outputs the gradient
Source code in torchzero/modules/ops/utility.py
GradToNone ¶
Bases: torchzero.core.module.Module
Sets :code:grad
attribute to None on :code:var
.
Source code in torchzero/modules/ops/utility.py
Graft ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs tensors rescaled to have the same norm as :code:magnitude(tensors)
.
Source code in torchzero/modules/ops/binary.py
GraftModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Outputs :code:direction
output rescaled to have the same norm as :code:magnitude
output.
Parameters:
-
direction
(Chainable
) –module to use the direction from
-
magnitude
(Chainable
) –module to use the magnitude from
-
tensorwise
(bool
, default:True
) –whether to calculate norm per-tensor or globally. Defaults to True.
-
ord
(float
, default:2
) –norm order. Defaults to 2.
-
eps
(float
, default:1e-06
) –clips denominator to be no less than this value. Defaults to 1e-6.
-
strength
(float
, default:1
) –strength of grafting. Defaults to 1.
Example
Shampoo grafted to Adam
.. code-block:: python
opt = tz.Modular(
model.parameters(),
tz.m.GraftModules(
direction = tz.m.Shampoo(),
magnitude = tz.m.Adam(),
),
tz.m.LR(1e-3)
)
Reference
Agarwal, N., Anil, R., Hazan, E., Koren, T., & Zhang, C. (2020). Disentangling adaptive gradient methods from learning rates. arXiv preprint arXiv:2002.11803. https://arxiv.org/pdf/2002.11803
Source code in torchzero/modules/ops/multi.py
GraftToUpdate ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs :code:magnitude(tensors)
rescaled to have the same norm as tensors
Source code in torchzero/modules/ops/binary.py
GramSchimdt ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
outputs tensors made orthogonal to other(tensors)
via Gram-Schmidt.
Source code in torchzero/modules/ops/binary.py
Identity ¶
Bases: torchzero.core.module.Module
Identity operator that is argument-insensitive. This also can be used as identity hessian for trust region methods.
Source code in torchzero/modules/ops/utility.py
LerpModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Does a linear interpolation of :code:input(tensors)
and :code:end(tensors)
based on a scalar :code:weight
.
The output is given by :code:output = input(tensors) + weight * (end(tensors) - input(tensors))
Source code in torchzero/modules/ops/multi.py
Maximum ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs :code:maximum(tensors, other(tensors))
Source code in torchzero/modules/ops/binary.py
MaximumModules ¶
Bases: torchzero.modules.ops.reduce.ReduceOperationBase
Outputs elementwise maximum of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
Mean ¶
Bases: torchzero.modules.ops.reduce.Sum
Outputs a mean of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
USE_MEAN
class-attribute
¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
Minimum ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs :code:minimum(tensors, other(tensors))
Source code in torchzero/modules/ops/binary.py
MinimumModules ¶
Bases: torchzero.modules.ops.reduce.ReduceOperationBase
Outputs elementwise minimum of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
Mul ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Multiply tensors by :code:other
. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:tensors * other(tensors)
Source code in torchzero/modules/ops/binary.py
MultiOperationBase ¶
Bases: torchzero.core.module.Module
, abc.ABC
Base class for operations that use operands. This is an abstract class, subclass it and override transform
method to use it.
Methods:
-
transform
–applies the operation to operands
Source code in torchzero/modules/ops/multi.py
NanToNum ¶
Bases: torchzero.core.transform.Transform
Convert nan
, inf
and -inf
to numbers.
Parameters:
-
nan
(optional
, default:None
) –the value to replace NaNs with. Default is zero.
-
posinf
(optional
, default:None
) –if a Number, the value to replace positive infinity values with. If None, positive infinity values are replaced with the greatest finite value representable by input's dtype. Default is None.
-
neginf
(optional
, default:None
) –if a Number, the value to replace negative infinity values with. If None, negative infinity values are replaced with the lowest finite value representable by input's dtype. Default is None.
Source code in torchzero/modules/ops/unary.py
Negate ¶
Bases: torchzero.core.transform.Transform
Returns :code:- input
Source code in torchzero/modules/ops/unary.py
Noop ¶
Bases: torchzero.core.module.Module
Identity operator that is argument-insensitive. This also can be used as identity hessian for trust region methods.
Source code in torchzero/modules/ops/utility.py
Ones ¶
Bases: torchzero.core.module.Module
Outputs ones
Source code in torchzero/modules/ops/utility.py
Params ¶
Bases: torchzero.core.module.Module
Outputs parameters
Source code in torchzero/modules/ops/utility.py
Pow ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Take tensors to the power of :code:exponent
. :code:exponent
can be a number or a module.
If :code:exponent
is a module, this calculates :code:tensors ^ exponent(tensors)
Source code in torchzero/modules/ops/binary.py
PowModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Calculates :code:input ** exponent
. :code:input
and :code:other
can be numbers or modules.
Source code in torchzero/modules/ops/multi.py
Prod ¶
Bases: torchzero.modules.ops.reduce.ReduceOperationBase
Outputs product of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
RCopySign ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Returns :code:other(tensors)
with sign copied from tensors.
Source code in torchzero/modules/ops/binary.py
RDiv ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Divide :code:other
by tensors. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:other(tensors) / tensors
Source code in torchzero/modules/ops/binary.py
RGraft ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs :code:magnitude(tensors)
rescaled to have the same norm as tensors
Source code in torchzero/modules/ops/binary.py
RPow ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Take :code:other
to the power of tensors. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:other(tensors) ^ tensors
Source code in torchzero/modules/ops/binary.py
RSub ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Subtract tensors from :code:other
. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:other(tensors) - tensors
Source code in torchzero/modules/ops/binary.py
Randn ¶
Bases: torchzero.core.module.Module
Outputs tensors filled with random numbers from a normal distribution with mean 0 and variance 1.
Source code in torchzero/modules/ops/utility.py
RandomSample ¶
Bases: torchzero.core.module.Module
Outputs tensors filled with random numbers from distribution depending on value of :code:distribution
.
Source code in torchzero/modules/ops/utility.py
Reciprocal ¶
Bases: torchzero.core.transform.Transform
Returns :code:1 / input
Source code in torchzero/modules/ops/unary.py
ReduceOperationBase ¶
Bases: torchzero.core.module.Module
, abc.ABC
Base class for reduction operations like Sum, Prod, Maximum. This is an abstract class, subclass it and override transform
method to use it.
Methods:
-
transform
–applies the operation to operands
Source code in torchzero/modules/ops/reduce.py
Sign ¶
Bases: torchzero.core.transform.Transform
Returns :code:sign(input)
Source code in torchzero/modules/ops/unary.py
Sqrt ¶
Bases: torchzero.core.transform.Transform
Returns :code:sqrt(input)
Source code in torchzero/modules/ops/unary.py
SqrtEMASquared ¶
Bases: torchzero.core.transform.Transform
Maintains an exponential moving average of squared updates, outputs optionally debiased square root.
Parameters:
-
beta
(float
, default:0.999
) –momentum value. Defaults to 0.999.
-
amsgrad
(bool
, default:False
) –whether to maintain maximum of the exponential moving average. Defaults to False.
-
debiased
(bool
, default:False
) –whether to multiply the output by a debiasing term from the Adam method. Defaults to False.
-
pow
(float
, default:2
) –power, absolute value is always used. Defaults to 2.
Methods:
-
SQRT_EMA_SQ_FN
–Updates
exp_avg_sq_
with EMA of squaredtensors
and calculates it's square root,
Source code in torchzero/modules/ops/higher_level.py
SQRT_EMA_SQ_FN ¶
SQRT_EMA_SQ_FN(tensors: TensorList, exp_avg_sq_: TensorList, beta: float | NumberList, max_exp_avg_sq_: TensorList | None, debiased: bool, step: int, pow: float = 2, ema_sq_fn: Callable = ema_sq_)
Updates exp_avg_sq_
with EMA of squared tensors
and calculates it's square root,
with optional AMSGrad and debiasing.
Returns new tensors.
Source code in torchzero/modules/functional.py
Sub ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Subtract :code:other
from tensors. :code:other
can be a number or a module.
If :code:other
is a module, this calculates :code:tensors - other(tensors)
Source code in torchzero/modules/ops/binary.py
SubModules ¶
Bases: torchzero.modules.ops.multi.MultiOperationBase
Calculates :code:input - other
. :code:input
and :code:other
can be numbers or modules.
Source code in torchzero/modules/ops/multi.py
Sum ¶
Bases: torchzero.modules.ops.reduce.ReduceOperationBase
Outputs sum of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
USE_MEAN
class-attribute
¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
Threshold ¶
Bases: torchzero.modules.ops.binary.BinaryOperationBase
Outputs tensors thresholded such that values above :code:threshold
are set to :code:value
.
Source code in torchzero/modules/ops/binary.py
UnaryLambda ¶
Bases: torchzero.core.transform.Transform
Applies :code:fn
to input tensors.
:code:fn
must accept and return a list of tensors.
Source code in torchzero/modules/ops/unary.py
UnaryParameterwiseLambda ¶
Bases: torchzero.core.transform.TensorwiseTransform
Applies :code:fn
to each input tensor.
:code:fn
must accept and return a tensor.
Source code in torchzero/modules/ops/unary.py
Uniform ¶
Bases: torchzero.core.module.Module
Outputs tensors filled with random numbers from uniform distribution between :code:low
and :code:high
.
Source code in torchzero/modules/ops/utility.py
UpdateToNone ¶
Bases: torchzero.core.module.Module
Sets :code:update
attribute to None on :code:var
.
Source code in torchzero/modules/ops/utility.py
WeightedMean ¶
Bases: torchzero.modules.ops.reduce.WeightedSum
Outputs weighted mean of :code:inputs
that can be modules or numbers.
Source code in torchzero/modules/ops/reduce.py
USE_MEAN
class-attribute
¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
WeightedSum ¶
Bases: torchzero.modules.ops.reduce.ReduceOperationBase
Source code in torchzero/modules/ops/reduce.py
USE_MEAN
class-attribute
¶
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
Zeros ¶
Bases: torchzero.core.module.Module
Outputs zeros