# Buggy code
def __init__(self, task, classification_head_name):
    super().__init__(task)
    self.classification_head_name = classification_head_name


# Traceback (AttributeError)
2020-03-08 13:40:11 | INFO | fairseq_cli.train | model roberta_large, criterion SentencePredictionCriterion
2020-03-08 13:40:11 | INFO | fairseq_cli.train | num. model params: 357499983 (num. trained: 357499983)
2020-03-08 13:40:11 | INFO | fairseq_cli.train | training on 1 GPUs
2020-03-08 13:40:11 | INFO | fairseq_cli.train | max tokens per GPU = 4 and max sentences per GPU = 2
2020-03-08 13:40:11 | INFO | fairseq.models.roberta.model | Overwriting classification_heads.head_name.dense.weight
2020-03-08 13:40:11 | INFO | fairseq.models.roberta.model | Overwriting classification_heads.head_name.dense.bias
2020-03-08 13:40:11 | INFO | fairseq.models.roberta.model | Overwriting classification_heads.head_name.out_proj.weight
2020-03-08 13:40:11 | INFO | fairseq.models.roberta.model | Overwriting classification_heads.head_name.out_proj.bias
2020-03-08 13:40:11 | INFO | fairseq.trainer | loaded checkpoint roberta.large/model.pt (epoch 1 @ 0 updates)
2020-03-08 13:40:11 | INFO | fairseq.trainer | loading train data for epoch 1
2020-03-08 13:40:11 | INFO | fairseq.data.data_utils | loaded 160600 examples from: ../data/input0/train
2020-03-08 13:40:11 | INFO | fairseq.data.data_utils | loaded 160600 examples from: ../data/label/train
2020-03-08 13:40:11 | INFO | fairseq.tasks.sentence_prediction | Loaded train with #samples: 160600
2020-03-08 13:40:11 | WARNING | fairseq.data.data_utils | 160580 samples have invalid sizes and will be skipped, max_positions=4, first few sample ids=[141335, 12811, 122058, 104432, 1925, 141500, 65517, 143950, 59283, 155828]
Traceback (most recent call last):
File "train.py", line 11, in <module>
cli_main()
File "/nas/home/thawani/MCS/fairseq/fairseq_cli/train.py", line 322, in cli_main
main(args)
File "/nas/home/thawani/MCS/fairseq/fairseq_cli/train.py", line 100, in main
train(args, trainer, task, epoch_itr)
File "/nas/home/thawani/anaconda3/envs/env/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "/nas/home/thawani/MCS/fairseq/fairseq_cli/train.py", line 177, in train
log_output = trainer.train_step(samples)
File "/nas/home/thawani/anaconda3/envs/env/lib/python3.7/contextlib.py", line 74, in inner
return func(*args, **kwds)
File "/nas/home/thawani/MCS/fairseq/fairseq/trainer.py", line 319, in train_step
ignore_grad=is_dummy_batch,
File "/nas/home/thawani/MCS/fairseq/fairseq/tasks/fairseq_task.py", line 337, in train_step
loss, sample_size, logging_output = criterion(model, sample)
File "/nas/home/thawani/anaconda3/envs/env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/nas/home/thawani/MCS/fairseq/fairseq/criterions/sentence_prediction.py", line 40, in forward
and self.args.classification_head_name in model.classification_heads
File "/nas/home/thawani/anaconda3/envs/env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 576, in __getattr__
type(self).__name__, name))
AttributeError: 'SentencePredictionCriterion' object has no attribute 'args'

# Fixed code
def __init__(self, task, classification_head_name, regression_target):
    super().__init__(task)
    self.classification_head_name = classification_head_name
    self.regression_target = regression_target