I run this exact script and get the Unknown type annotation nn.Module error. It includes a successful export to onnx just as a sanity check that there isn’t something wrong with the model.
import torch
import torch.nn as nn


class DcganGenerator(nn.Module):
    __main: nn.Module

    def __init__(self, shape_originals, shape_targets):
        super().__init__()
        num_channels = shape_originals[0]
        shape_originals  # TODO upsample to this shape
        ngf = 64
        ndf = 64

        self.__main = nn.Sequential(
            nn.ConvTranspose2d(num_channels, ngf * 8, 4, 1, 0, bias=False),
            nn.BatchNorm2d(ngf * 8),
            nn.PReLU(),
            nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 4),
            nn.PReLU(),
            nn.ConvTranspose2d(ngf * 4, ngf * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 2),
            nn.PReLU(),
            nn.ConvTranspose2d(ngf * 2, ngf, 4, 1, 1, bias=False),
            nn.BatchNorm2d(ngf),
            nn.PReLU(),
            nn.ConvTranspose2d(ngf, num_channels, 4, 1, 1, bias=False),
            nn.PReLU(),
        )

    def forward(self, inputs):
        return {"generated": self.__main(inputs)}

def load_generator():
    print("Instantiating generator")
    g = DcganGenerator([3, 128, 128], [3, 512, 512])
    print(g)
    return g


def to_torch_jit(generator):
    print("Converting to JIT pytorch")
    try:
        jitted = torch.jit.script(generator)
        torch.jit.save(jitted, "model.pt")

        print("Created model.pt")
    except Exception as e:
        print(f"Failed. {e}")


def to_onnx(generator):
    print("Converting to ONNX")
    try:
        torch.onnx.export(
            generator,
            torch.rand(1, 3, 128, 128),
            "model.onnx",
            export_params=True,
            opset_version=11,
            input_names=["in"],
            output_names=["out"],
        )
        print("Created model.onnx")
    except Exception as e:
        print(f"Failed. {e}")


generator = load_generator()
print()
to_torch_jit(generator)
to_onnx(generator)

Saved as jit-it.py, output:
$ python3 jit-it.py 
Instantiating generator
DcganGenerator(
  (_DcganGenerator__main): Sequential(
    (0): ConvTranspose2d(3, 512, kernel_size=(4, 4), stride=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): PReLU(num_parameters=1)
    (3): ConvTranspose2d(512, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (4): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (5): PReLU(num_parameters=1)
    (6): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (7): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (8): PReLU(num_parameters=1)
    (9): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
    (10): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (11): PReLU(num_parameters=1)
    (12): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
    (13): PReLU(num_parameters=1)
  )
)

Converting to JIT pytorch
Failed. Unknown type annotation: '<class 'torch.nn.modules.module.Module'>'
Converting to ONNX
Created model.onnx