aiauto-client 0.1.6__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/PKG-INFO +36 -3
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/README.md +35 -2
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/examples/example_torch_multiple_objective.py +7 -7
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/examples/example_torch_single_objective.py +6 -6
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/examples/simple_example.py +4 -4
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/pyproject.toml +1 -1
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/serializer.py +20 -10
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto_client.egg-info/PKG-INFO +36 -3
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/MANIFEST.in +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/setup.cfg +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/__init__.py +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/_config.py +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/constants.py +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/core.py +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto/http_client.py +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto_client.egg-info/SOURCES.txt +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto_client.egg-info/dependency_links.txt +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto_client.egg-info/requires.txt +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/src/aiauto_client.egg-info/top_level.txt +0 -0
- {aiauto_client-0.1.6 → aiauto_client-0.1.7}/tests/test_local_storage.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: aiauto-client
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.7
|
4
4
|
Summary: AI Auto HPO (Hyperparameter Optimization) Client Library
|
5
5
|
Author-email: AIAuto Team <ainode@zeroone.ai>
|
6
6
|
Project-URL: Homepage, https://dashboard.aiauto.pangyo.ainode.ai
|
@@ -50,8 +50,8 @@ AIAuto는 Kubernetes 기반의 분산 HPO(Hyperparameter Optimization) 시스템
|
|
50
50
|
- `parallelism` (int): 동시 실행 Pod 수 (기본값: 2)
|
51
51
|
- `requirements_file` (str): requirements.txt 파일 경로 (requirements_list와 상호 배타적)
|
52
52
|
- `requirements_list` (List[str]): 패키지 리스트 (requirements_file과 상호 배타적)
|
53
|
-
- `resources_requests` (Dict[str, str]):
|
54
|
-
- `resources_limits` (Dict[str, str]):
|
53
|
+
- `resources_requests` (Dict[str, str]): 리소스 요청 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
54
|
+
- `resources_limits` (Dict[str, str]): 리소스 제한 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
55
55
|
- `runtime_image` (str): 커스텀 런타임 이미지 (None이면 자동 선택)
|
56
56
|
- `use_gpu` (bool): GPU 사용 여부 (기본값: False)
|
57
57
|
|
@@ -95,6 +95,39 @@ study_wrapper.optimize(
|
|
95
95
|
)
|
96
96
|
```
|
97
97
|
|
98
|
+
## Jupyter Notebook 사용 시 주의사항
|
99
|
+
|
100
|
+
Jupyter Notebook이나 Python REPL에서 정의한 함수는 Serialize 할 수 없습니다
|
101
|
+
대신 `%%writefile` magic 울 사용하여 파일로 저장한 후 import 하세요.
|
102
|
+
|
103
|
+
### Jupyter에서 objective 함수 작성 방법
|
104
|
+
- objective 함수를 파일로 저장
|
105
|
+
```python
|
106
|
+
%%writefile my_objective.py
|
107
|
+
import aiauto
|
108
|
+
import optuna
|
109
|
+
|
110
|
+
def objective(trial: optuna.trial.Trial):
|
111
|
+
"""
|
112
|
+
이 함수는 외부 서버에서 실행됩니다.
|
113
|
+
모든 import는 함수 내부에 작성하세요.
|
114
|
+
"""
|
115
|
+
import torch # 함수 내부에서 import
|
116
|
+
|
117
|
+
x = trial.suggest_float('x', -10, 10)
|
118
|
+
y = trial.suggest_float('y', -10, 10)
|
119
|
+
return (x - 2) ** 2 + (y - 3) ** 2
|
120
|
+
```
|
121
|
+
- 저장한 함수를 import해서 사용
|
122
|
+
```python
|
123
|
+
import aiauto
|
124
|
+
from my_objective import objective
|
125
|
+
|
126
|
+
ac = aiauto.AIAutoController('<token>')
|
127
|
+
study = ac.create_study('test', 'minimize')
|
128
|
+
study.optimize(objective, n_trials=10, parallelism=2)
|
129
|
+
```
|
130
|
+
|
98
131
|
## 빠른 시작
|
99
132
|
|
100
133
|
### 1. 간단한 예제 (수학 함수 최적화)
|
@@ -23,8 +23,8 @@ AIAuto는 Kubernetes 기반의 분산 HPO(Hyperparameter Optimization) 시스템
|
|
23
23
|
- `parallelism` (int): 동시 실행 Pod 수 (기본값: 2)
|
24
24
|
- `requirements_file` (str): requirements.txt 파일 경로 (requirements_list와 상호 배타적)
|
25
25
|
- `requirements_list` (List[str]): 패키지 리스트 (requirements_file과 상호 배타적)
|
26
|
-
- `resources_requests` (Dict[str, str]):
|
27
|
-
- `resources_limits` (Dict[str, str]):
|
26
|
+
- `resources_requests` (Dict[str, str]): 리소스 요청 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
27
|
+
- `resources_limits` (Dict[str, str]): 리소스 제한 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
28
28
|
- `runtime_image` (str): 커스텀 런타임 이미지 (None이면 자동 선택)
|
29
29
|
- `use_gpu` (bool): GPU 사용 여부 (기본값: False)
|
30
30
|
|
@@ -68,6 +68,39 @@ study_wrapper.optimize(
|
|
68
68
|
)
|
69
69
|
```
|
70
70
|
|
71
|
+
## Jupyter Notebook 사용 시 주의사항
|
72
|
+
|
73
|
+
Jupyter Notebook이나 Python REPL에서 정의한 함수는 Serialize 할 수 없습니다
|
74
|
+
대신 `%%writefile` magic 울 사용하여 파일로 저장한 후 import 하세요.
|
75
|
+
|
76
|
+
### Jupyter에서 objective 함수 작성 방법
|
77
|
+
- objective 함수를 파일로 저장
|
78
|
+
```python
|
79
|
+
%%writefile my_objective.py
|
80
|
+
import aiauto
|
81
|
+
import optuna
|
82
|
+
|
83
|
+
def objective(trial: optuna.trial.Trial):
|
84
|
+
"""
|
85
|
+
이 함수는 외부 서버에서 실행됩니다.
|
86
|
+
모든 import는 함수 내부에 작성하세요.
|
87
|
+
"""
|
88
|
+
import torch # 함수 내부에서 import
|
89
|
+
|
90
|
+
x = trial.suggest_float('x', -10, 10)
|
91
|
+
y = trial.suggest_float('y', -10, 10)
|
92
|
+
return (x - 2) ** 2 + (y - 3) ** 2
|
93
|
+
```
|
94
|
+
- 저장한 함수를 import해서 사용
|
95
|
+
```python
|
96
|
+
import aiauto
|
97
|
+
from my_objective import objective
|
98
|
+
|
99
|
+
ac = aiauto.AIAutoController('<token>')
|
100
|
+
study = ac.create_study('test', 'minimize')
|
101
|
+
study.optimize(objective, n_trials=10, parallelism=2)
|
102
|
+
```
|
103
|
+
|
71
104
|
## 빠른 시작
|
72
105
|
|
73
106
|
### 1. 간단한 예제 (수학 함수 최적화)
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
주의사항:
|
7
7
|
- torch는 로컬에 설치하지 마세요
|
8
|
-
- objective 함수 내부의 모든 import 와 코드는
|
8
|
+
- objective 함수 내부의 모든 import 와 코드는 외부 서버에서 실행됨
|
9
9
|
- Mac ARM 환경에서도 문제없이 실행 가능
|
10
10
|
|
11
11
|
실행:
|
@@ -32,11 +32,11 @@ def objective_multi(trial: optuna.trial.Trial):
|
|
32
32
|
다중 목적 함수: accuracy 최대화 + FLOPS 최소화
|
33
33
|
hyper parameter tuning을 할 때는 데이터의 일부만 사용하여 빠르게 HPO를 한다
|
34
34
|
|
35
|
-
이 함수는
|
35
|
+
이 함수는 외부 서버의 GPU 인스턴스에서 실행됩니다.
|
36
36
|
모든 import 와 클래스 정의는 objective 함수 내부에 있어야 합니다.
|
37
37
|
이 안에서 import 하는 lib 들은 optimize 를 호출할 때 requirements list 로 넘겨야 합니다
|
38
38
|
"""
|
39
|
-
# ======================
|
39
|
+
# ====================== 외부 서버에서만 실행되는 코드 시작 =========================
|
40
40
|
from os.path import join
|
41
41
|
from typing import List
|
42
42
|
|
@@ -240,14 +240,14 @@ def objective_multi(trial: optuna.trial.Trial):
|
|
240
240
|
|
241
241
|
# objective 함수 리턴
|
242
242
|
return accuracy, flops
|
243
|
-
# ======================
|
243
|
+
# ====================== 외부 서버에서만 실행되는 코드 끝 ===========================
|
244
244
|
|
245
245
|
|
246
246
|
def objective_detailed(trial):
|
247
247
|
"""
|
248
248
|
best trial의 세팅으로 전체 데이터를 학습한다
|
249
249
|
"""
|
250
|
-
# ======================
|
250
|
+
# ====================== 외부 서버에서만 실행되는 코드 시작 =========================
|
251
251
|
from typing import List
|
252
252
|
|
253
253
|
import torch
|
@@ -420,7 +420,7 @@ def objective_detailed(trial):
|
|
420
420
|
flops = FlopCountAnalysis(model, (dummy_input,)).total()
|
421
421
|
|
422
422
|
return accuracy, flops
|
423
|
-
# ======================
|
423
|
+
# ====================== 외부 서버에서만 실행되는 코드 끝 ===========================
|
424
424
|
|
425
425
|
|
426
426
|
if __name__ == '__main__':
|
@@ -439,7 +439,7 @@ if __name__ == '__main__':
|
|
439
439
|
parallelism=4, # n_jobs 대신 parallelism 사용
|
440
440
|
use_gpu=True, # GPU 사용
|
441
441
|
# runtime_image = "pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime", # default image for use_gpu True
|
442
|
-
# requirements.txt 대신 리스트로 전달 (
|
442
|
+
# requirements.txt 대신 리스트로 전달 (외부 서버에서 설치)
|
443
443
|
requirements_list=[
|
444
444
|
'torch',
|
445
445
|
'torchvision',
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
주의사항:
|
7
7
|
- torch는 로컬에 설치하지 마세요
|
8
|
-
- objective 함수 내부의 모든 import 와 코드는
|
8
|
+
- objective 함수 내부의 모든 import 와 코드는 외부 서버에서 실행됨
|
9
9
|
- Mac ARM 환경에서도 문제없이 실행 가능
|
10
10
|
|
11
11
|
실행:
|
@@ -32,11 +32,11 @@ def objective_single(trial: optuna.trial.Trial):
|
|
32
32
|
단일 목적 함수: accuracy 최대화
|
33
33
|
hyper parameter tuning 할 때는 데이터의 일부만 사용하여 빠르게 HPO를 한다
|
34
34
|
|
35
|
-
이 함수는
|
35
|
+
이 함수는 외부 서버의 GPU 인스턴스에서 실행됩니다.
|
36
36
|
모든 import 와 클래스 정의는 objective 함수 내부에 있어야 합니다.
|
37
37
|
이 안에서 import 하는 lib 들은 optimize 를 호출할 때 requirements list 로 넘겨야 합니다
|
38
38
|
"""
|
39
|
-
# ======================
|
39
|
+
# ====================== 외부 서버에서만 실행되는 코드 시작 =========================
|
40
40
|
from os.path import join
|
41
41
|
from typing import List
|
42
42
|
|
@@ -243,14 +243,14 @@ def objective_single(trial: optuna.trial.Trial):
|
|
243
243
|
|
244
244
|
# objective 함수 리턴
|
245
245
|
return accuracy
|
246
|
-
# ======================
|
246
|
+
# ====================== 외부 서버에서만 실행되는 코드 끝 ===========================
|
247
247
|
|
248
248
|
|
249
249
|
def objective_detailed(trial):
|
250
250
|
"""
|
251
251
|
best trial의 세팅으로 전체 데이터를 학습한다
|
252
252
|
"""
|
253
|
-
# ======================
|
253
|
+
# ====================== 외부 서버에서만 실행되는 코드 시작 =========================
|
254
254
|
from typing import List
|
255
255
|
|
256
256
|
import torch
|
@@ -424,7 +424,7 @@ def objective_detailed(trial):
|
|
424
424
|
tc.log(f'accuracy for test: {accuracy:.4f}')
|
425
425
|
|
426
426
|
return accuracy
|
427
|
-
# ======================
|
427
|
+
# ====================== 외부 서버에서만 실행되는 코드 끝 ===========================
|
428
428
|
|
429
429
|
|
430
430
|
if __name__ == '__main__':
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# ac = aiauto.AIAutoController('<token>')
|
5
5
|
|
6
6
|
주의사항:
|
7
|
-
- objective 함수 내부의 모든 import 와 코드는
|
7
|
+
- objective 함수 내부의 모든 import 와 코드는 외부 서버에서 실행됨
|
8
8
|
- Mac ARM 환경에서도 문제없이 실행 가능
|
9
9
|
|
10
10
|
실행:
|
@@ -31,11 +31,11 @@ def simple_objective(trial: optuna.trial.Trial):
|
|
31
31
|
간단한 2차 함수 최적화
|
32
32
|
(x - 2)^2 + (y - 3)^2 를 최소화
|
33
33
|
|
34
|
-
이 함수는
|
34
|
+
이 함수는 외부서버에서 실행됩니다.
|
35
35
|
모든 import 와 클래스 정의는 objective 함수 내부에 있어야 합니다.
|
36
36
|
이 안에서 import 하는 lib 들은 optimize 를 호출할 때 requirements list 로 넘겨야 합니다
|
37
37
|
"""
|
38
|
-
# ======================
|
38
|
+
# ====================== 외부 서버에서만 실행되는 코드 시작 =========================
|
39
39
|
# objective 함수의 매개변수로 받아온 optuna 자체의 trial 을 aiauto 에서 사용하는 TrialController 로 Warpping Log 찍는 용도
|
40
40
|
# log 는 optuna dashboard 에서 확인 가능
|
41
41
|
# 하나의 trial objective 함수 안에서만 사용하는 trial 객체
|
@@ -52,7 +52,7 @@ def simple_objective(trial: optuna.trial.Trial):
|
|
52
52
|
tc.log(f'Objective value: {value:.4f}')
|
53
53
|
|
54
54
|
return value
|
55
|
-
# ======================
|
55
|
+
# ====================== 외부 서버에서만 실행되는 코드 끝 ===========================
|
56
56
|
|
57
57
|
|
58
58
|
if __name__ == '__main__':
|
@@ -6,14 +6,24 @@ from typing import Callable, Union, List, Optional
|
|
6
6
|
def serialize(objective: Callable) -> str:
|
7
7
|
try:
|
8
8
|
return inspect.getsource(objective)
|
9
|
-
except
|
10
|
-
raise ValueError(
|
9
|
+
except (OSError, TypeError) as e:
|
10
|
+
raise ValueError(
|
11
|
+
"Serialize 실패 objective 함수는 파일로 저장되어야 합니다\n"
|
12
|
+
"REPL/Jupyter Notebook에서는 %%writefile magic을 사용해서 local 에 file 로 저장하세요\n\n"
|
13
|
+
"%%writefile objective.py\n"
|
14
|
+
"def objective(trial):\n"
|
15
|
+
" # 함수 내용\n"
|
16
|
+
" ...\n\n"
|
17
|
+
"그 다음:\n"
|
18
|
+
"from objective import objective\n"
|
19
|
+
"study.optimize(objective, ...)"
|
20
|
+
) from e
|
11
21
|
|
12
22
|
|
13
23
|
def build_requirements(file_path: Optional[str] = None, reqs: Optional[List[str]] = None) -> str:
|
14
24
|
if file_path and reqs:
|
15
25
|
raise ValueError("requirements_file과 requirements_list는 동시에 지정할 수 없습니다")
|
16
|
-
|
26
|
+
|
17
27
|
if file_path:
|
18
28
|
with open(file_path, 'r') as f:
|
19
29
|
return f.read()
|
@@ -26,20 +36,20 @@ def build_requirements(file_path: Optional[str] = None, reqs: Optional[List[str]
|
|
26
36
|
def object_to_json(obj: Union[object, dict, None]) -> str:
|
27
37
|
if obj is None:
|
28
38
|
return ""
|
29
|
-
|
39
|
+
|
30
40
|
if isinstance(obj, dict):
|
31
41
|
return json.dumps(obj)
|
32
|
-
|
42
|
+
|
33
43
|
cls = type(obj)
|
34
44
|
module_name = cls.__module__
|
35
45
|
class_name = cls.__name__
|
36
|
-
|
46
|
+
|
37
47
|
if not module_name.startswith('optuna.'):
|
38
48
|
raise ValueError(f"optuna 코어 클래스만 지원합니다: {class_name}")
|
39
|
-
|
49
|
+
|
40
50
|
sig = inspect.signature(cls)
|
41
51
|
kwargs = {}
|
42
|
-
|
52
|
+
|
43
53
|
for param_name, param in sig.parameters.items():
|
44
54
|
if param_name == 'self':
|
45
55
|
continue
|
@@ -47,9 +57,9 @@ def object_to_json(obj: Union[object, dict, None]) -> str:
|
|
47
57
|
value = getattr(obj, param_name)
|
48
58
|
if param.default != value:
|
49
59
|
kwargs[param_name] = value
|
50
|
-
|
60
|
+
|
51
61
|
return json.dumps({
|
52
62
|
"module": module_name,
|
53
63
|
"class": class_name,
|
54
64
|
"kwargs": kwargs
|
55
|
-
})
|
65
|
+
})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: aiauto-client
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.7
|
4
4
|
Summary: AI Auto HPO (Hyperparameter Optimization) Client Library
|
5
5
|
Author-email: AIAuto Team <ainode@zeroone.ai>
|
6
6
|
Project-URL: Homepage, https://dashboard.aiauto.pangyo.ainode.ai
|
@@ -50,8 +50,8 @@ AIAuto는 Kubernetes 기반의 분산 HPO(Hyperparameter Optimization) 시스템
|
|
50
50
|
- `parallelism` (int): 동시 실행 Pod 수 (기본값: 2)
|
51
51
|
- `requirements_file` (str): requirements.txt 파일 경로 (requirements_list와 상호 배타적)
|
52
52
|
- `requirements_list` (List[str]): 패키지 리스트 (requirements_file과 상호 배타적)
|
53
|
-
- `resources_requests` (Dict[str, str]):
|
54
|
-
- `resources_limits` (Dict[str, str]):
|
53
|
+
- `resources_requests` (Dict[str, str]): 리소스 요청 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
54
|
+
- `resources_limits` (Dict[str, str]): 리소스 제한 (기본값: {"cpu": "256m", "memory": "256Mi"})
|
55
55
|
- `runtime_image` (str): 커스텀 런타임 이미지 (None이면 자동 선택)
|
56
56
|
- `use_gpu` (bool): GPU 사용 여부 (기본값: False)
|
57
57
|
|
@@ -95,6 +95,39 @@ study_wrapper.optimize(
|
|
95
95
|
)
|
96
96
|
```
|
97
97
|
|
98
|
+
## Jupyter Notebook 사용 시 주의사항
|
99
|
+
|
100
|
+
Jupyter Notebook이나 Python REPL에서 정의한 함수는 Serialize 할 수 없습니다
|
101
|
+
대신 `%%writefile` magic 울 사용하여 파일로 저장한 후 import 하세요.
|
102
|
+
|
103
|
+
### Jupyter에서 objective 함수 작성 방법
|
104
|
+
- objective 함수를 파일로 저장
|
105
|
+
```python
|
106
|
+
%%writefile my_objective.py
|
107
|
+
import aiauto
|
108
|
+
import optuna
|
109
|
+
|
110
|
+
def objective(trial: optuna.trial.Trial):
|
111
|
+
"""
|
112
|
+
이 함수는 외부 서버에서 실행됩니다.
|
113
|
+
모든 import는 함수 내부에 작성하세요.
|
114
|
+
"""
|
115
|
+
import torch # 함수 내부에서 import
|
116
|
+
|
117
|
+
x = trial.suggest_float('x', -10, 10)
|
118
|
+
y = trial.suggest_float('y', -10, 10)
|
119
|
+
return (x - 2) ** 2 + (y - 3) ** 2
|
120
|
+
```
|
121
|
+
- 저장한 함수를 import해서 사용
|
122
|
+
```python
|
123
|
+
import aiauto
|
124
|
+
from my_objective import objective
|
125
|
+
|
126
|
+
ac = aiauto.AIAutoController('<token>')
|
127
|
+
study = ac.create_study('test', 'minimize')
|
128
|
+
study.optimize(objective, n_trials=10, parallelism=2)
|
129
|
+
```
|
130
|
+
|
98
131
|
## 빠른 시작
|
99
132
|
|
100
133
|
### 1. 간단한 예제 (수학 함수 최적화)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|