Repository navigation
madspace: float32 networks - #274
Draft
theoheimel wants to merge 13 commits into
Draft
theoheimel wants to merge 13 commits into
theoheimel wants to merge 13 commits into
Conversation
DataType becomes {dt_int32, dt_float32, dt_float64, batch_sizes}. float32 is
supported in npy I/O, DLPack import/export, graph JSON and the Python enum.
Tensor views now check that the element type matches the tensor dtype.
Instructions with a 'precision' field in instruction_set.yaml are expanded into <name>_float32 and <name>_float64, each with its own opcode. The FunctionBuilder method <name> dispatches on the dtype of its arguments. Kernel policies are templated on the float type (CpuTypes32, GpuTypes32). - matmul and the activations are available in both precisions (sgemm/dgemm) - new instructions convert_float32 and convert_float64 - device copy/zero/add and gradient allocation handle float32 - activation backward kernels now accumulate into the input gradient - fix the shape check of single (non-batch) inputs from Python
Every SIMD backend gets a float32 family FVec32/IVec32/BVec32 with twice the lanes of the float64 vectors and int32 indices and masks of the same width (NEON 4, AVX2/AVX512Y 8, AVX512 16 lanes), used by SimdTypes32. - vector types carry their lane count, which the views and the foreach loop use instead of the global simd_vec_size - loads and gathers dispatch on a VecTag, as int loads exist in both families - jobs are aligned to and literals padded to the largest lane count
- the contiguous global gradient buffer takes the dtype of the trainable globals, which must all share one dtype - Adam step for float32 parameters - the gradient clipper computes the norm in float64 for float32 gradients - Tensor::cast for a CPU copy with converted element type
MLP takes a precision (float32 or float64) for its weights and evaluation. Its input and output stay float64, with conversions at the boundary, so softmaxes, splines and Jacobians around it are unchanged. Flow, DiscreteFlow and ChannelWeightNetwork forward it as subnet_precision / precision. Tests for float32 MLP training against torch, float32 flows and saving and loading float32 globals.
The backward kernels of gather and select declared the (unused) gradient of their integer index input as a float view, while the runtime allocates it as an int32 tensor. The view dtype check rejected this in the backward pass of float32 flows. Also test the gradients of a flow with float32 subnetworks.
Selects float32 or float64 for the weights and evaluation of all MadNIS networks (flow, discrete flows, channel weight network). One setting for all of them, as the optimizer trains them together.
The float32 matmul calls sgemm_ and sgemv_, which the bundled OpenBLAS did not build.
The precision arguments default to DataType.float64, which pybind11_stubgen can only render with an enum class location.
Contributor
|
fyi #Should fix
#Minor
|
Contributor
Author
|
@oliviermattelaer Thanks, I've fixed the issues (except for the gridpack one, since we're not aiming for cross-version compatibility and are still alpha anyways) |
theoheimel
added this pull request to stack #299
October 17, 2026 12:32
# Conflicts: # .github/gpu_ci/madspace_checks.py # madspace/src/cpu/runtime.cpp # madspace/src/driver/systematics.cpp # madspace/src/gpu/runtime.cu # madspace/src/phasespace/phasespace.cpp # madspace/tests/test_histogram_op.py # madspace/tests/test_mlp.py # madspace/tests/test_simd_layout.py
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds single-precision support to madspace, mainly so the MadNIS networks can be evaluated and trained in float32. This will enable faster MadNIS training and sampling, and reduce gridpack sizes by a factor 2. In terms of unweighting efficiency, i would not expect a difference, but this will need some investigation especially for longer trainings.
Everything else (including normalizing flow jacobians) remains fp64. However, these changes can also be used as a basis to investigate moving more of phasespace to fp32 in the future.
Stacked on #222 (
fix-madspace-simd).Changes
DataTypeis nowint32 / float32 / float64 / batch_sizes. This is a clean break: graph JSON, the Python enum and npy files use the new names, and npy and DLPack gain<f4/f32 support. Tensor views now check that the element type matches the tensor dtype.precision: [float32, float64]. The generator expands it intoX_float32andX_float64, each with its own opcode. The builder methodXdispatches on the argument dtype, so frontend code doesn't change. A float64 literal passed to a float32 call is converted first.matmul(sgemm/dgemm, and the same on cuBLAS/rocBLAS) and all activations exist in both precisions. Newconvert_float32andconvert_float64instructions are differentiable.MLP(..., precision=...)converts at its boundaries.Flow,DiscreteFlowandChannelWeightNetworkforward this assubnet_precision/precision.madnis.nn_float_precision(float64by default, orfloat32).Fixes found along the way
gatherandselectbackward kernels used float views for int gradients. The new dtype check caught this..pyistub generation needs to know whereDataTypelives to render its default arguments.Testing
e+ e- > w+ w-with MadNIS: the cross section is 2.6902468 pb in float64 and 2.6902465 pb in float32.