code-loader 1.0.58__py3-none-any.whl → 1.0.59__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.
- code_loader/code_inegration_processes_manager.py +83 -0
- code_loader/inner_leap_binder/leapbinder_decorators.py +3 -3
- code_loader/leaploader.py +3 -5
- {code_loader-1.0.58.dist-info → code_loader-1.0.59.dist-info}/METADATA +1 -1
- {code_loader-1.0.58.dist-info → code_loader-1.0.59.dist-info}/RECORD +7 -7
- code_loader/dualstream.py +0 -32
- {code_loader-1.0.58.dist-info → code_loader-1.0.59.dist-info}/LICENSE +0 -0
- {code_loader-1.0.58.dist-info → code_loader-1.0.59.dist-info}/WHEEL +0 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
# mypy: ignore-errors
|
2
|
+
import traceback
|
3
|
+
from dataclasses import dataclass
|
4
|
+
|
5
|
+
from typing import List, Tuple, Optional
|
6
|
+
|
7
|
+
from multiprocessing import Process, Queue
|
8
|
+
|
9
|
+
from code_loader.leap_loader_parallelized_base import LeapLoaderParallelizedBase
|
10
|
+
from code_loader.leaploader import LeapLoader
|
11
|
+
from code_loader.contract.enums import DataStateEnum
|
12
|
+
from code_loader.metric_calculator_parallelized import MetricCalculatorParallelized
|
13
|
+
from code_loader.samples_generator_parallelized import SamplesGeneratorParallelized
|
14
|
+
|
15
|
+
|
16
|
+
@dataclass
|
17
|
+
class SampleSerializableError:
|
18
|
+
state: DataStateEnum
|
19
|
+
index: int
|
20
|
+
leap_script_trace: str
|
21
|
+
exception_as_str: str
|
22
|
+
|
23
|
+
|
24
|
+
class CodeIntegrationProcessesManager:
|
25
|
+
def __init__(self, code_path: str, code_entry_name: str, n_workers: Optional[int] = 2,
|
26
|
+
max_samples_in_queue: int = 128) -> None:
|
27
|
+
self.metric_calculator_parallelized = MetricCalculatorParallelized(code_path, code_entry_name)
|
28
|
+
self.samples_generator_parallelized = SamplesGeneratorParallelized(code_path, code_entry_name)
|
29
|
+
|
30
|
+
def _create_and_start_process(self) -> Process:
|
31
|
+
process = self.multiprocessing_context.Process(
|
32
|
+
target=CodeIntegrationProcessesManager._process_func,
|
33
|
+
args=(self.code_path, self.code_entry_name, self._inputs_waiting_to_be_process,
|
34
|
+
self._ready_processed_results))
|
35
|
+
process.daemon = True
|
36
|
+
process.start()
|
37
|
+
return process
|
38
|
+
|
39
|
+
def _run_and_warm_first_process(self):
|
40
|
+
process = self._create_and_start_process()
|
41
|
+
self.processes = [process]
|
42
|
+
|
43
|
+
# needed in order to make sure the preprocess func runs once in nonparallel
|
44
|
+
self._start_process_inputs([(DataStateEnum.training, 0)])
|
45
|
+
self._get_next_ready_processed_result()
|
46
|
+
|
47
|
+
def _operation_decider(self):
|
48
|
+
if self.metric_calculator_parallelized._ready_processed_results.empty() and not \
|
49
|
+
self.metric_calculator_parallelized._inputs_waiting_to_be_process.empty():
|
50
|
+
return 'metric'
|
51
|
+
|
52
|
+
if self.samples_generator_parallelized._ready_processed_results.empty() and not \
|
53
|
+
self.samples_generator_parallelized._inputs_waiting_to_be_process.empty():
|
54
|
+
return 'dataset'
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
@staticmethod
|
60
|
+
def _process_func(code_path: str, code_entry_name: str,
|
61
|
+
samples_to_process: Queue, ready_samples: Queue,
|
62
|
+
metrics_to_process: Queue, ready_metrics: Queue) -> None:
|
63
|
+
import os
|
64
|
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
65
|
+
|
66
|
+
leap_loader = LeapLoader(code_path, code_entry_name)
|
67
|
+
while True:
|
68
|
+
|
69
|
+
# decide on sample or metric to process
|
70
|
+
state, idx = samples_to_process.get(block=True)
|
71
|
+
leap_loader._preprocess_result()
|
72
|
+
try:
|
73
|
+
sample = leap_loader.get_sample(state, idx)
|
74
|
+
except Exception as e:
|
75
|
+
leap_script_trace = traceback.format_exc().split('File "<string>"')[-1]
|
76
|
+
ready_samples.put(SampleSerializableError(state, idx, leap_script_trace, str(e)))
|
77
|
+
continue
|
78
|
+
|
79
|
+
ready_samples.put(sample)
|
80
|
+
|
81
|
+
def generate_samples(self, sample_identities: List[Tuple[DataStateEnum, int]]):
|
82
|
+
return self.start_process_inputs(sample_identities)
|
83
|
+
|
@@ -357,9 +357,9 @@ def tensorleap_custom_loss(name: str):
|
|
357
357
|
(f'tensorleap_custom_loss validation failed: '
|
358
358
|
f'The return type should be a numpy array or a tensorflow tensor. Got {type(result)}.')
|
359
359
|
|
360
|
-
def inner(
|
361
|
-
_validate_input_args(
|
362
|
-
result = user_function(
|
360
|
+
def inner(*args, **kwargs):
|
361
|
+
_validate_input_args(*args, **kwargs)
|
362
|
+
result = user_function(*args, **kwargs)
|
363
363
|
_validate_result(result)
|
364
364
|
return result
|
365
365
|
|
code_loader/leaploader.py
CHANGED
@@ -19,7 +19,6 @@ from code_loader.contract.exceptions import DatasetScriptException
|
|
19
19
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
20
20
|
DatasetPreprocess, DatasetSetup, DatasetInputInstance, DatasetOutputInstance, DatasetMetadataInstance, \
|
21
21
|
VisualizerInstance, PredictionTypeInstance, ModelSetup, CustomLayerInstance, MetricInstance, CustomLossInstance
|
22
|
-
from code_loader.dualstream import DualStream
|
23
22
|
from code_loader.inner_leap_binder import global_leap_binder
|
24
23
|
from code_loader.utils import get_root_exception_file_and_line_number
|
25
24
|
|
@@ -124,9 +123,8 @@ class LeapLoader:
|
|
124
123
|
test_payloads: List[DatasetTestResultPayload] = []
|
125
124
|
setup_response = None
|
126
125
|
general_error = None
|
127
|
-
|
128
|
-
|
129
|
-
with redirect_stdout(dual_stream):
|
126
|
+
stdout_steam = io.StringIO()
|
127
|
+
with redirect_stdout(stdout_steam):
|
130
128
|
try:
|
131
129
|
self.exec_script()
|
132
130
|
preprocess_test_payload = self._check_preprocess()
|
@@ -144,7 +142,7 @@ class LeapLoader:
|
|
144
142
|
general_error = f"Something went wrong. {repr(e.__cause__)} in file {file_name}, line_number: {line_number}\nStacktrace:\n{stacktrace}"
|
145
143
|
is_valid = False
|
146
144
|
|
147
|
-
print_log =
|
145
|
+
print_log = stdout_steam.getvalue()
|
148
146
|
is_valid_for_model = bool(global_leap_binder.setup_container.custom_layers)
|
149
147
|
model_setup = self.get_model_setup_response()
|
150
148
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
2
2
|
code_loader/__init__.py,sha256=6MMWr0ObOU7hkqQKgOqp4Zp3I28L7joGC9iCbQYtAJg,241
|
3
|
+
code_loader/code_inegration_processes_manager.py,sha256=XslWOPeNQk4RAFJ_f3tP5Oe3EgcIR7BE7Y8r9Ty73-o,3261
|
3
4
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
5
|
code_loader/contract/datasetclasses.py,sha256=lFS7_weizsjzx4_tYwYGrrRUj1sgIl010h9FON4brb8,6670
|
5
6
|
code_loader/contract/enums.py,sha256=6Lo7p5CUog68Fd31bCozIuOgIp_IhSiPqWWph2k3OGU,1602
|
6
7
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
7
8
|
code_loader/contract/responsedataclasses.py,sha256=w7xVOv2S8Hyb5lqyomMGiKAWXDTSOG-FX1YW39bXD3A,3969
|
8
9
|
code_loader/contract/visualizer_classes.py,sha256=iIa_O2rKvPTwN5ILCTZvRpsGYiiFABKdwQwfIXGigDo,11928
|
9
|
-
code_loader/dualstream.py,sha256=mlpwTEiFSHFMg2xd9Gd3pv5n0HLWdRAxA-kbtdhRt4M,807
|
10
10
|
code_loader/experiment_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
11
|
code_loader/experiment_api/api.py,sha256=a7wh6Hhe7IaVxu46eV2soSz-yxnmXG3ipU1BBtsEAaQ,2493
|
12
12
|
code_loader/experiment_api/cli_config_utils.py,sha256=n6JMyNrquxql3KKxHhAP8jAzezlRT-PV2KWI95kKsm0,1140
|
@@ -19,12 +19,12 @@ code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZ
|
|
19
19
|
code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
|
20
20
|
code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
|
21
21
|
code_loader/inner_leap_binder/leapbinder.py,sha256=35hyesDdmjOD9wdrTLyayb-vm9aDfmEbMA0c4EQR1LA,25090
|
22
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
23
|
-
code_loader/leaploader.py,sha256=
|
22
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=uuM_ht9HZ1GH2IabKeGQ_x9NmD3poK_h1Gt0NruwJuY,19704
|
23
|
+
code_loader/leaploader.py,sha256=POUgD6x1GH_iF_eDGz-VLX4DsIl2kddufKVDdrA_K-U,19491
|
24
24
|
code_loader/utils.py,sha256=aw2i_fqW_ADjLB66FWZd9DfpCQ7mPdMyauROC5Nd51I,2197
|
25
25
|
code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
26
26
|
code_loader/visualizers/default_visualizers.py,sha256=VoqO9FN84yXyMjRjHjUTOt2GdTkJRMbHbXJ1cJkREkk,2230
|
27
|
-
code_loader-1.0.
|
28
|
-
code_loader-1.0.
|
29
|
-
code_loader-1.0.
|
30
|
-
code_loader-1.0.
|
27
|
+
code_loader-1.0.59.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
28
|
+
code_loader-1.0.59.dist-info/METADATA,sha256=F3b6BUv0E3jFu6ciMsIu0EzSPQMlnP1aKKG7GGSTu0I,888
|
29
|
+
code_loader-1.0.59.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
30
|
+
code_loader-1.0.59.dist-info/RECORD,,
|
code_loader/dualstream.py
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
from io import StringIO
|
2
|
-
from typing import IO
|
3
|
-
|
4
|
-
|
5
|
-
class DualStream(StringIO):
|
6
|
-
def __init__(self, stream1: IO[str], stream2: StringIO):
|
7
|
-
super().__init__()
|
8
|
-
self.stream1 = stream1 # Usually sys.stdout
|
9
|
-
self.stream2 = stream2 # The StringIO stream
|
10
|
-
|
11
|
-
def write(self, s: str) -> int:
|
12
|
-
# Write to both streams and return the length of the written string
|
13
|
-
self.stream1.write(s)
|
14
|
-
self.stream2.write(s)
|
15
|
-
return len(s)
|
16
|
-
|
17
|
-
def flush(self) -> None:
|
18
|
-
self.stream1.flush()
|
19
|
-
self.stream2.flush()
|
20
|
-
|
21
|
-
def close(self) -> None:
|
22
|
-
# Do not close sys.stdout
|
23
|
-
self.stream2.close()
|
24
|
-
|
25
|
-
def readable(self) -> bool:
|
26
|
-
return False
|
27
|
-
|
28
|
-
def writable(self) -> bool:
|
29
|
-
return True
|
30
|
-
|
31
|
-
def seekable(self) -> bool:
|
32
|
-
return False
|
File without changes
|
File without changes
|