FedAvgKernelCodec

Marshals the FedAvg training kernel's linear-memory ABI payloads (see the wire layout in the F2 plan/spec). All integers and IEEE-754 f64 values are little-endian, so the bytes are bit-deterministic across platforms — matching FedAvg's reproducibility requirement.

Dimension is fixed at D = 2 (one feature + bias) for the v1 kernel.

Samples

// A peer encodes its local batch + the shared model, runs the kernel (omitted), and folds the
// decoded update into FedAvg. Here we use the reference trainer in place of the wasm run.
val model = listOf(0.0, 0.0)
val batch = listOf(1.0 to 3.0, 2.0 to 5.0)            // y = 2x + 1
val input = FedAvgKernelCodec.encodeInput(model, batch, learnRate = 0.05)
require(input.isNotEmpty())

val updatedWeights = ReferenceTrainer.step(model, batch, 0.05)
val update = TrainingUpdate(batch.size.toLong(), updatedWeights)
val contribution = update.toContribution(ReplicaId("alice"))
require(contribution.weights.size == 2)

Properties

Link copied to clipboard
const val RESULT_LEN: Int = 32

Length in bytes of the kernel's output region.

Functions

Link copied to clipboard

Decodes the kernel output region into a TrainingUpdate; fails loud on a bad shape.

Link copied to clipboard
fun encodeInput(weights: List<Double>, examples: List<Pair<Double, Double>>, learnRate: Double): ByteArray

Encodes (weights, examples, learnRate) into the kernel input layout.