TorchScript JIT can't handle Tuple[Tensor, Tensor] + Tuple[Tensor] statement

How can I workaround the errors?

RuntimeError:
Arguments for call are not valid.
The following variants are available:

aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) → (Tensor):
Expected a value of type ‘Tensor’ for argument ‘self’ but instead found type ‘Optional[Tuple[]]’.

aten::add.Scalar(Tensor self, Scalar other, Scalar alpha=1) → (Tensor):
Expected a value of type ‘Tensor’ for argument ‘self’ but instead found type ‘Optional[Tuple[]]’.

aten::add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) → (Tensor(a!)):
Expected a value of type ‘Tensor’ for argument ‘self’ but instead found type ‘Optional[Tuple[]]’.

aten::add.t(t[] a, t[] b) → (t[]):
Could not match type Optional[Tuple[]] to List[t] in argument ‘a’: Cannot match List[t] to Optional[Tuple[]].

aten::add.str(str a, str b) → (str):
Expected a value of type ‘str’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

aten::add.int(int a, int b) → (int):
Expected a value of type ‘int’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

aten::add.float(float a, float b) → (float):
Expected a value of type ‘float’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

aten::add.int_float(int a, float b) → (float):
Expected a value of type ‘int’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

aten::add.float_int(float a, int b) → (float):
Expected a value of type ‘float’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

aten::add(Scalar a, Scalar b) → (Scalar):
Expected a value of type ‘number’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

add(float a, Tensor b) → (Tensor):
Expected a value of type ‘float’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

add(int a, Tensor b) → (Tensor):
Expected a value of type ‘int’ for argument ‘a’ but instead found type ‘Optional[Tuple[]]’.

The original call is:
File “…/transformers/src/transformers/models/bert/modeling_bert.py”, line 546
for i, layer_module in enumerate(self.layer):
if output_hidden_states:
all_hidden_states = all_hidden_states + (hidden_states,)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <— HERE

        layer_head_mask = head_mask[i] if head_mask is not None else None

It seems that the Tuple[Tensor, Tensor] is actually Optional[Tuple[Tensor, Tensor]]; you need to refine it so that TorchScript can safely conclude it is not none:

if all_hidden_states is not None:
   ...

or

assert all_hidden_states is not None