I’m working with a library that does some heavy multithreading and it hangs if I use the ‘fork’ multiprocessing context, so I need to use ‘spawn’ (not using windows jfc…).
Then getting the classic “AttributeError: Can’t pickle local object ‘main..collate_fn’” when defining the collate function something like this inside the main()
:
def collate_fn(x):
return functions.collate(collate_params, x)
What can I do?
Someone somewhere mentioned using dill instead of pickle (it can serialize anything I guess), but this is a problem with pytorch using pickle, so can’t just use dill I think…
EDIT: OK the form of the collate function is not really important, but that it’s defined inside the main() and then right after I define the Dataloader(collate_fn=collate_fn, ...)