synapse-sdk 1.0.0a16__py3-none-any.whl → 1.0.0a18__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.

Potentially problematic release.


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

@@ -9,9 +9,7 @@ class MLClientMixin(BaseClient):
9
9
 
10
10
  def get_model(self, pk, params=None, url_conversion=None):
11
11
  path = f'models/{pk}/'
12
- url_conversion = get_default_url_conversion(
13
- url_conversion, files_fields=['files', 'parent.files'], is_list=False
14
- )
12
+ url_conversion = get_default_url_conversion(url_conversion, files_fields=['file'], is_list=False)
15
13
  return self._get(path, params=params, url_conversion=url_conversion)
16
14
 
17
15
  def create_model(self, data):
@@ -147,7 +147,8 @@ class Action:
147
147
  return self.start_by_restapi()
148
148
  else:
149
149
  result = self.start()
150
- self.post_action_by_job(result)
150
+ if self.job_id:
151
+ self.post_action_by_job(result)
151
152
  return result
152
153
  return getattr(self, f'start_by_{self.method.value}')()
153
154
 
@@ -227,10 +228,9 @@ class Action:
227
228
  raise ActionError('Unable to connect to serve application')
228
229
 
229
230
  def post_action_by_job(self, result):
230
- if self.client:
231
- job_client = self.get_job_client()
232
- logs = job_client.get_job_logs(self.job_id).split('\n')
233
- self.client.update_job(self.job_id, data={'result': result or {}, 'console_logs': logs})
231
+ job_client = self.get_job_client()
232
+ logs = job_client.get_job_logs(self.job_id).split('\n')
233
+ self.client.update_job(self.job_id, data={'result': result or {}, 'console_logs': logs})
234
234
 
235
235
  def get_job_client(self):
236
236
  from ray.dashboard.modules.job.sdk import JobSubmissionClient
@@ -11,7 +11,12 @@ class DeploymentAction(Action):
11
11
  method = RunMethod.JOB
12
12
 
13
13
  def get_actor_options(self):
14
- return {'runtime_env': self.get_runtime_env()}
14
+ options = {'runtime_env': self.get_runtime_env()}
15
+ for option in ['num_cpus', 'num_gpus']:
16
+ option_value = self.params.get(option)
17
+ if option_value:
18
+ options[option] = option_value
19
+ return options
15
20
 
16
21
  def start(self):
17
22
  from ray import serve
@@ -12,7 +12,7 @@ from synapse_sdk.plugins.categories.base import Action
12
12
  from synapse_sdk.plugins.categories.decorators import register_action
13
13
  from synapse_sdk.plugins.enums import PluginCategory, RunMethod
14
14
  from synapse_sdk.plugins.models import Run
15
- from synapse_sdk.utils.file import archive
15
+ from synapse_sdk.utils.file import archive, get_temp_path, unarchive
16
16
  from synapse_sdk.utils.pydantic.validators import non_blank
17
17
 
18
18
 
@@ -83,10 +83,15 @@ class TrainAction(Action):
83
83
  self.run.log_message('Preparing dataset for training.')
84
84
  input_dataset = self.get_dataset()
85
85
 
86
+ # retrieve checkpoint
87
+ checkpoint = None
88
+ if self.params['checkpoint']:
89
+ self.run.log_message('Retrieving checkpoint.')
90
+ checkpoint = self.get_model(self.params['checkpoint'])
91
+
86
92
  # train dataset
87
93
  self.run.log_message('Starting model training.')
88
-
89
- result = self.entrypoint(self.run, input_dataset, hyperparameter)
94
+ result = self.entrypoint(self.run, input_dataset, hyperparameter, checkpoint=checkpoint)
90
95
 
91
96
  # upload model_data
92
97
  self.run.log_message('Registering model data.')
