synapse-sdk 1.0.0a2__tar.gz → 1.0.0a3__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.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

Files changed (71) hide show
  1. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/PKG-INFO +1 -1
  2. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/agent/__init__.py +2 -2
  3. synapse_sdk-1.0.0a3/synapse_sdk/clients/agent/service.py +54 -0
  4. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/backend/__init__.py +1 -0
  5. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/backend/integration.py +15 -4
  6. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/exceptions.py +0 -8
  7. synapse_sdk-1.0.0a3/synapse_sdk/loggers.py +52 -0
  8. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/base.py +29 -11
  9. synapse_sdk-1.0.0a3/synapse_sdk/plugins/categories/neural_net/actions/train.py +37 -0
  10. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/cli/run.py +8 -7
  11. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk.egg-info/PKG-INFO +1 -1
  12. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk.egg-info/SOURCES.txt +0 -1
  13. synapse_sdk-1.0.0a2/synapse_sdk/clients/agent/core.py +0 -11
  14. synapse_sdk-1.0.0a2/synapse_sdk/clients/agent/service.py +0 -15
  15. synapse_sdk-1.0.0a2/synapse_sdk/loggers.py +0 -48
  16. synapse_sdk-1.0.0a2/synapse_sdk/plugins/categories/neural_net/actions/train.py +0 -96
  17. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/.github/workflows/lint.yml +0 -0
  18. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/.github/workflows/pypi-publish.yml +0 -0
  19. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/.gitignore +0 -0
  20. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/.pre-commit-config.yaml +0 -0
  21. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/LICENSE +0 -0
  22. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/README.md +0 -0
  23. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/pyproject.toml +0 -0
  24. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/requirements.txt +0 -0
  25. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/setup.cfg +0 -0
  26. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/__init__.py +0 -0
  27. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/__init__.py +0 -0
  28. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/backend/annotation.py +0 -0
  29. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/backend/dataset.py +0 -0
  30. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/backend/ml.py +0 -0
  31. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/base.py +0 -0
  32. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/clients/utils.py +0 -0
  33. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/__init__.py +0 -0
  34. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/__init__.py +0 -0
  35. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/data_validation/__init__.py +0 -0
  36. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/data_validation/actions/__init__.py +0 -0
  37. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/data_validation/actions/validation.py +0 -0
  38. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/decorators.py +0 -0
  39. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/export/__init__.py +0 -0
  40. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/export/actions/__init__.py +0 -0
  41. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/export/actions/export.py +0 -0
  42. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/import/__init__.py +0 -0
  43. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/import/actions/__init__.py +0 -0
  44. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/import/actions/import.py +0 -0
  45. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/neural_net/__init__.py +0 -0
  46. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/neural_net/actions/__init__.py +0 -0
  47. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/neural_net/actions/deployment.py +0 -0
  48. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/neural_net/actions/inference.py +0 -0
  49. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/neural_net/actions/test.py +0 -0
  50. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/post_annotation/__init__.py +0 -0
  51. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/post_annotation/actions/__init__.py +0 -0
  52. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/post_annotation/actions/post_annotation.py +0 -0
  53. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/pre_annotation/__init__.py +0 -0
  54. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/pre_annotation/actions/__init__.py +0 -0
  55. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/pre_annotation/actions/pre_annotation.py +0 -0
  56. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/categories/registry.py +0 -0
  57. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/cli/__init__.py +0 -0
  58. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/cli/publish.py +0 -0
  59. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/enums.py +0 -0
  60. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/job.py +0 -0
  61. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/upload.py +0 -0
  62. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/plugins/utils.py +0 -0
  63. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/__init__.py +0 -0
  64. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/debug.py +0 -0
  65. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/file.py +0 -0
  66. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/module_loading.py +0 -0
  67. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/storage.py +0 -0
  68. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk/utils/string.py +0 -0
  69. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk.egg-info/dependency_links.txt +0 -0
  70. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk.egg-info/requires.txt +0 -0
  71. {synapse_sdk-1.0.0a2 → synapse_sdk-1.0.0a3}/synapse_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a2
3
+ Version: 1.0.0a3
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -1,8 +1,8 @@
1
- from synapse_sdk.clients.agent.core import CoreClientMixin
2
1
  from synapse_sdk.clients.agent.service import ServiceClientMixin
3
2
 
4
3
 
5
- class AgentClient(CoreClientMixin, ServiceClientMixin):
4
+ class AgentClient(ServiceClientMixin):
5
+ name = 'Agent'
6
6
  agent_token = None
7
7
  user_token = None
8
8
  tenant = None
@@ -0,0 +1,54 @@
1
+ from synapse_sdk.clients.base import BaseClient
2
+
3
+
4
+ class ServiceClientMixin(BaseClient):
5
+ def run_plugin_release(self, code, data):
6
+ path = f'plugin_releases/{code}/run/'
7
+ return self._post(path, data=data)
8
+
9
+ def run_debug_plugin_release(self, data):
10
+ path = 'plugin_releases/run_debug/'
11
+ return self._post(path, data=data)
12
+
13
+ def create_plugin_release(self, data):
14
+ path = 'plugin_releases/'
15
+ return self._post(path, data=data)
16
+
17
+ def get_job(self, pk):
18
+ path = f'jobs/{pk}/'
19
+ return self._get(path)
20
+
21
+ def list_jobs(self):
22
+ path = 'jobs/'
23
+ return self._get(path)
24
+
25
+ def list_job_logs(self, pk):
26
+ path = f'jobs/{pk}/logs/'
27
+ return self._get(path)
28
+
29
+ def tail_job_logs(self, pk):
30
+ path = f'jobs/{pk}/tail_logs/'
31
+
32
+ url = self._get_url(path)
33
+ headers = self._get_headers()
34
+
35
+ response = self.requests_session.get(url, headers=headers, stream=True)
36
+ for line in response.iter_lines():
37
+ if line:
38
+ yield line.decode('utf-8')
39
+
40
+ def get_node(self, pk):
41
+ path = f'nodes/{pk}/'
42
+ return self._get(path)
43
+
44
+ def list_nodes(self):
45
+ path = 'nodes/'
46
+ return self._get(path)
47
+
48
+ def get_task(self, pk):
49
+ path = f'tasks/{pk}/'
50
+ return self._get(path)
51
+
52
+ def list_tasks(self):
53
+ path = 'tasks/'
54
+ return self._get(path)
@@ -5,6 +5,7 @@ from synapse_sdk.clients.backend.ml import MLClientMixin
5
5
 
6
6
 
7
7
  class BackendClient(AnnotationClientMixin, DatasetClientMixin, IntegrationClientMixin, MLClientMixin):
8
+ name = 'Backend'
8
9
  token = None
9
10
  tenant = None
10
11
 
@@ -27,10 +27,21 @@ class IntegrationClientMixin(BaseClient):
27
27
  files = {'file': data.pop('file')}
28
28
  return self._post(path, data=data, files=files)
29
29
 
30
+ def list_job_console_logs(self, pk):
31
+ path = f'jobs/{pk}/console_logs/'
32
+ return self._get(path)
33
+
34
+ def tail_job_console_logs(self, pk):
35
+ path = f'jobs/{pk}/tail_console_logs/'
36
+
37
+ url = self._get_url(path)
38
+ headers = self._get_headers()
39
+
40
+ response = self.requests_session.get(url, headers=headers, stream=True)
41
+ for line in response.iter_lines():
42
+ if line:
43
+ yield line.decode('utf-8')
44
+
30
45
  def create_logs(self, data):
31
46
  path = 'logs/'
32
47
  return self._post(path, data=data)
