Skip to content

Commit c11937d

Browse files
fix tests
1 parent 03ec110 commit c11937d

19 files changed

Lines changed: 724 additions & 322 deletions

src/main/python/systemds/scuro/dataloader/audio_loader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class AudioStats:
3434
max_length: int
3535
avg_length: float
3636
num_instances: int
37+
output_shape_is_known: bool
3738

3839
@property
3940
def output_shape(self):
@@ -91,4 +92,4 @@ def get_stats(self, source_path: str):
9192
max_length = max(max_length, audio.shape[0])
9293
avg_length += audio.shape[0]
9394
avg_length /= num_instances
94-
return AudioStats(sampling_rate, max_length, avg_length, num_instances)
95+
return AudioStats(sampling_rate, max_length, avg_length, num_instances, True)

src/main/python/systemds/scuro/dataloader/timeseries_loader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class TimeseriesStats:
3434
max_length: int
3535
num_instances: int
3636
num_signals: int
37+
output_shape: tuple
38+
output_shape_is_known: bool
3739

3840

3941
class TimeseriesLoader(BaseLoader):

src/main/python/systemds/scuro/dataloader/video_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class VideoStats:
3535
max_length: int
3636
max_width: int
3737
max_height: int
38-
max_num_channels: int
38+
max_channels: int
3939
num_instances: int
4040

