code-loader 1.0.146__tar.gz → 1.0.148__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.
- {code_loader-1.0.146 → code_loader-1.0.148}/PKG-INFO +1 -1
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/inner_leap_binder/leapbinder_decorators.py +103 -88
- {code_loader-1.0.146 → code_loader-1.0.148}/pyproject.toml +1 -1
- {code_loader-1.0.146 → code_loader-1.0.148}/LICENSE +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/README.md +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/datasetclasses.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/mapping.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/responsedataclasses.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/default_losses.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/default_metrics.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/inner_leap_binder/leapbinder.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/leaploader.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/leaploaderbase.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/mixpanel_tracker.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/plot_functions/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/plot_functions/plot_functions.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/plot_functions/visualize.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/utils.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.146 → code_loader-1.0.148}/code_loader/visualizers/default_visualizers.py +0 -0
{code_loader-1.0.146 → code_loader-1.0.148}/code_loader/inner_leap_binder/leapbinder_decorators.py
RENAMED
|
@@ -31,9 +31,7 @@ import functools
|
|
|
31
31
|
|
|
32
32
|
_called_from_inside_tl_decorator = 0
|
|
33
33
|
_called_from_inside_tl_integration_test_decorator = False
|
|
34
|
-
_call_from_tl_platform=
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
_call_from_tl_platform = os.environ.get('IS_TENSORLEAP_PLATFORM') == 'true'
|
|
37
35
|
|
|
38
36
|
|
|
39
37
|
def validate_args_structure(*args, types_order, func_name, expected_names, **kwargs):
|
|
@@ -94,7 +92,7 @@ def validate_args_structure(*args, types_order, func_name, expected_names, **kwa
|
|
|
94
92
|
)
|
|
95
93
|
|
|
96
94
|
|
|
97
|
-
def validate_output_structure(result, func_name: str, expected_type_name="np.ndarray",gt_flag=False):
|
|
95
|
+
def validate_output_structure(result, func_name: str, expected_type_name="np.ndarray", gt_flag=False):
|
|
98
96
|
if result is None or (isinstance(result, float) and np.isnan(result)):
|
|
99
97
|
if gt_flag:
|
|
100
98
|
raise AssertionError(
|
|
@@ -132,6 +130,7 @@ def validate_output_structure(result, func_name: str, expected_type_name="np.nda
|
|
|
132
130
|
f"{expected_type_name} (e.g., by concatenation or stacking)."
|
|
133
131
|
)
|
|
134
132
|
|
|
133
|
+
|
|
135
134
|
def batch_warning(result, func_name):
|
|
136
135
|
if result.shape[0] == 1:
|
|
137
136
|
warnings.warn(
|
|
@@ -141,6 +140,8 @@ def batch_warning(result, func_name):
|
|
|
141
140
|
f"Please ensure that the output of '{func_name}' is not already batched "
|
|
142
141
|
f"to avoid computation errors."
|
|
143
142
|
)
|
|
143
|
+
|
|
144
|
+
|
|
144
145
|
def _add_mapping_connection(user_unique_name, connection_destinations, arg_names, name, node_mapping_type):
|
|
145
146
|
connection_destinations = [connection_destination for connection_destination in connection_destinations
|
|
146
147
|
if not isinstance(connection_destination, SamplePreprocessResponse)]
|
|
@@ -164,7 +165,7 @@ def tensorleap_integration_test():
|
|
|
164
165
|
leap_binder.integration_test_func = integration_test_function
|
|
165
166
|
|
|
166
167
|
def _validate_input_args(*args, **kwargs):
|
|
167
|
-
sample_id,preprocess_response=args
|
|
168
|
+
sample_id, preprocess_response = args
|
|
168
169
|
assert type(sample_id) == preprocess_response.sample_id_type, (
|
|
169
170
|
f"tensorleap_integration_test validation failed: "
|
|
170
171
|
f"sample_id type ({type(sample_id).__name__}) does not match the expected "
|
|
@@ -173,7 +174,7 @@ def tensorleap_integration_test():
|
|
|
173
174
|
|
|
174
175
|
def inner(*args, **kwargs):
|
|
175
176
|
validate_args_structure(*args, types_order=[Union[int, str], PreprocessResponse],
|
|
176
|
-
func_name='integration_test',expected_names=["idx", "preprocess"]
|
|
177
|
+
func_name='integration_test', expected_names=["idx", "preprocess"], **kwargs)
|
|
177
178
|
_validate_input_args(*args, **kwargs)
|
|
178
179
|
|
|
179
180
|
global _called_from_inside_tl_integration_test_decorator
|
|
@@ -185,7 +186,8 @@ def tensorleap_integration_test():
|
|
|
185
186
|
try:
|
|
186
187
|
_called_from_inside_tl_integration_test_decorator = True
|
|
187
188
|
if not _call_from_tl_platform:
|
|
188
|
-
update_env_params_func("tensorleap_integration_test",
|
|
189
|
+
update_env_params_func("tensorleap_integration_test",
|
|
190
|
+
"v") # put here because otherwise it will become v only if it finishes all the script
|
|
189
191
|
ret = integration_test_function(*args, **kwargs)
|
|
190
192
|
|
|
191
193
|
try:
|
|
@@ -197,16 +199,15 @@ def tensorleap_integration_test():
|
|
|
197
199
|
file_name = Path(first_tb.filename).name
|
|
198
200
|
line_number = first_tb.lineno
|
|
199
201
|
if isinstance(e, TypeError) and 'is not subscriptable' in str(e):
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
f"indexing is supported only on the model's predictions inside the integration test. Please remove this indexing operation usage from the integration test code.")
|
|
202
|
+
update_env_params_func("code_mapping", "x")
|
|
203
|
+
raise (f'Invalid integration code. File {file_name}, line {line_number}: '
|
|
204
|
+
f"indexing is supported only on the model's predictions inside the integration test. Please remove this indexing operation usage from the integration test code.")
|
|
204
205
|
else:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
raise(f'Invalid integration code. File {file_name}, line {line_number}: '
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
update_env_params_func("code_mapping", "x")
|
|
207
|
+
|
|
208
|
+
raise (f'Invalid integration code. File {file_name}, line {line_number}: '
|
|
209
|
+
f'Integration test is only allowed to call Tensorleap decorators. '
|
|
210
|
+
f'Ensure any arithmetics, external library use, Python logic is placed within Tensorleap decoders')
|
|
210
211
|
finally:
|
|
211
212
|
if mapping_runtime_mode_env_var_mame in os.environ:
|
|
212
213
|
del os.environ[mapping_runtime_mode_env_var_mame]
|
|
@@ -214,31 +215,34 @@ def tensorleap_integration_test():
|
|
|
214
215
|
_called_from_inside_tl_integration_test_decorator = False
|
|
215
216
|
|
|
216
217
|
leap_binder.check()
|
|
217
|
-
return inner
|
|
218
218
|
|
|
219
|
+
return inner
|
|
219
220
|
|
|
220
221
|
return decorating_function
|
|
221
222
|
|
|
223
|
+
|
|
222
224
|
def _safe_get_item(key):
|
|
223
225
|
try:
|
|
224
226
|
return NodeMappingType[f'Input{str(key)}']
|
|
225
227
|
except ValueError:
|
|
226
228
|
raise Exception(f'Tensorleap currently supports models with no more then 10 inputs')
|
|
227
229
|
|
|
230
|
+
|
|
228
231
|
def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]] = []):
|
|
229
|
-
assert isinstance(prediction_types, list),(
|
|
232
|
+
assert isinstance(prediction_types, list), (
|
|
230
233
|
f"tensorleap_load_model validation failed: "
|
|
231
|
-
|
|
234
|
+
f" prediction_types is an optional argument of type List[PredictionTypeHandler]] but got {type(prediction_types).__name__}."
|
|
232
235
|
)
|
|
233
236
|
for i, prediction_type in enumerate(prediction_types):
|
|
234
|
-
assert isinstance(prediction_type, PredictionTypeHandler),(f"tensorleap_load_model validation failed: "
|
|
235
|
-
|
|
237
|
+
assert isinstance(prediction_type, PredictionTypeHandler), (f"tensorleap_load_model validation failed: "
|
|
238
|
+
f" prediction_types at position {i} must be of type PredictionTypeHandler but got {type(prediction_types[i]).__name__}.")
|
|
236
239
|
leap_binder.add_prediction(prediction_type.name, prediction_type.labels, prediction_type.channel_dim, i)
|
|
237
240
|
|
|
238
241
|
def _validate_result(result) -> None:
|
|
239
|
-
valid_types=["onnxruntime","keras"]
|
|
240
|
-
err_message=f"tensorleap_load_model validation failed:\nSupported models are Keras and onnxruntime only and non of them was returned."
|
|
241
|
-
validate_output_structure(result, func_name="tensorleap_load_model",
|
|
242
|
+
valid_types = ["onnxruntime", "keras"]
|
|
243
|
+
err_message = f"tensorleap_load_model validation failed:\nSupported models are Keras and onnxruntime only and non of them was returned."
|
|
244
|
+
validate_output_structure(result, func_name="tensorleap_load_model",
|
|
245
|
+
expected_type_name=[" | ".join(t for t in valid_types)][0])
|
|
242
246
|
try:
|
|
243
247
|
import keras
|
|
244
248
|
except ImportError:
|
|
@@ -262,28 +266,39 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
|
|
|
262
266
|
is_onnx_model = bool(onnxruntime and isinstance(result, onnxruntime.InferenceSession))
|
|
263
267
|
|
|
264
268
|
if not any([is_keras_model, is_onnx_model]):
|
|
265
|
-
raise AssertionError(
|
|
266
|
-
|
|
267
|
-
|
|
269
|
+
raise AssertionError(err_message)
|
|
268
270
|
|
|
269
|
-
def decorating_function(load_model_func):
|
|
271
|
+
def decorating_function(load_model_func, prediction_types=prediction_types):
|
|
270
272
|
class TempMapping:
|
|
271
273
|
pass
|
|
272
274
|
|
|
273
275
|
@lru_cache()
|
|
274
276
|
def inner(*args, **kwargs):
|
|
275
277
|
validate_args_structure(*args, types_order=[],
|
|
276
|
-
func_name='tensorleap_load_model',expected_names=[]
|
|
278
|
+
func_name='tensorleap_load_model', expected_names=[], **kwargs)
|
|
279
|
+
|
|
277
280
|
class ModelPlaceholder:
|
|
278
|
-
def __init__(self):
|
|
279
|
-
self.model = load_model_func()
|
|
281
|
+
def __init__(self, prediction_types):
|
|
282
|
+
self.model = load_model_func() # TODO- check why this fails on onnx model
|
|
283
|
+
self.prediction_types = prediction_types
|
|
280
284
|
_validate_result(self.model)
|
|
281
285
|
|
|
282
286
|
# keras interface
|
|
283
287
|
def __call__(self, arg):
|
|
284
288
|
ret = self.model(arg)
|
|
289
|
+
self.validate_declared_prediction_types(ret)
|
|
290
|
+
if isinstance(ret, list):
|
|
291
|
+
return [r.numpy() for r in ret]
|
|
285
292
|
return ret.numpy()
|
|
286
293
|
|
|
294
|
+
def validate_declared_prediction_types(self, ret):
|
|
295
|
+
if not (len(self.prediction_types) == len(ret) if isinstance(ret, list) else 1) or len(
|
|
296
|
+
self.prediction_types) == 0:
|
|
297
|
+
if not _call_from_tl_platform:
|
|
298
|
+
update_env_params_func("tensorleap_load_model", "x")
|
|
299
|
+
raise Exception(
|
|
300
|
+
f"tensorleap_load_model validation failed: number of declared prediction types({len(prediction_types)}) != number of model outputs({len(ret) if isinstance(ret, list) else 1})")
|
|
301
|
+
|
|
287
302
|
def _convert_onnx_inputs_to_correct_type(
|
|
288
303
|
self, float_arrays_inputs: Dict[str, np.ndarray]
|
|
289
304
|
) -> Dict[str, np.ndarray]:
|
|
@@ -337,11 +352,14 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
|
|
|
337
352
|
# onnx runtime interface
|
|
338
353
|
def run(self, output_names, input_dict):
|
|
339
354
|
corrected_type_inputs = self._convert_onnx_inputs_to_correct_type(input_dict)
|
|
340
|
-
|
|
355
|
+
ret = self.model.run(output_names, corrected_type_inputs)
|
|
356
|
+
self.validate_declared_prediction_types(ret)
|
|
357
|
+
return ret
|
|
341
358
|
|
|
342
359
|
def get_inputs(self):
|
|
343
360
|
return self.model.get_inputs()
|
|
344
|
-
|
|
361
|
+
|
|
362
|
+
model_placeholder = ModelPlaceholder(prediction_types)
|
|
345
363
|
if not _call_from_tl_platform:
|
|
346
364
|
update_env_params_func("tensorleap_load_model", "v")
|
|
347
365
|
return model_placeholder
|
|
@@ -391,7 +409,7 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
|
|
|
391
409
|
def get_inputs(self):
|
|
392
410
|
class FollowIndex:
|
|
393
411
|
def __init__(self, index):
|
|
394
|
-
self.name =
|
|
412
|
+
self.name = _safe_get_item(index)
|
|
395
413
|
|
|
396
414
|
class FollowInputIndex:
|
|
397
415
|
def __init__(self):
|
|
@@ -412,6 +430,7 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
|
|
|
412
430
|
return mapping_inner()
|
|
413
431
|
else:
|
|
414
432
|
return inner(*args, **kwargs)
|
|
433
|
+
|
|
415
434
|
return final_inner
|
|
416
435
|
|
|
417
436
|
return decorating_function
|
|
@@ -422,6 +441,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
422
441
|
compute_insights: Optional[Union[bool, Dict[str, bool]]] = None,
|
|
423
442
|
connects_to=None):
|
|
424
443
|
name_to_unique_name = defaultdict(set)
|
|
444
|
+
|
|
425
445
|
def decorating_function(
|
|
426
446
|
user_function: Union[CustomCallableInterfaceMultiArgs, CustomMultipleReturnCallableInterfaceMultiArgs,
|
|
427
447
|
ConfusionMatrixCallableInterfaceMultiArgs]):
|
|
@@ -494,7 +514,6 @@ def tensorleap_custom_metric(name: str,
|
|
|
494
514
|
f"but found element types: {invalid_elems}."
|
|
495
515
|
)
|
|
496
516
|
|
|
497
|
-
|
|
498
517
|
_validate_decorators_signature()
|
|
499
518
|
|
|
500
519
|
for metric_handler in leap_binder.setup_container.metrics:
|
|
@@ -503,7 +522,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
503
522
|
f'Please choose another')
|
|
504
523
|
|
|
505
524
|
def _validate_input_args(*args, **kwargs) -> None:
|
|
506
|
-
assert len(args)+len(kwargs) > 0, (
|
|
525
|
+
assert len(args) + len(kwargs) > 0, (
|
|
507
526
|
f"{user_function.__name__}() validation failed: "
|
|
508
527
|
f"Expected at least one positional|key-word argument of type np.ndarray, "
|
|
509
528
|
f"but received none. "
|
|
@@ -536,7 +555,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
536
555
|
f'{user_function.__name__}() has returned unsupported type.\nSupported types are List[float|int|None], '
|
|
537
556
|
f'List[List[ConfusionMatrixElement]], NDArray[np.float32] or dictonary with one of these types as its values types. ')
|
|
538
557
|
|
|
539
|
-
def _validate_single_metric(single_metric_result,key=None):
|
|
558
|
+
def _validate_single_metric(single_metric_result, key=None):
|
|
540
559
|
if isinstance(single_metric_result, list):
|
|
541
560
|
if isinstance(single_metric_result[0], list):
|
|
542
561
|
assert all(isinstance(cm, ConfusionMatrixElement) for cm in single_metric_result[0]), (
|
|
@@ -546,7 +565,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
546
565
|
)
|
|
547
566
|
|
|
548
567
|
else:
|
|
549
|
-
assert all(isinstance(v, (float,int,type(None),np.float32)) for v in single_metric_result), (
|
|
568
|
+
assert all(isinstance(v, (float, int, type(None), np.float32)) for v in single_metric_result), (
|
|
550
569
|
f"{supported_types_message}\n"
|
|
551
570
|
f"Got {'a dict where the value of ' + str(key) + ' is of type ' if key is not None else ''}"
|
|
552
571
|
f"List[{', '.join(type(v).__name__ for v in single_metric_result)}]."
|
|
@@ -563,7 +582,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
563
582
|
|
|
564
583
|
if isinstance(result, dict):
|
|
565
584
|
for key, value in result.items():
|
|
566
|
-
_validate_single_metric(value,key)
|
|
585
|
+
_validate_single_metric(value, key)
|
|
567
586
|
|
|
568
587
|
assert isinstance(key, str), \
|
|
569
588
|
(f'{user_function.__name__}() validation failed: '
|
|
@@ -624,7 +643,7 @@ def tensorleap_custom_metric(name: str,
|
|
|
624
643
|
|
|
625
644
|
_validate_result(result)
|
|
626
645
|
if not _call_from_tl_platform:
|
|
627
|
-
update_env_params_func("tensorleap_custom_metric","v")
|
|
646
|
+
update_env_params_func("tensorleap_custom_metric", "v")
|
|
628
647
|
return result
|
|
629
648
|
|
|
630
649
|
def mapping_inner(*args, **kwargs):
|
|
@@ -664,9 +683,9 @@ def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
|
|
|
664
683
|
name_to_unique_name = defaultdict(set)
|
|
665
684
|
|
|
666
685
|
def decorating_function(user_function: VisualizerCallableInterface):
|
|
667
|
-
assert isinstance(visualizer_type,LeapDataType),(f"{user_function.__name__} validation failed: "
|
|
668
|
-
|
|
669
|
-
|
|
686
|
+
assert isinstance(visualizer_type, LeapDataType), (f"{user_function.__name__} validation failed: "
|
|
687
|
+
f"visualizer_type should be of type {LeapDataType.__name__} but got {type(visualizer_type)}"
|
|
688
|
+
)
|
|
670
689
|
|
|
671
690
|
for viz_handler in leap_binder.setup_container.visualizers:
|
|
672
691
|
if viz_handler.visualizer_handler_data.name == name:
|
|
@@ -746,7 +765,7 @@ def tensorleap_custom_visualizer(name: str, visualizer_type: LeapDataType,
|
|
|
746
765
|
|
|
747
766
|
_validate_result(result)
|
|
748
767
|
if not _call_from_tl_platform:
|
|
749
|
-
update_env_params_func("tensorleap_custom_visualizer","v")
|
|
768
|
+
update_env_params_func("tensorleap_custom_visualizer", "v")
|
|
750
769
|
return result
|
|
751
770
|
|
|
752
771
|
def mapping_inner(*args, **kwargs):
|
|
@@ -824,19 +843,19 @@ def tensorleap_metadata(
|
|
|
824
843
|
|
|
825
844
|
leap_binder.set_metadata(inner_without_validate, name, metadata_type)
|
|
826
845
|
|
|
827
|
-
def inner(*args
|
|
846
|
+
def inner(*args, **kwargs):
|
|
828
847
|
if os.environ.get(mapping_runtime_mode_env_var_mame):
|
|
829
848
|
return None
|
|
830
849
|
validate_args_structure(*args, types_order=[Union[int, str], PreprocessResponse],
|
|
831
|
-
func_name=user_function.__name__, expected_names=["idx", "preprocess"]
|
|
832
|
-
sample_id, preprocess_response = args if len(args)!=0 else
|
|
850
|
+
func_name=user_function.__name__, expected_names=["idx", "preprocess"], **kwargs)
|
|
851
|
+
sample_id, preprocess_response = args if len(args) != 0 else kwargs.values()
|
|
833
852
|
_validate_input_args(sample_id, preprocess_response)
|
|
834
853
|
|
|
835
854
|
result = inner_without_validate(sample_id, preprocess_response)
|
|
836
855
|
|
|
837
856
|
_validate_result(result)
|
|
838
857
|
if not _call_from_tl_platform:
|
|
839
|
-
update_env_params_func("tensorleap_metadata","v")
|
|
858
|
+
update_env_params_func("tensorleap_metadata", "v")
|
|
840
859
|
return result
|
|
841
860
|
|
|
842
861
|
return inner
|
|
@@ -844,7 +863,6 @@ def tensorleap_metadata(
|
|
|
844
863
|
return decorating_function
|
|
845
864
|
|
|
846
865
|
|
|
847
|
-
|
|
848
866
|
def tensorleap_custom_latent_space():
|
|
849
867
|
def decorating_function(user_function: SectionCallableInterface):
|
|
850
868
|
def _validate_input_args(sample_id: Union[int, str], preprocess_response: PreprocessResponse):
|
|
@@ -996,6 +1014,8 @@ def tensorleap_element_instance_preprocess(
|
|
|
996
1014
|
|
|
997
1015
|
result = user_function_instance()
|
|
998
1016
|
_validate_result(result)
|
|
1017
|
+
if not _call_from_tl_platform:
|
|
1018
|
+
update_env_params_func("tensorleap_preprocess", "v")
|
|
999
1019
|
return result
|
|
1000
1020
|
|
|
1001
1021
|
return inner
|
|
@@ -1078,6 +1098,7 @@ def tensorleap_instances_masks_encoder(name: str):
|
|
|
1078
1098
|
|
|
1079
1099
|
return decorating_function
|
|
1080
1100
|
|
|
1101
|
+
|
|
1081
1102
|
def tensorleap_instances_length_encoder(name: str):
|
|
1082
1103
|
def decorating_function(user_function: InstanceLengthCallableInterface):
|
|
1083
1104
|
def _validate_input_args(sample_id: str, preprocess_response: PreprocessResponse):
|
|
@@ -1123,6 +1144,7 @@ def tensorleap_instances_length_encoder(name: str):
|
|
|
1123
1144
|
|
|
1124
1145
|
return decorating_function
|
|
1125
1146
|
|
|
1147
|
+
|
|
1126
1148
|
def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
|
|
1127
1149
|
def decorating_function(user_function: SectionCallableInterface):
|
|
1128
1150
|
for input_handler in leap_binder.setup_container.inputs:
|
|
@@ -1139,7 +1161,7 @@ def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
|
|
|
1139
1161
|
f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
|
|
1140
1162
|
|
|
1141
1163
|
def _validate_result(result):
|
|
1142
|
-
validate_output_structure(result, func_name=user_function.__name__, expected_type_name
|
|
1164
|
+
validate_output_structure(result, func_name=user_function.__name__, expected_type_name="np.ndarray")
|
|
1143
1165
|
assert isinstance(result, np.ndarray), \
|
|
1144
1166
|
(f'{user_function.__name__}() validation failed: '
|
|
1145
1167
|
f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
|
|
@@ -1162,11 +1184,10 @@ def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
|
|
|
1162
1184
|
|
|
1163
1185
|
leap_binder.set_input(inner_without_validate, name, channel_dim=channel_dim)
|
|
1164
1186
|
|
|
1165
|
-
|
|
1166
1187
|
def inner(*args, **kwargs):
|
|
1167
1188
|
validate_args_structure(*args, types_order=[Union[int, str], PreprocessResponse],
|
|
1168
|
-
func_name=user_function.__name__,
|
|
1169
|
-
sample_id, preprocess_response = args if len(args)!=0 else
|
|
1189
|
+
func_name=user_function.__name__, expected_names=["idx", "preprocess"], **kwargs)
|
|
1190
|
+
sample_id, preprocess_response = args if len(args) != 0 else kwargs.values()
|
|
1170
1191
|
_validate_input_args(sample_id, preprocess_response)
|
|
1171
1192
|
|
|
1172
1193
|
result = inner_without_validate(sample_id, preprocess_response)
|
|
@@ -1174,7 +1195,7 @@ def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
|
|
|
1174
1195
|
_validate_result(result)
|
|
1175
1196
|
|
|
1176
1197
|
if _called_from_inside_tl_decorator == 0 and _called_from_inside_tl_integration_test_decorator:
|
|
1177
|
-
batch_warning(result,user_function.__name__)
|
|
1198
|
+
batch_warning(result, user_function.__name__)
|
|
1178
1199
|
result = np.expand_dims(result, axis=0)
|
|
1179
1200
|
# Emit integration test event once per test
|
|
1180
1201
|
try:
|
|
@@ -1190,7 +1211,6 @@ def tensorleap_input_encoder(name: str, channel_dim=-1, model_input_index=None):
|
|
|
1190
1211
|
|
|
1191
1212
|
return result
|
|
1192
1213
|
|
|
1193
|
-
|
|
1194
1214
|
node_mapping_type = NodeMappingType.Input
|
|
1195
1215
|
if model_input_index is not None:
|
|
1196
1216
|
node_mapping_type = NodeMappingType(f'Input{str(model_input_index)}')
|
|
@@ -1235,7 +1255,8 @@ def tensorleap_gt_encoder(name: str):
|
|
|
1235
1255
|
f'{preprocess_response.sample_id_type}. Got {type(sample_id)}.')
|
|
1236
1256
|
|
|
1237
1257
|
def _validate_result(result):
|
|
1238
|
-
validate_output_structure(result, func_name=user_function.__name__, expected_type_name
|
|
1258
|
+
validate_output_structure(result, func_name=user_function.__name__, expected_type_name="np.ndarray",
|
|
1259
|
+
gt_flag=True)
|
|
1239
1260
|
assert isinstance(result, np.ndarray), \
|
|
1240
1261
|
(f'{user_function.__name__}() validation failed: '
|
|
1241
1262
|
f'Unsupported return type. Should be a numpy array. Got {type(result)}.')
|
|
@@ -1256,7 +1277,6 @@ def tensorleap_gt_encoder(name: str):
|
|
|
1256
1277
|
|
|
1257
1278
|
leap_binder.set_ground_truth(inner_without_validate, name)
|
|
1258
1279
|
|
|
1259
|
-
|
|
1260
1280
|
def inner(*args, **kwargs):
|
|
1261
1281
|
validate_args_structure(*args, types_order=[Union[int, str], PreprocessResponse],
|
|
1262
1282
|
func_name=user_function.__name__, expected_names=["idx", "preprocess"], **kwargs)
|
|
@@ -1321,26 +1341,16 @@ def tensorleap_custom_loss(name: str, connects_to=None):
|
|
|
1321
1341
|
def _validate_input_args(*args, **kwargs):
|
|
1322
1342
|
assert len(args) + len(kwargs) > 0, (
|
|
1323
1343
|
f"{user_function.__name__}() validation failed: "
|
|
1324
|
-
f"Expected at least one positional|key-word argument of the allowed types (np.ndarray|SamplePreprocessResponse|
|
|
1344
|
+
f"Expected at least one positional|key-word argument of the allowed types (np.ndarray|SamplePreprocessResponse|). "
|
|
1325
1345
|
f"but received none. "
|
|
1326
1346
|
f"Correct usage example: {user_function.__name__}(input_array: np.ndarray, ...)"
|
|
1327
1347
|
)
|
|
1328
1348
|
for i, arg in enumerate(args):
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
assert isinstance(elem, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1332
|
-
f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
|
|
1333
|
-
else:
|
|
1334
|
-
assert isinstance(arg, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1335
|
-
f'Argument #{i} should be a numpy array. Got {type(arg)}.')
|
|
1349
|
+
assert isinstance(arg, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1350
|
+
f'Argument #{i} should be a numpy array. Got {type(arg)}.')
|
|
1336
1351
|
for _arg_name, arg in kwargs.items():
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
assert isinstance(elem, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1340
|
-
f'Element #{y} of list should be a numpy array. Got {type(elem)}.')
|
|
1341
|
-
else:
|
|
1342
|
-
assert isinstance(arg, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1343
|
-
f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
|
|
1352
|
+
assert isinstance(arg, valid_types), (f'{user_function.__name__}() validation failed: '
|
|
1353
|
+
f'Argument #{_arg_name} should be a numpy array. Got {type(arg)}.')
|
|
1344
1354
|
|
|
1345
1355
|
def _validate_result(result):
|
|
1346
1356
|
validate_output_structure(result, func_name=user_function.__name__,
|
|
@@ -1348,8 +1358,8 @@ def tensorleap_custom_loss(name: str, connects_to=None):
|
|
|
1348
1358
|
assert isinstance(result, np.ndarray), \
|
|
1349
1359
|
(f'{user_function.__name__} validation failed: '
|
|
1350
1360
|
f'The return type should be a numpy array. Got {type(result)}.')
|
|
1351
|
-
assert
|
|
1352
|
-
|
|
1361
|
+
assert result.ndim < 2, (f'{user_function.__name__} validation failed: '
|
|
1362
|
+
f'The return type should be a 1Dim numpy array but got {result.ndim}Dim.')
|
|
1353
1363
|
|
|
1354
1364
|
@functools.wraps(user_function)
|
|
1355
1365
|
def inner_without_validate(*args, **kwargs):
|
|
@@ -1460,7 +1470,7 @@ def tensorleap_status_table():
|
|
|
1460
1470
|
import traceback
|
|
1461
1471
|
CHECK = "✅"
|
|
1462
1472
|
CROSS = "❌"
|
|
1463
|
-
code_mapping_failure=[0]
|
|
1473
|
+
code_mapping_failure = [0]
|
|
1464
1474
|
table = [
|
|
1465
1475
|
{"name": "tensorleap_preprocess", "Added to integration": CROSS},
|
|
1466
1476
|
{"name": "tensorleap_integration_test", "Added to integration": CROSS},
|
|
@@ -1477,7 +1487,7 @@ def tensorleap_status_table():
|
|
|
1477
1487
|
_finalizer_called = {"done": False}
|
|
1478
1488
|
|
|
1479
1489
|
def _remove_suffix(s: str, suffix: str) -> str:
|
|
1480
|
-
#This is needed because str.remove_suffix was presented in python3.9+
|
|
1490
|
+
# This is needed because str.remove_suffix was presented in python3.9+
|
|
1481
1491
|
if suffix and s.endswith(suffix):
|
|
1482
1492
|
return s[:-len(suffix)]
|
|
1483
1493
|
return s
|
|
@@ -1486,7 +1496,7 @@ def tensorleap_status_table():
|
|
|
1486
1496
|
ready_mess = "\nAll parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system."
|
|
1487
1497
|
not_ready_mess = "\nSome mandatory components have not yet been added to the Integration test. Recommended next interface to add is: "
|
|
1488
1498
|
mandatory_ready_mess = "\nAll mandatory parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system or continue to the next optional reccomeded interface,adding: "
|
|
1489
|
-
code_mapping_failure_mes= "Tensorleap_integration_test code flow failed, check raised exception."
|
|
1499
|
+
code_mapping_failure_mes = "Tensorleap_integration_test code flow failed, check raised exception."
|
|
1490
1500
|
|
|
1491
1501
|
name_width = max(len(row["name"]) for row in table)
|
|
1492
1502
|
status_width = max(len(row["Added to integration"]) for row in table)
|
|
@@ -1494,32 +1504,37 @@ def tensorleap_status_table():
|
|
|
1494
1504
|
sep = "-" * len(header)
|
|
1495
1505
|
print("\n" + header)
|
|
1496
1506
|
print(sep)
|
|
1497
|
-
ready=True
|
|
1507
|
+
ready = True
|
|
1498
1508
|
for row in table:
|
|
1499
1509
|
print(f"{row['name'].ljust(name_width)} | {row['Added to integration'].ljust(status_width)}")
|
|
1500
|
-
if row['Added to integration']==CROSS and ready:
|
|
1501
|
-
ready=False
|
|
1502
|
-
next_step=row['name']
|
|
1510
|
+
if row['Added to integration'] == CROSS and ready:
|
|
1511
|
+
ready = False
|
|
1512
|
+
next_step = row['name']
|
|
1503
1513
|
|
|
1504
|
-
if code_mapping_failure:
|
|
1505
|
-
print(f"\n{
|
|
1514
|
+
if code_mapping_failure[0]:
|
|
1515
|
+
print(f"\n{CROSS + code_mapping_failure_mes}.")
|
|
1506
1516
|
else:
|
|
1507
|
-
print(ready_mess) if ready else print(
|
|
1517
|
+
print(ready_mess) if ready else print(
|
|
1518
|
+
mandatory_ready_mess + next_step) if "optional" in next_step else print(not_ready_mess + next_step)
|
|
1519
|
+
|
|
1508
1520
|
def update_env_params(name: str, status: str = "✓"):
|
|
1509
1521
|
for row in table:
|
|
1510
|
-
if _remove_suffix(row["name"]," (optional)") == name:
|
|
1511
|
-
row["Added to integration"] = CHECK if status=="v" else CROSS
|
|
1522
|
+
if _remove_suffix(row["name"], " (optional)") == name:
|
|
1523
|
+
row["Added to integration"] = CHECK if status == "v" else CROSS
|
|
1512
1524
|
break
|
|
1513
|
-
if name=="code_mapping":
|
|
1514
|
-
code_mapping_failure[0]=1
|
|
1525
|
+
if name == "code_mapping":
|
|
1526
|
+
code_mapping_failure[0] = 1
|
|
1527
|
+
|
|
1515
1528
|
def run_on_exit():
|
|
1516
1529
|
if _finalizer_called["done"]:
|
|
1517
1530
|
return
|
|
1518
1531
|
_finalizer_called["done"] = True
|
|
1519
1532
|
_print_table()
|
|
1533
|
+
|
|
1520
1534
|
def handle_exception(exc_type, exc_value, exc_traceback):
|
|
1521
1535
|
traceback.print_exception(exc_type, exc_value, exc_traceback)
|
|
1522
1536
|
run_on_exit()
|
|
1537
|
+
|
|
1523
1538
|
atexit.register(run_on_exit)
|
|
1524
1539
|
sys.excepthook = handle_exception
|
|
1525
1540
|
return update_env_params
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/experiment_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.146 → code_loader-1.0.148}/code_loader/experiment_api/workingspace_config_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|