experiment
Module diagram
classDiagram
class experiment {
}
class importlib {
}
class multiprocessing {
}
class sweep {
}
experiment
importlib
get_module_from_path
입력으로 받은 파이썬 파일을 모듈화하여 반환합니다.
Parameters:
-
file_path(str) –path to python file
Returns:
-
ModuleType(ModuleType) –loaded module
Source code in ResearchToolkit/experiment/importlib.py
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.
Source code in ResearchToolkit/experiment/multiprocessing.py
sweep
SweepList
SweepList(sweep_list: List[Any], tag: Optional[str] = None, descriptions: Optional[List[Any]] = None, rank: Union[int, float] = float('inf'))
sweep 하고 싶은 config를 나타낼 때 사용하는 class 입니다.
Parameters:
-
sweep_list(List) –sweep할 element들이 들어있는 List입니다.
-
tag(str, default:None) –SweepList를 group으로 묶고 싶을 때 사용하는 tag 입니다. tag가 같은 SweepList는 Group으로 묶여서 동시에 sweep 됩니다. Defaults to None.
-
descriptions(List[Any], default:None) –sweep할 element들을 설명해주는 description이 들어있는 List입니다. sweep_list와 길이가 일치해야 합니다. Defaults to None.
-
rank(Union[int, float], default:float('inf')) –생성된 config의 반복 되는 순서를 정해주는 값입니다. rank가 낮은 SweepList가 먼저 반복되어 생성됩니다. Defaults to float("inf").
Source code in ResearchToolkit/experiment/sweep.py
_NoDescription
Description이 없는지를 나타내기 위한 class
_SweepList
_SweepList(sweeplist: SweepList, key_list: List)
Bases: SweepList
sweep 함수의 쉬운 구현을 위해 SweepList에 약간의 구현이 추가된 class
Source code in ResearchToolkit/experiment/sweep.py
__iter__
_SweepGroup
_SweepGroup(sweeplist_list: Optional[List[_SweepList]] = None)
tag가 같은 _SweepList를 Group으로 묶어서 관리하는 class
Source code in ResearchToolkit/experiment/sweep.py
append
append(sweeplist: _SweepList) -> None
__iter__
_SweepListManager
_SweepListManager(sweeplist_list: List[_SweepList])
_SweepList를 관리하고 데카르트 곱(cartesian product)을 iterator로 만들어주는 class
Source code in ResearchToolkit/experiment/sweep.py
__iter__
Source code in ResearchToolkit/experiment/sweep.py
_find_sweeplist
_find_sweeplist(config: Dict, key_list: List) -> List[_SweepList]
Find the SweepList by recursively traversing the config dictionary. For subsequent operations, SweepList is changed to _SweepList.
Parameters:
-
config(Dict) –The config dictionary in which to find the SweepList.
-
key_list(List) –List containing the keys of the dictionary sequentially.
Returns:
-
List[_SweepList]–List[_SweepList]: List of _SweepList
Source code in ResearchToolkit/experiment/sweep.py
_set_value
Set the value in the config dict using the keys in key_list.
Parameters:
-
config(Dict) –The dictionary in which you want to set the value.
-
key_list(List) –List containing the keys of the dictionary sequentially.
-
value(Any) –The value you want to set.
Example
config = { "A": { "B": { "C" = 3 } } }
_set_value(config=config, key_list=["A", "B", "C"], value=5)
results: { "A": { "B": { "C" = 5 } } }
Source code in ResearchToolkit/experiment/sweep.py
sweep
config 내부에 있는 SweepList를 찾아 데카르트 곱(cartesian product)을 만들어줍니다.
Parameters:
-
config(Dict) –sweep을 진행하고자 하는 config dictionary.
Returns:
-
List[Dict]–List[Dict]: 만들어진 (description, config)들이 들어있는 List.
-
Dict(List[Dict]) –{ "description": Dict, 해당 config에 대해 설정한 description. config와 같은 구조를 가집니다. "config": Dict, 만들어진 config
-
List[Dict]–}
Example
config = { "A": 3, "B": SweepList([1, 2], description=["1", "2"]), "C": SweepList([3, 4]), }
configs = sweep(config)
results: configs => [ { "description": {"B": "1",}, "config": {"A": 3, "B": 1, "C": 3}, }, { "description": {"B": "1"}, "config": {"A": 3, "B": 1, "C": 4}, } { "description": {"B": "2"}, "config": {"A": 3, "B": 2, "C": 3}, } { "description": {"B": "2"}, "config": {"A": 3, "B": 2, "C": 4}, } ]
Source code in ResearchToolkit/experiment/sweep.py
sweep_native
SweepList 없이 native list 를 이용해 sweep을 수행합니다.
Example
config = { "A": [3], "B": [1, 2], "C": [3, 4], }
configs = sweep_native(config)
results: configs => [ {"A": 3, "B": 1, "C": 3}, {"A": 3, "B": 1, "C": 4}, {"A": 3, "B": 2, "C": 3}, {"A": 3, "B": 2, "C": 4}, ]