Skip to main content

engine.solvers.neural

engine.solvers.neural

Neural computation solvers: a dense network’s counts, and one training epoch’s time.

Domain implementations behind mlsysim.solvers (added 2026-10-20).

Classes

Name Description
DenseNetworkModel Parameters, operations, bytes moved, and memory of a dense network at one batch size.
EpochOverheadModel One training epoch of a small network: arithmetic and data movement against fixed per-operation overhead.

DenseNetworkModel

engine.solvers.neural.DenseNetworkModel()

Parameters, operations, bytes moved, and memory of a dense network at one batch size.

The network is its layer widths. Forward work counts each layer’s matrix multiply (2 B n_in n_out) and its bias add and activation (2 B n_out). Traffic assumes each layer runs as its own kernel: the weights are read once, the input and output cross memory once, and each hidden activation is written and read back. Training keeps every layer’s output for the backward pass and holds a gradient per parameter plus the optimizer’s state; inference keeps only the weights and the largest adjacent pair of activation buffers.

Literature Source: 1. Williams, Waterman, and Patterson (2009), “Roofline” (operations per byte moved). 2. Rumelhart, Hinton, and Williams (1986), backpropagation (two products per layer).

Methods

Name Description
solve Count dense-network arithmetic, traffic, and resident training state.
solve
engine.solvers.neural.DenseNetworkModel.solve(
    layer_widths,
    batch_size,
    bytes_per_value,
    optimizer_bytes_per_parameter,
    training_examples=None,
)

Count dense-network arithmetic, traffic, and resident training state.

Parameters
Name Type Description Default
layer_widths list of int Positive widths including input and output, with at least two entries. required
batch_size int Positive examples processed together in one step. required
bytes_per_value Quantity Positive storage size of one weight, activation, or gradient value, expressed as bytes. This model uses a common representation for all three. required
optimizer_bytes_per_parameter Quantity Nonnegative extra optimizer-state bytes per parameter, excluding gradients. required
training_examples int Nonnegative examples per epoch; whole-batch step count discards a remainder. None
Returns
Name Type Description
DenseNetworkResult Parameter and FLOP counts, byte footprints, FLOP/byte intensity, and training/inference ratios. No hardware capacity or feasibility is tested.
See Also

mlsysim.physics.neural.calc_dense_forward_flops : Forward-work accounting. mlsysim.physics.neural.calc_training_state : Weight, gradient, optimizer bytes.

Notes

Equation: layer weights = n_in*n_out, biases = n_out, and forward work = 2*B*sum(n_in*n_out) + 2*B*sum(n_out). Training memory adds weights, gradients, optimizer state, and saved activations. Inference memory retains weights and the largest adjacent activation-buffer pair.

Assumptions: fully connected layers execute separately. Traffic includes weight reads plus layer inputs/outputs; hidden activations cross memory between kernels. Training-step FLOPs count matrix products, whereas the reported forward FLOPs also include bias and activation work.

Excludes: kernel fusion, reuse in caches, optimizer arithmetic, activation checkpointing, and device workspaces. Layer widths and batch size are cast to integers, so callers must supply integer counts rather than fractions.

References

Derivation: count the coefficients of each dense matrix and bias vector; a multiply-accumulate contributes two FLOPs. Saved tensors and state arrays are counted by element cardinality times representation size.

Examples
>>> from mlsysim import Q_
>>> result = DenseNetworkModel().solve([2, 3, 1], 2, Q_("4 byte"), Q_("8 byte"))
>>> result.parameters == (2 * 3 + 3) + (3 * 1 + 1)
True
>>> result.training_memory > result.inference_memory
True

EpochOverheadModel

engine.solvers.neural.EpochOverheadModel()

One training epoch of a small network: arithmetic and data movement against fixed per-operation overhead.

Work: steps x FLOPs per step at the attainable rate, the roofline’s min(peak, bandwidth x intensity) at the network’s batch intensity. Overhead: steps x operations launched per step x a fixed cost per operation, the framework’s dispatch on the host and dispatch plus a kernel launch on the accelerator. Energy: DRAM energy for the bytes behind one FLOP, against the energy of that FLOP.

Literature Source: 1. Williams, Waterman, and Patterson (2009), “Roofline”. 2. Horowitz (2014), “Computing’s energy problem” (per-op and per-byte energy).

Methods

Name Description
solve Compare epoch work and fixed launch overhead on two devices.
solve
engine.solvers.neural.EpochOverheadModel.solve(
    network,
    network_batch1,
    host,
    accelerator,
    precision,
    dispatch,
    launch,
    steps,
    dram_energy_per_byte,
    flop_energy,
)

Compare epoch work and fixed launch overhead on two devices.

Parameters
Name Type Description Default
network DenseNetworkResult Target-batch network counts, training-step FLOPs, and FLOP/byte intensity. required
network_batch1 DenseNetworkResult Same architecture at batch one for the attainable-rate comparison. required
host HardwareNode Host profile with positive memory bandwidth and selected precision rate. required
accelerator HardwareNode Accelerator profile with positive bandwidth and selected precision rate. required
precision str Key present in both devices’ compute.precision_flops dictionaries. required
dispatch Quantity Nonnegative host dispatch time per modeled operation. required
launch Quantity Nonnegative additional accelerator kernel-launch time per operation. required
steps int Positive number of batch steps in the epoch. required
dram_energy_per_byte Quantity Nonnegative energy to transfer one byte, convertible to J/byte. required
flop_energy Quantity Positive energy per arithmetic FLOP, convertible to J/flop. required
Returns
Name Type Description
EpochOverheadResult Per-device attainable FLOP/s, memory bandwidth, intensity ridge, work/overhead/total times in ms, and dimensionless speed and energy ratios. This result does not check memory residency.
See Also

mlsysim.physics.neural.calc_training_step_ops : Modeled launches per step.

Notes

Equation: rate = min(precision_peak, bandwidth*intensity); work_time = steps*training_step_flops/rate; overhead_time = steps*ops_per_step * per_operation_time. Host per-operation time is dispatch; accelerator time is dispatch + launch. Movement/arithmetic energy = energy_per_byte / (intensity*energy_per_flop).

Assumptions: a common intensity represents epoch work, and overhead adds serially to arithmetic time. Each step has the operation count returned by calc_training_step_ops for the layer count.

Excludes: overlap of launch and work, actual kernel traces, input loading, clock variation, and empirical power measurements.

References

Derivation: the slower of compute and byte transfer limits the attainable rate; dividing work by that rate gives time. Independent launch costs add per operation, and energy rates convert bytes/FLOP into an energy ratio.

Examples
>>> from mlsysim import Hardware, Q_
>>> network = DenseNetworkModel().solve([2, 3, 1], 1, Q_("4 byte"), Q_("8 byte"))
>>> result = EpochOverheadModel().solve(network, network, Hardware.Cloud.H100,
...     Hardware.Cloud.H100, "fp32", Q_("1 us"), Q_("0 us"), 1,
...     Q_("1 pJ/byte"), Q_("1 pJ/flop"))
>>> result.total_time["host"] == result.total_time["accelerator"]
True
Back to top