Module warm.engine
PyWarm engine to the functional interface.
Functions
activate
def :
x,
spec,
lookup=None
specification.
x: Tensor or list of Tensor; The tensors to be initialized.spec: str or callable or 2-tuple; If astr, should be one of the nonlinearity functions contained intorch.nn.functionalortorch. If acallable, it will be applied toxdirectly, i.e.spec(x). If a 2-tuple, it must be of format(callable, kwargs), i.e.callable(x, **kwargs).lookup: None or list of module; Parent modules to look forspec. IfNone,[nn.functional, torch]is used.return: Tensor or list of Tensor; Activation results.
forward
def :
x,
base_class,
base_name=None,
name=None,
base_arg=None,
base_kw=None,
parent=None,
infer_kw=None,
in_shape='BCD',
base_shape='BCD',
out_shape='BCD',
tuple_out=False,
forward_arg=None,
forward_kw=None,
initialization=None,
activation=None,
**kw
x: Tensor; The nd-tensor to be forwarded.base_class: Module; A childtorch.nn.Modulethat will be created at the first time this function is called.base_name: str; Name for thebase_class. Default: base_class name.name: str; Name for the child module instance. Default: class name plus ordinal.base_arg: tuple; Positional args to be passed to create the child module instance. Default: None.base_kw: dict; KWargs to be passed to create the child module instance. Default: None.parent: Module; The parent of the child instance. Default: None. IfNone, will useget_default_parent.infer_kw: dict; Key should be valid for the child instance. Value shoud be a character, one of'B','C', or'D'(seepermute), to substitute for a dimension ofx. Default: None.in_shape: str; The dimension shape ofx. See alsopermute. Default:'BCD'.base_shape: str; The dimension shape required by the child module. See alsopermute. Default:'BCD'.out_shape: str or tuple or None; The dimension shape of returned tensor. See alsopermute. Default:'BCD'.tuple_out: bool; Whether the child module will return more than 1 outputs (e.g.nn.RNN). IfTrue, the returned value of the function will be a tuple containing all outputs. Default: False.forward_arg: tuple; positional args to be passed when calling the child module instance. Default: None.forward_kw: dict; KWargs to be passed when calling the child module instance. Default: None.initialization: dict; Keys are name of parameters to initialize. Values are init specs, which can be a,str, acallable, or2-tuple; See thespecargument ofinitialize_for details. Default: None.activation: str or callable or 2-tuple; See thespecargument ofactivate. Default: None.return: Tensor or tuple; Iftuple_outisTrue, the returned value will be atuple.
get_default_parent
def :
parent module.
initialize_
def :
x,
spec
specification.
x: Tensor or list of Tensor; The tensors to be initialized.spec: str or callable or 2-tuple; If astr, should be one of the nonlinearity functions contained intorch.nn.init. If acallable, it will be applied toxdirectly, i.e.spec(x). If a 2-tuple, it must be of format(callable, kwargs), i.e.callable(x, **kwargs).
is_ready
def :
model
model is prepared.
namespace
def :
f
name kw.
permute
def :
x,
in_shape='BCD',
out_shape='BCD',
**kw
x: Tensor; The nd-tensor to be permuted.in_shape: str; The dimension shape ofx. Can only have characters'B'or'C'or'D', which stand for Batch, Channel, or extra Dimensions. The default value'BCD'means the input tensorxshould be at lest 2-d with shape(Batch, Channel, Dim0, Dim1, Dim2, ...), whereDim0, Dim1, Dim2 ...stand for any number of extra dimensions.out_shape: str or tuple or None; The dimension shape of returned tensor. Default:'BCD'. If astr, it is restricted to the same three characters'B','C'or'D'as thein_shape. If atuple,in_shapeis ignored, and simplyx.permute(out_shape)is returned. IfNone, no permution will be performed.return: Tensor; Permuted nd-tensor.
prepare_model_
def :
model,
*data,
device='cpu'
warm in a parent model.
model: Module; The parent model to be prepared.data: Tensor, or list of int; A batch of data with the correct shape and type to be forwarded by model.datacan also be a list ofint, in which case it is interpreted as the shape of the input data.device: str, or torch.device; Should be the same formodelanddata. Default:'cpu'.return: Module; The prepared model, with all children modules defined bywarminitialized.
set_default_parent
def :
parent
parent module.
unused_kwargs
def :
kw
forward and return the rest.