Hello,
Here’s what I would do (assuming I understood your problem correctly):
class NoiseLayer(nn.Module):
    # I do not think you need the x and y dimensions here
    def __init__(self, noise_percentage):
        super(NoiseLayer, self).__init__()
        self.n_p = noise_percentage

    def forward(self, x):
        # shape of noise_tensor is the same as input x
        noise_tensor = torch.rand(size=(x.size(0), x.size(1), x.size(2), x.size(3))) * self.n_p
        print(noise_tensor)
        '''
        tensor([[[[0.0683, 0.2465, 0.2814, 0.4447],
          [0.2304, 0.1329, 0.3671, 0.3631],
          [0.1392, 0.0553, 0.1882, 0.1521],
          [0.0744, 0.4937, 0.3658, 0.1365]]],


        [[[0.4729, 0.4658, 0.2843, 0.4314],
          [0.1264, 0.4564, 0.2930, 0.2984],
          [0.0604, 0.1626, 0.0920, 0.2806],
          [0.3901, 0.0894, 0.3852, 0.1959]]]])
        '''
        mask_ones = (x == 1.0)
        mask_zeros = (x == 0.0)
        x[mask_ones] = x[mask_ones] - noise_tensor[mask_ones]
        x[mask_zeros] = x[mask_zeros] + noise_tensor[mask_zeros]
        return x

# small example
nl = NoiseLayer(0.5)
x = torch.empty(size=(2, 1, 4, 4), dtype=torch.float32).random_(0, 2)
print(x)
'''
tensor([[[[1., 0., 0., 0.],
          [1., 1., 1., 0.],
          [1., 0., 1., 0.],
          [0., 1., 0., 1.]]],


        [[[1., 0., 0., 1.],
          [1., 0., 0., 1.],
          [1., 0., 0., 0.],
          [1., 0., 1., 1.]]]])
'''
o = nl(x)
print(o)
'''
tensor([[[[0.9317, 0.2465, 0.2814, 0.4447],
          [0.7696, 0.8671, 0.6329, 0.3631],
          [0.8608, 0.0553, 0.8118, 0.1521],
          [0.0744, 0.5063, 0.3658, 0.8635]]],


        [[[0.5271, 0.4658, 0.2843, 0.5686],
          [0.8736, 0.4564, 0.2930, 0.7016],
          [0.9396, 0.1626, 0.0920, 0.2806],
          [0.6099, 0.0894, 0.6148, 0.8041]]]])
'''

Basically, you mask out the 1.0 and 0.0 values in your x tensor and subtract or add noise to only those values. Your x tensor will therefore always be in the [0, 1] range.
Let me know if this is not what you wanted!