in fastchat/serve/gradio_block_arena_anony.py [0:0]
def get_battle_pair():
if len(models) == 1:
return models[0], models[0]
model_weights = []
for model in models:
weight = get_sample_weight(model)
model_weights.append(weight)
total_weight = np.sum(model_weights)
model_weights = model_weights / total_weight
chosen_idx = np.random.choice(len(models), p=model_weights)
chosen_model = models[chosen_idx]
rival_models = []
rival_weights = []
for model in models:
if model == chosen_model:
continue
weight = get_sample_weight(model)
if (
weight != 0
and chosen_model in BATTLE_TARGETS
and model in BATTLE_TARGETS[chosen_model]
):
# boost to 50% chance
weight = total_weight / len(BATTLE_TARGETS[chosen_model])
rival_models.append(model)
rival_weights.append(weight)
# for p, w in zip(rival_models, rival_weights):
# print(p, w)
rival_weights = rival_weights / np.sum(rival_weights)
rival_idx = np.random.choice(len(rival_models), p=rival_weights)
rival_model = rival_models[rival_idx]
swap = np.random.randint(2)
if swap == 0:
return chosen_model, rival_model
else:
return rival_model, chosen_model