Mamba's first synthetic benchmark is Selective Copying: a handful of data tokens are scattered at random positions among noise tokens, and at the end of the sequence the model must output the data tokens in the order they appeared. Build the data generator, the plain fixed-spacing Copying variant it is compared against, and the exact-match evaluator.
Token convention for both tasks: the noise token is 0, data tokens are 1, ..., n_data, and the marker token is n_data + 1 (vocabulary size n_data + 2). Every row has length seq_len: the first seq_len - n_to_copy positions are the context, and the last n_to_copy positions are all marker tokens, the slots where the model must answer.
make_selective_copying(n_samples, seq_len, n_data, n_to_copy, seed)
(inputs, targets), int64 arrays of shapes (n_samples, seq_len) and (n_samples, n_to_copy).n_to_copy distinct context positions hold data tokens and every other context position is noise. The target row is the row's data tokens in order of position.np.random.default_rng(seed) per call, called rng below. For each sample in order, first draw the positions with rng.choice(seq_len - n_to_copy, size=n_to_copy, replace=False) and sort them ascending, then draw the tokens with rng.integers(1, n_data + 1, size=n_to_copy). The i-th token goes to the i-th smallest position.make_copying(n_samples, seq_len, n_data, n_to_copy, seed)
0, ..., n_to_copy - 1 (fixed spacing) and the rest of the context is noise. Per sample, draw only the tokens, with the same rng.integers call.Both generators raise ValueError unless n_data >= 1 and 1 <= n_to_copy <= seq_len - n_to_copy.
copy_accuracy(predictions, targets)
predictions and targets are array-likes of the same shape (n, n_to_copy); raise ValueError if the shapes differ.{"token_acc": ..., "seq_acc": ...}: the fraction of answer slots predicted exactly, and the fraction of rows whose every slot is exact, as Python floats rounded to 4 decimals.i always sits exactly seq_len - n_to_copy positions before its answer slot. Check that your generator makes this true, and that it is false for Selective Copying.