synapse-sdk 1.0.0b5__py3-none-any.whl → 2025.12.3__py3-none-any.whl
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.
- synapse_sdk/__init__.py +24 -0
- synapse_sdk/cli/code_server.py +305 -33
- synapse_sdk/clients/agent/__init__.py +2 -1
- synapse_sdk/clients/agent/container.py +143 -0
- synapse_sdk/clients/agent/ray.py +296 -38
- synapse_sdk/clients/backend/annotation.py +1 -1
- synapse_sdk/clients/backend/core.py +31 -4
- synapse_sdk/clients/backend/data_collection.py +82 -7
- synapse_sdk/clients/backend/hitl.py +1 -1
- synapse_sdk/clients/backend/ml.py +1 -1
- synapse_sdk/clients/base.py +211 -61
- synapse_sdk/loggers.py +46 -0
- synapse_sdk/plugins/README.md +1340 -0
- synapse_sdk/plugins/categories/base.py +59 -9
- synapse_sdk/plugins/categories/export/actions/__init__.py +3 -0
- synapse_sdk/plugins/categories/export/actions/export/__init__.py +28 -0
- synapse_sdk/plugins/categories/export/actions/export/action.py +165 -0
- synapse_sdk/plugins/categories/export/actions/export/enums.py +113 -0
- synapse_sdk/plugins/categories/export/actions/export/exceptions.py +53 -0
- synapse_sdk/plugins/categories/export/actions/export/models.py +74 -0
- synapse_sdk/plugins/categories/export/actions/export/run.py +195 -0
- synapse_sdk/plugins/categories/export/actions/export/utils.py +187 -0
- synapse_sdk/plugins/categories/export/templates/config.yaml +19 -1
- synapse_sdk/plugins/categories/export/templates/plugin/__init__.py +390 -0
- synapse_sdk/plugins/categories/export/templates/plugin/export.py +153 -177
- synapse_sdk/plugins/categories/neural_net/actions/train.py +1130 -32
- synapse_sdk/plugins/categories/neural_net/actions/tune.py +157 -4
- synapse_sdk/plugins/categories/neural_net/templates/config.yaml +7 -4
- synapse_sdk/plugins/categories/pre_annotation/actions/__init__.py +4 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/pre_annotation/__init__.py +3 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/pre_annotation/action.py +10 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/__init__.py +28 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/action.py +148 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/enums.py +269 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/exceptions.py +14 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/factory.py +76 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/models.py +100 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/orchestrator.py +248 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/run.py +64 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/__init__.py +17 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/annotation.py +265 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/base.py +170 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/extraction.py +83 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/metrics.py +92 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/preprocessor.py +243 -0
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task/strategies/validation.py +143 -0
- synapse_sdk/plugins/categories/upload/actions/upload/__init__.py +19 -0
- synapse_sdk/plugins/categories/upload/actions/upload/action.py +236 -0
- synapse_sdk/plugins/categories/upload/actions/upload/context.py +185 -0
- synapse_sdk/plugins/categories/upload/actions/upload/enums.py +493 -0
- synapse_sdk/plugins/categories/upload/actions/upload/exceptions.py +36 -0
- synapse_sdk/plugins/categories/upload/actions/upload/factory.py +138 -0
- synapse_sdk/plugins/categories/upload/actions/upload/models.py +214 -0
- synapse_sdk/plugins/categories/upload/actions/upload/orchestrator.py +183 -0
- synapse_sdk/plugins/categories/upload/actions/upload/registry.py +113 -0
- synapse_sdk/plugins/categories/upload/actions/upload/run.py +179 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/base.py +107 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/cleanup.py +62 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/collection.py +63 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/generate.py +91 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/initialize.py +82 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/metadata.py +235 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/organize.py +201 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/upload.py +104 -0
- synapse_sdk/plugins/categories/upload/actions/upload/steps/validate.py +71 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/base.py +82 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/data_unit/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/data_unit/batch.py +39 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/data_unit/single.py +29 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/file_discovery/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/file_discovery/flat.py +300 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/file_discovery/recursive.py +287 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/metadata/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/metadata/excel.py +174 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/metadata/none.py +16 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/upload/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/upload/sync.py +84 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/validation/__init__.py +1 -0
- synapse_sdk/plugins/categories/upload/actions/upload/strategies/validation/default.py +60 -0
- synapse_sdk/plugins/categories/upload/actions/upload/utils.py +250 -0
- synapse_sdk/plugins/categories/upload/templates/README.md +470 -0
- synapse_sdk/plugins/categories/upload/templates/config.yaml +28 -2
- synapse_sdk/plugins/categories/upload/templates/plugin/__init__.py +310 -0
- synapse_sdk/plugins/categories/upload/templates/plugin/upload.py +82 -20
- synapse_sdk/plugins/models.py +111 -9
- synapse_sdk/plugins/templates/plugin-config-schema.json +7 -0
- synapse_sdk/plugins/templates/schema.json +7 -0
- synapse_sdk/plugins/utils/__init__.py +3 -0
- synapse_sdk/plugins/utils/ray_gcs.py +66 -0
- synapse_sdk/shared/__init__.py +25 -0
- synapse_sdk/utils/converters/dm/__init__.py +42 -41
- synapse_sdk/utils/converters/dm/base.py +137 -0
- synapse_sdk/utils/converters/dm/from_v1.py +208 -562
- synapse_sdk/utils/converters/dm/to_v1.py +258 -304
- synapse_sdk/utils/converters/dm/tools/__init__.py +214 -0
- synapse_sdk/utils/converters/dm/tools/answer.py +95 -0
- synapse_sdk/utils/converters/dm/tools/bounding_box.py +132 -0
- synapse_sdk/utils/converters/dm/tools/bounding_box_3d.py +121 -0
- synapse_sdk/utils/converters/dm/tools/classification.py +75 -0
- synapse_sdk/utils/converters/dm/tools/keypoint.py +117 -0
- synapse_sdk/utils/converters/dm/tools/named_entity.py +111 -0
- synapse_sdk/utils/converters/dm/tools/polygon.py +122 -0
- synapse_sdk/utils/converters/dm/tools/polyline.py +124 -0
- synapse_sdk/utils/converters/dm/tools/prompt.py +94 -0
- synapse_sdk/utils/converters/dm/tools/relation.py +86 -0
- synapse_sdk/utils/converters/dm/tools/segmentation.py +141 -0
- synapse_sdk/utils/converters/dm/tools/segmentation_3d.py +83 -0
- synapse_sdk/utils/converters/dm/types.py +168 -0
- synapse_sdk/utils/converters/dm/utils.py +162 -0
- synapse_sdk/utils/converters/dm_legacy/__init__.py +56 -0
- synapse_sdk/utils/converters/dm_legacy/from_v1.py +627 -0
- synapse_sdk/utils/converters/dm_legacy/to_v1.py +367 -0
- synapse_sdk/utils/file/__init__.py +58 -0
- synapse_sdk/utils/file/archive.py +32 -0
- synapse_sdk/utils/file/checksum.py +56 -0
- synapse_sdk/utils/file/chunking.py +31 -0
- synapse_sdk/utils/file/download.py +385 -0
- synapse_sdk/utils/file/encoding.py +40 -0
- synapse_sdk/utils/file/io.py +22 -0
- synapse_sdk/utils/file/upload.py +165 -0
- synapse_sdk/utils/file/video/__init__.py +29 -0
- synapse_sdk/utils/file/video/transcode.py +307 -0
- synapse_sdk/utils/{file.py → file.py.backup} +77 -0
- synapse_sdk/utils/network.py +272 -0
- synapse_sdk/utils/storage/__init__.py +6 -2
- synapse_sdk/utils/storage/providers/file_system.py +6 -0
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/METADATA +19 -2
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/RECORD +134 -74
- synapse_sdk/devtools/docs/.gitignore +0 -20
- synapse_sdk/devtools/docs/README.md +0 -41
- synapse_sdk/devtools/docs/blog/2019-05-28-first-blog-post.md +0 -12
- synapse_sdk/devtools/docs/blog/2019-05-29-long-blog-post.md +0 -44
- synapse_sdk/devtools/docs/blog/2021-08-01-mdx-blog-post.mdx +0 -24
- synapse_sdk/devtools/docs/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg +0 -0
- synapse_sdk/devtools/docs/blog/2021-08-26-welcome/index.md +0 -29
- synapse_sdk/devtools/docs/blog/authors.yml +0 -25
- synapse_sdk/devtools/docs/blog/tags.yml +0 -19
- synapse_sdk/devtools/docs/docusaurus.config.ts +0 -138
- synapse_sdk/devtools/docs/package-lock.json +0 -17455
- synapse_sdk/devtools/docs/package.json +0 -47
- synapse_sdk/devtools/docs/sidebars.ts +0 -44
- synapse_sdk/devtools/docs/src/components/HomepageFeatures/index.tsx +0 -71
- synapse_sdk/devtools/docs/src/components/HomepageFeatures/styles.module.css +0 -11
- synapse_sdk/devtools/docs/src/css/custom.css +0 -30
- synapse_sdk/devtools/docs/src/pages/index.module.css +0 -23
- synapse_sdk/devtools/docs/src/pages/index.tsx +0 -21
- synapse_sdk/devtools/docs/src/pages/markdown-page.md +0 -7
- synapse_sdk/devtools/docs/static/.nojekyll +0 -0
- synapse_sdk/devtools/docs/static/img/docusaurus-social-card.jpg +0 -0
- synapse_sdk/devtools/docs/static/img/docusaurus.png +0 -0
- synapse_sdk/devtools/docs/static/img/favicon.ico +0 -0
- synapse_sdk/devtools/docs/static/img/logo.png +0 -0
- synapse_sdk/devtools/docs/static/img/undraw_docusaurus_mountain.svg +0 -171
- synapse_sdk/devtools/docs/static/img/undraw_docusaurus_react.svg +0 -170
- synapse_sdk/devtools/docs/static/img/undraw_docusaurus_tree.svg +0 -40
- synapse_sdk/devtools/docs/tsconfig.json +0 -8
- synapse_sdk/plugins/categories/export/actions/export.py +0 -346
- synapse_sdk/plugins/categories/export/enums.py +0 -7
- synapse_sdk/plugins/categories/neural_net/actions/gradio.py +0 -151
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task.py +0 -943
- synapse_sdk/plugins/categories/upload/actions/upload.py +0 -954
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/WHEEL +0 -0
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/entry_points.txt +0 -0
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/licenses/LICENSE +0 -0
- {synapse_sdk-1.0.0b5.dist-info → synapse_sdk-2025.12.3.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import tempfile
|
|
3
|
+
from numbers import Number
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from typing import Annotated, Optional
|
|
5
6
|
|
|
@@ -23,16 +24,86 @@ class TuneRun(TrainRun):
|
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
class SearchAlgo(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
Configuration for Ray Tune search algorithms.
|
|
29
|
+
|
|
30
|
+
Supported algorithms:
|
|
31
|
+
- 'bayesoptsearch': Bayesian optimization using Gaussian Processes
|
|
32
|
+
- 'hyperoptsearch': Tree-structured Parzen Estimator (TPE)
|
|
33
|
+
- 'basicvariantgenerator': Random search (default)
|
|
34
|
+
|
|
35
|
+
Attributes:
|
|
36
|
+
name (str): Name of the search algorithm (case-insensitive)
|
|
37
|
+
points_to_evaluate (Optional[dict]): Optional initial hyperparameter
|
|
38
|
+
configurations to evaluate before starting optimization
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
{
|
|
42
|
+
"name": "hyperoptsearch",
|
|
43
|
+
"points_to_evaluate": [
|
|
44
|
+
{"learning_rate": 0.001, "batch_size": 32}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
"""
|
|
48
|
+
|
|
26
49
|
name: str
|
|
27
50
|
points_to_evaluate: Optional[dict] = None
|
|
28
51
|
|
|
29
52
|
|
|
30
53
|
class Scheduler(BaseModel):
|
|
54
|
+
"""
|
|
55
|
+
Configuration for Ray Tune schedulers.
|
|
56
|
+
|
|
57
|
+
Supported schedulers:
|
|
58
|
+
- 'fifo': First-In-First-Out scheduler (default, runs all trials)
|
|
59
|
+
- 'hyperband': HyperBand early stopping scheduler
|
|
60
|
+
|
|
61
|
+
Attributes:
|
|
62
|
+
name (str): Name of the scheduler (case-insensitive)
|
|
63
|
+
options (Optional[str]): Optional scheduler-specific configuration parameters
|
|
64
|
+
|
|
65
|
+
Example:
|
|
66
|
+
{
|
|
67
|
+
"name": "hyperband",
|
|
68
|
+
"options": {
|
|
69
|
+
"max_t": 100,
|
|
70
|
+
"reduction_factor": 3
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
"""
|
|
74
|
+
|
|
31
75
|
name: str
|
|
32
76
|
options: Optional[str] = None
|
|
33
77
|
|
|
34
78
|
|
|
35
79
|
class TuneConfig(BaseModel):
|
|
80
|
+
"""
|
|
81
|
+
Configuration for Ray Tune hyperparameter optimization.
|
|
82
|
+
|
|
83
|
+
Attributes:
|
|
84
|
+
mode (Optional[str]): Optimization mode - 'max' or 'min'
|
|
85
|
+
metric (Optional[str]): Name of the metric to optimize
|
|
86
|
+
num_samples (int): Number of hyperparameter configurations to try (default: 1)
|
|
87
|
+
max_concurrent_trials (Optional[int]): Maximum number of trials to run in parallel
|
|
88
|
+
search_alg (Optional[SearchAlgo]): Search algorithm configuration
|
|
89
|
+
scheduler (Optional[Scheduler]): Trial scheduler configuration
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
{
|
|
93
|
+
"mode": "max",
|
|
94
|
+
"metric": "accuracy",
|
|
95
|
+
"num_samples": 20,
|
|
96
|
+
"max_concurrent_trials": 4,
|
|
97
|
+
"search_alg": {
|
|
98
|
+
"name": "hyperoptsearch"
|
|
99
|
+
},
|
|
100
|
+
"scheduler": {
|
|
101
|
+
"name": "hyperband",
|
|
102
|
+
"options": {"max_t": 100}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
"""
|
|
106
|
+
|
|
36
107
|
mode: Optional[str] = None
|
|
37
108
|
metric: Optional[str] = None
|
|
38
109
|
num_samples: int = 1
|
|
@@ -42,10 +113,51 @@ class TuneConfig(BaseModel):
|
|
|
42
113
|
|
|
43
114
|
|
|
44
115
|
class TuneParams(BaseModel):
|
|
116
|
+
"""
|
|
117
|
+
Parameters for TuneAction (DEPRECATED - use TrainAction with is_tune=True instead).
|
|
118
|
+
|
|
119
|
+
Attributes:
|
|
120
|
+
name (str): Name for the tuning job
|
|
121
|
+
description (str): Description of the job
|
|
122
|
+
checkpoint (int | None): Optional checkpoint ID to resume from
|
|
123
|
+
dataset (int): Dataset ID to use for training
|
|
124
|
+
hyperparameter (list): Hyperparameter search space
|
|
125
|
+
tune_config (TuneConfig): Tune configuration
|
|
126
|
+
|
|
127
|
+
Hyperparameter format:
|
|
128
|
+
Each item in hyperparameter list must have:
|
|
129
|
+
- 'name': Parameter name (string)
|
|
130
|
+
- 'type': Distribution type (string)
|
|
131
|
+
- Type-specific parameters:
|
|
132
|
+
- uniform/quniform: 'min', 'max'
|
|
133
|
+
- loguniform/qloguniform: 'min', 'max', 'base'
|
|
134
|
+
- randn/qrandn: 'mean', 'sd'
|
|
135
|
+
- randint/qrandint: 'min', 'max'
|
|
136
|
+
- lograndint/qlograndint: 'min', 'max', 'base'
|
|
137
|
+
- choice/grid_search: 'options'
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
{
|
|
141
|
+
"name": "my_tuning",
|
|
142
|
+
"dataset": 123,
|
|
143
|
+
"hyperparameter": [
|
|
144
|
+
{"name": "batch_size", "type": "choice", "options": [16, 32, 64]},
|
|
145
|
+
{"name": "learning_rate", "type": "loguniform", "min": 0.0001, "max": 0.01, "base": 10},
|
|
146
|
+
{"name": "epochs", "type": "randint", "min": 5, "max": 15}
|
|
147
|
+
],
|
|
148
|
+
"tune_config": {
|
|
149
|
+
"mode": "max",
|
|
150
|
+
"metric": "accuracy",
|
|
151
|
+
"num_samples": 10
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
"""
|
|
155
|
+
|
|
45
156
|
name: Annotated[str, AfterValidator(non_blank)]
|
|
46
157
|
description: str
|
|
47
158
|
checkpoint: int | None
|
|
48
159
|
dataset: int
|
|
160
|
+
hyperparameter: list
|
|
49
161
|
tune_config: TuneConfig
|
|
50
162
|
|
|
51
163
|
@field_validator('name')
|
|
@@ -73,6 +185,23 @@ class TuneParams(BaseModel):
|
|
|
73
185
|
@register_action
|
|
74
186
|
class TuneAction(TrainAction):
|
|
75
187
|
"""
|
|
188
|
+
**DEPRECATED**: This action is deprecated. Please use TrainAction with is_tune=True instead.
|
|
189
|
+
|
|
190
|
+
To migrate from tune to train with tuning:
|
|
191
|
+
- Change action from "tune" to "train"
|
|
192
|
+
- Add "is_tune": true to params
|
|
193
|
+
- Keep tune_config and hyperparameter as they are
|
|
194
|
+
|
|
195
|
+
Example:
|
|
196
|
+
{
|
|
197
|
+
"action": "train",
|
|
198
|
+
"params": {
|
|
199
|
+
"is_tune": true,
|
|
200
|
+
"tune_config": { ... },
|
|
201
|
+
"hyperparameter": [ ... ]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
76
205
|
**Must read** Important notes before using Tune:
|
|
77
206
|
|
|
78
207
|
1. Path to the model output (which is the return value of your train function)
|
|
@@ -176,8 +305,13 @@ class TuneAction(TrainAction):
|
|
|
176
305
|
entrypoint = self.entrypoint
|
|
177
306
|
if not self._tune_override_exists():
|
|
178
307
|
# entrypoint must be train entrypoint
|
|
308
|
+
train_entrypoint = entrypoint
|
|
309
|
+
|
|
179
310
|
def _tune(param_space, run, dataset, checkpoint=None, **kwargs):
|
|
180
|
-
|
|
311
|
+
result = train_entrypoint(run, dataset, param_space, checkpoint, **kwargs)
|
|
312
|
+
if isinstance(result, Number) or isinstance(result, dict):
|
|
313
|
+
return result
|
|
314
|
+
return {'result': result}
|
|
181
315
|
|
|
182
316
|
entrypoint = _tune
|
|
183
317
|
|
|
@@ -256,6 +390,10 @@ class TuneAction(TrainAction):
|
|
|
256
390
|
|
|
257
391
|
Returns:
|
|
258
392
|
object: Ray Tune scheduler instance.
|
|
393
|
+
|
|
394
|
+
Supported schedulers:
|
|
395
|
+
- 'fifo': FIFOScheduler (default)
|
|
396
|
+
- 'hyperband': HyperBandScheduler
|
|
259
397
|
"""
|
|
260
398
|
|
|
261
399
|
from ray.tune.schedulers import (
|
|
@@ -278,7 +416,12 @@ class TuneAction(TrainAction):
|
|
|
278
416
|
}
|
|
279
417
|
|
|
280
418
|
scheduler_type = tune_config['scheduler'].get('name', 'fifo').lower()
|
|
281
|
-
scheduler_class = scheduler_map.get(scheduler_type
|
|
419
|
+
scheduler_class = scheduler_map.get(scheduler_type)
|
|
420
|
+
|
|
421
|
+
if scheduler_class is None:
|
|
422
|
+
raise ValueError(
|
|
423
|
+
f'Unsupported scheduler: {scheduler_type}. Supported schedulers are: {", ".join(scheduler_map.keys())}'
|
|
424
|
+
)
|
|
282
425
|
|
|
283
426
|
# 옵션이 있는 경우 전달하고, 없으면 기본 생성자 호출
|
|
284
427
|
options = tune_config['scheduler'].get('options')
|
|
@@ -291,13 +434,18 @@ class TuneAction(TrainAction):
|
|
|
291
434
|
@staticmethod
|
|
292
435
|
def convert_tune_search_alg(tune_config):
|
|
293
436
|
"""
|
|
294
|
-
Convert YAML hyperparameter configuration to Ray Tune search algorithm
|
|
437
|
+
Convert YAML hyperparameter configuration to Ray Tune search algorithm.
|
|
295
438
|
|
|
296
439
|
Args:
|
|
297
440
|
tune_config (dict): Hyperparameter configuration.
|
|
298
441
|
|
|
299
442
|
Returns:
|
|
300
|
-
|
|
443
|
+
object: Ray Tune search algorithm instance or None
|
|
444
|
+
|
|
445
|
+
Supported search algorithms:
|
|
446
|
+
- 'bayesoptsearch': Bayesian optimization
|
|
447
|
+
- 'hyperoptsearch': Tree-structured Parzen Estimator
|
|
448
|
+
- 'basicvariantgenerator': Random search (default)
|
|
301
449
|
"""
|
|
302
450
|
|
|
303
451
|
if tune_config.get('search_alg') is None:
|
|
@@ -328,6 +476,11 @@ class TuneAction(TrainAction):
|
|
|
328
476
|
from ray.tune.search.basic_variant import BasicVariantGenerator
|
|
329
477
|
|
|
330
478
|
search_alg = BasicVariantGenerator(points_to_evaluate=points_to_evaluate)
|
|
479
|
+
else:
|
|
480
|
+
raise ValueError(
|
|
481
|
+
f'Unsupported search algorithm: {search_alg_name}. '
|
|
482
|
+
f'Supported algorithms are: bayesoptsearch, hyperoptsearch, basicvariantgenerator'
|
|
483
|
+
)
|
|
331
484
|
|
|
332
485
|
return search_alg
|
|
333
486
|
|
|
@@ -14,8 +14,8 @@ actions:
|
|
|
14
14
|
entrypoint: plugin.train.train
|
|
15
15
|
metrics:
|
|
16
16
|
train:
|
|
17
|
-
epoch:
|
|
18
|
-
loss:
|
|
17
|
+
epoch:
|
|
18
|
+
loss: # Use the plugin's internal variable as the key, and the user-facing title in name.
|
|
19
19
|
name: Loss
|
|
20
20
|
validation:
|
|
21
21
|
epoch:
|
|
@@ -25,7 +25,7 @@ actions:
|
|
|
25
25
|
ui_schema: |
|
|
26
26
|
Dumped FormKit Schema for hyperparameters
|
|
27
27
|
visualizations:
|
|
28
|
-
validation_samples_per_epochs:
|
|
28
|
+
validation_samples_per_epochs: # put in log_visualization name
|
|
29
29
|
type: vis_type
|
|
30
30
|
name: user-facing title
|
|
31
31
|
options:
|
|
@@ -39,5 +39,8 @@ actions:
|
|
|
39
39
|
method: restapi
|
|
40
40
|
endpoints:
|
|
41
41
|
- method: get
|
|
42
|
+
required_resources: # Specify required resources for inference deployment
|
|
43
|
+
required_cpu_count: 1
|
|
44
|
+
required_gpu_count: 0.1
|
|
42
45
|
test:
|
|
43
|
-
entrypoint: plugin.test.test
|
|
46
|
+
entrypoint: plugin.test.test
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from synapse_sdk.plugins.categories.base import Action
|
|
2
|
+
from synapse_sdk.plugins.categories.decorators import register_action
|
|
3
|
+
from synapse_sdk.plugins.enums import PluginCategory, RunMethod
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@register_action
|
|
7
|
+
class PreAnnotationAction(Action):
|
|
8
|
+
name = 'pre_annotation'
|
|
9
|
+
category = PluginCategory.PRE_ANNOTATION
|
|
10
|
+
method = RunMethod.TASK
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from .action import ToTaskAction
|
|
2
|
+
from .enums import AnnotateTaskDataStatus, AnnotationMethod, LogCode
|
|
3
|
+
from .exceptions import CriticalError, PreAnnotationToTaskFailed
|
|
4
|
+
|
|
5
|
+
# Advanced imports for extending the system
|
|
6
|
+
from .factory import ToTaskStrategyFactory
|
|
7
|
+
from .models import MetricsRecord, ToTaskParams, ToTaskResult
|
|
8
|
+
from .orchestrator import ToTaskOrchestrator
|
|
9
|
+
from .run import ToTaskRun
|
|
10
|
+
from .strategies.base import ToTaskContext
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
# Core public API (maintains backward compatibility)
|
|
14
|
+
'ToTaskAction',
|
|
15
|
+
'ToTaskRun',
|
|
16
|
+
'ToTaskParams',
|
|
17
|
+
'ToTaskResult',
|
|
18
|
+
'AnnotationMethod',
|
|
19
|
+
'AnnotateTaskDataStatus',
|
|
20
|
+
'LogCode',
|
|
21
|
+
'CriticalError',
|
|
22
|
+
'PreAnnotationToTaskFailed',
|
|
23
|
+
'MetricsRecord',
|
|
24
|
+
# Advanced components for customization and testing
|
|
25
|
+
'ToTaskOrchestrator',
|
|
26
|
+
'ToTaskContext',
|
|
27
|
+
'ToTaskStrategyFactory',
|
|
28
|
+
]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Refactored ToTask action using Strategy and Facade patterns."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
from synapse_sdk.clients.backend import BackendClient
|
|
6
|
+
from synapse_sdk.clients.backend.models import JobStatus
|
|
7
|
+
from synapse_sdk.plugins.categories.base import Action
|
|
8
|
+
from synapse_sdk.plugins.categories.decorators import register_action
|
|
9
|
+
from synapse_sdk.plugins.enums import PluginCategory, RunMethod
|
|
10
|
+
|
|
11
|
+
from .enums import LogCode
|
|
12
|
+
from .exceptions import PreAnnotationToTaskFailed
|
|
13
|
+
from .models import ToTaskParams, ToTaskResult
|
|
14
|
+
from .orchestrator import ToTaskOrchestrator
|
|
15
|
+
from .run import ToTaskRun
|
|
16
|
+
from .strategies.base import ToTaskContext
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@register_action
|
|
20
|
+
class ToTaskAction(Action):
|
|
21
|
+
"""ToTask action for pre-annotation data processing using Strategy and Facade patterns.
|
|
22
|
+
|
|
23
|
+
This action handles the process of annotating data to tasks in a project. It supports
|
|
24
|
+
two annotation methods: file-based annotation and inference-based annotation.
|
|
25
|
+
|
|
26
|
+
The action uses a Strategy pattern to handle different annotation methods and validation
|
|
27
|
+
approaches, coordinated by an Orchestrator (Facade pattern) that manages the complete
|
|
28
|
+
workflow with rollback capabilities.
|
|
29
|
+
|
|
30
|
+
File-based annotation fetches data from file URLs specified in task data units,
|
|
31
|
+
downloads and processes JSON data, and updates task data with the processed information.
|
|
32
|
+
It also validates target specification names against file specifications.
|
|
33
|
+
|
|
34
|
+
Inference-based annotation uses pre-processor plugins for model inference
|
|
35
|
+
for automatic data annotation.
|
|
36
|
+
|
|
37
|
+
Attrs:
|
|
38
|
+
name (str): Action name, set to 'to_task'.
|
|
39
|
+
category (PluginCategory): Plugin category, set to PRE_ANNOTATION.
|
|
40
|
+
method (RunMethod): Execution method, set to JOB.
|
|
41
|
+
run_class (Type[ToTaskRun]): Run class for this action.
|
|
42
|
+
params_model (Type[ToTaskParams]): Parameter validation model.
|
|
43
|
+
progress_categories (Dict): Progress tracking configuration.
|
|
44
|
+
metrics_categories (Set[str]): Metrics categories for this action.
|
|
45
|
+
|
|
46
|
+
Note:
|
|
47
|
+
This action requires a valid project with an associated data collection.
|
|
48
|
+
For file-based annotation, the target_specification_name must exist in the
|
|
49
|
+
project's file specifications.
|
|
50
|
+
|
|
51
|
+
Raises:
|
|
52
|
+
ValueError: If run instance or parameters are not properly initialized.
|
|
53
|
+
PreAnnotationToTaskFailed: If the annotation workflow fails.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
name = 'to_task'
|
|
57
|
+
category = PluginCategory.PRE_ANNOTATION
|
|
58
|
+
method = RunMethod.JOB
|
|
59
|
+
run_class = ToTaskRun
|
|
60
|
+
params_model = ToTaskParams
|
|
61
|
+
progress_categories = {
|
|
62
|
+
'annotate_task_data': {
|
|
63
|
+
'proportion': 100,
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
metrics_categories = {
|
|
67
|
+
'annotate_task_data': {
|
|
68
|
+
'stand_by': 0,
|
|
69
|
+
'failed': 0,
|
|
70
|
+
'success': 0,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def __init__(self, *args, **kwargs):
|
|
75
|
+
"""Initialize the action with orchestrator context."""
|
|
76
|
+
super().__init__(*args, **kwargs)
|
|
77
|
+
self.context = None
|
|
78
|
+
|
|
79
|
+
def start(self) -> Dict:
|
|
80
|
+
"""Start to_task action using orchestrator facade.
|
|
81
|
+
|
|
82
|
+
The action now uses a simplified workflow:
|
|
83
|
+
1. Validate initialization
|
|
84
|
+
2. Create execution context
|
|
85
|
+
3. Execute workflow through orchestrator
|
|
86
|
+
4. Handle results and errors
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
dict: Validated result with status and message.
|
|
90
|
+
"""
|
|
91
|
+
# Validate initialization
|
|
92
|
+
if not self.run or not self.params:
|
|
93
|
+
result = ToTaskResult(
|
|
94
|
+
status=JobStatus.FAILED, message='Run instance or parameters not properly initialized'
|
|
95
|
+
)
|
|
96
|
+
raise PreAnnotationToTaskFailed(result.message)
|
|
97
|
+
|
|
98
|
+
# Type assertions for better IDE support
|
|
99
|
+
assert isinstance(self.run, ToTaskRun)
|
|
100
|
+
assert isinstance(self.run.client, BackendClient)
|
|
101
|
+
|
|
102
|
+
# Log action start
|
|
103
|
+
self.run.log_message_with_code(LogCode.TO_TASK_STARTED)
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
# Create execution context
|
|
107
|
+
self.context = ToTaskContext(
|
|
108
|
+
params=self.params,
|
|
109
|
+
client=self.run.client,
|
|
110
|
+
logger=self.run,
|
|
111
|
+
entrypoint=self.entrypoint,
|
|
112
|
+
config=self.config,
|
|
113
|
+
plugin_config=self.plugin_config,
|
|
114
|
+
job_id=self.job_id,
|
|
115
|
+
progress_categories=self.progress_categories,
|
|
116
|
+
metrics_categories=self.metrics_categories,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Create and execute orchestrator
|
|
120
|
+
orchestrator = ToTaskOrchestrator(self.context)
|
|
121
|
+
result = orchestrator.execute_workflow()
|
|
122
|
+
|
|
123
|
+
# Log successful completion
|
|
124
|
+
self.run.log_message_with_code(LogCode.TO_TASK_COMPLETED)
|
|
125
|
+
return result
|
|
126
|
+
|
|
127
|
+
except PreAnnotationToTaskFailed as e:
|
|
128
|
+
# Re-raise pre-annotation specific errors
|
|
129
|
+
self.run.log_message_with_code(LogCode.TO_TASK_FAILED, str(e))
|
|
130
|
+
raise e
|
|
131
|
+
|
|
132
|
+
except Exception as e:
|
|
133
|
+
# Handle unexpected errors
|
|
134
|
+
error_msg = f'ToTask action failed: {str(e)}'
|
|
135
|
+
self.run.log_message_with_code(LogCode.TO_TASK_FAILED, error_msg)
|
|
136
|
+
result = ToTaskResult(status=JobStatus.FAILED, message=error_msg)
|
|
137
|
+
raise PreAnnotationToTaskFailed(result.message)
|
|
138
|
+
finally:
|
|
139
|
+
# Always emit completion log so backend can record end time even on failures
|
|
140
|
+
self.run.end_log()
|
|
141
|
+
|
|
142
|
+
def get_context(self) -> ToTaskContext:
|
|
143
|
+
"""Get the current execution context for testing/debugging.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
ToTaskContext: The current execution context, or None if not initialized.
|
|
147
|
+
"""
|
|
148
|
+
return self.context
|