Documentation

Hesper.Op.Activation

Activation Functions as Verified Operators #

Implements element-wise activation functions (ReLU, Sigmoid, Tanh) as verified operators with kernel fusion support.

These are perfect examples of fusable operations because they:

  1. Are element-wise (no cross-element dependencies)
  2. Compose nicely: MatMul |> ReLU |> Softmax
  3. Can be fused into preceding operations

Mathematical Definitions #

ReLU: f(x) = max(0, x)

Sigmoid: f(x) = 1 / (1 + exp(-x))

Tanh: f(x) = tanh(x)

Activation function type

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      ReLU Activation #

      ReLU input: single tensor

      Instances For

        ReLU output: single tensor

        Instances For

          CPU ReLU forward pass: element-wise max(0, x)

          Equations
          Instances For

            CPU ReLU backward pass: gradient is 1 if x > 0, else 0

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              GPU ReLU Kernel #

              ReLU as a WGSL expression transformation. This is a pure function that can be fused into other kernels.

              Equations
              Instances For

                GPU ReLU forward kernel. Element-wise operation that can be fused with other kernels.

                Example usage:

                let fused = matmul_kernel |> relu_kernel  -- Fuses matmul + relu
                
                Equations
                Instances For

                  GPU ReLU backward kernel. Gradient: 1 if x > 0, else 0

                  Takes (input, grad_output) and returns grad_input. For ReLU: grad_input = grad_output if input > 0, else 0

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    VerifiedOpFusion Instance for ReLU #

                    Helper Functions #

                    Create ReLU input from TensorData

                    Equations
                    Instances For

                      Extract TensorData from ReLU output

                      Equations
                      Instances For

                        Sigmoid Activation (TODO) #

                        Tanh Activation (TODO) #