Skip to content

Set multiprocessing to spawn for Linux #7804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

fonnesbeck
Copy link
Member

@fonnesbeck fonnesbeck commented May 28, 2025

Description

Multiprocess sampling often fails randomly on Linux due to the start method defaulting to "fork". This sets it to "spawn" when mcmc is imported.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7804.org.readthedocs.build/en/7804/

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to fix random failures in multiprocess sampling on Linux by forcing the multiprocessing start method to "spawn".

  • Added a platform check for Linux
  • Configured the multiprocessing start method to "spawn" when importing the mcmc module

@ricardoV94
Copy link
Member

ricardoV94 commented May 28, 2025

We should be very careful about doing this change as it has been working for decades now just fine and it's the fastest form of starting multiprocessing.

Are you doing this because of JAX? Because JAX is still pretty useless without special handling on our side.

@ricardoV94
Copy link
Member

Also there's at least one known issue with spawn: #7790

@fonnesbeck
Copy link
Member Author

That issue appears to be restricted to MacOS.
This change in this PR only applies to Linux.

At the moment I have to manually switch to spawn on pretty much every model I run because it fails so frequently. Do we have any reports of failure using spawn on Linux?

@ricardoV94
Copy link
Member

ricardoV94 commented May 28, 2025

Can you show some code to see if anybody can reproduce, before changing for everyone?

This multiprocessing thing is something I see people come and flip flop around because it fails on their machine, then someone comes and puts it back because the new one fails on their machine.

I don't think the issue I linked is due to mac, but due to spawn which mac uses by default. If we make that default in Linux we would also see it. It's just an example of something subtle that may break for existing users who have no problem with fork.

Also I think you can change the default python method once and that's what pymc would use?

@fonnesbeck fonnesbeck closed this May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConnectionResetError from multiprocess sampling
2 participants