@@ -106,6 +111,7 @@ class TrainAction(Action):
106
111
  ground_truths, count_dataset = client.list_ground_truth_events(
107
112
  params={
108
113
  'fields': ['category', 'files', 'data'],
114
+ 'expand': ['data'],
109
115
  'ground_truth_dataset_versions': self.params['dataset'],
110
116
  },
111
117
  list_all=True,
@@ -120,11 +126,16 @@ class TrainAction(Action):
120
126
 
121
127
  return input_dataset
122
128
 
123
- def create_model(self, path):
124
- if not self.client:
125
- print(path)
126
- return None
129
+ def get_model(self, model_id):
130
+ model = self.client.get_model(model_id)
131
+ model_file = Path(model['file'])
132
+ output_path = get_temp_path(f'models/{model_file.stem}')
133
+ if not output_path.exists():
134
+ unarchive(model_file, output_path)
135
+ model['path'] = output_path
136
+ return model
127
137
 
138
+ def create_model(self, path):
128
139
  params = copy.deepcopy(self.params)
129
140
  configuration_fields = ['hyperparameter']
130
141
  configuration = {field: params.pop(field) for field in configuration_fields}
@@ -26,8 +26,8 @@ def publish(ctx, host, user_token, tenant, debug_modules):
26
26
 
27
27
  data = {'plugin': plugin_release.plugin, 'file': str(archive_path), 'debug': debug}
28
28
  if debug:
29
- if debug_modules:
30
- data['debug_meta'] = json.dumps({'modules': debug_modules.split(',')})
29
+ modules = debug_modules.split(',') if debug_modules else []
30
+ data['debug_meta'] = json.dumps({'modules': modules})
31
31
 
32
32
  client = BackendClient(host, user_token, tenant=tenant)
33
33
  client.create_plugin_release(data)
synapse_sdk/utils/file.py CHANGED
@@ -30,14 +30,17 @@ def download_file(url, path_download, name=None, coerce=None):
30
30
  return path
31
31
 
32
32
 
33
- def files_url_to_path(files, coerce=None):
33
+ def files_url_to_path(files, coerce=None, file_field=None):
34
34
  path_download = Path('/tmp/datamaker') / 'media'
35
35
  path_download.mkdir(parents=True, exist_ok=True)
36
- for file_name in files:
37
- if isinstance(files[file_name], str):
38
- files[file_name] = download_file(files[file_name], path_download, coerce=coerce)
39
- else:
40
- files[file_name]['path'] = download_file(files[file_name].pop('url'), path_download, coerce=coerce)
36
+ if file_field:
37
+ files[file_field] = download_file(files[file_field], path_download, coerce=coerce)
38
+ else:
39
+ for file_name in files:
40
+ if isinstance(files[file_name], str):
41
+ files[file_name] = download_file(files[file_name], path_download, coerce=coerce)
42
+ else:
43
+ files[file_name]['path'] = download_file(files[file_name].pop('url'), path_download, coerce=coerce)
41
44
 
42
45
 
43
46
  def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False, is_async=False):
@@ -51,7 +54,10 @@ def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False,
51
54
  for files_field in files_fields:
52
55
  try:
53
56
  files = reduce(operator.getitem, files_field.split('.'), obj)
54
- files_url_to_path(files, coerce=coerce)
57
+ if isinstance(files, str):
58
+ files_url_to_path(obj, coerce=coerce, file_field=files_field)
59
+ else:
60
+ files_url_to_path(files, coerce=coerce)
55
61
  except KeyError:
56
62
  pass
57
63
 
@@ -78,7 +84,7 @@ async def adownload_file(url, path_download, name=None, coerce=None):
78
84
 
79
85
 
80
86
  async def afiles_url_to_path(files, coerce=None):
81
- path_download = Path('/tmp/datamaker') / 'media'
87
+ path_download = get_temp_path('media')
82
88
  path_download.mkdir(parents=True, exist_ok=True)
83
89
  for file_name in files:
84
90
  if isinstance(files[file_name], str):
@@ -138,3 +144,25 @@ def archive(input_path, output_path):
138
144
  if file_path.is_file(): # Only add files, skip directories
139
145
  arcname = file_path.relative_to(input_path.parent)
140
146
  zipf.write(file_path, arcname)
147
+
148
+
149
+ def unarchive(file_path, output_path):
150
+ """
151
+ Unarchives a ZIP file to a given directory.
152
+
153
+ Parameters:
154
+ file_path (str | Path): The path to the ZIP file.
155
+ output_path (str): The directory where the files will be extracted.
156
+ """
157
+ output_path = Path(output_path)
158
+ output_path.mkdir(parents=True, exist_ok=True)
159
+
160
+ with zipfile.ZipFile(str(file_path), 'r') as zip_ref:
161
+ zip_ref.extractall(output_path)
162
+
163
+
164
+ def get_temp_path(sub_path=None):
165
+ path = Path('/tmp/datamaker')
166
+ if sub_path:
167
+ path = path / sub_path
168
+ return path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a16
3
+ Version: 1.0.0a18
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -19,7 +19,7 @@ synapse_sdk/clients/backend/__init__.py,sha256=50MW1CMWGaKnALSv2fOjhJZG55Xb3yrql
19
19
  synapse_sdk/clients/backend/annotation.py,sha256=eZc5EidgR_RfMGwvv1r1_mLkPdRd8e52c4zuuMjMX34,979
