Skip to content

Frame generation: net1's delivered wiring and arithmetic in the CPU reference - #181

Merged
phantoslayer21 merged 2 commits into
mainfrom
fg/net1-wiring
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
fg/net1-wiring

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Adds net1's delivered wiring and arithmetic to the CPU reference (lane h). net1, the 17-blob U-Net, is now complete and needs no required arguments; net2 keeps its required wiring until its own wiring is delivered. This PR stacks on #180 (map v1.1, natural weights); after #180 merges, its base becomes main.

clean/fg/reference/net1.py (all fixed, nothing an argument)

  • Fold: the 10 per-pixel values go into 48-channel cells, channel 4v + q with q = 2dy + dx. Channels 40–47 and pixels outside the input are zero. The 16 output channels per cell unfold the same way to 4 values per pixel.
  • NET1_WIRING: the 32 steps as data. Five levels down (convolution, then 2×2 max-pool), the two bottom 1×1 convolutions, then five levels up (upscale to the skip's size, float16 add of the skip, two 1×1 convolutions). Level sizes halve with floor.
  • Convolution: stride 1, zero border, cross-correlation over the natural weights.
    • The float16 accumulator starts at the bias.
    • Products are taken in 16-term chunks, each summed exactly and added with one float16 rounding, in the layer's chunk order: 1×1 ascending; blobs 1, 3 and 4 channel block outer, then kx, then ky; blob 5 kx, then channel block, then ky.
  • Leaky ReLU: y = max(x, h(s·x)) after every convolution except the last, with the delivered slope s = 0.0099945068359375 (float16 0x211E).
  • Max-pool: the delivered formula m ← (x > m)·x + (x ≤ m)·m, in float16.
  • Upscale: bilinear, align corners, with single-precision positions and float16 weights, products and sums.
  • Add: float16.

clean/fg/reference/fp16acc.py: the exact chunk accumulation, RN16(acc + Σ₁₆ aᵢbᵢ), in integer arithmetic (high/low splits of the 2⁻²⁴ integer form, then one nearest-even rounding). Non-finite operands follow IEEE.

forward.py

  • net1_forward(values, params) takes no other arguments.
  • New params_from_model_file and read_model_file read the converter's model.wgcm (container version 1, checksum checked).
  • net2 keeps run_graph/net2_forward with a required wiring and border rule.

clean/fg/tools/net1_digest.py: runs net1 on a converter model file with a fixed synthetic input (seeded, 64×64 pixels) and records digests only: the output's SHA-256, its shape, the non-finite count and the model file's SHA-256.

Notes

  • The delivered slope is labelled "h(0.01)", but nearest-even rounding of 0.01 gives the next float16 value up (0x211F). The delivered value 0x211E is used as given.
  • The original computes the upscale ratio with an approximate division. Here it is the correctly rounded single-precision quotient, so the two can differ in the last bit.

Refs #96

Tested

  • test_fg_fp16acc: about 2,100 random rows (every exponent, subnormals, large values) plus ties, sticky bits, cancellation to ±0 and overflow, against an exact Fraction reference written in the test.
  • test_fg_net1, against versions written separately in the test:
    • one convolution per chunk order, with and without the activation, against exact rationals; the chunk order provably changes results;
    • the zero border; the upscale against a scalar implementation of the rule (sizes 1→2 up to 5→11, extent 1); the max-pool against NumPy max and, with inf/NaN, against every tap order;
    • fold/unfold positions, the wiring data and the floor level sizes;
    • net1 end to end on synthetic weights (64×64 and 66×71) against a hand-composed 32-step version, bit for bit.
  • The model-file reader and the digest tool are tested on a synthetic model.wgcm written by the test.
  • The whole clean/fg set passes (73 tests).
  • Locally, net1 was also run on the real converted weights: the converter's output of a player's own library with map v1.1, all 42 stage digests matching. With the fixed synthetic input, all 4×64×64 outputs are finite and the output digest is identical across two runs. The digest is recorded privately; the converted file was deleted.
  • The line-ending check and the public gates pass, with no hits in clean/fg.

Not tested

  • A comparison with the original's output: net1's input images and the input grid size are not delivered yet.
  • net2 (its wiring is not delivered).

…eference

clean/fg/reference/net1.py runs net1 end to end as delivered: the 2x2 fold
(channel 4v + q), 32 steps as data (five levels down with 2x2 max-pool, the
bottom, five levels up with an align-corners upscale and a float16 skip add),
zero border, leaky ReLU with the delivered slope (0x211E) after every
convolution but the last, and float16 accumulation from the bias in 16-term
chunks in each layer's chunk order. clean/fg/reference/fp16acc.py does the
chunk accumulation exactly with integer arithmetic.

forward.net1_forward(values, params) takes no other arguments now; net2 keeps
its required wiring and border rule. Parameters can also come from the
converter's model file; tools/net1_digest.py records the digest of net1's
output for a fixed synthetic input.

Refs #96

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 18:14
Base automatically changed from fg/map-v1.1 to main November 14, 2026 18:15
@phantoslayer21
phantoslayer21 merged commit 6622148 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/net1-wiring branch November 14, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant