Create 2 separate independent GPmodels but their prediction seems to be tangled?

I’m having a weird issue when I use two GPRegression models in the same program.

say I have two GPRegression models -
gp1 = gp.models.GPRegression(X1, y1, kernel, noise=torch.tensor(0.1), jitter=1.0e-4)
gp2 = gp.models.GPRegression(X2, y2, kernel, noise=torch.tensor(0.1), jitter=1.0e-4)

after training, I can use them for prediction -
mu1, variance1 = gp1(x_new, full_cov=False, noiseless=False)
mu2, variance2 = gp2(x_new, full_cov=False, noiseless=False)

If now I train gp1 with more new data, as expected the gp1 now predicting mu1, variance1 differently because the gp1 is changed by the new data.

however, for some unknown/mysterious reason that the prediction from gp2 is also changed… I didn’t train the gp2 with new data therefore there should be no change for gp2 at all… I notice that the gp2 is predicting smaller and smaller variance which seems to be following the variance from gp1…

not sure where I did wrong…

@jay This is unfortunate. In recent release, classes are integrated with pyro.nn.Module, whose parameters are stored in a global Pyro ParamStoreDict. In this situation, parameters of two models use the same entry in that global dict. I guess you can add the following dummy code:

dummy = pyro.nn.PyroModule()
dummy.gp1 = gp1
dummy.gp2 = gp2

to distinguish the parameter names of two models, and train gp1, gp2 as usual (no need to use dummy).

ah~ that solves the problem! thank you so much!

that makes sense, I was also suspecting the global variable is somehow entangled. would this be considered as a bug and fixed in future release?

this problem took me about 4 hrs trying to either fix it or go around it but all seems to fail. hope I asked the question earlier :slight_smile: :grinning:

hi fehiepsi,

do you know if this bug is fixed in more recent release? thanks.

@jay This has not been solved yet in the last release.

@fritzo I am thinking about leveraging name arg of PyroModule and add a name arg to those GP models to solve this issue. Do you have other ideas?