![]() |
NeuZephyr
Simple DL Framework
|
Represents a Hard Swish activation function node in a computational graph. More...
Public Member Functions | |
HardSwishNode (Node *input, Tensor::value_type alpha=1.0f, Tensor::value_type beta=0.5f) | |
Constructor to initialize a HardSwishNode for applying the Hard Swish activation function. | |
void | forward () override |
Forward pass for the HardSwishNode to apply the Hard Swish activation function. | |
void | backward () override |
Backward pass for the HardSwishNode to compute gradients. | |
![]() | |
virtual void | print (std::ostream &os) const |
Prints the type, data, and gradient of the node. | |
void | dataInject (Tensor::value_type *data, bool grad=false) const |
Injects data into a relevant tensor object, optionally setting its gradient requirement. | |
template<typename Iterator > | |
void | dataInject (Iterator begin, Iterator end, const bool grad=false) const |
Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement. | |
void | dataInject (const std::initializer_list< Tensor::value_type > &data, bool grad=false) const |
Injects data from a std::initializer_list into the output tensor of the Node, optionally setting its gradient requirement. | |
Represents a Hard Swish activation function node in a computational graph.
The HardSwishNode
class applies the Hard Swish activation function to the input tensor. The Hard Swish function is a computationally efficient approximation of the Swish function and is defined as:
where alpha
and beta
control the slope and offset of the linear part of the function.
Key features:
This class is part of the nz::nodes
namespace and is used in models to improve performance while maintaining computational efficiency.
alpha
and beta
parameters default to 1.0
and 0.5
, respectively, but can be customized during construction.
|
explicit |
Constructor to initialize a HardSwishNode
for applying the Hard Swish activation function.
The constructor initializes a HardSwishNode
, which applies the Hard Swish activation function to an input tensor. It establishes a connection to the input node, initializes the output tensor, and sets the alpha
and beta
parameters as well as the node type.
input | A pointer to the input node. Its output tensor will have the Hard Swish activation applied. |
alpha | The slope parameter for the Hard Swish function. Controls the steepness of the curve. |
beta | The offset parameter for the Hard Swish function. Shifts the function horizontally. |
The Hard Swish activation function is defined as:
Key operations performed by the constructor:
inputs
vector, establishing the connection in the computational graph.requiresGrad
property.output
tensor with the same shape as the input tensor and appropriate gradient tracking.alpha
and beta
parameters, which control the shape of the Hard Swish function.alpha
and beta
parameters allow for customization of the activation function's behavior.
|
overridevirtual |
Backward pass for the HardSwishNode
to compute gradients.
This method implements the backward pass of the Hard Swish activation function. It computes the gradient of the loss with respect to the input by applying the derivative of the Hard Swish function to the incoming gradient.
The derivative of the Hard Swish function is:
where alpha
and beta
are the parameters that control the shape of the function.
Key operations:
HardSwishBackward
) to compute gradients on the GPU.CUDA kernel configuration:
HardSwishBackward
is defined elsewhere and correctly implements the derivative of the Hard Swish function.alpha
and beta
parameters.Implements nz::nodes::Node.
Definition at line 515 of file Nodes.cu.
|
overridevirtual |
Forward pass for the HardSwishNode
to apply the Hard Swish activation function.
This method implements the forward pass of the Hard Swish activation function. It applies the Hard Swish operation element-wise to the input tensor and stores the result in the output tensor.
The Hard Swish function is defined as:
where alpha
and beta
are parameters that control the shape of the function.
Key operations:
HardSwish
) to perform the Hard Swish computation on the GPU.CUDA kernel configuration:
HardSwish
is defined elsewhere and properly implements the Hard Swish function.alpha
and beta
parameters.Implements nz::nodes::Node.
Definition at line 509 of file Nodes.cu.