Average the Checkpoints
EmbeddingGemma's final model is the parameter-wise average of checkpoints fine-tuned on different data mixtures. Gemini Embedding 2 also soups a fine-tuned model with its base to keep a gain without a regression. Implement the three recipes on checkpoints represented as dicts from parameter name to NumPy array.
uniform_soup(states)
- The element-wise mean of a list of state dicts (all share the same keys and shapes). Return a dict.
interpolate(base, ft, alpha)
- (1−α)θbase+αθft for every parameter.
best_interpolation(base, ft, alphas, score_fn)
- Evaluate
score_fn(interpolate(base, ft, a)) for each a in alphas and return the alpha with the highest score (the first one on ties).
greedy_soup(states, score_fn)
- Sort the checkpoints by their individual score, highest first (stable, so the lower original index wins ties). Start with the best one in the soup. For each remaining checkpoint in that order, form the uniform soup of the current members plus the candidate; keep the candidate if the score of that soup is at least the current soup's score. Return
(member_indices_in_original_order, soup).
Hints
- Keys can be iterated from
states[0]; np.mean(np.stack([s[k] for s in states]), axis=0) averages one parameter.
- Keep the soup as a list of member indices and recompute the uniform soup from the members; do not accumulate running means.