33
-
34
- def create_task(self, data):
35
- path = 'agent_tasks/'
36
- return self._post(path, data=data)
@@ -6,11 +6,3 @@ class ClientError(Exception):
6
6
  self.status = status
7
7
  self.reason = reason
8
8
  super().__init__(status, reason, *args)
9
-
10
- def as_validation_error(self):
11
- if self.status == 400:
12
- error = self.reason
13
- else:
14
- error = str(self)
15
-
16
- return {'backend_errors': error}
@@ -0,0 +1,52 @@
1
+ import datetime
2
+
3
+ from synapse_sdk.clients.exceptions import ClientError
4
+
5
+
6
+ class BaseLogger:
7
+ progress_records = {}
8
+
9
+ def set_progress(self, current, total, category=''):
10
+ percent = 0
11
+ if total > 0:
12
+ percent = (current / total) * 100
13
+ percent = float(round(percent, 2))
14
+
15
+ self.progress_records[category] = {'current': current, 'total': total, 'percent': percent}
16
+
17
+
18
+ class ConsoleLogger(BaseLogger):
19
+ def set_progress(self, current, total, category=''):
20
+ super().set_progress(current, total, category=category)
21
+ print(self.progress_records)
22
+
23
+ def log(self, action, data):
24
+ print(action, data)
25
+
26
+
27
+ class BackendLogger(BaseLogger):
28
+ logs_queue = []
29
+ client = None
30
+ job_id = None
31
+
32
+ def __init__(self, client, job_id):
33
+ self.client = client
34
+ self.job_id = job_id
35
+
36
+ def set_progress(self, current, total, category=''):
37
+ super().set_progress(current, total, category=category)
38
+ # TODO set_progress to the job
39
+
40
+ def log(self, action, data):
41
+ log = {
42
+ 'action': action,
43
+ 'data': data,
44
+ 'datetime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'),
45
+ 'job': self.job_id,
46
+ }
47
+ self.logs_queue.append(log)
48
+ try:
49
+ self.client.create_logs(self.logs_queue)
50
+ self.logs_queue.clear()
51
+ except ClientError as e:
52
+ print(e)
@@ -8,7 +8,8 @@ import ray
8
8
  import requests
9
9
  from ray.dashboard.modules.job.sdk import JobSubmissionClient
10
10
 
11
- from synapse_sdk.loggers import ConsoleLogger
11
+ from synapse_sdk.clients.backend import BackendClient
12
+ from synapse_sdk.loggers import ConsoleLogger, BackendLogger
12
13
  from synapse_sdk.plugins.enums import RunMethod
13
14
  from synapse_sdk.plugins.upload import build_and_upload, archive_and_upload, download_and_upload
14
15
  from synapse_sdk.plugins.utils import get_plugin_checksum
@@ -33,6 +34,9 @@ class Action:
33
34
  'SYNAPSE_PLUGIN_STORAGE',
34
35
  'SYNAPSE_DEBUG_PLUGIN_PATH',
35
36
  'SYNAPSE_DEBUG_MODULES',
37
+ 'SYNAPSE_PLUGIN_RUN_HOST',
38
+ 'SYNAPSE_PLUGIN_RUN_USER_TOKEN',
39
+ 'SYNAPSE_PLUGIN_RUN_TENANT',
36
40
  ]
37
41
 
38
42
  def __init__(self, params, plugin_config, envs=None, job_id=None, direct=False, debug=False):
@@ -42,13 +46,8 @@ class Action:
42
46
  self.job_id = job_id
43
47
  self.direct = direct
44
48
  self.debug = debug
45
- if envs:
46
- self.envs = {**envs, **self.get_default_envs()}
47
- else:
48
- self.envs = self.get_default_envs()
49
-
50
- # TODO logger 지정 방식 개선
51
- self.logger = ConsoleLogger()
49
+ self.envs = {**envs, **self.get_default_envs()} if envs else self.get_default_envs()
50
+ self.set_logger()
52
51
 
53
52
  @cached_property
