gurudesh/pytracebugs huggingface dataset:
# Buggy code
def release(self) -> None:
    self.semaphore.release()


# Traceback (AssertionError)
Traceback (most recent call last):
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 57, in <module>
asyncio.get_event_loop().run_until_complete(cl.embedd_batch())
File "/Users/primoz/miniconda3/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 19, in embedd_batch
embeddings = await asyncio.gather(*requests)
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 43, in _send_to_server
emb = await self._send_request(client, im, url)
File "/Users/primoz/PycharmProjects/orange3-imageanalytics/example.py", line 50, in _send_request
response = await client.post(url, headers=headers, data=image)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 492, in post
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 634, in request
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 658, in send
trust_env=trust_env,
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 273, in _get_response
return await get_response(request)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/middleware/redirect.py", line 31, in __call__
response = await get_response(request)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/client.py", line 228, in get_response
request, verify=verify, cert=cert, timeout=timeout
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/dispatch/connection_pool.py", line 126, in send
raise exc
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/dispatch/connection_pool.py", line 121, in send
request, verify=verify, cert=cert, timeout=timeout
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/dispatch/connection.py", line 62, in send
response = await self.h2_connection.send(request, timeout=timeout)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/dispatch/http2.py", line 49, in send
stream_id = await self.send_headers(request, timeout)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/dispatch/http2.py", line 121, in send_headers
await self.stream.write(data_to_send, timeout)
File "/Users/primoz/venv/orange/lib/python3.7/site-packages/httpx/concurrency/asyncio.py", line 149, in write
self.stream_writer.drain(), timeout.write_timeout
File "/Users/primoz/miniconda3/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
return fut.result()
File "/Users/primoz/miniconda3/lib/python3.7/asyncio/streams.py", line 348, in drain
await self._protocol._drain_helper()
File "/Users/primoz/miniconda3/lib/python3.7/asyncio/streams.py", line 206, in _drain_helper
assert waiter is None or waiter.cancelled()
AssertionError

# Fixed code
def release(self) -> None:
    self._lock.release()
# Buggy code
def reduce_metrics(logging_outputs) -> None:
    """Aggregate logging outputs from data parallel training."""
    loss_sum = sum(log.get("loss", 0) for log in logging_outputs)
    ntokens = sum(log.get("ntokens", 0) for log in logging_outputs)
    sample_size = sum(log.get("sample_size", 0) for log in logging_outputs)

    metrics.log_scalar(
        "loss", loss_sum / sample_size / math.log(2), sample_size, round=3
    )
    if sample_size != ntokens:
        metrics.log_scalar(
            "nll_loss", loss_sum / ntokens / math.log(2), ntokens, round=3
        )
        metrics.log_derived(
            "ppl", lambda meters: utils.get_perplexity(meters["nll_loss"].avg)
        )
    else:
        metrics.log_derived(
            "ppl", lambda meters: utils.get_perplexity(meters["loss"].avg)
        )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def reduce_metrics(logging_outputs) -> None:
    """Aggregate logging outputs from data parallel training."""
    loss_sum = sum(log.get("loss", 0) for log in logging_outputs)
    ntokens = sum(log.get("ntokens", 0) for log in logging_outputs)
    sample_size = sum(log.get("sample_size", 0) for log in logging_outputs)

    # we divide by log(2) to convert the loss from base e to base 2
    metrics.log_scalar(
        "loss", loss_sum / sample_size / math.log(2), sample_size, round=3
    )
    if sample_size != ntokens:
        metrics.log_scalar(
            "nll_loss", loss_sum / ntokens / math.log(2), ntokens, round=3
        )
        metrics.log_derived(
            "ppl", lambda meters: utils.get_perplexity(meters["nll_loss"].avg)
        )
    else:
        metrics.log_derived(
            "ppl", lambda meters: utils.get_perplexity(meters["loss"].avg)
        )
# Buggy code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise RuntimeError("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise RuntimeError("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            if p32.grad:
                p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)
# Buggy code
def add_args(parser):
    """Add arguments to the parser for this LR scheduler."""
    # fmt: off
    parser.add_argument('--force-anneal', '--fa', type=int, metavar='N',
                            help='force annealing at specified epoch')
    parser.add_argument('--lr-shrink', default=0.1, type=float, metavar='LS',
                            help='shrink factor for annealing, lr_new = (lr * lr_shrink)')
    parser.add_argument('--warmup-updates', default=0, type=int, metavar='N',
                            help='warmup the learning rate linearly for the first N updates')


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def add_args(parser):
    """Add arguments to the parser for this LR scheduler."""
    # fmt: off
    parser.add_argument('--force-anneal', '--fa', type=int, metavar='N',
                            help='force annealing at specified epoch (epochs start at 1)')
    parser.add_argument('--lr-shrink', default=0.1, type=float, metavar='LS',
                            help='shrink factor for annealing, lr_new = (lr * lr_shrink)')
    parser.add_argument('--warmup-updates', default=0, type=int, metavar='N',
                            help='warmup the learning rate linearly for the first N updates')
# Buggy code
def get_next_lr(self, epoch):
    lrs = self.args.lr
    if self.args.force_anneal is None or epoch < self.args.force_anneal:
        # use fixed LR schedule
        next_lr = lrs[min(epoch, len(lrs) - 1)]
    else:
        # annneal based on lr_shrink
        next_lr = lrs[-1] * self.args.lr_shrink ** (epoch + 1 - self.args.force_anneal)
    return next_lr


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def get_next_lr(self, epoch):
    lrs = self.args.lr
    if self.args.force_anneal is None or epoch < self.args.force_anneal:
        # use fixed LR schedule
        next_lr = lrs[min(epoch - 1, len(lrs) - 1)]
    else:
        # annneal based on lr_shrink
        next_lr = lrs[-1] * self.args.lr_shrink ** (epoch + 1 - self.args.force_anneal)
    return next_lr
# Buggy code
def begin_epoch(self, epoch):
    """Called at the beginning of each epoch."""
    logger.info("begin training epoch {}".format(epoch))

    if self.quantizer is not None:
        self.quantizer.begin_epoch(epoch)

    # task specific setup per epoch
    self.task.begin_epoch(epoch, self.get_model())

    if self.tpu:
        import torch_xla.core.xla_model as xm

        xm.rendezvous("begin_epoch")  # wait for all workers
        xm.mark_step()


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def begin_epoch(self, epoch):
    """Called at the beginning of each epoch."""
    logger.info("begin training epoch {}".format(epoch))

    self.lr_step_begin_epoch(epoch)

    if self.quantizer is not None:
        self.quantizer.begin_epoch(epoch)

    # task specific setup per epoch
    self.task.begin_epoch(epoch, self.get_model())

    if self.tpu:
        import torch_xla.core.xla_model as xm

        xm.rendezvous("begin_epoch")  # wait for all workers
        xm.mark_step()
# Buggy code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise ("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap
fn(i, *args)
File "/workspace/fairseq/fairseq/distributed_utils.py", line 283, in distributed_main
main(cfg, **kwargs)
File "/workspace/fairseq/fairseq_cli/train.py", line 124, in main
valid_losses, should_stop = train(cfg, trainer, task, epoch_itr)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq_cli/train.py", line 202, in train
log_output = trainer.train_step(samples)
File "/opt/conda/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/workspace/fairseq/fairseq/trainer.py", line 459, in train_step
self.zero_grad()
File "/workspace/fairseq/fairseq/trainer.py", line 783, in zero_grad
self.optimizer.zero_grad()
File "/workspace/fairseq/fairseq/optim/fp16_optimizer.py", line 218, in zero_grad
p32.grad.zero_()
AttributeError: 'NoneType' object has no attribute 'zero_'

# Fixed code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise ("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            if p32.grad:
                p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)
