diff --git a/clean/fg/FORMATS.md b/clean/fg/FORMATS.md index 3bfdf3bf..385322f5 100644 --- a/clean/fg/FORMATS.md +++ b/clean/fg/FORMATS.md @@ -45,7 +45,21 @@ delivered by the spec side; the code never guesses it (it raises, or takes the c - Required arguments where the behaviour is OPEN: the convolution border rule (`pad`: zero, replicate or mirror), ReLU after a net2 layer (`relu_after`), the pooling kind (`kind`: max or avg), net1's feature channel order (`order`), the fold order inside a cell (`order`). What the cell padding holds is OPEN too (zeros here). -- `net1_forward` and `net2_forward` raise `OpenItem`: the wiring of both networks is not delivered. +- `ops.net1_forward` and `ops.net2_forward` raise `OpenItem`: the original's wiring is not delivered. + +## Forward pass (`reference/forward.py`) + +- Parameters per layer (layout names `net1_01`..`net2_25`): storage-order weights and the bias, from blobs + (`params_from_blobs`) or from the converter's `--raw` output of the preset-FG map (`params_from_raw`, stages + `dl1.lNN` / `dl2.lNN`; every value checked to be exact in float16). +- `run_layer`: one convolution with `ops.conv2d`. `run_graph`: a network as a list of steps (`conv` with its layer and + ReLU flag, `pool` with its kind, `upscale`, `add`, `concat`, `slice`), checked before it runs (known steps, exact + fields, buffers written once before they are read, each layer used at most once). `net1_forward` adds the 2 x 2 + fold before and the unfold (16 values per cell to 4 per pixel) after; `net2_forward` returns the named buffers. +- Required arguments (OPEN): `wiring` (the steps); `weight_view` (storage to natural `[out, k, k, in]`: map v1 holds + the weights as stored, the natural view comes with v1.1; `view_by_axes` covers a plain axis reorder); `pad`; `blob2` + ("1x1" runs net1's blob 2 as a 1 x 1 convolution, "2x2" raises `OpenItem`); `fold_order`. The real wiring plugs in + as data; the layers do not change. ## Configuration (`reference/config.py`) diff --git a/clean/fg/README.md b/clean/fg/README.md index 329f7e26..e6130796 100644 --- a/clean/fg/README.md +++ b/clean/fg/README.md @@ -11,6 +11,8 @@ front end or the launcher yet. Status, open items and formats: [FORMATS.md](FORM | `tests/test_fg_layout.py` | the table against the totals the spec side gives | | `reference/ops.py` | NumPy CPU reference of the networks' building blocks: float16 convolution (3 x 3, 1 x 1) with bias and ReLU, 2x pooling, bilinear 2x upscale (align corners), element-wise combines, net1's input features and 2 x 2 fold; each open behaviour is a required argument or raises `OpenItem` | | `tests/test_fg_reference.py` | the building blocks against plain loop versions, on synthetic data | +| `reference/forward.py` | both networks' forward pass: each layer from its stage's parameters (from blobs or the converter's raw output), and a network run from a wiring the caller supplies (conv / pool / upscale / add / concat / slice steps); the wiring, the natural weight order, the border rule and net1's blob 2 are required arguments | +| `tests/test_fg_forward.py` | every layer of both networks against a direct NumPy convolution on synthetic weights; each step kind; wiring checks; stand-in wirings against layers composed by hand; parameters from blobs and from raw files | | `../converter` (preset FG) | the converter reads a version-1 map with `"preset": "FG"`: one block source per weight blob; see the converter's README, "Preset FG" | | `reference/config.py` | the settled per-call configuration: the multi-frame intermediate time (one single-precision division), the index checks and flags, UI recomposition (FG preset A / B) with the profile values that force it | | `tests/test_fg_config.py` | the intermediate time against exactly rounded quotients, the index rules, every forcing profile value | diff --git a/clean/fg/reference/forward.py b/clean/fg/reference/forward.py new file mode 100644 index 00000000..9ec8929a --- /dev/null +++ b/clean/fg/reference/forward.py @@ -0,0 +1,217 @@ +# SPDX-License-Identifier: MIT +"""Frame generation (issue #96): CPU reference of both networks' forward pass, as far as it is delivered. + +Written for this project. The layers are settled: their shapes (clean/fg/layout.py), the weights and biases the +converter map gives per stage, float16 convolutions with bias, ReLU, 2x pooling, bilinear 2x upscale, element-wise +combines, and net1's 2 x 2 fold (clean/fg/reference/ops.py). How they are connected is not delivered, so the network +is run from a wiring the caller supplies. When the real wiring arrives it is passed in as data; the layers do not +change. + +Required arguments for what is OPEN (clean/fg/FORMATS.md): +- `wiring`: the list of steps (which layer reads which buffers, where the pooling, upscales, combines and channel + splits sit, ReLU after each convolution, the pooling kind). Format: see run_graph. +- `weight_view`: a function (storage weights [n] float16, layer) -> natural weights [out, k, k, in]. The converter + map v1 gives the weights as stored (the matrix unit's own tiling), so the natural view comes with map v1.1. + `view_by_axes` makes one for a plain axis order, for tests and for a map revision that is a plain reorder. +- `pad`: the border rule of the 3 x 3 convolutions (ops.PAD_MODES). +- `blob2`: net1's blob 2 is a 1 x 1 or a 2 x 2 convolution. "1x1" runs; "2x2" raises OpenItem (its stride and its + grouping of the 32 input values into 4 taps x 8 channels are not delivered). + +Parameters are {layer name: (storage weights [n] float16, bias [out] float16)} with the layout's layer names +(net1_01 .. net1_17, net2_01 .. net2_25): from synthetic or converted blobs (params_from_blobs) or from the +converter's raw output (params_from_raw: stages dl1.lNN / dl2.lNN of the preset-FG map). +""" +import os + +import numpy as np + +from clean.fg import layout as L +from clean.fg.reference import blobs as _blobs +from clean.fg.reference import ops +from clean.fg.reference.ops import OpenItem + +LAYERS = {l.name: l for l in list(L.NET1) + list(L.NET2)} +BLOB2_FORMS = ("1x1", "2x2") + + +# ---- parameters ------------------------------------------------------------------------------------------------- + +def params_from_blobs(blob_bytes, *, check=True): + """{layer name: (weights, bias)} from {blob name: bytes} (layout.blobs() names), via blobs.split_all.""" + return _blobs.split_all(blob_bytes, check=check) + + +def map_stage_name(layer): + """The preset-FG map's stage of a layout layer: net1_NN -> dl1.lNN, net2_NN -> dl2.lNN.""" + net, idx = layer.name.split("_") + return "dl%s.l%s" % (net[-1], idx) + + +def params_from_raw(raw_dir): + """{layer name: (weights, bias)} from the converter's --raw output (raw//.bin, float32 little + endian; tensors W_storage and b (net1) or b_storage (net2)). Every value must be exact in float16.""" + out = {} + for name, l in LAYERS.items(): + st = os.path.join(raw_dir, map_stage_name(l)) + w = np.fromfile(os.path.join(st, "W_storage.bin"), dtype=", "in": , "out": , "relu": true|false} + {"op": "pool", "in": , "out": , "kind": "max"|"avg"} + {"op": "upscale", "in": , "out": } (bilinear 2x, align corners) + {"op": "add", "in": [, ...], "out": } (element-wise, float16 after each sum) + {"op": "concat", "in": [, ...], "out": } (channels) + {"op": "slice", "in": , "out": , "channels": [first, end]} + on the input buffers {name: [c, H, W]}. Returns every buffer {name: array}.""" + check_wiring(wiring, inputs) + buf = {k: ops.f16(v) for k, v in inputs.items()} + for s in wiring: + kind = s["op"] + if kind == "conv": + y = run_layer(s["layer"], buf[s["in"]], params, weight_view=weight_view, pad=pad, relu_after=s["relu"], + blob2=blob2) + elif kind == "pool": + y = ops.pool2x(buf[s["in"]], kind=s["kind"]) + elif kind == "upscale": + y = ops.upscale2x_bilinear(buf[s["in"]]) + elif kind == "add": + y = buf[s["in"][0]] + for n in s["in"][1:]: + y = ops.add(y, buf[n]) + elif kind == "concat": + y = ops.concat(*[buf[n] for n in s["in"]]) + else: # slice + a, e = s["channels"] + src = buf[s["in"]] + if not (0 <= a < e <= src.shape[0]): + raise ValueError("slice %s outside %d channels" % (s["channels"], src.shape[0])) + y = src[a:e].copy() + buf[s["out"]] = y + return buf + + +def net1_forward(features, params, *, wiring, weight_view, pad, blob2, fold_order, output): + """net1 on its per-pixel features [10, H, W] (ops.net1_features): fold 2 x 2 into 48-value cells (fold_order: + OPEN, required), run the wiring on the input buffer "cells", and unfold the buffer named `output` (16 values per + cell) back to 4 values per pixel -> [4, H, W].""" + if features.shape[0] != ops.NET1_FEATURES: + raise ValueError("net1 takes %d features per pixel" % ops.NET1_FEATURES) + cells = ops.fold2x2(features, order=fold_order) + buf = run_graph(wiring, {"cells": cells}, params, weight_view=weight_view, pad=pad, blob2=blob2) + out = buf[output] + if out.shape[0] != 16: + raise ValueError("net1's output has 16 values per cell, got %d" % out.shape[0]) + return ops.unfold2x2(out, 4, order=fold_order) + + +def net2_forward(inputs, params, *, wiring, weight_view, pad, outputs): + """net2 on its input buffers {name: [c, H, W]}: runs the wiring and returns {name: buffer} for `outputs`.""" + buf = run_graph(wiring, inputs, params, weight_view=weight_view, pad=pad) + return {n: buf[n] for n in outputs} diff --git a/clean/fg/reference/ops.py b/clean/fg/reference/ops.py index c4e7603e..459dc384 100644 --- a/clean/fg/reference/ops.py +++ b/clean/fg/reference/ops.py @@ -207,12 +207,14 @@ def weight_shape(layer): # ---- the networks as a whole ---------------------------------------------------------------------------------------- def net1_forward(*args, **kwargs): - """net1 end to end: OPEN (decoder levels and skip connections, blob 2's tap count, the upsampling, the grid size - and the launch order are not delivered).""" + """net1 end to end with the original's wiring: OPEN (decoder levels and skip connections, blob 2's tap count, the + upsampling, the grid size and the launch order are not delivered). clean/fg/reference/forward.py runs it from a + wiring the caller supplies.""" raise OpenItem("net1 wiring: launch order, decoder levels, skip connections, blob 2 (1 x 1 or 2 x 2)") def net2_forward(*args, **kwargs): - """net2 end to end: OPEN (which layer reads which buffer, where the pooling, upscales and combines sit, which - layers end in ReLU, the grid size).""" + """net2 end to end with the original's wiring: OPEN (which layer reads which buffer, where the pooling, upscales + and combines sit, which layers end in ReLU, the grid size). clean/fg/reference/forward.py runs it from a wiring the + caller supplies.""" raise OpenItem("net2 wiring: launch order, pooling / upscale / combine placement, ReLU per layer") diff --git a/clean/fg/tests/test_fg_forward.py b/clean/fg/tests/test_fg_forward.py new file mode 100644 index 00000000..0cd16498 --- /dev/null +++ b/clean/fg/tests/test_fg_forward.py @@ -0,0 +1,285 @@ +# SPDX-License-Identifier: MIT +"""Frame generation (#96): the forward-pass reference (clean/fg/reference/forward.py) on synthetic weights, against +direct NumPy versions written separately here. The wirings used are stand-ins (the real one is not delivered); they +only show that a wiring runs the layers unchanged. + + python -m unittest clean.fg.tests.test_fg_forward +""" +import os +import shutil +import tempfile +import unittest + +import numpy as np +from numpy.lib.stride_tricks import sliding_window_view + +from clean.fg import layout as L +from clean.fg.reference import blobs as B +from clean.fg.reference import forward as F +from clean.fg.reference import ops + +ORDER = "out in ky kx" # the stand-in storage order of the synthetic weights + + +def f16(x): + return np.asarray(x, dtype=np.float64).astype(np.float16).astype(np.float64) + + +def natural_shape(l): + return (l.out, 1, 1, l.k) if l.name == "net1_02" else ops.weight_shape(l) + + +def synthetic_params(rng, scale=0.05): + """{layer: (storage weights, bias)} with natural weights stored in ORDER; also returns the natural weights.""" + params, natural = {}, {} + for name, l in F.LAYERS.items(): + cout, k, _, cin = natural_shape(l) + nat = rng.uniform(-scale, scale, (cout, k, k, cin)).astype(np.float16) + stored = nat.transpose(0, 3, 1, 2).reshape(-1) # out, in, ky, kx + params[name] = (stored, rng.uniform(-0.1, 0.1, cout).astype(np.float16)) + natural[name] = nat.astype(np.float64) + return params, natural + + +def direct_conv(x, w, b, pad, relu): + """Direct NumPy convolution: sliding windows and one tensordot (float64 sums), then one float16 rounding.""" + k = w.shape[1] + p = k // 2 + mode = {"zero": "constant", "replicate": "edge", "mirror": "reflect"}[pad] + xp = np.pad(f16(x), ((0, 0), (p, p), (p, p)), mode=mode) if p else f16(x) + win = sliding_window_view(xp, (k, k), axis=(1, 2)) # cin, H, W, ky, kx + y = np.tensordot(f16(w), win, axes=([3, 1, 2], [0, 3, 4])) + f16(b)[:, None, None] + y = f16(y) + return np.maximum(y, 0.0) if relu else y + + +VIEW = F.view_by_axes(ORDER) + + +class Layers(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.params, cls.natural = synthetic_params(np.random.default_rng(1)) + + def test_every_layer_against_direct(self): + rng = np.random.default_rng(2) + for name, l in F.LAYERS.items(): + cin = natural_shape(l)[3] + x = f16(rng.uniform(-1, 1, (cin, 5, 4))) + for pad in ("zero", "mirror"): + got = F.run_layer(name, x, self.params, weight_view=VIEW, pad=pad, relu_after=True, blob2="1x1") + want = direct_conv(x, self.natural[name], self.params[name][1], pad, True) + np.testing.assert_array_equal(got, want, err_msg="%s pad=%s" % (name, pad)) + got = F.run_layer(name, x, self.params, weight_view=VIEW, pad="replicate", relu_after=False, blob2="1x1") + np.testing.assert_array_equal(got, direct_conv(x, self.natural[name], self.params[name][1], "replicate", False)) + + def test_blob2_is_required(self): + x = f16(np.ones((32, 2, 2))) + with self.assertRaises(ValueError): + F.run_layer("net1_02", x, self.params, weight_view=VIEW, pad="zero", relu_after=True) + with self.assertRaises(ops.OpenItem): + F.run_layer("net1_02", x, self.params, weight_view=VIEW, pad="zero", relu_after=True, blob2="2x2") + # other layers do not need it + F.run_layer("net1_16", x, self.params, weight_view=VIEW, pad="zero", relu_after=True) + + def test_required_arguments(self): + x = f16(np.ones((32, 2, 2))) + for missing in ("weight_view", "pad", "relu_after"): + kw = {"weight_view": VIEW, "pad": "zero", "relu_after": True} + del kw[missing] + with self.assertRaises(TypeError, msg=missing): + F.run_layer("net1_16", x, self.params, **kw) + + def test_weight_view_checks(self): + x = f16(np.ones((32, 2, 2))) + bad = lambda w, l: np.zeros((1, 1, 1, 1)) # noqa: E731 + with self.assertRaises(ValueError): + F.run_layer("net1_16", x, self.params, weight_view=bad, pad="zero", relu_after=True) + with self.assertRaises(ValueError): + F.view_by_axes("out in ky") + p = dict(self.params) + p["net1_16"] = (p["net1_16"][0][:-1], p["net1_16"][1]) + with self.assertRaises(ValueError): + F.run_layer("net1_16", x, p, weight_view=VIEW, pad="zero", relu_after=True) + + def test_view_by_axes_orders(self): + rng = np.random.default_rng(3) + l = F.LAYERS["net2_14"] + nat = rng.standard_normal(ops.weight_shape(l)) + for order in ("out ky kx in", "out in ky kx", "in ky kx out", "ky kx in out"): + axes = order.split() + stored = nat.transpose([("out", "ky", "kx", "in").index(a) for a in axes]).reshape(-1) + np.testing.assert_array_equal(F.view_by_axes(order)(stored, l), nat, err_msg=order) + + +class GraphSteps(unittest.TestCase): + def setUp(self): + self.rng = np.random.default_rng(4) + self.params, _ = synthetic_params(np.random.default_rng(5)) + + def run_one(self, step, inputs): + return F.run_graph([step], inputs, self.params, weight_view=VIEW, pad="zero")[step["out"]] + + def test_pool_upscale_add_concat_slice(self): + a = f16(self.rng.uniform(-2, 2, (3, 4, 6))) + b = f16(self.rng.uniform(-2, 2, (3, 4, 6))) + mx = a.reshape(3, 2, 2, 3, 2).max(axis=(2, 4)) + av = f16(a.reshape(3, 2, 2, 3, 2).mean(axis=(2, 4))) + np.testing.assert_array_equal(self.run_one({"op": "pool", "in": "a", "out": "y", "kind": "max"}, {"a": a}), mx) + np.testing.assert_array_equal(self.run_one({"op": "pool", "in": "a", "out": "y", "kind": "avg"}, {"a": a}), av) + # bilinear, align corners: separable linear interpolation at i * (n - 1) / (2n - 1) + def interp(v, n, axis): + pos = np.arange(2 * n) * (n - 1) / (2 * n - 1) + return np.apply_along_axis(lambda r: np.interp(pos, np.arange(n), r), axis, v) + up = f16(interp(interp(a, 4, 1), 6, 2)) + got = self.run_one({"op": "upscale", "in": "a", "out": "y"}, {"a": a}) + np.testing.assert_allclose(got, up, rtol=2 ** -10, atol=1e-6) + np.testing.assert_array_equal(self.run_one({"op": "add", "in": ["a", "b"], "out": "y"}, {"a": a, "b": b}), + f16(a + b)) + np.testing.assert_array_equal(self.run_one({"op": "concat", "in": ["a", "b"], "out": "y"}, {"a": a, "b": b}), + np.concatenate([a, b])) + np.testing.assert_array_equal(self.run_one({"op": "slice", "in": "a", "out": "y", "channels": [1, 3]}, {"a": a}), + a[1:3]) + + def test_wiring_checks(self): + x = {"x": f16(np.ones((32, 2, 2)))} + conv = {"op": "conv", "layer": "net1_16", "in": "x", "out": "y", "relu": True} + bad = [ + [dict(conv, op="dense")], + [{k: v for k, v in conv.items() if k != "relu"}], # relu is required + [dict(conv, relu=1)], + [dict(conv, extra=1)], + [dict(conv, **{"in": "nope"})], + [dict(conv, layer="net9_01")], + [conv, dict(conv, out="z", **{"in": "y"})], # a layer used twice + [conv, dict(conv, layer="net1_15", out="y")], # a buffer written twice + [{"op": "pool", "in": "x", "out": "p"}], # pool kind is required + [{"op": "add", "in": ["x"], "out": "s"}], + [{"op": "upscale", "in": ["x", "x"], "out": "u"}], + ] + for w in bad: + with self.assertRaises(ValueError, msg=w): + F.run_graph(w, x, self.params, weight_view=VIEW, pad="zero") + with self.assertRaises(ValueError): + F.run_graph([{"op": "slice", "in": "x", "out": "s", "channels": [30, 40]}], x, self.params, + weight_view=VIEW, pad="zero") + + +class Networks(unittest.TestCase): + """Stand-in wirings over the real layer shapes: each network result equals the same layers composed by hand with + the direct reference. Two different wirings reuse the same parameters and layers unchanged.""" + + @classmethod + def setUpClass(cls): + cls.params, cls.natural = synthetic_params(np.random.default_rng(6)) + + def direct(self, name, x, pad, relu): + return direct_conv(x, self.natural[name], self.params[name][1], pad, relu) + + def test_net1_stand_in(self): + rng = np.random.default_rng(7) + feats = f16(rng.uniform(0, 1, (10, 8, 12))) + wiring = [ + {"op": "conv", "layer": "net1_01", "in": "cells", "out": "e0", "relu": True}, # 48 -> 32 + {"op": "conv", "layer": "net1_02", "in": "e0", "out": "e1", "relu": True}, # 32 -> 64 (1x1) + {"op": "pool", "in": "e1", "out": "e1p", "kind": "max"}, + {"op": "conv", "layer": "net1_14", "in": "e1p", "out": "d1", "relu": True}, # 64 -> 64 + {"op": "upscale", "in": "d1", "out": "d1u"}, + {"op": "add", "in": ["d1u", "e1"], "out": "s1"}, + {"op": "conv", "layer": "net1_15", "in": "s1", "out": "d0", "relu": True}, # 64 -> 32 + {"op": "conv", "layer": "net1_16", "in": "d0", "out": "d0b", "relu": True}, # 32 -> 32 + {"op": "conv", "layer": "net1_17", "in": "d0b", "out": "out", "relu": False}, # 32 -> 16 + ] + for pad in ("zero", "replicate"): + got = F.net1_forward(feats, self.params, wiring=wiring, weight_view=VIEW, pad=pad, blob2="1x1", + fold_order="dy dx c", output="out") + cells = ops.fold2x2(feats, order="dy dx c") + e0 = self.direct("net1_01", cells, pad, True) + e1 = self.direct("net1_02", e0, pad, True) + d1 = self.direct("net1_14", ops.pool2x(e1, kind="max"), pad, True) + s1 = f16(ops.upscale2x_bilinear(d1) + e1) + d0 = self.direct("net1_16", self.direct("net1_15", s1, pad, True), pad, True) + out = self.direct("net1_17", d0, pad, False) + want = ops.unfold2x2(out, 4, order="dy dx c") + self.assertEqual(got.shape, (4, 8, 12)) + np.testing.assert_array_equal(got, want, err_msg=pad) + for missing in ("wiring", "weight_view", "pad", "blob2", "fold_order", "output"): + kw = dict(wiring=wiring, weight_view=VIEW, pad="zero", blob2="1x1", fold_order="dy dx c", output="out") + del kw[missing] + with self.assertRaises(TypeError, msg=missing): + F.net1_forward(feats, self.params, **kw) + with self.assertRaises(ValueError): # the output must have 16 values per cell + F.net1_forward(feats, self.params, wiring=wiring, weight_view=VIEW, pad="zero", blob2="1x1", + fold_order="dy dx c", output="d0") + + def test_net2_stand_in(self): + rng = np.random.default_rng(8) + x18 = f16(rng.uniform(-1, 1, (18, 8, 8))) + wiring = [ + {"op": "conv", "layer": "net2_14", "in": "x18", "out": "h", "relu": True}, # 18 -> 16 + {"op": "pool", "in": "h", "out": "hp", "kind": "avg"}, + {"op": "conv", "layer": "net2_15", "in": "hp", "out": "q", "relu": True}, # 16 -> 32 + {"op": "conv", "layer": "net2_16", "in": "q", "out": "q1", "relu": True}, # 32 -> 32 + {"op": "conv", "layer": "net2_24", "in": "q1", "out": "g", "relu": False}, # 32 -> 48 + {"op": "upscale", "in": "g", "out": "gu"}, + {"op": "slice", "in": "gu", "out": "g0", "channels": [0, 16]}, + {"op": "slice", "in": "gu", "out": "g1", "channels": [16, 32]}, + {"op": "add", "in": ["g0", "g1", "h"], "out": "s"}, + {"op": "conv", "layer": "net2_25", "in": "s", "out": "y", "relu": False}, # 16 -> 8 + ] + got = F.net2_forward({"x18": x18}, self.params, wiring=wiring, weight_view=VIEW, pad="mirror", outputs=["y", "q"]) + h = self.direct("net2_14", x18, "mirror", True) + q = self.direct("net2_15", ops.pool2x(h, kind="avg"), "mirror", True) + g = self.direct("net2_24", self.direct("net2_16", q, "mirror", True), "mirror", False) + gu = ops.upscale2x_bilinear(g) + s = f16(f16(gu[:16] + gu[16:32]) + h) + np.testing.assert_array_equal(got["y"], self.direct("net2_25", s, "mirror", False)) + np.testing.assert_array_equal(got["q"], q) + + def test_same_layers_under_two_wirings(self): + rng = np.random.default_rng(9) + x = f16(rng.uniform(-1, 1, (32, 4, 4))) + w1 = [{"op": "conv", "layer": "net1_16", "in": "x", "out": "a", "relu": True}] + w2 = [{"op": "concat", "in": ["x", "x"], "out": "xx"}, + {"op": "slice", "in": "xx", "out": "x2", "channels": [32, 64]}, + {"op": "conv", "layer": "net1_16", "in": "x2", "out": "a", "relu": True}] + a1 = F.run_graph(w1, {"x": x}, self.params, weight_view=VIEW, pad="zero")["a"] + a2 = F.run_graph(w2, {"x": x}, self.params, weight_view=VIEW, pad="zero")["a"] + np.testing.assert_array_equal(a1, a2) + + +class Params(unittest.TestCase): + def test_from_blobs_and_raw(self): + rng = np.random.default_rng(10) + blobs = {} + for l in L.NET1: + blobs[l.name] = B.build_net1(l, rng.uniform(-1, 1, l.weight_elements).astype("