AugMix accepts a seed and even writes it into get_config. Then it picked its augmentation with Python's global random, which never sees that seed. So AugMix(seed=1234) was not reproducible, and nothing in the API said so.
Worse under tf.data
Inside a tf.data pipeline the layer is traced once. A Python random.choice runs at trace time, its result is baked into the graph, and every batch after that goes through the exact same augmentations. Data augmentation that never varies is just a fixed transform.
-import random as py_random
-
import keras.src.layers as layersThe design came from the issue
The person who triaged the issue had reproduced the bug on TensorFlow, JAX and PyTorch, then assigned it to me with a precise design: draw the indices with the backend's own generator, in a (num_chains, chain_depth) grid where one extra index means no augmentation, and select each branch with ops.switch while tracing. In eager mode the drawn index is already known, so only that candidate is sampled: at most 9 transformations per call instead of 63.
The test that could not fail
RandAugment already had a tf.data test, so I measured it before copying it. It counts distinct values inside one draw, not distinct draws across batches. On 20,000 simulated runs with a frozen choice, it still passes 90.8% of the time on RandAugment's indices, and 100% of the time on the grid AugMix uses. The new test stacks the batches first, then compares them.
The price, named out loud
Under JAX every one of the nine slots is a switch over every candidate, so the traced graph holds them all. The reviewing maintainer measured compile time at about 35 s before the change and 270 s after, and requested changes over that cost. The description now states it: a model pays it once, on its first fit step.
An automated reviewer also suggested replacing the tracing check with try/except. I measured both forms instead of arguing: functional model construction never reaches that code, and under torch.compile nothing raises, so both take the same path. I wrote that down and left the call to the maintainers. They kept the design from the issue.
What I take from it
A seed that is accepted, serialized and ignored is worse than no seed: it looks like a guarantee. And a regression test earns its place only once you have watched it fail on the bug it claims to catch.
Ayoub Hammoudi, Software engineer, full-stack and AI platforms. github.com/Ayoubhm07