# Buggy code
def add_args(parser):
    # fmt: off
    super(TransformerAlignModel, TransformerAlignModel).add_args(parser)
    parser.add_argument('--alignment-heads', type=int, metavar='D',
                            help='Number of cross attention heads per layer to supervised with alignments')
    parser.add_argument('--alignment-layer', type=int, metavar='D',
                            help='Layer number which has to be supervised. 0 corresponding to the bottommost layer.')
    parser.add_argument('--full-context-alignment', type=bool, metavar='D',
                            help='Whether or not alignment is supervised conditioned on the full target context.')


# Traceback (TypeError)
Traceback (most recent call last):
File ".../bin/fairseq-train", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-train')()
File ".../fairseq_cli/train.py", line 351, in cli_main
distributed_utils.call_main(args, main)
File ".../fairseq/distributed_utils.py", line 254, in call_main
main(args, **kwargs)
File ".../fairseq_cli/train.py", line 125, in main
valid_losses, should_stop = train(args, trainer, task, epoch_itr)
File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File ".../fairseq_cli/train.py", line 207, in train
log_output = trainer.train_step(samples)
File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File ".../fairseq/trainer.py", line 479, in train_step
ignore_grad=is_dummy_batch,
File ".../fairseq/tasks/fairseq_task.py", line 408, in train_step
loss, sample_size, logging_output = criterion(model, sample)
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File ".../fairseq/criterions/label_smoothed_cross_entropy_with_alignment.py", line 36, in forward
net_output = model(**sample['net_input'])
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File ".../fairseq/models/transformer_align.py", line 51, in forward
return self.forward_decoder(prev_output_tokens, encoder_out)
File ".../fairseq/models/transformer_align.py", line 75, in forward_decoder
**extra_args,
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'full_context_alignment'

# Fixed code
def add_args(parser):
    # fmt: off
    super(TransformerAlignModel, TransformerAlignModel).add_args(parser)
    parser.add_argument('--alignment-heads', type=int, metavar='D',
                            help='Number of cross attention heads per layer to supervised with alignments')
    parser.add_argument('--alignment-layer', type=int, metavar='D',
                            help='Layer number which has to be supervised. 0 corresponding to the bottommost layer.')
    parser.add_argument('--full-context-alignment', action='store_true',
                            help='Whether or not alignment is supervised conditioned on the full target context.')
# Buggy code
def forward_align(self, src_tokens, src_lengths, prev_output_tokens):
    avg_attn = None
    for model in self.models:
        decoder_out = model(src_tokens, src_lengths, prev_output_tokens)
        attn = decoder_out[1]["attn"]
        if avg_attn is None:
            avg_attn = attn
        else:
            avg_attn.add_(attn)
    if len(self.models) > 1:
        avg_attn.div_(len(self.models))
    return avg_attn


# Traceback (TypeError)
Traceback (most recent call last):
File ".../bin/fairseq-train", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-train')()
File ".../fairseq_cli/train.py", line 351, in cli_main
distributed_utils.call_main(args, main)
File ".../fairseq/distributed_utils.py", line 254, in call_main
main(args, **kwargs)
File ".../fairseq_cli/train.py", line 125, in main
valid_losses, should_stop = train(args, trainer, task, epoch_itr)
File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File ".../fairseq_cli/train.py", line 207, in train
log_output = trainer.train_step(samples)
File "/usr/lib64/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File ".../fairseq/trainer.py", line 479, in train_step
ignore_grad=is_dummy_batch,
File ".../fairseq/tasks/fairseq_task.py", line 408, in train_step
loss, sample_size, logging_output = criterion(model, sample)
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File ".../fairseq/criterions/label_smoothed_cross_entropy_with_alignment.py", line 36, in forward
net_output = model(**sample['net_input'])
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File ".../fairseq/models/transformer_align.py", line 51, in forward
return self.forward_decoder(prev_output_tokens, encoder_out)
File ".../fairseq/models/transformer_align.py", line 75, in forward_decoder
**extra_args,
File ".../lib64/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'full_context_alignment'

