Warning using Minibatch and Censored together (RNG Variable has shared clients)

Hi everyone!
When I use Minibatch together with Censored, I get a warning about the RNG having multiple clients. I think this is a result of the observed variable being a minibatched object. From reading other posts here, it sounds like this could cause some issues with sampling the prior and posterior predictives. But I don’t have a good enough grasp yet of what is going on internally here to know if this is ok to ignore.

Here is some minimal code that produces the warning:

    y = X * 2
    X_mb, y_mb = pm.Minibatch(X, y, batch_size=100)
    with pm.Model() as model:
        beta = pm.Normal('b', mu=0, sigma=1)
        mu = beta * X_mb
        y_uncensored = pm.Normal.dist(mu=mu, sigma=1)
        y_obs = pm.Censored('y_obs', y_uncensored, lower=0, upper = None, observed=y_mb)
        pm.fit()

And this is the warning:

UserWarning: RNG Variable RandomGeneratorSharedVariable(<Generator(PCG64) at 0x16114C9E0>) has multiple clients. This is likely an inconsistent random graph.

Here are is relevant version info from conda list:

pymc                      5.15.1               hd8ed1ab_1    conda-forge
pymc-base                 5.15.1             pyhd8ed1ab_1    conda-forge
pytensor                  2.22.1          py312hb2f6674_0    conda-forge
pytensor-base             2.22.1          py312hf1ba2cd_0    conda-forge
python                    3.12.4          h37a9e06_0_cpython    conda-forge

Can you try with he latest version of PyMC?

Ok, here is the warning I get running the above code with pymc v5.16.2 and pytensor v2.25.2. The warning is more verbose, but seems to be basically the same:

UserWarning: RNG Variable RNG(<Generator(PCG64) at 0x14E1A2A40>) has multiple distinct clients [(integers_rv{"(),()->()"}(RNG(<Generator(PCG64) at 0x14E1A2A40>), [100], [0], [1000]), 0), (integers_rv{"(),()->()"}(RNG(<Generator(PCG64) at 0x14E1A2A40>), [100], ExpandDims{axis=0}.0, ExpandDims{axis=0}.0), 0)], likely due to an inconsistent random graph. No default update will be returned.
  warnings.warn(

So just to have an idea in case I ever want to try this again… is minibatching with a Censored likelihood is not currently supported? Is there a workaround? Is the warning safe to ignore? Thanks!

Not safe to ignore but I haven’t been able to investigate yet why it’s happening

1 Like

The bug should be fixed in Allow Minibatch of derived RVs and deprecate generators as data by ricardoV94 · Pull Request #7480 · pymc-devs/pymc · GitHub, which also allows rescaling the logp of minibatch Censored RVs with total_size.

I don’t know if you meant to use total_size or not, but after the changes, you’ll be able to :slight_smile:

1 Like

Awesome, thanks Ricardo!