Skip to content

Conversation

@bohJiang12
Copy link

Issue description

Ran the app doctr-wrapper on both standalone and containerized ways, and faced error:

Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method

Implementations

  • Imported torch.multiprocessing module
  • Forced the start method of multiprocess as spawn instead of fork, such that multiprocessing.set_start_method('spawn', force=True)
  • Then placed the setting outside of the class

@keighrim
Copy link
Member

keighrim commented Aug 4, 2024

@bohJiang12 found that the error doesn't occur when the app runs in development mode (i.e., w/o --production flag). Hence this might be an issue in the SDK code, as also discussed in pytorch/pytorch#68861. I will investigate the gunicorn wrapper in the SDK code.

@keighrim
Copy link
Member

Just tried to run this fix, and got the same errors. Will investigate further.

@keighrim
Copy link
Member

The root cause of this issue was the previous implementation's use on Python's built-in concurrent for multithreading, which doesn't work with CUDA. Given that the application has been single-threaded as of v1.2, this specific error related to CUDA re-initialization should be resolved. Closing this pull request without merging the changes.

@keighrim keighrim closed this Nov 22, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in apps Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants