Yes doing with torch.no_grad() will prevent gradient from flowing back all the way to moduleA.
You can set the requires_grad flag on each parameter to False though to avoid that:
self.B.requires_grad_(False)
b = self.B(a)
self.B.requires_grad_(True)
c = self.B(y)

That will make sure that what is computed using b, won’t update the gradients of module.B.