def calc_weight_multi(args, model, batch, lang_adapter_names, task_name, adapter_weights, step=10, lang=None):
    inputs = {'input_ids': batch[0], 'attention_mask': batch[1], 'return_sequence_out': True, 'labels': batch[3]}
    adapter_weights = [torch.FloatTensor([0.5 for _ in range(len(lang_adapter_names))]).to(args.device) for _ in range(13)]
    if args.lang_to_vec:
        logger.info(lang)
        logger.info(lang_adapter_names)
        adapter_weights = calc_l2v_weights(lang, lang_adapter_names, args.en_weight)
        logger.info(adapter_weights)
    for step_no in range(step):
        for w in adapter_weights:
            w.requires_grad = True
        if (args.lang_to_vec and (step_no == 0)):
            normed_adapter_weights = adapter_weights
        else:
            normed_adapter_weights = [torch.nn.functional.softmax(w) for w in adapter_weights]
        model.set_active_adapters([lang_adapter_names, [task_name]])
        inputs['adapter_names'] = [lang_adapter_names, [task_name]]
        inputs['adapter_weights'] = normed_adapter_weights
        outputs = model(**inputs)
        (loss, logits, orig_sequence_output) = outputs[:3]
        kept_logits = outputs[(- 1)]
        entropy = (torch.nn.functional.softmax(kept_logits, dim=1) * torch.nn.functional.log_softmax(kept_logits, dim=1))
        entropy = ((- entropy.sum()) / kept_logits.size(0))
        grads = torch.autograd.grad(entropy, adapter_weights)
        for (i, w) in enumerate(adapter_weights):
            adapter_weights[i] = (adapter_weights[i].data - (10 * grads[i].data))
    normed_adapter_weights = [torch.nn.functional.softmax(w) for w in adapter_weights]
    return normed_adapter_weights
def calc_weight_multi(args, model, batch, lang_adapter_names, task_name, adapter_weights, step=10, lang=None):
    inputs = {'input_ids': batch[0], 'attention_mask': batch[1], 'return_sequence_out': True, 'labels': batch[3]}
    adapter_weights = [torch.FloatTensor([0.5 for _ in range(len(lang_adapter_names))]).to(args.device) for _ in range(13)]
    if args.lang_to_vec:
        logger.info(lang)
        logger.info(lang_adapter_names)
        adapter_weights = calc_l2v_weights(lang, lang_adapter_names, args.en_weight)
        logger.info(adapter_weights)
    for step_no in range(step):
        for w in adapter_weights:
            w.requires_grad = True
        if (args.lang_to_vec and (step_no == 0)):
            normed_adapter_weights = adapter_weights
        else:
            normed_adapter_weights = [torch.nn.functional.softmax(w) for w in adapter_weights]
        model.set_active_adapters([lang_adapter_names, [task_name]])
        inputs['adapter_names'] = [lang_adapter_names, [task_name]]
        inputs['adapter_weights'] = normed_adapter_weights
        outputs = model(**inputs)
        (loss, logits, orig_sequence_output) = outputs[:3]
        kept_logits = outputs[(- 1)]
        entropy = (torch.nn.functional.softmax(kept_logits, dim=1) * torch.nn.functional.log_softmax(kept_logits, dim=1))
        entropy = ((- entropy.sum()) / kept_logits.size(0))
        grads = torch.autograd.grad(entropy, adapter_weights)
        for (i, w) in enumerate(adapter_weights):
            adapter_weights[i] = (adapter_weights[i].data - (10 * grads[i].data))
    normed_adapter_weights = [torch.nn.functional.softmax(w) for w in adapter_weights]
    return normed_adapter_weights