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