Skip to content

Frame generation: CPU reference of both networks' forward pass from a supplied wiring - #179

Merged
phantoslayer21 merged 1 commit into
mainfrom
fg/cpu-forward
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
fg/cpu-forward

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

The CPU reference of both frame-generation networks' forward pass, as far as parts 1–2 and the map define it (lane h). The layers are settled. How they are connected is not delivered yet, so a network runs from a wiring the caller supplies. When the real wiring arrives it is passed in as data, without changing the layers.

clean/fg/reference/forward.py

  • Parameters per layer (layout names net1_01..net2_25): storage-order weights and the bias. params_from_blobs builds them from blob bytes, via blobs.split_all. params_from_raw reads the converter's --raw output of the preset-FG map (stages dl1.lNN/dl2.lNN, tensors W_storage and b/b_storage), checking that every value is exact in float16.
  • run_layer: one convolution layer through ops.conv2d (float16 operands, float64 sums, one float16 rounding, optional ReLU).
  • run_graph: runs a list of steps:
    • conv (layer, ReLU flag), pool (kind), upscale (bilinear 2×, align corners), add, concat and slice;
    • the wiring is checked before it runs: known steps, exact fields, every buffer written once before it is read, and each layer used at most once.
  • net1_forward: the 2×2 fold of the 10 features into 48-value cells, the wiring, then the unfold of 16 values per cell to 4 per pixel.
  • net2_forward: the wiring, returning the named buffers.

Required arguments for what is still OPEN (clean/fg/FORMATS.md):

  • wiring;
  • weight_view: storage to natural [out, k, k, in]. Map v1 gives the weights as stored, and the natural view comes with v1.1. view_by_axes covers a plain axis reorder.
  • pad: the border rule;
  • blob2: "1x1" runs net1's blob 2 as a 1×1 convolution; "2x2" raises OpenItem, because its stride and channel grouping are not delivered.
  • fold_order.

Refs #96

Tested

  • python -m unittest clean.fg.tests.test_fg_forward: 11 tests pass locally, all on synthetic weights.
    • Every layer of both networks (all 42, blob 2 as 1×1) matches a direct NumPy convolution (sliding windows plus one tensordot) bit for bit, for all three border rules, with and without ReLU.
    • Pool, upscale, add, concat and slice match direct NumPy versions.
    • Every wiring error is checked, along with the required arguments and the blob2 rule.
    • A net1 stand-in wiring (fold, encoder, pool, upscale with a skip add, decoder to 16, unfold) and a net2 stand-in wiring (pool, block, 48-channel upscale with a 3-group split and add, output) equal the same layers composed by hand. The same layers give the same result under two different wirings.
    • Parameters from blobs and from raw converter files agree, and a value that is not exact in float16 is refused.
  • The whole clean/fg test set and the line-ending check pass. The public gates pass, with no hits in clean/fg. The branch also merges cleanly with Converter: the delivered preset-FG map, storage order and offset axes #177 and Frame generation: real-file check tool (execute-only, digests and verdict only) #178.

Not tested

  • The original's wiring, the natural weight order and float16 accumulation are not delivered, so nothing is compared with the original's network output. The stand-in wirings only show that a wiring runs the layers unchanged.

… supplied wiring

clean/fg/reference/forward.py: each convolution layer from its stage's
parameters (from blobs, or from the converter's raw output of the preset-FG map),
and a network run as a checked list of steps (conv, pool, upscale, add, concat,
slice); net1_forward adds the 2x2 fold and unfold. Undelivered behaviour stays a
required argument: the wiring, the storage-to-natural weight view, the border
rule, net1 blob 2 (1x1 runs, 2x2 raises OpenItem) and the fold order. The real
wiring plugs in as data without changing the layers.

Refs #96

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 17:16
@phantoslayer21
phantoslayer21 merged commit a17aaff into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/cpu-forward branch November 14, 2026 17:25
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