20
20
  synapse_sdk/clients/backend/dataset.py,sha256=a_svyCKgzF7N99l8V4u4wXD8JxiGuLW9z2EBinnz7b8,1738
21
21
  synapse_sdk/clients/backend/integration.py,sha256=Jg_8fEmbrgYXfZZcG8cDtLxR6ugPmnbNhPDyRu_Uib0,2160
22
- synapse_sdk/clients/backend/ml.py,sha256=lg978cCMcPiLN4ByjhrSlJHlw1_kgZQgaNZNKr9zPsI,1054
22
+ synapse_sdk/clients/backend/ml.py,sha256=vNo1FOG9welXGizcnylLSW_-l9iJSQrTI3DhyCCyFKw,1015
23
23
  synapse_sdk/clients/ray/__init__.py,sha256=9ZSPXVVxlJ8Wp8ku7l021ENtPjVrGgQDgqifkkVAXgM,187
24
24
  synapse_sdk/clients/ray/core.py,sha256=a4wyCocAma2HAm-BHlbZnoVbpfdR-Aad2FM0z6vPFvw,731
25
25
  synapse_sdk/clients/ray/serve.py,sha256=rbCpXZYWf0oP8XJ9faa9QFNPYU7h8dltIG8xn9ZconY,907
@@ -30,7 +30,7 @@ synapse_sdk/plugins/models.py,sha256=T3ZuTw7BZwMKpz2QGaErnEPetKRD9d4z3qceJkV363o
30
30
  synapse_sdk/plugins/upload.py,sha256=VJOotYMayylOH0lNoAGeGHRkLdhP7jnC_A0rFQMvQpQ,3228
31
31
  synapse_sdk/plugins/utils.py,sha256=UYkwxkmrs0-mRgQB63SkTGD1HpIQEIiHndzTcpdNaF4,2936
32
32
  synapse_sdk/plugins/categories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
- synapse_sdk/plugins/categories/base.py,sha256=5BrOWXbLiwZw4I1sfElQ5CF12kLDXY97b8MSvpdNIb0,8179
33
+ synapse_sdk/plugins/categories/base.py,sha256=jpwIptMcBBrkrUlzfWUbQDWStm4tOckASGi5Zec-yjA,8179
34
34
  synapse_sdk/plugins/categories/decorators.py,sha256=Gw6T-UHwpCKrSt596X-g2sZbY_Z1zbbogowClj7Pr5Q,518
35
35
  synapse_sdk/plugins/categories/registry.py,sha256=KdQR8SUlLT-3kgYzDNWawS1uJnAhrcw2j4zFaTpilRs,636
36
36
  synapse_sdk/plugins/categories/templates.py,sha256=FF5FerhkZMeW1YcKLY5cylC0SkWSYdJODA_Qcm4OGYQ,887
@@ -48,10 +48,10 @@ synapse_sdk/plugins/categories/import/actions/__init__.py,sha256=47DEQpj8HBSa-_T
48
48
  synapse_sdk/plugins/categories/import/actions/import.py,sha256=URn6TOp081odMT5D4NlZ2XEcyKelJx8fxzdoKSkXSAI,320
49
49
  synapse_sdk/plugins/categories/neural_net/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  synapse_sdk/plugins/categories/neural_net/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
- synapse_sdk/plugins/categories/neural_net/actions/deployment.py,sha256=HeNGfRBIjiw_rRwzoApAuPm6nuT0qEj-BlJBpI8nGKc,1505
51
+ synapse_sdk/plugins/categories/neural_net/actions/deployment.py,sha256=qQ1LKGfmpVcJrmtfxJUxf5Pf3L2-KEb57ReKgSXSM7Q,1706
52
52
  synapse_sdk/plugins/categories/neural_net/actions/inference.py,sha256=i18bDDjkuF9V8nxxW-T_umNIOD-Jnq_MMjIjZc6W8n8,645
53
53
  synapse_sdk/plugins/categories/neural_net/actions/test.py,sha256=JY25eg-Fo6WbgtMkGoo_qNqoaZkp3AQNEypJmeGzEog,320
54
- synapse_sdk/plugins/categories/neural_net/actions/train.py,sha256=7SNhETRw-L-dNEXXANejHMPYCYeqmYjpuUaRFS5vIYA,4554
54
+ synapse_sdk/plugins/categories/neural_net/actions/train.py,sha256=ZjBE4uHOdVZ318BuepBt2l0KvSflLr1Fqt3dt4KYXJs,5113
55
55
  synapse_sdk/plugins/categories/neural_net/templates/config.yaml,sha256=dXKB1hO53hDZB73xnxLVCNQl8Sm7svMmVmuMrOCQmEU,343
