nx_f32_groupnorm.nx
buildroot/runtime/nx_f32_groupnorm.nx
about
nx_f32_groupnorm.nx -- software-f32 Group Normalisation (Wu & He 2018), the R3 vision-op re-tier.
sd-server -> Nishi migration, rung 3 ("unify the two numeric universes"): the existing diffusion
GroupNorm `nx_groupnorm.nx` is i64 Q10 (10 fractional bits) and has only ever run on identity weights;
this is the SAME math in the sovereign software-f32 tier (`nx_f32_*`, bit-exact IEEE-754 emulated in
i64) so the REAL dequantized GGUF weights (`nx_q4k_to_f32` etc.) flow through it. GroupNorm(32) is the
load-bearing norm in SD/Flux/Z-Image UNet + VAE ResBlocks.
Tensor representation: a FLAT `*i64` whose every element is an f32 bit-pattern, laid out [N,C,H,W]
row-major, with dims passed explicitly. This deliberately avoids `nx_tensor`'s F32 dtype, which is
DTYPE_GATED / unusable today (TODO_COMPILER_F32_F64 parked) -- the flat-f32-bits convention is how the
whole `nx_f32_*` stack already works.
Composes ONLY gated primitives: nx_f32_add/sub/mul/sqrt (nx_f32.nx), nx_f32_div (nx_f32_div.nx),
nx_i32_to_f32 (nx_f32_cvt.nx). No libm, no third-party. eps = 1e-5 (Z-Image norm_eps), built from
cvt+div so there is no hand-coded float bit-pattern.
Math (per group g of a sample n): mean,var over (C/G * H * W) elements; y = (x-mean)/sqrt(var+eps)*gamma+beta.
license_tier: ORIGINAL
dependencies 4 imports · 1 importers
imports: nx_syscalls.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nx
imported by: nx_f32_resblock.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 24 | const NX_MAGIC_100000: i64 = 100000 |
| 26 | const NX_F32GN_OK: i64 = 0 |
| 27 | const NX_F32GN_ERR_BAD_GROUPS: i64 = 5 |
functions
| 30 | func nx_f32gn_eps() -> i64 { return nx_f32_div(nx_i32_to_f32(1), nx_i32_to_f32(NX_MAGIC_100000)) } |
| 34 | func nx_f32_groupnorm_forward(x: *i64, N: i64, C: i64, H: i64, W: i64, n_groups: i64, called by 2: mainnx_f32_resblock_forward calls 7: nx_i32_to_f32nx_f32gn_epsnx_f32_addnx_f32_divnx_f32_subnx_f32_mul+1 |
| 105 | func main() -> i64 |