EmbeddingGemma trains on a mixture of datasets, every batch drawn from exactly one of them, with mixture weights found by a search over the simplex. Implement the bookkeeping.
normalize_weights(raw)
batches_per_dataset(weights, total)
total batches to the datasets by the largest-remainder method: give each dataset floor(w_i * total), then hand the leftover batches one at a time to the datasets with the largest fractional remainders (lower index wins ties). Return a list of ints summing to total.batch_schedule(weights, u)
u is a list of numbers in [0, 1). For each u_k choose the dataset by inverse CDF: the smallest index i with u_k < cumulative(weights)[i]. Return the list of dataset indices, one batch each.tokens_seen(schedule, tokens_per_batch, n_datasets)
tokens_per_batch[i] is the number of tokens in one batch from dataset i. Return the list of total tokens seen per dataset over the schedule.perturb_mixture(weights, index, delta)
delta to weights[index], scale the other weights by a common factor so the total stays 1, and return the result rounded to 4 decimals. delta never exceeds 1 - weights[index].itertools.accumulate or np.cumsum for the cumulative weights; the last cumulative value is 1.(1 - w_i - delta) / (1 - w_i).