Skip to content

Commit a861e68

Browse files
Pathways-on-Cloud Teamcopybara-github
authored andcommitted
Batch Pathways persistence writes in Orbax handler.
PiperOrigin-RevId: 949982430
1 parent 1089127 commit a861e68

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

pathwaysutils/persistence/orbax_handler.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,21 @@ async def serialize(
144144

145145
self._wait_for_directory_creation_signals()
146146
locations, names = extract_parent_dir_and_name(infos)
147-
f = functools.partial(helper.write_one_array, timeout=self.timeout)
148-
futures_results = list(map(f, locations, names, arrays))
147+
148+
# Group by location (parent_dir) to batch writes.
149+
by_location = collections.defaultdict(list)
150+
for loc, name, arr in zip(locations, names, arrays):
151+
by_location[loc].append((name, arr))
152+
153+
futures_results = []
154+
for loc, items in by_location.items():
155+
grouped_names = [item[0] for item in items]
156+
grouped_arrays = [item[1] for item in items]
157+
futures_results.append(
158+
helper.write_arrays(
159+
loc, grouped_names, grouped_arrays, timeout=self.timeout
160+
)
161+
)
149162

150163
return [
151164
future.CommitFutureAwaitingContractedSignals(

0 commit comments

Comments
 (0)