I guess the flattening of the output might cause this issue:
output = discriminator(real_cpu).view(-1)
# and/or
output = discriminator(fake.detach()).view(-1)

Depending on the used loss function, you might need to pass an output and/or target with multiple dimensions.