56
56
  synapse_sdk/plugins/categories/neural_net/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  synapse_sdk/plugins/categories/neural_net/templates/plugin/inference.py,sha256=InfqKWJYi6sqiUnfPKHC5KYGhxckDaWZNQ202u-uVP4,366
@@ -76,7 +76,7 @@ synapse_sdk/plugins/categories/smart_tool/templates/config.yaml,sha256=3jxW8daip
76
76
  synapse_sdk/plugins/categories/smart_tool/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  synapse_sdk/plugins/categories/smart_tool/templates/plugin/auto_label.py,sha256=eevNg0nOcYFR4z_L_R-sCvVOYoLWSAH1jwDkAf3YCjY,320
78
78
  synapse_sdk/plugins/cli/__init__.py,sha256=LPtUO0jqkhKq6xR1grpse7da2R6OoT_BeDyCNyUY0T4,380
79
- synapse_sdk/plugins/cli/publish.py,sha256=rhUtJsKhYyeDTQlul8mQthfMeNuQCou64faHyaP9y1c,1230
79
+ synapse_sdk/plugins/cli/publish.py,sha256=Kg_MaOeTNCra9BIzWBASsIZxLfhnNkzbRPqdlf6aTyk,1251
80
80
  synapse_sdk/plugins/cli/run.py,sha256=lw1KbsL-xTGllF4NtD2cq-Rh6HMbhi-sO862_Ds-sUo,2330
81
81
  synapse_sdk/plugins/templates/cookiecutter.json,sha256=NxOWk9A_v1pO0Ny4IYT9Cj5iiJ16--cIQrGC67QdR0I,396
82
82
  synapse_sdk/plugins/templates/hooks/post_gen_project.py,sha256=jqlYkY1O2TxIR-Vh3gnwILYy8k-D39Xx66d2KNQVMCs,147
@@ -95,7 +95,7 @@ synapse_sdk/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
95
95
  synapse_sdk/shared/enums.py,sha256=WMZPag9deVF7VCXaQkLk7ly_uX1KwbNzRx9TdvgaeFE,138
96
96
  synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
97
  synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
98
- synapse_sdk/utils/file.py,sha256=y1POYiVg1r7DDcB4HAhnB0GdrjjIPDD6qNfzYupgUjM,4277
98
+ synapse_sdk/utils/file.py,sha256=r7KBH2uKkpj7qWTWT75zHGgm5Vfw3XKzwgkrCBLqTUU,5163
99
99
  synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
100
100
  synapse_sdk/utils/storage.py,sha256=a8OVbd38ATr0El4G4kuV07lr_tJZrpIJBSy4GHb0qZ8,2581
101
101
  synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
@@ -103,9 +103,9 @@ synapse_sdk/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
103
103
  synapse_sdk/utils/pydantic/config.py,sha256=1vYOcUI35GslfD1rrqhFkNXXJOXt4IDqOPSx9VWGfNE,123
104
104
  synapse_sdk/utils/pydantic/errors.py,sha256=0v0T12eQBr1KrFiEOBu6KMaPK4aPEGEC6etPJGoR5b4,1061
105
105
  synapse_sdk/utils/pydantic/validators.py,sha256=G47P8ObPhsePmd_QZDK8EdPnik2CbaYzr_N4Z6En8dc,193
106
- synapse_sdk-1.0.0a16.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
107
- synapse_sdk-1.0.0a16.dist-info/METADATA,sha256=Xied9eLdg3w-l21B9xpFvP-GUULIMIg2YEWOH4_9kZA,1049
108
- synapse_sdk-1.0.0a16.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
109
- synapse_sdk-1.0.0a16.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
110
- synapse_sdk-1.0.0a16.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
111
- synapse_sdk-1.0.0a16.dist-info/RECORD,,
106
+ synapse_sdk-1.0.0a18.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
107
+ synapse_sdk-1.0.0a18.dist-info/METADATA,sha256=f3pDUz--xd-2W8tTimkIm8Smw4wrMRDI7eVli95La1o,1049
108
+ synapse_sdk-1.0.0a18.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
109
+ synapse_sdk-1.0.0a18.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
110
+ synapse_sdk-1.0.0a18.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
111
+ synapse_sdk-1.0.0a18.dist-info/RECORD,,