mindsponge.cell.Transition

View Source On Gitee
class mindsponge.cell.Transition(num_intermediate_factor, input_dim, batch_size=None, slice_num=0)[source]

This is 2-layer MLP where the intermediate layer expands number of channels of the input by a factor(num_intermediate_factor).

\[Transition(\mathbf{act}) = Linear(Linear(\mathbf{act}))\]
Parameters
  • num_intermediate_factor (float) – The expand factor of intermediate output channels compared to the input.

  • input_dim (int) – The channels of the input.

  • batch_size (int) – The batch size of parameters in Transition, used in while control flow. Default: "None".

  • slice_num (int) – The slice num used in transition layer when the memory is overflow. Default: 0.

Inputs:
  • act (Tensor) - The input with channels equal to input_dim, shape is (…, input_dim).

  • index (Tensor) - The index of while loop, only used in case of while control flow. Default: "None".

  • mask (Tensor) - The mask of act when to do layernorm with shape \((32, input_{dim})\), Default: "None".

Outputs:

Tensor, the float tensor of the output of the layer with shape (…, input_dim).

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindsponge.cell import Transition
>>> from mindspore import dtype as mstype
>>> from mindspore import Tensor
>>> model = Transition(num_intermediate_factor=4, input_dim=128)
>>> input = Tensor(np.ones((32, 128, 128)), mstype.float32)
>>> output= model(input)
>>> print(output.shape)
(32, 128, 128)