I’m not aware of any built-in method, so you might need to implement it manually.
Maybe you could use this manual example of the batch norm calculation 33 as a starter and change the mean and var calculation using the masked method:
# Create dummy input
x = torch.randn(2, 3, 10)
x[0, 0, 5:] = 0.
x[0, 1, 6:] = 0.
x[0, 2, 7:] = 0.
x[1, 0, 8:] = 0.
x[1, 1, 9:] = 0.

# Use mask for manual calculation
mask = x!=0
mask_mean = (x.sum(2) / mask.float().sum(2)).mean(0)

# Alternatively rescale BatchNorm1d.running_mean
mean = x.mean([0, 2])
mean * x.size(2) / (x.size(2) - (x==0).float().sum(2)).sum()

The second example would work, if you would like to use the PyTorch batch norm implementation (e.g. for performance reasons) and “rescale” the running estimates.
Let me know, if that helps.