Debug a multiprocessing job that fails with pickling and CUDA errors
Interview insights are lockedSee how often this is asked and which companies asked it with Buncho Pro.import torch, multiprocessing as mp
model = Net().cuda()
def predict(batch):
return model(batch.cuda()).cpu()
if True:
with mp.Pool(4) as pool:
results = pool.map(lambda b: predict(b), batches)
The script fails with Can't pickle local object / Can't pickle <function <lambda>> and, after you remove the lambda, with RuntimeError: Cannot re-initialize CUDA in forked subprocess. Explain both errors and give a correct design.