4141
@property
@@ -48,7 +48,7 @@ def output_shape(self):
4848
the per-instance tensor shape. For videos we approximate this as
4949
(max_length, max_height, max_width, max_num_channels).
5050
"""
51-
return (self.max_length, self.max_height, self.max_width, self.max_num_channels)
51+
return (self.max_length, self.max_height, self.max_width, self.max_channels)
5252

5353

5454
class VideoLoader(BaseLoader):

src/main/python/systemds/scuro/drsearch/node_executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
from systemds.scuro.representations.representation import RepresentationStats
4848
from systemds.scuro.representations.unimodal import UnimodalRepresentation
4949
from systemds.scuro.utils.checkpointing import CheckpointManager
50-
import sys
5150
import threading
5251
import time
5352
import psutil
@@ -371,6 +370,10 @@ def submit_new_ready_nodes():
371370
try:
372371
result = future.result()
373372
except Exception as e:
373+
err_cls = type(e)
374+
err_mod = err_cls.__module__
375+
if err_mod.startswith("torch"):
376+
torch.cuda.empty_cache()
374377
print(f"Error executing node {node_id}: {e}")
375378
self.scheduler.add_failed_node(node_id)
376379
continue

src/main/python/systemds/scuro/drsearch/node_scheduler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def __init__(
8181
for info in self.gpu_memory_info
8282
},
8383
}
84+
self._initialized = False
8485

8586
def update_cpu_memory_in_use(self, delta_bytes: int):
8687
self.memory_stats["cpu_in_use"] += delta_bytes
@@ -145,8 +146,13 @@ def complete_node(self, node_id: str):
145146
self.remaining_children[parent_id] -= 1
146147

147148
def is_finished(self) -> bool:
149+
if not self._initialized:
150+
self._initialized = True
151+
return False
152+
148153
if self._is_deadlock():
149154
self.deadlock = True
155+
self.success = False
150156
return True
151157

152158
if self._is_success():
@@ -258,6 +264,7 @@ def _check_memory_constraints(self, node_id: str) -> bool:
258264
if cpu_mem > self.memory_budget["cpu"] - self.memory_stats["cpu_in_use"]:
259265
if cpu_mem > self.memory_budget["cpu"]:
260266
self.blocked_memory_nodes_perm.append(node_id)
267+
self.topo_order.remove(node_id)
261268
return False, None
262269

263270
if gpu_mem > 0.0 and self.n_gpu > 0:

src/main/python/systemds/scuro/modality/transformed.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def __init__(
7070
if "attention_masks" in v:
7171
del self.metadata[k]["attention_masks"]
7272

73+
def copy_from_instance(self):
74+
"""
75+
Create a copy of the transformed modality instance
76+
"""
77+
return type(self)(self, None, self.modality_type)
78+
7379
def calculate_memory_usage(self):
7480
data_bytes = 0
7581
for instance in self.data:

src/main/python/systemds/scuro/representations/concatenation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,10 @@ def get_output_stats(self, input_stats_list) -> RepresentationStats:
9696
output_shape = stats_list[0].output_shape
9797

9898
return RepresentationStats(num_instances, output_shape)
99+
100+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
101+
# TODO
102+
return {
103+
"cpu_peak_bytes": 0,
104+
"gpu_peak_bytes": 0,
105+
}

src/main/python/systemds/scuro/representations/covarep_audio_features.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,6 @@ def transform(self, modality, aggregation=None):
7878
return transformed_modality
7979

8080
def get_output_stats(self, input_stats) -> RepresentationStats:
81-
"""
82-
Estimate output shape of Spectral features.
83-
84-
We compute 4 spectral feature sequences (centroid, bandwidth,
85-
rolloff, flatness), each over frames of length ``hop_length``.
86-
The resulting tensors have shape (num_frames, 4).
87-
"""
8881
num_instances = getattr(input_stats, "num_instances", 0)
8982

9083
# Try to infer signal length from stats
@@ -103,6 +96,13 @@ def get_output_stats(self, input_stats) -> RepresentationStats:
10396

10497
return RepresentationStats(num_instances, (num_frames, 4))
10598

99+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
100+
# TODO
101+
return {
102+
"cpu_peak_bytes": 0,
103+
"gpu_peak_bytes": 0,
104+
}
105+
106106

107107
@register_representation(ModalityType.AUDIO)
108108
class ZeroCrossing(UnimodalRepresentation):
@@ -130,13 +130,6 @@ def transform(self, modality, aggregation=None):
130130
return transformed_modality
131131

132132
def get_output_stats(self, input_stats) -> RepresentationStats:
133-
"""
134-
Estimate output shape of ZeroCrossing features.
135-
136-
``librosa.feature.zero_crossing_rate`` returns an array of shape
137-
(1, num_frames), so each instance is treated as a sequence of
138-
scalar features over frames.
139-
"""
140133
num_instances = getattr(input_stats, "num_instances", 0)
141134

142135
if hasattr(input_stats, "max_length"):
@@ -152,9 +145,15 @@ def get_output_stats(self, input_stats) -> RepresentationStats:
152145
num_frames = 1 + max(int((signal_length - 1) // self.hop_length), 0)
153146
num_frames = max(int(num_frames), 1)
154147

155-
# shape (num_frames, 1): one scalar feature per frame
156148
return RepresentationStats(num_instances, (num_frames, 1))
157149

150+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
151+
# TODO
152+
return {
153+
"cpu_peak_bytes": 0,
154+
"gpu_peak_bytes": 0,
155+
}
156+
158157

159158
@register_representation(ModalityType.AUDIO)
160159
class RMSE(UnimodalRepresentation):
@@ -183,12 +182,6 @@ def transform(self, modality, aggregation=None):
183182
return transformed_modality
184183

185184
def get_output_stats(self, input_stats) -> RepresentationStats:
186-
"""
187-
Estimate output shape of RMSE features.
188-
189-
``librosa.feature.rms`` returns an array of shape (1, num_frames),
190-
so each instance is a sequence of scalar RMS values over frames.
191-
"""
192185
num_instances = getattr(input_stats, "num_instances", 0)
193186

194187
if hasattr(input_stats, "max_length"):
@@ -201,12 +194,18 @@ def get_output_stats(self, input_stats) -> RepresentationStats:
201194
if signal_length <= 0:
202195
num_frames = 1
203196
else:
204-
# librosa.rms uses frame_length and hop_length; approximate
205197
num_frames = 1 + max(int((signal_length - 1) // self.hop_length), 0)
206198
num_frames = max(int(num_frames), 1)
207199

208200
return RepresentationStats(num_instances, (num_frames, 1))
209201

202+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
203+
# TODO
204+
return {
205+
"cpu_peak_bytes": 0,
206+
"gpu_peak_bytes": 0,
207+
}
208+
210209

211210
@register_representation(ModalityType.AUDIO)
212211
class Pitch(UnimodalRepresentation):
@@ -253,3 +252,10 @@ def get_output_stats(self, input_stats) -> RepresentationStats:
253252
num_frames = max(int(num_frames), 1)
254253

255254
return RepresentationStats(num_instances, (num_frames, 1))
255+
256+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
257+
# TODO
258+
return {
259+
"cpu_peak_bytes": 0,
260+
"gpu_peak_bytes": 0,
261+
}

src/main/python/systemds/scuro/representations/hadamard.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ def num_elements(stats: RepresentationStats) -> int:
6363

6464
largest = max(stats_list, key=num_elements)
6565
return RepresentationStats(largest.num_instances, largest.output_shape)
66+
67+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
68+
# TODO
69+
return {
70+
"cpu_peak_bytes": 0,
71+
"gpu_peak_bytes": 0,
72+
}

src/main/python/systemds/scuro/representations/spectrogram.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
register_representation,
3131
register_context_representation_operator,
3232
)
33+
from systemds.scuro.utils.static_variables import (
34+
NP_ARRAY_HEADER_BYTES,
35+
PY_LIST_HEADER_BYTES,
36+
PY_LIST_SLOT_BYTES,
37+
)
3338

3439

3540
@register_representation(ModalityType.AUDIO)
@@ -60,6 +65,46 @@ def compute_feature(self, instance):
6065
)
6166
return librosa.amplitude_to_db(np.abs(spectrogram)).T
6267

68+
def estimate_peak_memory_bytes(self, input_stats) -> dict:
69+
# TODO: validate this function
70+
n = int(input_stats.num_instances)
71+
output_shape = input_stats.output_shape
72+
73+
signal_length = output_shape[0]
74+
if signal_length < self.n_fft:
75+
num_frames = 1
76+
else:
77+
num_frames = 1 + (signal_length - self.n_fft) // self.hop_length
78+
num_frames = max(int(num_frames), 1)
79+
num_freq_bins = 1 + self.n_fft // 2
80+
81+
output_payload_bytes = (
82+
num_frames * num_freq_bins * np.dtype(np.float32).itemsize
83+
)
84+
per_instance_retained = (
85+
output_payload_bytes + NP_ARRAY_HEADER_BYTES + PY_LIST_SLOT_BYTES
86+
)
87+
retained_output_bytes = PY_LIST_HEADER_BYTES + n * per_instance_retained
88+
input_copy_bytes = max(signal_length, 1) * np.dtype(np.float32).itemsize
89+
stft_bytes = num_frames * num_freq_bins * np.dtype(np.complex64).itemsize
90+
91+
magnitude_bytes = num_frames * num_freq_bins * np.dtype(np.float32).itemsize
92+
db_bytes = output_payload_bytes
93+
fft_workspace_bytes = max(2 * 1024 * 1024, stft_bytes // 2)
94+
transient_one_instance_bytes = (
95+
input_copy_bytes
96+
+ stft_bytes
97+
+ magnitude_bytes
98+
+ db_bytes
99+
+ fft_workspace_bytes
100+
)
101+
cpu_peak = retained_output_bytes + transient_one_instance_bytes
102+
103+
return {
104+
"cpu_peak_bytes": int(cpu_peak),
105+
"gpu_peak_bytes": 0,
106+
}
107+
63108
def get_output_stats(self, input_stats) -> RepresentationStats:
64109
num_instances = getattr(input_stats, "num_instances", 0)
65110

0 commit comments

Comments
 (0)