54
53
  def plugin_id(self):
@@ -95,6 +94,17 @@ class Action:
95
94
  self.envs['SYNAPSE_DEBUG_MODULES'] = ','.join(debug_modules)
96
95
  return debug_modules
97
96
 
97
+ def set_logger(self):
98
+ if self.job_id:
99
+ client = BackendClient(
100
+ self.envs['SYNAPSE_PLUGIN_RUN_HOST'],
101
+ self.envs['SYNAPSE_PLUGIN_RUN_USER_TOKEN'],
102
+ self.envs['SYNAPSE_PLUGIN_RUN_TENANT'],
103
+ )
104
+ self.logger = BackendLogger(client, self.job_id)
105
+ else:
106
+ self.logger = ConsoleLogger()
107
+
98
108
  def get_default_envs(self):
99
109
  return {env: os.environ[env] for env in self.default_envs if env in os.environ}
100
110
 
@@ -150,14 +160,22 @@ class Action:
150
160
  return ray.get(run_task.remote(self.category.value, self.name, *args, **kwargs))
151
161
 
152
162
  def run_by_job(self):
153
- entrypoint_args = ['run', self.name, f'"{json.dumps(self.params)}"', '--direct']
163
+ main_options = []
164
+ options = ['run', '--direct']
165
+ arguments = [self.name, f'{json.dumps(json.dumps(self.params))}']
166
+
154
167
  if self.debug:
155
- entrypoint_args.insert(0, '--debug')
168
+ main_options.append('--debug')
169
+
170
+ if self.job_id:
171
+ options.append(f'--job-id={self.job_id}')
172
+
173
+ cmd = ' '.join(main_options + options + arguments)
156
174
 
157
175
  client = JobSubmissionClient(address=self.envs.get('RAY_DASHBOARD_URL'))
158
176
  return client.submit_job(
159
177
  submission_id=self.job_id,
160
- entrypoint=f'python main.py {" ".join(entrypoint_args)}',
178
+ entrypoint=f'python main.py {cmd}',
161
179
  runtime_env=self.get_runtime_env(),
162
180
  )
163
181
 
@@ -0,0 +1,37 @@
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 RunMethod, PluginCategory
4
+
5
+
6
+ @register_action
7
+ class TrainAction(Action):
8
+ name = 'train'
9
+ category = PluginCategory.NEURAL_NET
10
+ method = RunMethod.JOB
11
+
12
+ def get_dataset(self):
13
+ return {}
14
+
15
+ def run(self):
16
+ hyperparameter = self.params['hyperparameter']
17
+
18
+ # download dataset
19
+ self.log_event('Preparing dataset for training.')
20
+ input_dataset = self.get_dataset()
21
+
22
+ # train dataset
23
+ self.log_event('Starting model training.')
24
+
25
+ model_files = self.entrypoint(self, input_dataset, hyperparameter)
26
+
27
+ # upload model_data
28
+ self.log_event('Registering model data.')
29
+
30
+ self.end_log()
31
+ return model_files
32
+
33
+ def log_metric(self, x, i, **kwargs):
34
+ self.log(x, {x: i, **kwargs})
35
+
36
+ def log_model(self, files, status=None):
37
+ pass
@@ -10,6 +10,7 @@ from synapse_sdk.plugins.utils import get_action, read_config
10
10
  @click.command()
11
11
  @click.argument('action')
12
12
  @click.argument('params')
13
+ @click.option('--job-id')
13
14
  @click.option('--direct/--no-direct', default=False)
14
15
  @click.option('--run-by', type=click.Choice(['script', 'agent', 'backend']), default='script')
15
16
  @click.option('--agent-host')
@@ -19,28 +20,28 @@ from synapse_sdk.plugins.utils import get_action, read_config
19
20
  @click.option('--user-token')
20
21
  @click.option('--tenant')
21
22
  @click.pass_context
