multiprocessing
experiment.multiprocessing
MultiJobHandler
여러 실험을 여러 GPU에서 parallel하게 돌려주는 class 입니다.
Example
100가지의 서로 다른 실험을 0, 1 GPU에, GPU당 실험 2개씩 순차적으로 실행
multi_job_handler = MultiJobHandler(gpu_ids=[0, 1], job_per_gpu=2) multi_job_handler.launch(func=some_function, kwargs_list=[ config1, config2, config3, ... , config 100 ])
Note
- launch 함수를 실행하기 전에 pytorch의 GPU 기능을 사용할 수 없습니다. 1-1. fork 대신 spawn을 사용하면 해결할 수 있으나, spawn을 사용할 경우 code변경 이슈가 생길 수 있음.
- CUDA_VISIBLE_DEVICES를 사용할 경우 주의가 필요합니다. 현재 구현 방식은 CUDA_VISIBLE_DEVICES=1,3,5,7 이고 gpu_ids=[1, 2]라면 실제 GPU는 3, 5를 사용합니다.
Parameters:
-
gpu_ids(Union[int, List[int]]) –실험에 사용할 GPU id list.
-
job_per_gpu(int) –각 GPU device에 최대로 할당할 수 있는 job의 개 수.
Source code in ResearchToolkit/experiment/multiprocessing.py
cuda_visible_devices
instance-attribute
launch
여러 실험을 여러 GPU에서 parallel하게 실행합니다.
Parameters:
-
func(Callable) –Function to be executed by the child process.
-
kwargs_list(List) –List of Keyword arguments to be input to the function.
Source code in ResearchToolkit/experiment/multiprocessing.py
_is_busy
Check devices are busy
Returns:
-
bool(bool) –Returns True if all devices are working else False
Source code in ResearchToolkit/experiment/multiprocessing.py
_join
Waits until the child process is finished or as long as the timeout time.
Parameters:
-
timeout(float, default:0.1) –Waiting time for each child process. Defaults to 0.1.
Source code in ResearchToolkit/experiment/multiprocessing.py
_get_gpu_id
Returns the available gpu id.
Returns:
-
int(int) –gpu id
Source code in ResearchToolkit/experiment/multiprocessing.py
run
Set the GPU id and execute the function.
Parameters:
-
gpu_id(int) –GPU id
-
func(Callable) –Function to be executed by the child process.
-
kwargs(_type_) –Keyword arguments to be input to the function.