Skip to content

Commit bf7e788

Browse files
Smoother pbars
1 parent 27f75f8 commit bf7e788

10 files changed

Lines changed: 52 additions & 31 deletions

File tree

accelforge/frontend/mapping/mapping.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ def _merge(self, other: "TensorHolder") -> "TensorHolder":
607607
)
608608

609609
if self._lower != other._lower:
610-
raise ValueError(f"Lower flags do not match: {self._lower} != {other._lower}")
610+
raise ValueError(
611+
f"Lower flags do not match: {self._lower} != {other._lower}"
612+
)
611613

612614
new = type(self)(
613615
tensors=self.tensors + other.tensors,
@@ -772,7 +774,9 @@ def _consolidate_reservations(self) -> None:
772774
found = False
773775
for n in new_nodes[::-1]:
774776
if isinstance(n, Reservation) and n.resource == node.resource:
775-
n.purposes.extend(n2 for n2 in node.purposes if n2 not in n.purposes)
777+
n.purposes.extend(
778+
n2 for n2 in node.purposes if n2 not in n.purposes
779+
)
776780
found = True
777781
break
778782
if isinstance(n, Loop):
@@ -1109,8 +1113,16 @@ def _pop_loop_group(groups: list[list[MappingNode]]) -> list[MappingNode]:
11091113
f"Warning. Matching loops {l} and {l2}. Need rank variable translation here."
11101114
)
11111115

1112-
my_rv = l.rank_variable if isinstance(l.rank_variable, set) else set([l.rank_variable])
1113-
other_rv = l2.rank_variable if isinstance(l2.rank_variable, set) else set([l2.rank_variable])
1116+
my_rv = (
1117+
l.rank_variable
1118+
if isinstance(l.rank_variable, set)
1119+
else set([l.rank_variable])
1120+
)
1121+
other_rv = (
1122+
l2.rank_variable
1123+
if isinstance(l2.rank_variable, set)
1124+
else set([l2.rank_variable])
1125+
)
11141126
if switched:
11151127
my_rv, other_rv = other_rv, my_rv
11161128

accelforge/frontend/workload.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,7 @@ def _eval_expressions(
10391039
"workload_bits_per_value": bpv,
10401040
"workload_persistent_tensors": self.persistent_tensors,
10411041
}
1042-
evaluated, new_st = super()._eval_expressions(
1043-
new_st,
1044-
*args,
1045-
**kwargs
1046-
)
1042+
evaluated, new_st = super()._eval_expressions(new_st, *args, **kwargs)
10471043

10481044
# Ensure bits_per_value is consistent across Einsums
10491045
bits_per_value_per_einsum = {}

accelforge/mapper/FFM/_join_pmappings/join_pmappings.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,13 @@ def remove_unneeded_columns(s: PmappingGroup):
219219

220220
new_pmapping_groups = {}
221221
for einsum_name, einsum_pmapping_groups in pmapping_groups.items():
222-
new_pmapping_groups[einsum_name] = list(
223-
parallel(
224-
[delayed(remove_unneeded_columns)(s) for s in einsum_pmapping_groups],
225-
pbar=(
226-
f"Removing unneeded reservations for {einsum_name}"
227-
if print_progress
228-
else None
229-
),
230-
return_as="generator",
231-
)
222+
new_pmapping_groups[einsum_name] = parallel(
223+
[delayed(remove_unneeded_columns)(s) for s in einsum_pmapping_groups],
224+
pbar=(
225+
f"Removing unneeded reservations for {einsum_name}"
226+
if print_progress
227+
else None
228+
),
232229
)
233230
return new_pmapping_groups, ignore
234231

@@ -629,7 +626,6 @@ def no_match_lookahead_error(
629626
if print_progress
630627
else None
631628
),
632-
return_as="generator",
633629
)
634630
for c, mapping in zip(combined, mappings):
635631
c.mappings = mapping

accelforge/mapper/FFM/_join_pmappings/pmapping_dataframe.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,15 @@ def __len__(self) -> int:
883883
# with open(to_file, "wb") as f:
884884
# f.write(graph.create_png())
885885

886-
def clear_irrelevant_columns(self, compatibility: Compatibility) -> "PmappingDataframe":
886+
def clear_irrelevant_columns(
887+
self, compatibility: Compatibility
888+
) -> "PmappingDataframe":
887889
return self.update(
888890
data=compatibility.clear_unrelated_columns(self._data),
889891
skip_pareto=True,
890892
)
891893

