0

I would like to train a machine learning model with Python several times and pick the best one from them. Firstly I run the following sequential version and everything works fine:

for item in range(num_of_trainings):
    temp_list_of_models[item].train()

And I want to run them in parallel by running

for item in range(num_of_trainings):
    task_list[item] = Process(target = temp_list_of_models[item].train)
    task_list[item].start()

map(lambda x: x.join(), task_list)

But the problem is this version does not seem to train models in temp_list_of_models at all and all objects in them are stayed unchanged. I am wondering if anyone has idea what the problem might be?

Thanks!

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
username123
  • 913
  • 1
  • 11
  • 29
  • 1
    Is this Python 3? If so, `map` is returning a `map` object. This is an iterator and will not call `join` until you ask it to. See [this answer](http://stackoverflow.com/questions/13623634/python-3-map-function-is-not-calling-up-function) on using `map` in Python 3. – ChrisP Apr 18 '16 at 15:57
  • Another possible problem is that processes don't share memory, so any change you do in the worker processes will be lost – BlackBear Apr 18 '16 at 16:04
  • @ChrisP No, it is Python2 – username123 Apr 18 '16 at 16:32
  • @BlackBear I thought this might be the issue, so how should I save the result after training? I would not use multithreading since it is quite slow due to Global interpreter lock. – username123 Apr 18 '16 at 16:33

0 Answers0