mojolearn.MLPInference#

class mojolearn.MLPInference(weight1, bias1, weight2, bias2)[source]#

Bases: object

Forward-only SmallMLPTrainer network (8 -> 16 ReLU -> 3, float32) on the CPU.

Computes the same logits as SmallMLPTrainer.predict_logits from the same weights. The weights are copied at construction and never change; the weight matrices may also be given packed by mojolearn.lowbit, in which case they are unpacked exactly to float32. Each row’s logits depend on that row alone.

Parameters:
  • weight1 (array of float32) – First-layer weights.

  • bias1 (array of float32) – First-layer bias.

  • weight2 (array of float32) – Second-layer weights.

  • bias2 (array of float32) – Second-layer bias.

Variables:

weight_format (str) – Format the weight matrices were given in: “float32”, or the packed mojolearn.lowbit format.

Examples

>>> import mojolearn
>>> model = mojolearn.MLPInference.from_checkpoint("mlp.ckpt")
>>> logits = model.predict_logits(X)    # X: (rows, 8) float32, 1..256 rows
__init__(weight1, bias1, weight2, bias2)[source]#

Methods

from_checkpoint(path)

Build from a SmallMLPTrainer.save_checkpoint file.

predict_logits(X)

Logits for X.

Attributes

weights_

An independent copy of the four weights, keyed by name.

classmethod from_checkpoint(path)[source]#

Build from a SmallMLPTrainer.save_checkpoint file.

The file’s size, schema, SHA-256 and arithmetic profile are checked (any mismatch raises ValueError); the optimizer state is validated and dropped.

Parameters:

path (str or path-like) – Checkpoint file.

Returns:

MLPInference

property weights_#

An independent copy of the four weights, keyed by name.

predict_logits(X)[source]#

Logits for X.

Parameters:

X (array of float32, shape (rows, 8)) – Input rows, 1 to 256 of them.

Returns:

mojolearn.Array of float32, shape (rows, 3)