# Fixed code
def forward_align(self, src_tokens, src_lengths, prev_output_tokens):
    avg_attn = None
    for model in self.models:
        decoder_out = model(src_tokens, src_lengths, prev_output_tokens)
        attn = decoder_out[1]["attn"][0]
        if avg_attn is None:
            avg_attn = attn
        else:
            avg_attn.add_(attn)
    if len(self.models) > 1:
        avg_attn.div_(len(self.models))
    return avg_attn
# Buggy code
def get_perplexity(loss, round=2, base=2):
    if loss is None:
        return 0.0
    return safe_round(base**loss, round)


# Traceback (OverflowError)
Traceback (most recent call last):
File "/SFS/user/wp/prihodad/git/oas-training/data/examples/biophysical_properties/condaenv/bin/fairseq-train", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-train')()
File "/SFS/user/wp/prihodad/git/fairseq/fairseq_cli/train.py", line 321, in cli_main
main(args)
File "/SFS/user/wp/prihodad/git/fairseq/fairseq_cli/train.py", line 96, in main
train(args, trainer, task, epoch_itr)
File "/SFS/user/wp/prihodad/git/oas-training/condaenv/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "/SFS/user/wp/prihodad/git/fairseq/fairseq_cli/train.py", line 203, in train
stats = get_training_stats(metrics.get_smoothed_values('train'))
File "/SFS/user/wp/prihodad/git/fairseq/fairseq_cli/train.py", line 212, in get_training_stats
stats['ppl'] = utils.get_perplexity(stats['nll_loss'])
File "/SFS/user/wp/prihodad/git/fairseq/fairseq/utils.py", line 349, in get_perplexity
return safe_round(base**loss, round)
OverflowError: (34, 'Numerical result out of range')

# Fixed code
def get_perplexity(loss, round=2, base=2):
    if loss is None:
        return 0.0
    try:
        return safe_round(base**loss, round)
    except OverflowError:
        return float("inf")
# Buggy code
def collater(self, samples):
    samples = self.dataset.collater(samples)

    # TODO: support different padding direction
    if self.new_src_eos is not None:
        assert (samples["net_input"]["src_tokens"][:, -1] != self.src_eos).sum() == 0
        samples["net_input"]["src_tokens"][:, -1] = self.new_src_eos

    if self.new_tgt_bos is not None:
        assert (
            samples["net_input"]["prev_output_tokens"][:, 0] != self.tgt_bos
        ).sum() == 0
        samples["net_input"]["prev_output_tokens"][:, 0] = self.new_tgt_bos

    return samples


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def collater(self, samples):
    samples = self.dataset.collater(samples)

    if self.new_src_eos is not None:
        if self.dataset.left_pad_source:
            assert (
                samples["net_input"]["src_tokens"][:, -1] != self.src_eos
            ).sum() == 0
            samples["net_input"]["src_tokens"][:, -1] = self.new_src_eos
        else:
            eos_idx = samples["net_input"]["src_lengths"] - 1
            assert (
                samples["net_input"]["src_tokens"][
                    torch.arange(eos_idx.size(0)), eos_idx
                ]
                != self.src_eos
            ).sum() == 0
            eos_idx = eos_idx.resize_(len(samples["net_input"]["src_lengths"]), 1)
            samples["net_input"]["src_tokens"].scatter_(1, eos_idx, self.new_src_eos)

    if self.new_tgt_bos is not None and "prev_output_tokens" in samples["net_input"]:
        if self.dataset.left_pad_target:
            # TODO: support different padding direction on target side
            raise NotImplementedError(
                "TransformEosLangPairDataset does not implement --left-pad-target True option"
            )
        else:
            assert (
                samples["net_input"]["prev_output_tokens"][:, 0] != self.tgt_bos
            ).sum() == 0
            samples["net_input"]["prev_output_tokens"][:, 0] = self.new_tgt_bos

    return samples
# Buggy code
def load_state_dict(self, state_dict, strict=True):
    state_dict_subset = state_dict.copy()
    for k, _ in state_dict.items():
        assert k.startswith("models.")
        lang_pair = k.split(".")[1]
        if lang_pair not in self.models:
            del state_dict_subset[k]
    super().load_state_dict(state_dict_subset, strict=strict)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def load_state_dict(self, state_dict, strict=True, args=None):
    state_dict_subset = state_dict.copy()
    for k, _ in state_dict.items():
        assert k.startswith("models.")
        lang_pair = k.split(".")[1]
        if lang_pair not in self.models:
            del state_dict_subset[k]
    super().load_state_dict(state_dict_subset, strict=strict, args=args)
# Buggy code
def _match_types(arg1, arg2):
    if (isinstance(arg1, float) or isinstance(arg1, int)) and isinstance(arg2, tuple):
        arg1_tuple = (arg1, arg1)
        return arg1_tuple, arg2
    if (isinstance(arg2, float) or isinstance(arg2, int)) and isinstance(arg1, tuple):
        arg2_tuple = (arg2, arg2)
        return arg1, arg2_tuple
    return arg1, arg2


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def _match_types(arg1, arg2):
    """Convert the numerical argument to the same type as the other argument"""

    def upgrade(arg_number, arg_structure):
        if isinstance(arg_structure, tuple):
            return (arg_number, arg_number)
        elif isinstance(arg_structure, dict):
            arg = copy.deepcopy(arg_structure)
            for k in arg:
                arg[k] = upgrade(arg_number, arg_structure[k])
            return arg
        else:
            return arg_number

    if isinstance(arg1, float) or isinstance(arg1, int):
        return upgrade(arg1, arg2), arg2
    elif isinstance(arg2, float) or isinstance(arg2, int):
        return arg1, upgrade(arg2, arg1)

    return arg1, arg2
# Buggy code
def hydra_init() -> None:
    cs = ConfigStore.instance()

    for k in FairseqConfig.__dataclass_fields__:
        v = FairseqConfig.__dataclass_fields__[k].default
        try:
            cs.store(name=k, node=v)
        except BaseException:
            logger.error(f"{k} - {v}")
            raise

    register_module_dataclass(cs, TASK_DATACLASS_REGISTRY, "task")
    register_module_dataclass(cs, MODEL_DATACLASS_REGISTRY, "model")

    for k, v in REGISTRIES.items():
        register_module_dataclass(cs, v["dataclass_registry"], k)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def hydra_init(cfg_name="config") -> None:
    cs = ConfigStore.instance()
    cs.store(name=cfg_name, node=FairseqConfig)

    for k in FairseqConfig.__dataclass_fields__:
        v = FairseqConfig.__dataclass_fields__[k].default
        try:
            cs.store(name=k, node=v)
        except BaseException:
            logger.error(f"{k} - {v}")
            raise

    register_module_dataclass(cs, TASK_DATACLASS_REGISTRY, "task")
    register_module_dataclass(cs, MODEL_DATACLASS_REGISTRY, "model")

    for k, v in REGISTRIES.items():
        register_module_dataclass(cs, v["dataclass_registry"], k)
