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 the slot's step count differs from the one
it was built at, the param dtype changes (mixed-precision case), or
when set_lr / set_hyperparams changes a hyper-parameter.
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.