894+
892895
def row2pmappings(
893896
row: pd.Series,
894897
einsum_names: list[str],

accelforge/mapper/FFM/_join_pmappings/pmapping_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def check(tensors_to_check):
349349

350350
@staticmethod
351351
def group(
352-
pmapping_groups: list["PmappingGroup"], live_tensors: set[str]#, mixable_ranks: dict[Rank, set[Rank]] = None
352+
pmapping_groups: list["PmappingGroup"], live_tensors: set[str]
353353
) -> dict[tuple[Compatibility, ...], list[tuple["PmappingGroup", list[int]]]]:
354354
x = PmappingGroup._group(
355355
pmapping_groups,

accelforge/mapper/FFM/_make_pmappings/make_pmappings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def make_jobs_for_einsum(einsum_name: EinsumName, spec: Spec):
131131
for einsum_name, spec in einsum2spec.items()
132132
],
133133
pbar="Generating jobs" if print_progress else None,
134-
return_as="generator",
135134
):
136135
einsum2jobs.setdefault(einsum_name, {})
137136
for compatibility, job_list in jobs.items():

accelforge/mapper/FFM/_make_pmappings/make_pmappings_from_templates/run_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def run_model(
3636

3737
df = {}
3838

39-
reuse = analyze_reuse_and_add_reservations_to_mapping(job, add_reservations=add_reservations)
39+
reuse = analyze_reuse_and_add_reservations_to_mapping(
40+
job, add_reservations=add_reservations
41+
)
4042

4143
latency = component_latency(reuse, job.flattened_arch, pmapping, spec)
4244
try:

accelforge/mapper/FFM/_pareto_df/df_convention.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def is_fused_loop_col(c: str) -> bool:
209209
def is_n_iterations_col(c: str) -> bool:
210210
return c.startswith("fused_loop<SEP>n_iterations")
211211

212+
212213
def ensure_float_type(df, target, source):
213214
if target in df:
214215
target_type = df[target].dtype
@@ -234,13 +235,15 @@ def max_to_col(df, target, source):
234235
ensure_float_type(df, target, source)
235236
df.loc[:, target] = df[[target, source]].max(axis=1) if target in df else df[source]
236237

238+
237239
def add_to_col(df, target, source):
238240
ensure_float_type(df, target, source)
239241
if isinstance(source, pd.Series):
240242
df[target] = df[target] + source
241243
else:
242244
df.loc[:, target] = df[target] + df[source] if target in df else df[source]
243245

246+
244247
def is_objective_col(c):
245248
return partition_col(c, "Total") is not None
246249

accelforge/mapper/FFM/mappings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ def energy(
452452
for einsum in self.einsum_names:
453453
einsum_accessed = energy.access(einsum, col_idx=0)
454454
# None for computes
455-
for tensor in list(
456-
self.spec.workload.einsums[einsum].tensor_names
457-
) + ["None"]:
455+
for tensor in list(self.spec.workload.einsums[einsum].tensor_names) + [
456+
"None"
457+
]:
458458
tensor_accessed = einsum_accessed.access(tensor, col_idx=1)
459459
for col in tensor_accessed._get_keys_of_length(2):
460460
component, action = col.split("<SEP>")
@@ -644,9 +644,9 @@ def actions(
644644
for einsum in self.einsum_names:
645645
einsum_accessed = actions.access(einsum, col_idx=0)
646646
# None for computes
647-
for tensor in list(
648-
self.spec.workload.einsums[einsum].tensor_names
649-
) + ["None"]:
647+
for tensor in list(self.spec.workload.einsums[einsum].tensor_names) + [
648+
"None"
649+
]:
650650
tensor_accessed = einsum_accessed.access(tensor, col_idx=1)
651651
for col in tensor_accessed._get_keys_of_length(2):
652652
component, action = col.split("<SEP>")

accelforge/util/parallel.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,17 @@ def yield_results():
174174
if return_as in ["generator", "generator_unordered"]:
175175
return yield_results()
176176

177-
return list(yield_results())
177+
# Coerce into generator_unordered so that the progress bar won't hang on one slow
178+
# job.
179+
def f(i, job):
180+
return i, job[0](*job[1], **job[2])
181+
182+
jobs = [delayed(f)(i, job) for i, job in enumerate(jobs)]
183+
results = [None] * total_jobs
184+
args["return_as"] = "generator_unordered"
185+
for i, result in yield_results():
186+
results[i] = result
187+
return results
178188

179189

180190
# import cProfile

0 commit comments

Comments
 (0)