# Buggy code
def _override_attr(
    sub_node: str, data_class: Type[FairseqDataclass], args: Namespace
) -> List[str]:
    overrides = []

    def get_default(f):
        if not isinstance(f.default_factory, _MISSING_TYPE):
            return f.default_factory()
        return f.default

    for k, v in data_class.__dataclass_fields__.items():
        if k.startswith("_"):
            # private member, skip
            continue

        val = get_default(v) if not hasattr(args, k) else getattr(args, k)

        if val is None:
            overrides.append("{}.{}=null".format(sub_node, k))
        elif val == "":
            overrides.append("{}.{}=''".format(sub_node, k))
        elif isinstance(val, str):
            overrides.append("{}.{}='{}'".format(sub_node, k, val))
        else:
            overrides.append("{}.{}={}".format(sub_node, k, val))
    return overrides


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def _override_attr(
    sub_node: str, data_class: Type[FairseqDataclass], args: Namespace
) -> List[str]:
    overrides = []

    if not inspect.isclass(data_class) or not issubclass(data_class, FairseqDataclass):
        return overrides

    def get_default(f):
        if not isinstance(f.default_factory, _MISSING_TYPE):
            return f.default_factory()
        return f.default

    for k, v in data_class.__dataclass_fields__.items():
        if k.startswith("_"):
            # private member, skip
            continue

        val = get_default(v) if not hasattr(args, k) else getattr(args, k)

        if getattr(v.type, "__origin__", None) is List:
            # if type is int but val is float, then we will crash later - try to convert here
            t_args = v.type.__args__
            if len(t_args) == 1:
                val = list(map(t_args[0], val))

        if val is None:
            overrides.append("{}.{}=null".format(sub_node, k))
        elif val == "":
            overrides.append("{}.{}=''".format(sub_node, k))
        elif isinstance(val, str):
            overrides.append("{}.{}='{}'".format(sub_node, k, val))
        else:
            overrides.append("{}.{}={}".format(sub_node, k, val))
    return overrides
# Buggy code
def build_model(cfg: DictConfig, task):
    if isinstance(cfg, DictConfig):
        return ARCH_MODEL_REGISTRY[cfg._name].build_model(cfg, task)
    return ARCH_MODEL_REGISTRY[cfg.arch].build_model(cfg, task)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def build_model(cfg: DictConfig, task):
    model = None
    model_type = getattr(cfg, "_name", None) or getattr(cfg, "arch", None)

    if not model_type and len(cfg) == 1:
        # this is hit if config object is nested in directory that is named after model type

        model_type = next(iter(cfg))
        if model_type in MODEL_DATACLASS_REGISTRY:
            cfg = cfg[model_type]
        else:
            raise Exception(
                "Could not infer model type from directory. Please add _name field to indicate model type"
            )

    if model_type in ARCH_MODEL_REGISTRY:
        # case 1: legacy models
        model = ARCH_MODEL_REGISTRY[model_type]
    elif model_type in MODEL_DATACLASS_REGISTRY:
        # case 2: config-driven models
        model = MODEL_REGISTRY[model_type]

    if model_type in MODEL_DATACLASS_REGISTRY:
        # set defaults from dataclass. note that arch name and model name can be the same
        dc = MODEL_DATACLASS_REGISTRY[model_type]
        cfg = merge_with_parent(dc(), cfg)

    assert model is not None, f"Could not infer model type from {cfg}"

    return model.build_model(cfg, task)
# Buggy code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise RuntimeError("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            if p32.grad:
                p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def zero_grad(self):
    """Clears the gradients of all optimized parameters."""
    for p in self.fp16_params:
        p.grad = None
    if self.has_flat_params:
        if torch.is_tensor(self.fp32_params):
            self.fp32_params.grad.zero_()
        elif isinstance(self.fp32_params, dict):
            for fp32_params in self.fp32_params.values():
                fp32_params.grad.zero_()
        else:
            raise RuntimeError("self.fp32_params must be a tensor or dict")
    else:
        for p32 in self.fp32_params:
            if p32.grad is not None:
                p32.grad.zero_()
    self._needs_sync = False

    if self.scaler is not None:
        self._multiply_factor = 1.0 / float(self.scaler.loss_scale)
