Skip to content

Commit

Permalink
swap bar orders
Browse files Browse the repository at this point in the history
  • Loading branch information
christianazinn committed Jun 10, 2024
1 parent 4550826 commit efa0609
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions gguf-py/gguf/gguf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,25 @@ def write_tensors_to_file(self, *, progress: bool = False) -> None:

total_bytes = sum(ti.nbytes for t in self.tensors for ti in t.values())

bar = tqdm(desc="Writing", total=total_bytes, unit="byte", unit_scale=True)
if len(self.fout) > 1:
shard_bar = tqdm(desc=f"Shard (0/{len(self.fout)})", total=None, unit="byte", unit_scale=True)
bar = tqdm(desc="Writing", total=total_bytes, unit="byte", unit_scale=True)

for i, (fout, tensors) in enumerate(zip(self.fout, self.tensors)):
if shard_bar is not None:
shard_bar.set_description(f"Shard ({i + 1}/{len(self.fout)})")
total = sum(ti.nbytes for ti in tensors.values())
# bar behaves weirdly when total is 0
shard_bar.reset(total=(total if total > 0 else None))

# relying on the fact that Python dicts preserve insertion order (since 3.7)
for ti in tensors.values():
assert ti.tensor is not None # can only iterate once over the tensors
assert ti.tensor.nbytes == ti.nbytes
ti.tensor.tofile(fout)
if bar is not None:
bar.update(ti.nbytes)
if shard_bar is not None:
shard_bar.update(ti.nbytes)
if bar is not None:
bar.update(ti.nbytes)
self.write_padding(fout, ti.nbytes)
ti.tensor = None
else:
Expand Down

0 comments on commit efa0609

Please sign in to comment.