Could you try to assign the device to your new tensor using the device of another parameter?
E.g. if your A module has some layers or other parameters stored, try the following:
print(self.foo)
self.foo = torch.tensor(2018, device=self.another_parameter.device)
print(self.foo)