You can very probably bypass the error by cloning output before changing it inplace:
output = output.clone()
output[target != 1] = 1 - output[target != 1] 

The where function works with matrices but the sizes of the parameters have to be the same (or scalar). Here 1 - output[target != 1]  and output have different sizes. You should do:
output = torch.where(target != 1, 1 - output, output)