Skip to content

Fix parallel MCMC sampling segfault (cores=1 workaround) #2

Closed

Description

@thomaspinder

Problem

PyTensor 2.38 + NumPy 2.4 causes segfaults during multiprocessing MCMC sampling. All tests currently use cores=1 as a workaround, which makes slow tests even slower.

Root Cause

Same underlying incompatibility as #1 — PyTensor's multiprocessing backend crashes with recent NumPy versions when forking processes for parallel chain sampling.

Current Workaround

All NUTSSampler calls in tests use cores=1:

sampler = NUTSSampler(draws=100, tune=100, chains=2, cores=1, random_seed=42)

Desired Fix

  • Monitor PyTensor releases for multiprocessing fix
  • Once fixed, remove cores=1 constraint from test samplers
  • Consider defaulting NUTSSampler.cores to os.cpu_count() or similar

Related

Labels

tech-debt, testing

Activity

  1. thomaspinder commented on Jul 29, 2026

    @thomaspinder
    CollaboratorAuthor

    No actionable work remains here. NUTSSampler.cores already defaults to auto-detect (src/impulso/samplers.py:57), and the default backend is nutpie when installed (samplers.py:13-21), which uses threads rather than forked processes — the default path does not exercise PyMC's multiprocessing at all. The surviving cores=1 sites are deliberate: the SV default sampler (src/impulso/sv/spec.py:58-61) and slow tests that explicitly pin nuts_sampler="pymc". The constraint is documented in CLAUDE.md. To be clear, the underlying PyMC/macOS crash is not verified fixed upstream — this is a close-for-hygiene: if a parallel-sampling crash resurfaces, a fresh issue with a reproducer will be more useful than this monitoring ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions