synapse-sdk 1.0.0a7__tar.gz → 1.0.0a9__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 (114) hide show
  1. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/.gitignore +1 -1
  2. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/PKG-INFO +1 -1
  3. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/requirements.txt +1 -1
  4. synapse_sdk-1.0.0a9/synapse_sdk/clients/agent/__init__.py +23 -0
  5. synapse_sdk-1.0.0a9/synapse_sdk/clients/agent/core.py +7 -0
  6. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/backend/__init__.py +5 -4
  7. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/backend/annotation.py +10 -10
  8. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/backend/dataset.py +5 -5
  9. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/backend/integration.py +12 -0
  10. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/backend/ml.py +8 -7
  11. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/base.py +10 -1
  12. synapse_sdk-1.0.0a9/synapse_sdk/loggers.py +116 -0
  13. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/base.py +35 -5
  14. synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/neural_net/actions/train.py +142 -0
  15. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/templates/plugin/train.py +1 -1
  16. synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool/actions/auto_label.py +22 -0
  17. synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool/templates/config.yaml +6 -0
  18. synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool/templates/plugin/__init__.py +0 -0
  19. synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool/templates/plugin/auto_label.py +11 -0
  20. synapse_sdk-1.0.0a9/synapse_sdk/plugins/exceptions.py +6 -0
  21. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/models.py +10 -3
  22. synapse_sdk-1.0.0a9/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/.env.dist +24 -0
  23. synapse_sdk-1.0.0a9/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/config.yaml +6 -0
  24. synapse_sdk-1.0.0a9/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/main.py +4 -0
  25. synapse_sdk-1.0.0a9/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/plugin/__init__.py +0 -0
  26. synapse_sdk-1.0.0a9/synapse_sdk/utils/__init__.py +0 -0
  27. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/utils/file.py +15 -0
  28. synapse_sdk-1.0.0a9/synapse_sdk/utils/pydantic/__init__.py +0 -0
  29. synapse_sdk-1.0.0a9/synapse_sdk/utils/pydantic/config.py +4 -0
  30. synapse_sdk-1.0.0a9/synapse_sdk/utils/pydantic/errors.py +33 -0
  31. synapse_sdk-1.0.0a9/synapse_sdk/utils/pydantic/validators.py +7 -0
  32. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/PKG-INFO +1 -1
  33. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/SOURCES.txt +15 -1
  34. synapse_sdk-1.0.0a7/synapse_sdk/clients/agent/__init__.py +0 -21
  35. synapse_sdk-1.0.0a7/synapse_sdk/loggers.py +0 -54
  36. synapse_sdk-1.0.0a7/synapse_sdk/plugins/categories/neural_net/actions/train.py +0 -41
  37. synapse_sdk-1.0.0a7/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/config.yaml +0 -18
  38. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/.github/workflows/lint.yml +0 -0
  39. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/.github/workflows/pypi-publish.yml +0 -0
  40. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/.pre-commit-config.yaml +0 -0
  41. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/LICENSE +0 -0
  42. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/README.md +0 -0
  43. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/pyproject.toml +0 -0
  44. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/setup.cfg +0 -0
  45. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/__init__.py +0 -0
  46. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/cli/__init__.py +0 -0
  47. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/cli/create_plugin.py +0 -0
  48. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/__init__.py +0 -0
  49. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/agent/service.py +0 -0
  50. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/exceptions.py +0 -0
  51. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/clients/utils.py +0 -0
  52. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/__init__.py +0 -0
  53. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/__init__.py +0 -0
  54. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/__init__.py +0 -0
  55. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/actions/__init__.py +0 -0
  56. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/actions/validation.py +0 -0
  57. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/templates/config.yaml +0 -0
  58. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/templates/plugin/__init__.py +0 -0
  59. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/data_validation/templates/plugin/validation.py +0 -0
  60. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/decorators.py +0 -0
  61. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/export/__init__.py +0 -0
  62. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/export/actions/__init__.py +0 -0
  63. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/export/actions/export.py +0 -0
  64. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/import/__init__.py +0 -0
  65. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/import/actions/__init__.py +0 -0
  66. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/import/actions/import.py +0 -0
  67. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/__init__.py +0 -0
  68. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/actions/__init__.py +0 -0
  69. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/actions/deployment.py +0 -0
  70. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/actions/inference.py +0 -0
  71. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/actions/test.py +0 -0
  72. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/templates/config.yaml +0 -0
  73. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/templates/plugin/__init__.py +0 -0
  74. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/templates/plugin/inference.py +0 -0
  75. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/neural_net/templates/plugin/test.py +0 -0
  76. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/__init__.py +0 -0
  77. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/actions/__init__.py +0 -0
  78. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/actions/post_annotation.py +0 -0
  79. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/templates/config.yaml +0 -0
  80. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/templates/plugin/__init__.py +0 -0
  81. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/post_annotation/templates/plugin/post_annotation.py +0 -0
  82. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/__init__.py +0 -0
  83. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/actions/__init__.py +0 -0
  84. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/actions/pre_annotation.py +0 -0
  85. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/templates/config.yaml +0 -0
  86. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/templates/plugin/__init__.py +0 -0
  87. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/pre_annotation/templates/plugin/pre_annotation.py +0 -0
  88. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/registry.py +0 -0
  89. {synapse_sdk-1.0.0a7/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/plugin → synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool}/__init__.py +0 -0
  90. {synapse_sdk-1.0.0a7/synapse_sdk/utils → synapse_sdk-1.0.0a9/synapse_sdk/plugins/categories/smart_tool/actions}/__init__.py +0 -0
  91. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/categories/templates.py +0 -0
  92. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/cli/__init__.py +0 -0
  93. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/cli/publish.py +0 -0
  94. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/cli/run.py +0 -0
  95. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/enums.py +0 -0
  96. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/cookiecutter.json +0 -0
  97. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/hooks/post_gen_project.py +0 -0
  98. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/hooks/pre_prompt.py +0 -0
  99. /synapse_sdk-1.0.0a7/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/.env.dist → /synapse_sdk-1.0.0a9/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/.env +0 -0
  100. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/.gitignore +0 -0
  101. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/.pre-commit-config.yaml +0 -0
  102. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/README.md +0 -0
  103. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/pyproject.toml +0 -0
  104. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/templates/synapse-{{cookiecutter.plugin_code}}-plugin/requirements.txt +0 -0
  105. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/upload.py +0 -0
  106. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/plugins/utils.py +0 -0
  107. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/utils/debug.py +0 -0
  108. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/utils/module_loading.py +0 -0
  109. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/utils/storage.py +0 -0
  110. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk/utils/string.py +0 -0
  111. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/dependency_links.txt +0 -0
  112. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/entry_points.txt +0 -0
  113. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/requires.txt +0 -0
  114. {synapse_sdk-1.0.0a7 → synapse_sdk-1.0.0a9}/synapse_sdk.egg-info/top_level.txt +0 -0
