Function

scalation.modeling.autograd.Function
trait Function(using ops: AutogradOps)

The Function base trait for all differentiable operations in the autograd system. A Function encapsulates both the forward computation (producing outputs) and the backward computation (propagating gradients). It also provides utility methods for handling unbroadcasting of shapes during the backward pass, ensuring correct gradient flow. Every custom operation should extend this trait and implement forward and backward.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Abs
class Add
class AddConstant
class BatchMatMul
class Ceil
class Clip
class Concat
class Div
class DivConstant
class Dot
class ELU
class Exp
class Floor
class GRUCellFused
class GeLU
class Identity
class LeakyReLU
class Log
class LogBase
class MAELoss
class MSELoss
class MatMul
class Max
class MaxScalar
class MaxValue
class Mean
class Min
class MinScalar
class MinValue
class Mul
class MulConstant
class Neg
class Permute
class Pow
class RNNCellFused
class RNNFused
class ReLU
class Reciprocal
class Reshape
class Round
class SSELoss
class Sigmoid
class Sign
class Slice
class Softmax
class Sqrt
class Std
class StdAlongAxis
class Sub
class SubConstant
class Sum
class Tanh
class Transpose
class Variance
Show all

Members list

Value members

Abstract methods

def backward(gradOutput: TensorD): Unit

Performs the backward pass given the upstream gradient.

Performs the backward pass given the upstream gradient.

Value parameters

gradOutput

the gradient tensor from the next layer.

Attributes

def forward(): Variabl

Performs the forward pass to compute the output variable.

Performs the forward pass to compute the output variable.

Attributes

Returns

a Variabl containing the output data and gradient function.

Concrete methods

def attributes: Map[String, String]

Map of attributes for visualization/debugging (default: empty).

Map of attributes for visualization/debugging (default: empty).

Attributes

def backpropForTwoInputs(v1: Variabl, v2: Variabl, gradOutput: TensorD, computeGrad1: TensorD => TensorD, computeGrad2: TensorD => TensorD): Unit

Backpropagates gradients for functions with two inputs.

Backpropagates gradients for functions with two inputs.

Value parameters

computeGrad1

function to compute the gradient for v1.

computeGrad2

function to compute the gradient for v2.

gradOutput

the upstream gradient tensor.

v1

the first input variable.

v2

the second input variable.

Attributes

def inputs: Seq[Variabl]

Returns the input variables to this Function. This works automatically for all case-class ops by iterating over their constructor fields and collecting those of type Variabl.

Returns the input variables to this Function. This works automatically for all case-class ops by iterating over their constructor fields and collecting those of type Variabl.

Attributes

See also
def opName: String

Human-readable name of this op (defaults to simple class name).

Human-readable name of this op (defaults to simple class name).

Attributes

def unbroadcast(v: Variabl, oldShape: List[Int]): Variabl

Unbroadcasts a variable's tensor data to a specified old shape.

Unbroadcasts a variable's tensor data to a specified old shape.

Value parameters

oldShape

the target shape.

v

the variable to unbroadcast.

Attributes

Returns

a new Variabl with data unbroadcasted.

def unbroadcast(data: TensorD, oldShape: List[Int]): TensorD

Unbroadcasts a tensor to a given shape by summing across reduced dimensions.

Unbroadcasts a tensor to a given shape by summing across reduced dimensions.

Value parameters

data

the tensor data.

oldShape

the original shape.

Attributes

Returns

a TensorD with shape adjusted to oldShape.

Throws
Exception

if unbroadcasting is not feasible.

Concrete fields

val id: Int

Unique numeric ID for this Function node (for graph viz/debugging).

Unique numeric ID for this Function node (for graph viz/debugging).

Attributes