code wiki / (root) / nx_diffusion_loop.nx

nx_diffusion_loop.nx

buildroot/runtime/nx_diffusion_loop.nx

8523 B245 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_diffusion_loop.nx -- N-step diffusion sampler composer. L4 brick. Closes the image-gen forward path: given noise + a UNet block per layer + a denoising sigma schedule, produces a denoised latent over N sampler steps. Composes: nx_sampler (DPM++ 2M Euler-first + 2nd-order-mid, + Karras schedule via nx_root) nx_unet_block (per-layer ResBlock; caller stacks N layers) NxTensor (L1 4D containers) nx_loop.LoopVerdict (control) ===== High-level shape ========================================== noise -> x_0 for i in 0..n_steps: sigma_now = schedule[i] sigma_next = schedule[i+1] // Denoising prediction: caller's UNet (stack of nx_unet_block). // v1 takes a callback function pointer so the composer is // architecture-agnostic. d_now = denoise(x, sigma_now) // DPM++ 2M step. if i == 0: x = nx_sampler_step_euler(x, d_now, sigma_now, sigma_next) else: x = nx_sampler_step_2nd(x, d_now, d_prev, ratio) d_prev = d_now return x ===== v1 scope ================================================== v1 makes the denoiser callback signature explicit: func denoise(x_lanes: *i64, n_lanes: nx_int, sigma_q14: i64,

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_sampler.nx nx_diffusion_loop.nx

imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_sampler.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nx_sampler_fill_schedule_l nx_diffusion_loop sys_mmap ↻ _dl_ratio_q10 nx_sampler_step_euler _q10_lerp nx_sampler_step_2nd _q10_lerp ↻ nx_dl_verdict_is_valid

structs

none

consts

71const NX_DL_Q10: nx_int = 1024
72const NX_DL_Q14: nx_int = 16384
76const NX_DL_OK: nx_int = 0
77const NX_DL_ERR_BAD_DIMS: nx_int = 1
78const NX_DL_ERR_BAD_SCHEDULE: nx_int = 2
79const NX_DL_ERR_OOM: nx_int = 3
80const NX_DL_ERR_DENOISER: nx_int = 4
81const NX_DL_N_VERDICTS: nx_int = 5

functions

83func nx_dl_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
95func _dl_ratio_q10(sigma_now_q14: i64, sigma_next_q14: i64) -> nx_int
called by 1: nx_diffusion_loop
116func nx_diffusion_loop(x_io: *i64, n_lanes: nx_int,
186func _dl_identity_denoiser(x_lanes: *i64, n_lanes: nx_int, sigma_q14: i64,
206func main() -> i64