@@ -25,4 +25,4 @@ __pycache__/
25
25
  .cache
26
26
 
27
27
  # python
28
- main.py
28
+ /main.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a7
3
+ Version: 1.0.0a9
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -6,4 +6,4 @@ tqdm
6
6
  pyyaml
7
7
  pydantic
8
8
  python-dotenv
9
- ray[all]==2.38.0
9
+ ray[all]>=2.38.0
@@ -0,0 +1,23 @@
1
+ from synapse_sdk.clients.agent.core import CoreClientMixin
2
+ from synapse_sdk.clients.agent.service import ServiceClientMixin
3
+
4
+
5
+ class AgentClient(CoreClientMixin, ServiceClientMixin):
6
+ name = 'Agent'
7
+ agent_token = None
8
+ user_token = None
9
+ tenant = None
10
+
11
+ def __init__(self, base_url, agent_token, user_token=None, tenant=None):
12
+ super().__init__(base_url)
13
+ self.agent_token = agent_token
14
+ self.user_token = user_token
15
+ self.tenant = tenant
16
+
17
+ def _get_headers(self):
18
+ headers = {'Authorization': self.agent_token}
19
+ if self.user_token:
20
+ headers['SYNAPSE-User'] = f'Token {self.user_token}'
21
+ if self.tenant:
22
+ headers['SYNAPSE-Tenant'] = f'Token {self.tenant}'
23
+ return headers
@@ -0,0 +1,7 @@
1
+ from synapse_sdk.clients.base import BaseClient
2
+
3
+
4
+ class CoreClientMixin(BaseClient):
5
+ def health_check(self):
6
+ path = 'health/'
7
+ return self._get(path)
@@ -9,14 +9,15 @@ class BackendClient(AnnotationClientMixin, DatasetClientMixin, IntegrationClient
9
9
  token = None
10
10
  tenant = None
11
11
 
12
- def __init__(self, base_url, token, tenant=None):
12
+ def __init__(self, base_url, token=None, tenant=None):
13
13
  super().__init__(base_url)
14
14
  self.token = token
15
- if tenant:
16
- self.tenant = tenant
15
+ self.tenant = tenant
17
16
 
18
17
  def _get_headers(self):
19
- headers = {'Authorization': f'Token {self.token}'}
18
+ headers = {}
19
+ if self.token:
20
+ headers = {'Authorization': f'Token {self.token}'}
20
21
  if self.tenant:
21
22
  headers['SYNAPSE-Tenant'] = f'Token {self.tenant}'
22
23
  return headers
@@ -7,23 +7,23 @@ class AnnotationClientMixin(BaseClient):
7
7
  path = f'projects/{pk}/'
8
8
  return self._get(path)
9
9
 
10
- def get_label_tag(self, pk):
11
- path = f'label_tags/{pk}/'
10
+ def get_task_tag(self, pk):
11
+ path = f'task_tags/{pk}/'
12
12
  return self._get(path)
13
13
 
14
- def list_label_tags(self, data):
15
- path = 'label_tags/'
14
+ def list_task_tags(self, data):
15
+ path = 'task_tags/'
16
16
  return self._list(path, data=data)
17
17
 
18
- def list_labels(self, data, url_conversion=None, list_all=False):
19
- path = 'labels/'
18
+ def list_tasks(self, data, url_conversion=None, list_all=False):
19
+ path = 'tasks/'
20
20
  url_conversion = get_default_url_conversion(url_conversion, files_fields=['files'])
21
21
  return self._list(path, data=data, url_conversion=url_conversion, list_all=list_all)
22
22
 
23
- def create_labels(self, data):
24
- path = 'labels/'
23
+ def create_tasks(self, data):
24
+ path = 'tasks/'
25
25
  return self._post(path, data=data)
26
26
 
27
- def set_tags_labels(self, data, params=None):
28
- path = 'labels/set_tags/'
27
+ def set_tags_tasks(self, data, params=None):
28
+ path = 'tasks/set_tags/'
29
29
  return self._post(path, data=data, params=params)
@@ -33,15 +33,15 @@ class DatasetClientMixin(BaseClient):
33
33
  data_units = self.create_data_units(batch)
34
34
 
35
35
  if project_id:
36
- labels_data = []
36
+ tasks_data = []
37
37
  for data, data_unit in zip(batch, data_units):
38
- label_data = {'project': project_id, 'data_unit': data_unit['id']}
38
+ task_data = {'project': project_id, 'data_unit': data_unit['id']}
39
39
  if 'ground_truth' in data:
40
- label_data['ground_truth'] = data['ground_truth']
40
+ task_data['ground_truth'] = data['ground_truth']
41
41
 
42
- labels_data.append(label_data)
42
+ tasks_data.append(task_data)
43
43
 
44
- self.create_labels(labels_data)
44
+ self.create_tasks(tasks_data)
45
45
 
46
46
  def import_data_file(self, data, dataset_id):
47
47
  for name, path in data['files'].items():
@@ -2,6 +2,10 @@ from synapse_sdk.clients.base import BaseClient
2
2
 
3
3
 
4
4
  class IntegrationClientMixin(BaseClient):
5
+ def health_check_agent(self, token):
6
+ path = f'agents/{token}/connect/'
7
+ return self._post(path)
8
+
5
9
  def get_plugin(self, pk):
6
10
  path = f'plugins/{pk}/'
7
11
  return self._get(path)
@@ -27,6 +31,14 @@ class IntegrationClientMixin(BaseClient):
27
31
  files = {'file': data.pop('file')}
28
32
  return self._post(path, data=data, files=files)
29
33
 
34
+ def list_jobs(self, params=None):
35
+ path = 'jobs/'
36
+ return self._get(path, params=params)
37
+
38
+ def update_job(self, pk, data):
39
+ path = f'jobs/{pk}/'
40
+ return self._patch(path, data=data)
41
+
30
42
  def list_job_console_logs(self, pk):
31
43
  path = f'jobs/{pk}/console_logs/'
32
44
  return self._get(path)
@@ -3,6 +3,10 @@ from synapse_sdk.clients.utils import get_default_url_conversion
3
3
 
4
4
 
5
5
  class MLClientMixin(BaseClient):
6
+ def list_models(self, params=None):
7
+ path = 'models/'
8
+ return self._get(path, params=params)
9
+
6
10
  def get_model(self, pk, params=None, url_conversion=None):
7
11
  path = f'models/{pk}/'
8
12
  url_conversion = get_default_url_conversion(
@@ -12,13 +16,10 @@ class MLClientMixin(BaseClient):
12
16
 
13
17
  def create_model(self, data):
14
18
  path = 'models/'
15
- return self._post(path, data=data)
16
-
17
- def update_model(self, pk, data, files=None):
18
- path = f'models/{pk}/'
19
- return self._patch(path, data=data, files=files)
19
+ files = {'file': data.pop('file')}
20
+ return self._post(path, data=data, files=files)
20
21
 
21
- def list_train_dataset(self, params=None, url_conversion=None, list_all=False):
22
- path = 'train_dataset/'
22
+ def list_ground_truth_events(self, params=None, url_conversion=None, list_all=False):
23
+ path = 'ground_truth_events/'
23
24
  url_conversion = get_default_url_conversion(url_conversion, files_fields=['files'])
24
25
  return self._list(path, params=params, url_conversion=url_conversion, list_all=list_all)
@@ -33,6 +33,9 @@ class BaseClient:
33
33
  if kwargs.get('files') is not None:
34
34
  for name, file in kwargs['files'].items():
35
35
  kwargs['files'][name] = Path(str(file)).open(mode='rb')
36
+ for name, value in kwargs['data'].items():
37
+ if isinstance(value, dict):
38
+ kwargs['data'][name] = json.dumps(value)
36
39
  else:
37
40
  headers['Content-Type'] = 'application/json'
38
41
  if 'data' in kwargs:
@@ -47,7 +50,10 @@ class BaseClient:
47
50
  except requests.ConnectionError:
48
51
  raise ClientError(408, f'{self.name} is not responding')
49
52
 
50
- return response.json()
53
+ try:
54
+ return response.json()
55
+ except ValueError:
56
+ return response.text
51
57
 
52
58
  def _get(self, path, url_conversion=None, **kwargs):
53
59
  response = self._request('get', path, **kwargs)
@@ -79,3 +85,6 @@ class BaseClient:
79
85
  yield from response['results']
80
86
  if response['next']:
81
87
  yield from self._list_all(response['next'], url_conversion, **kwargs)
88
+
89
+ def exists(self, api, *args, **kwargs):
90
+ return getattr(self, api)(*args, **kwargs)['count'] > 0
@@ -0,0 +1,116 @@
1
+ import datetime
2
+ import time
3
+
4
+ from synapse_sdk.clients.exceptions import ClientError
5
+
6
+
7
+ class BaseLogger:
8
+ progress_record = {}
9
+ progress_categories = None
10
+ current_category = None
11
+ time_begin_per_category = {}
12
+
13
+ def __init__(self, progress_categories=None):
14
+ self.progress_categories = progress_categories
15
+ if progress_categories:
16
+ self.progress_record['categories'] = progress_categories
17
+
18
+ def set_progress(self, current, total, category=None):
19
+ assert 0 <= current <= total and total > 0
20
+ assert category is not None or 'categories' not in self.progress_record
21
+
22
+ percent = (current / total) * 100
23
+ percent = round(percent, 2)
24
+ # TODO current 0 으로 시작하지 않아도 작동되도록 수정
25
+ if current == 0:
26
+ self.time_begin_per_category[category] = time.time()
27
+ time_remaining = None
28
+ else:
29
+ seconds_per_item = (time.time() - self.time_begin_per_category[category]) / current
30
+ time_remaining = round(seconds_per_item * (total - current), 2)
31
+
32
+ current_progress = {'percent': percent, 'time_remaining': time_remaining}
33
+
34
+ if category:
35
+ self.current_category = category
36
+ self.progress_record['categories'][category].update(current_progress)
37
+ else:
38
+ self.progress_record.update(current_progress)
39
+
40
+ def get_current_progress(self):
41
+ categories = self.progress_record.get('categories')
42
+
43
+ if categories:
44
+ category_progress = None
45
+
46
+ overall = 0
47
+ for category, category_record in categories.items():
48
+ if category == self.current_category:
49
+ break
50
+ overall += category_record['proportion']
51
+
52
+ category_record = categories[self.current_category]
53
+ category_percent = category_record.get('percent', 0)
54
+ if not category_progress and 'percent' in category_record:
55
+ category_progress = {
56
+ 'category': self.current_category,
57
+ 'percent': category_percent,
58
+ 'time_remaining': category_record.get('time_remaining'),
59
+ }
60
+ if category_percent > 0:
61
+ overall += round(category_record['proportion'] / 100 * category_percent, 2)
62
+ progress = {'overall': overall, **category_progress}
63
+ else:
64
+ progress = {
65
+ 'overall': self.progress_record.get('percent'),
66
+ 'time_remaining': self.progress_record.get('time_remaining'),
67
+ }
68
+
69
+ return progress
70
+
71
+
72
+ class ConsoleLogger(BaseLogger):
73
+ def set_progress(self, current, total, category=None):
74
+ super().set_progress(current, total, category=category)
75
+ print(self.get_current_progress())
76
+
77
+ def log(self, action, data):
78
+ print(action, data)
79
+
80
+
81
+ class BackendLogger(BaseLogger):
82
+ logs_queue = []
83
+ client = None
84
+ job_id = None
85
+
86
+ def __init__(self, client, job_id, **kwargs):
87
+ super().__init__(**kwargs)
88
+ self.client = client
89
+ self.job_id = job_id
90
+
91
+ def set_progress(self, current, total, category=None):
92
+ super().set_progress(current, total, category=category)
93
+ try:
94
+ progress_record = {
95
+ 'record': self.progress_record,
96
+ 'current_progress': self.get_current_progress(),
97
+ }
98
+ self.client.update_job(self.job_id, data={'progress_record': progress_record})
99
+ except ClientError:
100
+ pass
101
+
102
+ def log(self, action, data):
103
+ print(action, data)
104
+
105
+ log = {
106
+ 'action': action,
107
+ 'data': data,
108
+ 'datetime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'),
109
+ 'job': self.job_id,
110
+ }
111
+ self.logs_queue.append(log)
112
+ try:
113
+ self.client.create_logs(self.logs_queue)
114
+ self.logs_queue.clear()
115
+ except ClientError as e:
116
+ print(e)
@@ -6,25 +6,35 @@ from pprint import pprint
6
6
 
7
7
  import ray
8
8
  import requests
9
+ from pydantic import ValidationError
9
10
  from ray.dashboard.modules.job.sdk import JobSubmissionClient
10
11
 
11
12
  from synapse_sdk.plugins.enums import RunMethod
13
+ from synapse_sdk.plugins.exceptions import ActionValidationError
12
14
  from synapse_sdk.plugins.models import PluginRelease, Run
13
15
  from synapse_sdk.plugins.upload import archive_and_upload, build_and_upload, download_and_upload
14
16
  from synapse_sdk.utils.module_loading import import_string
17
+ from synapse_sdk.utils.pydantic.errors import pydantic_to_drf_error
15
18
 
16
19
 
17
20
  class Action:
21
+ # class 변수
18
22
  name = None
19
23
  category = None
20
24
  method = None
25
+ run_class = Run
26
+ params_model = None
27
+ progress_categories = None
28
+
29
+ # init 변수
21
30
  params = None
22
31
  plugin_config = None
23
32
  plugin_release = None
24
33
  config = None
25
- client = None
26
- debug = False
27
- run_class = Run
34
+ job_id = None
35
+ direct = None
36
+ debug = None
37
+ envs = None
28
38
  run = None
29
39
 
30
40
  default_envs = [
@@ -57,10 +67,14 @@ class Action:
57
67
  def plugin_storage_url(self):
58
68
  return self.envs['SYNAPSE_PLUGIN_STORAGE']
59
69
 
70
+ @property
71
+ def client(self):
72
+ return self.run.client
73
+
60
74
  @property
61
75
  def plugin_url(self):
62
76
  if self.debug:
63
- plugin_path = self.envs.get('SYNAPSE_DEBUG_PLUGIN_PATH', '.')
77
+ plugin_path = self.envs.get('SYNAPSE_DEBUG_PLUGIN_PATH') or '.'
64
78
  if plugin_path.startswith('https://'): # TODO ray에서 지원하는 remote uri 형식 (https, s3, gs) 모두 지원
65
79
  plugin_url = plugin_path
66
80
  elif plugin_path.startswith('http://'):
@@ -85,6 +99,8 @@ class Action:
85
99
 
86
100
  def get_run(self):
87
101
  context = {
102
+ 'plugin_release': self.plugin_release,
103
+ 'progress_categories': self.progress_categories,
88
104
  'params': self.params,
89
105
  'envs': self.envs,
90
106
  'debug': self.debug,
@@ -110,12 +126,22 @@ class Action:
110
126
  pprint(runtime_env)
111
127
  return runtime_env
112
128
 
129
+ def validate_params(self):
130
+ if self.params_model:
131
+ try:
132
+ self.params_model.model_validate(self.params, context={'action': self})
133
+ except ValidationError as e:
134
+ raise ActionValidationError({'params': pydantic_to_drf_error(e)})
135
+
113
136
  def run_action(self):
137
+ self.validate_params()
114
138
  if self.direct:
115
139
  if self.method == RunMethod.RESTAPI:
116
140
  return self.start_by_restapi()
117
141
  else:
118
- return self.start()
142
+ result = self.start()
143
+ self.post_action_by_job(result)
144
+ return result
119
145
  return getattr(self, f'start_by_{self.method.value}')()
120
146
 
121
147
  def start(self):
@@ -175,3 +201,7 @@ class Action:
175
201
  response = getattr(requests, method)(url, **self.params)
176
202
  # TODO ok response가 아닌 경우 대응하기
177
203
  return response.json()
204
+
205
+ def post_action_by_job(self, result):
206
+ if self.client:
207
+ self.client.update_job(self.job_id, data={'result': result})
@@ -0,0 +1,142 @@
1
+ import copy
2
+ import tempfile
3
+ from decimal import Decimal
4
+ from pathlib import Path
5
+ from typing import Annotated
6
+
7
+ from pydantic import AfterValidator, BaseModel, field_validator
8
+ from pydantic_core import PydanticCustomError
9
+
10
+ from synapse_sdk.clients.exceptions import ClientError
11
+ from synapse_sdk.plugins.categories.base import Action
12
+ from synapse_sdk.plugins.categories.decorators import register_action
13
+ from synapse_sdk.plugins.enums import PluginCategory, RunMethod
14
+ from synapse_sdk.plugins.models import Run
15
+ from synapse_sdk.utils.file import archive
16
+ from synapse_sdk.utils.pydantic.validators import non_blank
17
+
18
+
19
+ class TrainRun(Run):
20
+ def log_metric(self, x, i, **kwargs):
21
+ self.log(x, {x: i, **kwargs})
22
+
23
+
24
+ class Hyperparameter(BaseModel):
25
+ batch_size: int
26
+ iterations: int
27
+ learning_rate: Decimal
28
+
29
+
30
+ class TrainParams(BaseModel):
31
+ name: Annotated[str, AfterValidator(non_blank)]
32
+ description: str
33
+ checkpoint: int | None
34
+ dataset: int
35
+ hyperparameter: Hyperparameter
36
+
37
+ @field_validator('name')
38
+ @staticmethod
39
+ def unique_name(value, info):
40
+ action = info.context['action']
41
+ client = action.client
42
+ try:
43
+ model_exists = client.exists('list_models', params={'name': value})
44
+ job_exists = client.exists(
45
+ 'list_jobs',
46
+ params={
47
+ 'ids_ex': action.job_id,
48
+ 'category': 'neural_net',
49
+ 'action': 'train',
50
+ 'is_active': True,
51
+ 'params': f'name:{value}',
52
+ },
53
+ )
54
+ assert not model_exists and not job_exists, '존재하는 학습 이름입니다.'
55
+ except ClientError:
56
+ raise PydanticCustomError('client_error', '')
57
+ return value
58
+
59
+
60
+ @register_action
61
+ class TrainAction(Action):
62
+ name = 'train'
63
+ category = PluginCategory.NEURAL_NET
64
+ method = RunMethod.JOB
65
+ run_class = TrainRun
66
+ params_model = TrainParams
67
+ progress_categories = {
68
+ 'dataset': {
69
+ 'proportion': 20,
70
+ },
71
+ 'train': {
72
+ 'proportion': 75,
73
+ },
74
+ 'model_upload': {
75
+ 'proportion': 5,
76
+ },
77
+ }
78
+
79
+ def start(self):
80
+ hyperparameter = self.params['hyperparameter']
81
+
82
+ # download dataset
83
+ self.run.log_event('Preparing dataset for training.')
84
+ input_dataset = self.get_dataset()
85
+
86
+ # train dataset
87
+ self.run.log_event('Starting model training.')
88
+
89
+ result = self.entrypoint(self.run, input_dataset, hyperparameter)
90
+
91
+ # upload model_data
92
+ self.run.log_event('Registering model data.')
93
+ self.run.set_progress(0, 1, category='model_upload')
94
+ model = self.create_model(result)
95
+ self.run.set_progress(1, 1, category='model_upload')
96
+
97
+ self.run.end_log()
98
+ return {'model_id': model['id']}
99
+
100
+ def get_dataset(self):
101
+ client = self.run.client
102
+ assert bool(client)
103
+
104
+ input_dataset = {}
105
+
106
+ ground_truths, count_dataset = client.list_ground_truth_events(
107
+ params={
108
+ 'fields': ['category', 'files', 'data'],
109
+ 'ground_truth_dataset_versions': self.params['dataset'],
110
+ },
111
+ list_all=True,
112
+ )
113
+ self.run.set_progress(0, count_dataset, category='dataset')
114
+ for i, ground_truth in enumerate(ground_truths, start=1):
115
+ self.run.set_progress(i, count_dataset, category='dataset')
116
+ try:
117
+ input_dataset[ground_truth['category']].append(ground_truth)
118
+ except KeyError:
119
+ input_dataset[ground_truth['category']] = [ground_truth]
120
+
121
+ return input_dataset
122
+
123
+ def create_model(self, path):
124
+ if not self.client:
125
+ print(path)
126
+
127
+ params = copy.deepcopy(self.params)
128
+ configuration_fields = ['hyperparameter']
129
+ configuration = {field: params.pop(field) for field in configuration_fields}
130
+
131
+ with tempfile.TemporaryDirectory() as temp_path:
132
+ input_path = Path(path)
133
+ archive_path = Path(temp_path, 'archive.zip')
134
+ archive(input_path, archive_path)
135
+
136
+ return self.client.create_model({
137
+ 'plugin': self.plugin_release.plugin,
138
+ 'version': self.plugin_release.version,
139
+ 'file': str(archive_path),
140
+ 'configuration': configuration,
141
+ **params,
142
+ })
@@ -9,6 +9,6 @@ def train(run, dataset, hyperparameter, checkpoint=None):
9
9
  loss = float(round((count_iterations - i) / count_iterations, 2))
10
10
  miou = 1 - loss
11
11
  run.log_metric('iteration', i, loss=loss, miou=miou)
12
- run.set_progress(i, count_iterations, category='iteration')
12
+ run.set_progress(i, count_iterations, category='train')
13
13
 
14
14
  return {'weight': '/tmp/agent/test/a.txt', 'config': '/tmp/agent/test/b.txt'}
@@ -0,0 +1,22 @@
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 AutoLabelAction(Action):
8
+ name = 'label'
9
+ category = PluginCategory.SMART_TOOL
10
+ method = RunMethod.TASK
11
+
12
+ def get_auto_label(self):
13
+ return self.entrypoint(**self.params)
14
+
15
+ def run_model(self, input_data):
16
+ return {}
17
+
18
+ def start(self):
19
+ auto_label = self.get_auto_label()
20
+ input_data = auto_label.handle_input(self.params['input_data'])
21
+ output_data = self.run_model(input_data)
22
+ return auto_label.handle_output(output_data)
@@ -0,0 +1,6 @@
1
+ actions:
2
+ auto_label:
3
+ category: interactive_segmentation
4
+ entrypoint: plugin.auto_label.MyAutoLabel
5
+ model:
6
+ neural_nets: [sam2]
@@ -0,0 +1,11 @@
1
+ class MyAutoLabel:
2
+ def __init__(self, **kwargs):
3
+ pass
4
+
5
+ def handle_input(self, input_data):
6
+ """smart tool의 input을 model의 input 형태로 변환"""
7
+ return
8
+
9
+ def handle_output(self, output_data):
10
+ """model의 output을 smart tool의 output 형태로 변환"""
11
+ return
@@ -0,0 +1,6 @@
1
+ class ActionValidationError(Exception):
2
+ errors = None
3
+
4
+ def __init__(self, errors, *args):
5
+ self.errors = errors
6
+ super().__init__(errors, *args)
@@ -11,12 +11,14 @@ from synapse_sdk.utils.string import hash_text
11
11
 
12
12
  class PluginRelease:
13
13
  config: Dict[str, Any]
14
+ envs = None
14
15
 
15
- def __init__(self, config=None, plugin_path=None):
16
+ def __init__(self, config=None, plugin_path=None, envs=None):
16
17
  if config:
17
18
  self.config = config
18
19
  else:
19
20
  self.config = read_plugin_config(plugin_path=plugin_path)
21
+ self.envs = envs
20
22
 
21
23
  @cached_property
22
24
  def plugin(self):
@@ -72,15 +74,20 @@ class Run:
72
74
  self.set_logger()
73
75
 
74
76
  def set_logger(self):
77
+ kwargs = {'progress_categories': self.context['progress_categories']}
75
78
  if self.job_id:
76
79
  client = BackendClient(
77
80
  self.context['envs']['SYNAPSE_PLUGIN_RUN_HOST'],
78
81
  self.context['envs']['SYNAPSE_PLUGIN_RUN_USER_TOKEN'],
79
82
  self.context['envs']['SYNAPSE_PLUGIN_RUN_TENANT'],
80
83
  )
81
- self.logger = BackendLogger(client, self.job_id)
84
+ self.logger = BackendLogger(client, self.job_id, **kwargs)
82
85
  else:
83
- self.logger = ConsoleLogger()
86
+ self.logger = ConsoleLogger(**kwargs)
87
+
88
+ @property
89
+ def client(self):
90
+ return getattr(self.logger, 'client', None)
84
91
 
85
92
  def set_progress(self, current, total, category=''):
86
93
  self.logger.set_progress(current, total, category)