pymc.step_methods.Metropolis.fork#

Metropolis.fork(rng)#

Return an independent copy of this step for a new chain/thread.

Gives the copy its own self.shared variables and its own storage for every compiled pytensor function it holds (via Function.copy(swap=...), so the compiled code is shared but not the mutable containers). Mutable tuning/adaptation state is cloned independently through the sampling_state round-trip.

The copy is not seeded from rng here: _iter_sample calls set_rng on every chain’s step in all sampling modes, and set_rng advances the passed generator (via spawn). Seeding here as well would consume the chain’s shared RNG twice and desynchronize threaded chains from the sequential/multiprocessing results.

A subclass whose extra per-chain state is not captured by self.shared, a compiled Function attribute, or sampling_state must override or re-disable fork (raise NotImplementedError) so threaded sampling falls back to multiprocessing.