# Buggy code
def __init__(
    self, hidden_size, vocab_size, hidden_act="gelu", task_name="lm", **kwargs
):
    super(BertLMHead, self).__init__()

    self.hidden_size = hidden_size
    self.hidden_act = hidden_act
    self.vocab_size = vocab_size
    self.loss_fct = CrossEntropyLoss(reduction="none", ignore_index=-1)
    self.num_labels = vocab_size  # vocab size
    # TODO Check if weight init needed!
    # self.apply(self.init_bert_weights)
    self.ph_output_type = "per_token"

    self.model_type = "language_modelling"
    self.task_name = task_name
    self.generate_config()

    # NN Layers
    # this is the "transform" module in the pytorch-transformers repo
    self.dense = nn.Linear(self.hidden_size, self.hidden_size)
    self.transform_act_fn = ACT2FN[self.hidden_act]
    self.LayerNorm = BertLayerNorm(self.hidden_size, eps=1e-12)

    # this is the "decoder" in the pytorch-transformers repo
    # The output weights are the same as the input embeddings, but there is
    # an output-only bias for each token.
    self.decoder = nn.Linear(hidden_size, vocab_size, bias=False)
    self.bias = nn.Parameter(torch.zeros(vocab_size))


# Traceback (torch.nn.modules.module.ModuleAttributeError)
Traceback (most recent call last):
File "conversion_huggingface_models.py", line 88, in <module>
convert_to_transformers("./farm_saved_models/bert-english-lm",
File "conversion_huggingface_models.py", line 46, in convert_to_transformers
transformer_model = model.convert_to_transformers()
File "/home/himanshu/.conda/envs/tf2/lib/python3.8/site-packages/farm/modeling/adaptive_model.py", line 509, in convert_to_transformers
elif len(self.prediction_heads[0].layer_dims) != 2:
File "/home/himanshu/.conda/envs/tf2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 771, in __getattr__
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'BertLMHead' object has no attribute 'layer_dims'

# Fixed code
def __init__(
    self, hidden_size, vocab_size, hidden_act="gelu", task_name="lm", **kwargs
):
    super(BertLMHead, self).__init__()

    self.hidden_size = hidden_size
    self.hidden_act = hidden_act
    self.vocab_size = vocab_size
    self.loss_fct = CrossEntropyLoss(reduction="none", ignore_index=-1)
    self.num_labels = vocab_size  # vocab size
    # Adding layer_dims (required for conversion to transformers)
    self.layer_dims = [hidden_size, vocab_size]
    # TODO Check if weight init needed!
    # self.apply(self.init_bert_weights)
    self.ph_output_type = "per_token"

    self.model_type = "language_modelling"
    self.task_name = task_name
    self.generate_config()

    # NN Layers
    # this is the "transform" module in the pytorch-transformers repo
    self.dense = nn.Linear(self.hidden_size, self.hidden_size)
    self.transform_act_fn = ACT2FN[self.hidden_act]
    self.LayerNorm = BertLayerNorm(self.hidden_size, eps=1e-12)

    # this is the "decoder" in the pytorch-transformers repo
    # The output weights are the same as the input embeddings, but there is
    # an output-only bias for each token.
    self.decoder = nn.Linear(hidden_size, vocab_size, bias=False)
    self.bias = nn.Parameter(torch.zeros(vocab_size))