Per-step scalar broadcast cache for Adam-family GPU updates.
Holds the eight broadcast scalars (, , , , , , , ) plus the optional weight-decay scalar and the AdamW decay factor as pre-allocated MLX scalar arrays. All entries are rebuilt once per optimiser step at the first parameter and reused across the remaining ~64 parameters of a typical ResNet-18 / transformer step.
Attributes
validbooltrue when the cached arrays match the current step / dtype.dtDtypefor_stepint64b1, omb1, b2, omb2mlx array (scalar)eps_a, lr_a, wd_amlx array (scalar)wd_a is present only when weight_decay != 0.inv_bc1, inv_bc2mlx array (scalar)wd_factormlx array (scalar)Notes
Without this cache, adam_step_gpu rebuilt params.size() * 8
MLX scalar arrays per call (~520 allocations for ResNet-18). Each
MLX array construction has constant overhead, and the bias-correction
factors don't depend on which parameter is being updated, so the
scalars are pure step-level invariants.
The cache invalidates when step_count_ advances, the param dtype
changes (mixed-precision case), or when set_lr mutates .
Constructors
1AdamScalarCache
void AdamScalarCache()Default-construct an empty (invalid) cache.
Destructor
1~AdamScalarCache
void ~AdamScalarCache()Out-of-line destructor — mlx::core::array is only forward- declared in this header, so unique_ptr cannot inline-destroy it. The definition lives in Adam.cpp.