22
- def run(ctx, action, params, direct, run_by, agent_host, agent_token, host, agent, user_token, tenant):
23
+ def run(ctx, action, params, job_id, direct, run_by, agent_host, agent_token, host, agent, user_token, tenant):
23
24
  debug = ctx.obj['DEBUG']
24
25
 
25
26
  if run_by == 'script':
26
- run_by_script(action, params, direct, debug)
27
+ run_by_script(action, params, job_id, direct, debug)
27
28
  elif run_by == 'agent':
28
- run_by_agent(action, params, agent_host, agent_token, user_token, tenant, debug)
29
+ run_by_agent(action, params, job_id, agent_host, agent_token, user_token, tenant, debug)
29
30
  elif run_by == 'backend':
30
31
  run_by_backend(action, params, agent, host, user_token, tenant)
31
32
 
32
33
 
33
- def run_by_script(action, params, direct, debug):
34
- action = get_action(action, params, direct=direct, debug=debug)
34
+ def run_by_script(action, params, job_id, direct, debug):
35
+ action = get_action(action, params, job_id=job_id, direct=direct, debug=debug)
35
36
  result = action.run_action()
36
37
 
37
38
  if debug:
38
39
  click.echo(result)
39
40
 
40
41
 
41
- def run_by_agent(action, params, agent_host, agent_token, user_token, tenant, debug):
42
+ def run_by_agent(action, params, job_id, agent_host, agent_token, user_token, tenant, debug):
42
43
  client = AgentClient(agent_host, agent_token, user_token, tenant)
43
- data = {'action': action, 'params': params}
44
+ data = {'action': action, 'params': params, 'job_id': job_id}
44
45
  if debug:
