This should work:
x = torch.tensor([[1, 1, 1, 1, 0, 0, 0],
                  [1, 1, 1, 0, 0, 0, 0],
                  [1, 1, 1, 1, 1, 0, 0]])

tmp = (x == 1).cumsum(dim=1) - 1
idx_start = tmp[:, 0] 
idx_stop = tmp[:, -1]
idx = torch.stack((idx_start, idx_stop), dim=1)
x[torch.arange(x.size(0)).unsqueeze(1), idx] = 0

print(x)
> tensor([[0, 1, 1, 0, 0, 0, 0],
          [0, 1, 0, 0, 0, 0, 0],
          [0, 1, 1, 1, 0, 0, 0]])