Repository navigation
mlx performance: MLX-sized grids, compiled stages, Adams on the GPU - #543
Merged
Merged
Conversation
track and ab take --backend mlx, which runs each case in single precision and noiselessly, and skips with a reason what mlx does not admit (the Adams integrator, the planar and general routes). --noise none drops a case's noise on any backend and --fft-size pow2 rebuilds its time grid at a power of two, so a cross-backend A/B can match the workload. ab's --baseline-backend and --candidate-backend give each arm its own backend. Relates to #343 and #325. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fft_size="auto" minimised one cost model, fitted to FFTW on CPUs, which prefers 2-3-5-smooth sizes. MLX's GPU FFT is direct at every smooth size up to 4096 and at powers of two, and takes Bluestein's algorithm elsewhere: an rfft/irfft pair at 10240 took 715 us against 63 us at 16384 on an Apple M5 Max. fft_cost takes the library, the grids' from_limits take transforms=, and the keyword interfaces choose MLX's costs for a single-precision run on mlx or auto. he_rdw_averaged, one DOPRI5 trial in process (contended Mac): 18.6 ms on the 10240 grid, 4.66 ms on 16384. Relates to #85. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each stage is one mx.compile graph on the Metal device, as are a stage's input combination, the step's end and the norm's reductions. What varies with position (taper, Kerr's, Raman's and the plasma channels' factors, the populations' parameters) is formed on the host in binary64, rounded once as before, and passed as one float32 vector, so a compiled graph sees only its inputs. MLX compiles each operation with the eager kernel's rounding, so trial states are bitwise the previous head's on every route checked (fibre with field and envelope plasma, Raman, radial, Cartesian, low-storage). The passes square by products, as MLX's eager x**2 rounds through pow. A propagator and its inverse come from one double-float combination (DoubleFloatTerms.pair), bitwise the two separate kernels, once per distinct stage fraction of a trial. One DOPRI5 trial, power-of-two grids, M5 Max under load, op by op against compiled: he_rdw_averaged 5.30/2.91 ms, rdw 7.76/4.76, radial_filament_256 14.1/6.88, spatial_absorber 3.69/2.38, kerr_beam_192 246/131, cartesian_filament_128 806/316. Relates to #343. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The alarm copied the last stage's projections to the host at every accepted step and transformed them there with a binary64 prefactor: 1.47 ms of a 5.8 ms step on rdw (four modes, Gauss-Kronrod). It is now formed on the device and its one scalar read with the next trial's norm, or when the quadrature_error statistic asks for it. The embedded projection's difference is taken before the transforms, which are linear: transformed apart, two binary32 spectra differ by their rounding at the alarm's own level. On rdw the device value is 3.2870e-7 against 3.2870e-7 recomputed in binary64 from the same rows (the binary32 oracle's separate transforms read 4.35e-7). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The scan ran 256 threads per row. 1024 threads for a few rows and 512 for many take a single 16383-sample row (a capillary's) from 105 to 62 us, and leave 1024 rows of 2047 at 114 against 116 (chained, Apple M5 Max). The additions and their order are unchanged, so the scan stays the oracle's prefix_sum to the bit. Holding the row in threadgroup memory was slower at every shape tried and is not used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mx.async_eval of each stage lets the device run it while the host builds the next, where the trial's graph was built whole and then run. One DOPRI5 trial, Apple M5 Max: he_rdw_averaged 2.75 -> 2.57 ms, rdw 3.89 -> 3.54, radial_filament_256 5.0 -> 4.4. The results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MlxBackend._adams_engine returns MlxAdams, an AdamsEngine that keeps the history's untransported source rows on the device and forms each trial there, as HostHistory forms it on the host: the flow and moments in binary64 on the host, rounded once; the predictor, corrector and defects as compiled device passes, their coefficients one batched real product over the stacked samples (Metal bounds a fused kernel's buffers); and one synchronisation per trial for the norms, the anchor's magnitude, finiteness and the envelope plasma's failures. A varying operator adds the transported compensation: each sample's state on the device and its rate on the host, the factor exp((1 - theta_j) x)(D(z_j) - x/h) formed in binary64 and rounded once. The interaction formulation and the untransported witness are refused by name, and the integrator admission at the interface now lists mlx. The backend takes the native package's compiled helpers (stage tables' rows, the Adams basis), which SEP 29 defines as bitwise the Python forms: the RDW run below is bitwise the same with either, 4.62 s -> 3.99 s. Single precision still refuses Adams outside the study admission; this commit runs it under study_admission(). Mode-averaged He RDW (1.5 m, 16384 samples, noiseless): binary32 Adams on mlx is 2.5e-6 from binary64 Adams on native (binary64 RK is 2.2e-6 from it, binary32 RK on mlx 4.3e-5). Relates to #342. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host phi functions took 1.5-3 ms a trial on a capillary's 16k bins and
19-44 ms on a 384 x 513 radial grid. A double-float kernel now forms the
step's exponent from the operator's terms, exp(x) and k! phi_{k+1}(x) -- the
reference's far recurrence beyond the join and its scaled series and
doubling within it, exp reduced by whole turns of a double-float 2 pi -- and
rounds each once: within one binary32 ulp of the binary64 forms rounded
(most orders bit for bit). The compensation's factors are double-float
combinations too: the flow at weights (1 - theta_j) w and the rates'
difference at r_j - w/h, its weights differenced in binary64 (native's
form), so a sample keeps its rate as weights and a snapshot holds
rate_weights. A carrier frame, or an operator without device terms, keeps
the host moments; Adams on MLX's CPU device is refused.
Full runs (study admission, Apple M5 Max under load), mlx Adams before ->
after: rdw 9.10 -> 4.99 s (native Adams 4.85 s), he_rdw_averaged 4.07 ->
3.58 s, radial_filament_256 3.76 -> 1.40 s; against binary64 Adams the
fields stay at 4.4e-6, 3.0e-6 and 6.8e-6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…actors DoubleFloatTerms.trial forms x, exp(x), the moments, every history sample's compensation factor exp(s_j x)(D(z_j) - x/h) (the product rounded once, as the reference rounds it) and the endpoint's D(z + h) - x/h in one kernel, reading the operator's terms once where each factor had two kernels of its own (18 terms on rdw's gradient). rdw, full run, interleaved against the previous commit: 6.71/5.32 s -> 4.87/4.66 s; the field stays 4.2e-6 from binary64 Adams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The predictor and the corrector with its defects were batched real matrix products over stacked samples, K at most seven, which MLX's GEMM runs poorly. A kernel now forms every formula's increment per element in registers, the reference's order (each moment's combination first), with the compensation's weighted rows: chained on rdw's 4 x 4097 state, the predictor 169 -> 35 us and the corrector with three defects 162 -> 64 us. A controller that weights each bin now reads the trial's own defects, compensation included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#342's rule: binary32 Adams against binary64 Adams at one tolerance. Eight cases, whole length, noise-free, power-of-two grids, mlx against native: binary32 Adams is 2.3e-6 to 2.2e-4 from binary64 Adams, all far inside the 1e-3 field envelope and, the GNLSE aside (binary32 runs at its 1e-6 floor against binary64's 1e-7), within a small multiple of binary64 RK's own difference from Adams. On the capillaries it is closer to the binary64 result than binary32 RK (rdw: 4.3e-6 against 1.3e-4). The record is in the single-precision guide. admit_precision no longer refuses Adams; its adams parameter and the study_admission switch go. A single-precision Adams history now resumes in binary32: HostHistory.load_rows keeps the state's precision and the oracle narrows a restored state (it came back complex128). New resume cases cover numpy_ref and mlx, the latter's compensated history included. The benchmarks run multistep on mlx and refuse its interaction formulation. The single-precision default integrator stays RungeKutta(). Closes part of #342. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replayed exponential Adams on a soliton fibre and, compensated, on an argon gradient, each against numpy_ref's binary32 Adams within the oracle tests' step bound; the trial kernel's flow, moments and compensation factor against binary64 rounded once (within one binary32 ulp, phases to thousands of radians); the interaction formulation refused by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A saved plane's species statistics scanned every node's field on the host in binary64: on cartesian_filament_128 the planes' statistics were 37.7 s of a 50.6 s run (a tenth of its length), the march 11.9 s. They now form the nodes on the device from the plane's field and run the stage's own rate kernel, running integral and stable population chunk by chunk, reading the final fractions and peak rates only -- what _envelope_populations already does for the envelope grid. The run took 21.5 s; the values agree with the oracle's to about 1e-6 of their largest (a test holds them to 1e-4 on a capillary and radial and Cartesian beams). Per RK trial the mlx Cartesian march is now 223 ms against native's 511 ms (all cores). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SINGLE_RTOL_CAP held a single-precision free-space run to 1e-5 until 1e-4 was qualified in binary32 (the maintainers' ruling of 2026-10-28, #85). RK, noise-free, power-of-two grids, against binary64 at 1e-6, binary64 at 1e-4 / binary32 at 1e-4: radial_filament_256 9.8e-5 / 2.0e-5, spatial_absorber 2.5e-5 / 2.1e-5, cartesian_filament_128 (1.5 cm, it leaves its grid at 2 cm) 6.9e-5 / 2.4e-5. The cap is now 1e-4, so no interface's default is capped; the record is in the single-precision guide. The Cartesian filament takes 48 steps instead of 61 (27.3 s on mlx against 42.5 s on native over that 1.5 cm). This changes a default the maintainers ruled on: it is one commit, to revert if the ruling should stand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs build listed FUSED and population_parameters without a target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With Adams admitted (#342), default_integrator no longer sends single precision to RungeKutta(): prop_capillary, prop_radial and prop_planar take Multistep(), as in binary64, so a run changes arithmetic and not method with its precision. On mlx this is the faster stepper on the four-mode capillary and the radial routes (A/B against native, a third of each run: rdw 0.84, radial_filament_256 0.42, spatial_absorber 0.27, against 1.24, 0.45 and 0.80 under RK). The overflow test names RungeKutta(): its point is the interaction picture's inverse propagator, which exponential Adams does not form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each stage returns its source before the inverse propagator. The last stage's input is the trial state, and the next first stage's propagators are exactly one, so its source is the next step's first stage, bitwise. mlx keeps it after an accepted step whose finish leaves the state as it is (not under the split-step collar, as native), keeps a first stage across a rejection at the same anchor, and drops both when the collar's quiet setting changes or a landing moved the anchor. Full RK runs, reuse off/on: he_rdw_averaged, rdw, argon_blueshift, argon_blueshift_envelope, h2_raman_averaged and gnlse_raman_shock are bitwise the same with the same steps; time 0-16 % less (one evaluation in seven). A test holds an adaptive and a replayed march to bitwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mporal collar Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge on device The binary32 exponent check refused any step whose |Re dPhi| passed 88.72, the Runge-Kutta interaction picture's inverse propagator's limit. The low-storage march and the exponential Adams flow apply forward flows only, which a damped bin underflows harmlessly towards zero, so they are now held to growth alone (Adams's times its history's reach, order + 1, as the binary64 budget does). The Kerr beams' 0.5-0.6 um replayed steps, refused on their spectral collar (150-180), run in binary32 and agree with binary64 to 2e-7. The check takes the operator's rate bounds on the free-space and radial routes, as the binary64 budget does, rather than forming the operator over the grid twice (5.7 s at 384^2 x 750; the bounds 2 ms). On mlx: the transverse edge is read on the device where no collar is requested (the node and column energies from the transverse transform or the radial synthesis, within 1e-6 of the state's energy of the host's, a test holds it); a Cartesian operator and its prefactor are built in one pass, bitwise as before; and the Cartesian route no longer forms the modal prefactor it does not use (1.6 s at 384^2 x 750). Whole runs, mlx/native: kerr_beam_192 1.05/2.64 s, kerr_beam_384 7.72/9.43 s, cartesian_filament_128 (0.3) 19.3/27.5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The interaction picture's stage input forms exp(-Phi_j), which overflows binary32 once a collar or loss puts |Re Phi| past 88.72: the controller rejected the trial with an infinite norm and shrank far below binary64's step. When a bound on the trial's |Re Phi| (DoubleFloatTerms.real_reach, from each term's largest |Re T_t|) passes 0.9 log FLT_MAX, the stages are combined as exp(Phi_i) a + h sum a_ij exp(Phi_i - Phi_j) S_j: forward flows only. Forced on every trial it agrees with the interaction picture to 3e-7..7e-6; it is taken only past the bound, so other runs are bitwise unchanged. The radial Kerr beam at |Re Phi| = 459 now takes its millimetre in one step (binary64 too), against 14 steps and 2 rejections. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jtravs
marked this pull request as ready for review
November 6, 2026 09:32
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ilders - mlx_gpu/backend.py imported solprop_native unconditionally, so the module failed to import where the native package is absent (the Read the Docs build); it now falls back to PLAIN, bitwise the same rows. - The recipe metadata names FieldGrid/EnvelopeGrid.from_limits' new `transforms` keyword. - The layers figure draws mlx_gpu/adams.py (redrawn). - The compiled-Multistep refusal test reads the message's new backend list. - The benchmark capillary and GNLSE builders pass the configured backend to the interface, so a single-precision variant on numpy_ref builds without MLX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Documentation build overview
30 files changed ·
|
…expects check_skips (SEP 43, from main) accepts "could not import 'mlx.core'" but not the cases' own "mlx needs an Apple GPU", so the Windows and Linux lanes failed on two expected skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Started on top of #542, which is now merged; this PR targets
main. The decisions it needed are taken (see "Decided since").Why
mlxwas slower thannativeon RDWFour causes stacked up:
fft_size="auto"took the 2-3-5-smooth sizes that FFTW prefers (RDW used 10240 fine samples). MLX's GPU FFT handles any smooth size up to 4096, and above that only powers of two; every other size goes through Bluestein's algorithm. On an Apple M5 Max an rfft/irfft pair took 715 µs at 10240 and 63 µs at 16384.mx.compile.nativedefaults to Adams (one evaluation per step), while single precision refused Adams, somlxran DOPRI5 (seven evaluations per step).What's here
track/abtake--backend mlx(single precision, noiseless),--noise noneand--fft-size pow2.ab --baseline-backend/--candidate-backendcompares two backends in one A/B.fft_cost(n, library)andfrom_limits(transforms="mlx"). The keyword interfaces build a single-precisionmlx/autorun's grid for MLX, so RDW now uses 16384 samples. Trials are 4× faster.mx.compilegraph, and its position-dependent coefficients arrive as one float32 vector. A propagator and its inverse come from one kernel, computed once per distinct fraction. Each stage starts withmx.async_eval. The results are bitwise identical to before on every route checked. Trials are 1.5–2.6× faster.mlx(MlxAdams). The history stays on the device. Each trial's flow, moments and transported compensation come from one double-float kernel, within one binary32 ulp of the binary64 values rounded once. The predictor and corrector are one kernel each, and a trial ends in one synchronisation.precision="single"still refuses needs decisions:Multistep(), noise, routes, binary32 outputs #342), by binary32 Adams against binary64 Adams; see the record below. A single-precision Adams history now resumes in binary32; before, it silently came back as complex128.mlx: what decides full support #85; record below).Qualification of binary32 Adams (#342)
Whole runs, noise-free, power-of-two grids, each interface's default tolerance; relative difference of the final fields:
he_rdw_averagedrdwargon_blueshiftargon_blueshift_envelopeh2_raman_averagedgnlse_raman_shockradial_filament_256spatial_absorberAll are far inside the 1e-3 field envelope. The GNLSE row is high because binary32 runs at its
rtolfloor of 1e-6 while binary64 runs at 1e-7.Timings
python -m benchmarks ab --baseline-backend native --candidate-backend mlx, a third of each run, two rounds, on a shared Apple M5 Max, so read the ratios rather than the times. Each figure is mlx time over native time; below 1, mlx is faster.rdwhe_rdw_averagedradial_filament_256spatial_absorbercartesian_filament_128The single-precision default integrator is still RK. On the capillaries, the middle column therefore compares mlx running DOPRI5 with native running Adams; with Adams on both, mlx wins on
rdw.These are short runs, so the planes' shared host statistics are a fixed cost in every one. On whole runs:
rtol=1e-4:radial_filament_256takes 0.67 s on mlx against 2.07 s on native, andspatial_absorber1.98 s against 5.54 s.cartesian_filament_128over 1.5 cm: 27.3 s against 42.5 s.rdwAdams step takes 1.48 ms on mlx.he_rdw_averagedstays slower. It is a single 16k-sample row, which the GPU can't fill, and its scans run in one threadgroup.Free space at its binary64 tolerance (#85)
Measured against a binary64 run at
rtol=1e-6:radial_filament_256spatial_absorbercartesian_filament_128, 1.5 cmOn this record
SINGLE_RTOL_CAPrises from 1e-5 to 1e-4, so single-precision free space takes binary64's default. That is commit 52450e1, kept separate so it can be reverted.Decided since
Adams is the single-precision default on
prop_capillary,prop_radialandprop_planar, the same as binary64 (0fdcefa). A run now changes arithmetic, not method, when it changes precision.The free-space tolerance change (52450e1) is accepted.
The Kerr beam's binary32 refusal is fixed (584bb21). The low-storage march and exponential Adams apply forward flows only, so the check now holds them to growth alone, using the operator's rate bounds (2 ms, against 5.7 s for forming the operator). On mlx the transverse edge is also read on the device, and the operator is built in one pass.
kerr_beam_192takes 1.05 s on mlx against 2.64 s on native, andkerr_beam_3847.72 s against 9.43 s; both agree with binary64 to 2e-7.FSAL on mlx's RK (0c748fa). An accepted DOPRI5 step's last stage becomes the next step's first, as on native. The reuse is bitwise: six capillary and fibre runs come out with identical fields and steps, and a test holds it. It is off under the split-step collar, whose finish changes the state.
Lab-frame DOPRI5 past binary32's range (935617b). The interaction picture's
exp(−ΔΦ)overflows binary32 once |Re ΔΦ| passes 88.7, and the controller then rejected the trial and shrank the step. When a cheap bound on the trial's |Re ΔΦ| (each operator term's largest |Re T|, stored at upload) passes 0.9·log FLT_MAX, mlx now combines the stages in the lab frame: each earlier stage is carried byexp(Φ_i − Φ_j). DOPRI5's nodes never decrease, so every factor is a forward flow.Remaining limit
A replayed
RungeKutta()schedule whose steps pass |Re ΔΦ| = 88.7 is still refused at translation for single precision on every backend. The translation-time check doesn't know the backend, and the numpy oracle still forms the inverse. Lifting the refusal on mlx would need the check to know the backend, and is left for a follow-up. The low-storage march and Adams aren't affected.How it was checked
Locally on the M5 Max, and by the full CI gate on this PR:
poe docs(clean).test_mlx,test_single_precision,test_precision,test_interface_defaults,test_resume_history(new single-precision resume cases), the Adams, exponential, snapshot and resume modules,test_grid, the benchmark tests,test_monitor,test_noise_defaultandtest_transverse_backends. All pass. The full gate has not run.Relates to #85, #342, #343, #325.
🤖 Generated with Claude Code