45
46
  data.update({
46
47
  'plugin_path': os.getcwd(),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a2
3
+ Version: 1.0.0a3
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -18,7 +18,6 @@ synapse_sdk/clients/base.py
18
18
  synapse_sdk/clients/exceptions.py
19
19
  synapse_sdk/clients/utils.py
20
20
  synapse_sdk/clients/agent/__init__.py
21
- synapse_sdk/clients/agent/core.py
22
21
  synapse_sdk/clients/agent/service.py
23
22
  synapse_sdk/clients/backend/__init__.py
24
23
  synapse_sdk/clients/backend/annotation.py
@@ -1,11 +0,0 @@
1
- from synapse_sdk.clients.base import BaseClient
2
-
3
-
4
- class CoreClientMixin(BaseClient):
5
- def get_agent_system(self):
6
- path = 'agents/system/'
7
- return self._get(path)
8
-
9
- def get_jobs_progress(self, data):
10
- path = 'integration/jobs/progress/'
11
- return self._post(path, data=data, timeout=1)
@@ -1,15 +0,0 @@
1
- from synapse_sdk.clients.base import BaseClient
2
-
3
-
4
- class ServiceClientMixin(BaseClient):
5
- def run_plugin_release(self, code, data):
6
- path = f'plugin_releases/{code}/run/'
7
- return self._post(path, data=data)
8
-
9
- def run_debug_plugin_release(self, data):
10
- path = 'plugin_releases/run_debug/'
11
- return self._post(path, data=data)
12
-
13
- def create_plugin_release(self, data):
14
- path = 'plugin_releases/'
15
- return self._post(path, data=data)
@@ -1,48 +0,0 @@
1
- import datetime
2
-
3
- from synapse_sdk.clients.exceptions import ClientError
4
-
5
-
6
- class BaseLogger:
7
- progress_records = {}
8
- logs_queue = []
9
- client = None
10
-
11
- def __init__(self, client=None, task=None):
12
- self.client = client
13
- self.task = task
14
-
15
- def set_progress(self, current, total, category=''):
16
- percent = 0
17
- if total > 0:
18
- percent = (current / total) * 100
19
- percent = float(round(percent, 2))
20
-
21
- self.progress_records[category] = {'current': current, 'total': total, 'percent': percent}
22
- if self.task:
23
- self.task.update_state(state='PROGRESS', meta=self.progress_records)
24
- else:
25
- print(self.progress_records)
26
-
27
- def log(self, action, data):
28
- log = {'action': action, 'data': data, 'datetime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')}
29
-
30
- if self.client and self.task:
31
- log['task_id'] = self.task.request.id
32
- self.logs_queue.append(log)
33
- try:
34
- self.client.create_logs(self.logs_queue)
35
- self.logs_queue.clear()
36
- except ClientError as e:
37
- print(e)
38
- else:
39
- print(log)
40
-
41
-
42
- class ConsoleLogger(BaseLogger):
43
- def log(self, action, data):
44
- print(action, data)
45
-
46
-
47
- class SynapseLogger(BaseLogger):
48
- pass
@@ -1,96 +0,0 @@
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 RunMethod, PluginCategory
4
- from synapse_sdk.utils.file import get_dict_from_file, files_url_to_path_from_objs
5
- from synapse_sdk.utils.module_loading import import_string
6
-
7
-
8
- @register_action
9
- class TrainAction(Action):
10
- name = 'train'
11
- category = PluginCategory.NEURAL_NET
12
- method = RunMethod.JOB
13
-
14
- def get_input_dataset_for_training(self, model_id=None):
15
- """
16
- :return:
17
- {
18
- "train": [
19
- {
20
- "files": {
21
- "image": {
22
- "path": "/path/to/image.jpg",
23
- "meta": {
24
- "width": 265,
25
- "height": 190,
26
- "created": 1651563526.0277045,
27
- "file_size": 5191,
28
- "last_modified": 1651563526.0277045
29
- }
30
- }
31
- },
32
- "ground_truth": {
33
- ...label_data
34
- }
35
- },
36
- ...
37
- ],
38
- "validation": ...,
39
- "test": ...
40
- }
41
- """
42
-
43
- client = self.logger.client
44
- input_dataset = {}
45
- category_int_to_str = {1: 'train', 2: 'validation', 3: 'test'}
46
-
47
- if client:
48
- train_dataset, count_dataset = client.list_train_dataset(
49
- payload={'fields': ['category', 'files', 'ground_truth'], 'model': model_id}, list_all=True
50
- )
51
-
52
- for i, train_data in enumerate(train_dataset, start=1):
53
- self.set_progress(i, count_dataset, category='dataset_download')
54
- category = category_int_to_str[train_data.pop('category')]
55
- try:
56
- input_dataset[category].append(train_data)
57
- except KeyError:
58
- input_dataset[category] = [train_data]
59
-
60
- else:
61
- for category in category_int_to_str.values():
62
- dataset_path = self.task['dataset'].get(category)
63
- if dataset_path:
64
- input_dataset[category] = get_dict_from_file(dataset_path)
65
- files_url_to_path_from_objs(input_dataset[category], ['files'], is_list=True)
66
-
67
- return input_dataset
68
-
69
- def run_train(self):
70
- hyperparameter = self.task['hyperparameter']
71
- train = import_string(self.plugin['train']['entrypoint'])
72
-
73
- # download dataset
74
- self.log_event('Preparing dataset for training.')
75
- input_dataset = self.get_input_dataset_for_training()
76
-
77
- # train dataset
78
- self.log_event('Starting model training.')
79
-
80
- model_files = train(self, input_dataset, hyperparameter)
81
-
82
- # upload model_data
83
- self.log_event('Registering model data.')
84
-
85
- self.end_log()
86
- return model_files
87
-
88
- def start(self):
89
- action = self.task['action']
90
- getattr(self, f'run_{action}')()
91
-
92
- def log_metric(self, x, i, **kwargs):
93
- self.log(x, {x: i, **kwargs})
94
-
95
- def log_model(self, files, status=None):
96
- pass
File without changes
File without changes
File without changes
File without changes