# Buggy code
def build_x(cfg: Union[DictConfig, str, Namespace], *extra_args, **extra_kwargs):
    if isinstance(cfg, DictConfig):
        choice = cfg._name
    elif isinstance(cfg, str):
        choice = cfg
        if choice in DATACLASS_REGISTRY:
            cfg = DATACLASS_REGISTRY[choice]()
    else:
        choice = getattr(cfg, registry_name, None)
        if choice in DATACLASS_REGISTRY:
            cfg = populate_dataclass(cfg, DATACLASS_REGISTRY[choice]())

    if choice is None:
        if required:
            raise ValueError("{} is required!".format(registry_name))
        return None

    cls = REGISTRY[choice]
    if hasattr(cls, "build_" + registry_name):
        builder = getattr(cls, "build_" + registry_name)
    else:
        builder = cls

    return builder(cfg, *extra_args, **extra_kwargs)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def build_x(cfg: Union[DictConfig, str, Namespace], *extra_args, **extra_kwargs):
    if isinstance(cfg, DictConfig):
        choice = cfg._name

        if choice and choice in DATACLASS_REGISTRY:
            dc = DATACLASS_REGISTRY[choice]
            cfg = merge_with_parent(dc(), cfg)
    elif isinstance(cfg, str):
        choice = cfg
        if choice in DATACLASS_REGISTRY:
            cfg = DATACLASS_REGISTRY[choice]()
    else:
        choice = getattr(cfg, registry_name, None)
        if choice in DATACLASS_REGISTRY:
            cfg = populate_dataclass(cfg, DATACLASS_REGISTRY[choice]())

    if choice is None:
        if required:
            raise ValueError("{} is required!".format(registry_name))
        return None

    cls = REGISTRY[choice]
    if hasattr(cls, "build_" + registry_name):
        builder = getattr(cls, "build_" + registry_name)
    else:
        builder = cls

    return builder(cfg, *extra_args, **extra_kwargs)
# Buggy code
def setup_task(cfg: DictConfig, **kwargs):
    if isinstance(cfg, DictConfig):
        return TASK_REGISTRY[cfg._name].setup_task(cfg, **kwargs)
    return TASK_REGISTRY[cfg.task].setup_task(cfg, **kwargs)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def setup_task(cfg: DictConfig, **kwargs):
    task = None
    task_name = getattr(cfg, "task", None)

    if isinstance(task_name, str):
        # legacy tasks
        task = TASK_REGISTRY[task_name]
    else:
        task_name = getattr(cfg, "_name", None)

        if task_name and task_name in TASK_DATACLASS_REGISTRY:
            dc = TASK_DATACLASS_REGISTRY[task_name]
            cfg = merge_with_parent(dc(), cfg)
            task = TASK_REGISTRY[task_name]

    assert task is not None, f"Could not infer task type from {cfg}"

    return task.setup_task(cfg, **kwargs)
# Buggy code
def setup_task(cls, args, **kwargs):
    """Setup the task (e.g., load dictionaries).

    Args:
        args (argparse.Namespace): parsed command-line arguments
    """
    dictionary, output_dictionary = cls.setup_dictionary(args, **kwargs)

    # upgrade old checkpoints
    if hasattr(args, "exclude_self_target"):
        args.self_target = not args.exclude_self_target

    targets = []
    if getattr(args, "self_target", False):
        targets.append("self")
    if getattr(args, "future_target", False):
        targets.append("future")
    if getattr(args, "past_target", False):
        targets.append("past")
    if len(targets) == 0:
        # standard language modeling
        targets = ["future"]

    return cls(args, dictionary, output_dictionary, targets=targets)


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def setup_task(cls, args, **kwargs):
    """Setup the task (e.g., load dictionaries).

    Args:
        args (argparse.Namespace): parsed command-line arguments
    """
    dictionary, output_dictionary = cls.setup_dictionary(args, **kwargs)

    # upgrade old checkpoints
    if getattr(args, "exclude_self_target", False):
        args.self_target = False

    targets = []
    if getattr(args, "self_target", False):
        targets.append("self")
    if getattr(args, "future_target", False):
        targets.append("future")
    if getattr(args, "past_target", False):
        targets.append("past")
    if len(targets) == 0:
        # standard language modeling
        targets = ["future"]

    return cls(args, dictionary, output_dictionary, targets=targets)