Given that the model loaded from PyTorch hub:
import torch
torch.cuda.is_available()
en2de = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-de.single_model')
en2de.translate('hello world') # [out]: 'Hallo Welt'

type(en2de.models[0])   # [out]: fairseq.models.transformer.TransformerModel

The quantization seems to be successful:
en2de_q0 = torch.quantization.quantize_dynamic(
    en2de.models[0], {torch.nn.Linear}, dtype=torch.qint8
)

type(en2de_q0) # [out]: fairseq.models.transformer.TransformerModel

But after trying to overwrite the model, the translate function inside TransformerModel fails:
en2de.models[0] = en2de_q0
en2de.translate('hello world')

[out]:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-adf73479cb54> in <module>
----> 1 en2de.translate('hello world')

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py in translate(self, sentences, beam, verbose, **kwargs)
    120 
    121     def translate(self, sentences: List[str], beam: int = 5, verbose: bool = False, **kwargs) -> List[str]:
--> 122         return self.sample(sentences, beam, verbose, **kwargs)
    123 
    124     def sample(self, sentences: List[str], beam: int = 1, verbose: bool = False, **kwargs) -> List[str]:

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py in sample(self, sentences, beam, verbose, **kwargs)
    124     def sample(self, sentences: List[str], beam: int = 1, verbose: bool = False, **kwargs) -> List[str]:
    125         if isinstance(sentences, str):
--> 126             return self.sample([sentences], beam=beam, verbose=verbose, **kwargs)[0]
    127         tokenized_sentences = [self.encode(sentence) for sentence in sentences]
    128         batched_hypos = self.generate(tokenized_sentences, beam, verbose, **kwargs)

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py in sample(self, sentences, beam, verbose, **kwargs)
    126             return self.sample([sentences], beam=beam, verbose=verbose, **kwargs)[0]
    127         tokenized_sentences = [self.encode(sentence) for sentence in sentences]
--> 128         batched_hypos = self.generate(tokenized_sentences, beam, verbose, **kwargs)
    129         return [self.decode(hypos[0]['tokens']) for hypos in batched_hypos]
    130 

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py in generate(self, tokenized_sentences, beam, verbose, skip_invalid_size_inputs, **kwargs)
    159         for batch in self._build_batches(tokenized_sentences, skip_invalid_size_inputs):
    160             batch = utils.apply_to_sample(lambda t: t.to(self.device), batch)
--> 161             translations = self.task.inference_step(generator, self.models, batch)
    162             for id, hypos in zip(batch["id"].tolist(), translations):
    163                 results.append((id, hypos))

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/tasks/fairseq_task.py in inference_step(self, generator, models, sample, prefix_tokens)
    304     def inference_step(self, generator, models, sample, prefix_tokens=None):
    305         with torch.no_grad():
--> 306             return generator.generate(models, sample, prefix_tokens=prefix_tokens)
    307 
    308     def update_step(self, num_updates):

/usr/local/lib/python3.7/site-packages/torch/autograd/grad_mode.py in decorate_no_grad(*args, **kwargs)
     47         def decorate_no_grad(*args, **kwargs):
     48             with self:
---> 49                 return func(*args, **kwargs)
     50         return decorate_no_grad
     51 

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py in generate(self, models, sample, **kwargs)
     90         """
     91         model = EnsembleModel(models)
---> 92         return self._generate(model, sample, **kwargs)
     93 
     94     @torch.no_grad()

/usr/local/lib/python3.7/site-packages/torch/autograd/grad_mode.py in decorate_no_grad(*args, **kwargs)
     47         def decorate_no_grad(*args, **kwargs):
     48             with self:
---> 49                 return func(*args, **kwargs)
     50         return decorate_no_grad
     51 

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py in _generate(self, model, sample, prefix_tokens, bos_token, **kwargs)
    130 
    131         # compute the encoder output for each beam
--> 132         encoder_outs = model.forward_encoder(encoder_input)
    133         new_order = torch.arange(bsz).view(-1, 1).repeat(1, beam_size).view(-1)
    134         new_order = new_order.to(src_tokens.device).long()

/usr/local/lib/python3.7/site-packages/torch/autograd/grad_mode.py in decorate_no_grad(*args, **kwargs)
     47         def decorate_no_grad(*args, **kwargs):
     48             with self:
---> 49                 return func(*args, **kwargs)
     50         return decorate_no_grad
     51 

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py in forward_encoder(self, encoder_input)
    520         if not self.has_encoder():
    521             return None
--> 522         return [model.encoder(**encoder_input) for model in self.models]
    523 
    524     @torch.no_grad()

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/sequence_generator.py in <listcomp>(.0)
    520         if not self.has_encoder():
    521             return None
--> 522         return [model.encoder(**encoder_input) for model in self.models]
    523 
    524     @torch.no_grad()

/usr/local/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/transformer.py in forward(self, src_tokens, src_lengths, cls_input, return_all_hiddens, **unused)
    404             dropout_probability = random.uniform(0, 1)
    405             if not self.training or (dropout_probability > self.encoder_layerdrop):
--> 406                 x = layer(x, encoder_padding_mask)
    407                 if return_all_hiddens:
    408                     encoder_states.append(x)

/usr/local/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/modules/transformer_layer.py in forward(self, x, encoder_padding_mask, attn_mask)
     93         # TODO: to formally solve this problem, we need to change fairseq's
     94         # MultiheadAttention. We will do this later on.
---> 95         x, _ = self.self_attn(query=x, key=x, value=x, key_padding_mask=encoder_padding_mask)
     96         x = F.dropout(x, p=self.dropout, training=self.training)
     97         x = residual + x

/usr/local/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

~/.cache/torch/hub/pytorch_fairseq_master/fairseq/modules/multihead_attention.py in forward(self, query, key, value, key_padding_mask, incremental_state, need_weights, static_kv, attn_mask, before_softmax, need_head_weights)
    126                                                   self.embed_dim, self.num_heads,
    127                                                   torch.empty([0]),
--> 128                                                   torch.cat((self.q_proj.bias, self.k_proj.bias, self.v_proj.bias)),
    129                                                   self.bias_k, self.bias_v,
    130                                                   self.add_zero_attn, self.dropout,

TypeError: expected Tensor as element 0 in argument 0, but got method

Anyone knows how to resolve this? And quantize the model and still make it translate?