sequential

inline fun <T : DType, V> sequential(content: NeuralNetworkDsl<T, V>.() -> Unit): Module<T, V>(source)

Generic network builder function that creates a neural network with specified data type and value type.

Return

A Module representing the complete neural network

Example usage:

val fpNetwork = network<FP32, Float> {
input(784)
dense(128) { weights { shape -> CpuTensorFP32.random(shape) } }
dense(10) { weights { shape -> CpuTensorFP32.random(shape) } }
}

val intNetwork = network<Int8, Byte> {
input(28)
dense(16) { weights { shape -> CpuTensorInt8.ones(shape) } }
}

Parameters

T

The data type (DType) - must extend DType (e.g., FP32, FP16, Int8, Int32, Ternary, Int4)

V

The value type - must match the DType's native type:

  • FP32 → Float

  • FP16 → Float (promoted)

  • Int32 → Int

  • Int8 → Byte

  • Int4 → Byte (promoted)

  • Ternary → Byte (special case)

content

The DSL content block that defines the network structure


inline fun <T : DType, V> sequential(executionContext: ExecutionContext, content: NeuralNetworkDsl<T, V>.() -> Unit): Module<T, V>(source)

Overload that wires both tensor factory and ops from an ExecutionContext.