Forking recommendations for MPS

I know that forking is not supported when using CUDA eg:

But there are some constrained scenarios where forking is possible, eg:

I wonder if there are some recommendations for using fork with MPS enabled builds of pytorch. Or when using MPS tensors.

FWIW I have tried forking with 3 simple different scenarios:

  1. Creating an MPS tensor:

    def mps_tensor ():
      torch.randn(100, 100, device = "mps")```
    
  2. Creating a tensor on the CPU

    def cpu_tensor ():
      torch.randn(100, 100, device = "cpu")
    
  3. Cpu but calling backward:

    def cpu_but_backward():
        x = torch.randn(100,100)
        y = torch.randn(100,100, requires_grad=True)
        loss = torch.mm(x, y).sum()
        loss.backward()
    

I then tried forking the process and running those functions with:

import multiprocessing
from multiprocessing import Process
multiprocessing.set_start_method("fork")
p = Process(target=mps_tensor)
p.start()

The 1 and 3 functions failed with:

The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
objc[60703]: +[NSPlaceholderMutableString initialize] may have been in progress in another thread when fork() was called.
objc[60703]: +[NSPlaceholderMutableString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

while 2 works normally.