    num_attention_heads=12,
    intermediate_size=3072,
    torchscript=True,
)
Instantiating the model
model = BertModel(config)
The model needs to be in evaluation mode
model.eval()
If you are instantiating the model with from_pretrained you can also easily set the TorchScript flag
model = BertModel.from_pretrained("bert-base-uncased", torchscript=True)
Creating the trace
traced_model = torch.jit.trace(model, [tokens_tensor, segments_tensors])
torch.jit.save(traced_model, "traced_bert.pt")
```
Loading a model
This snippet shows how to load the BertModel that was previously saved to disk under the name traced_bert.pt.
We are re-using the previously initialised dummy_input.
```python
loaded_model = torch.jit.load("traced_bert.pt")
loaded_model.eval()
all_encoder_layers, pooled_output = loaded_model(*dummy_input)
