I think torchscript supports Optional: https://pytorch.org/docs/master/jit.html#optional-type-refinement 93.
TorchScript doesn’t support Union. If you have a use case, opening a feature request on the repository (instead of a question) might be the way to go.