Skip to content

Commit 2a005db

Browse files
yichuan-wandylizf
andauthored
feat(embed): add tqdm progress bar to chunk stage, clean up embed logging (#108)
- chunk.py: add tqdm progress bar for article-level chunking so users see real-time progress during Stage 2 (e.g. "Chunking: 50%|█████ | 4/8") - embed_cpu.py: remove redundant "Embedded X/Y" logger.info every 10 items — tqdm already shows this and the log lines break the progress bar display Tested with 8 Wikipedia pages (64 chunks produced). Co-authored-by: Zhifei Li <andylizf@outlook.com>
1 parent 9d84f02 commit 2a005db

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

embed/src/pixelrag_embed/chunk.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from pathlib import Path
3737

3838
from PIL import Image
39+
from tqdm import tqdm
3940

4041
Image.MAX_IMAGE_PIXELS = None # some tiles exceed default 178M pixel limit
4142

@@ -307,21 +308,27 @@ def process_shard(
307308
# Flat structure — article dirs directly in shard_dir
308309
sub_dirs = [Path(shard_dir)]
309310

310-
for sub_dir in sub_dirs:
311-
for article_dir in sorted(sub_dir.iterdir()):
312-
if not article_dir.is_dir() or not article_dir.name.endswith(".png.tiles"):
313-
continue
314-
total_articles += 1
315-
316-
result = chunk_article(str(article_dir), dry_run=dry_run, force=force)
317-
if result is None:
318-
skipped_articles += 1
319-
continue
311+
all_article_dirs = [
312+
article_dir
313+
for sub_dir in sub_dirs
314+
for article_dir in sorted(sub_dir.iterdir())
315+
if article_dir.is_dir() and article_dir.name.endswith(".png.tiles")
316+
]
317+
318+
for article_dir in tqdm(
319+
all_article_dirs, desc="Chunking", disable=not all_article_dirs
320+
):
321+
total_articles += 1
322+
323+
result = chunk_article(str(article_dir), dry_run=dry_run, force=force)
324+
if result is None:
325+
skipped_articles += 1
326+
continue
320327

321-
chunked_articles += 1
322-
total_tiles += result["num_tiles"]
323-
total_chunks += result["num_chunks"]
324-
total_files += result["files_written"]
328+
chunked_articles += 1
329+
total_tiles += result["num_tiles"]
330+
total_chunks += result["num_chunks"]
331+
total_files += result["files_written"]
325332

326333
# Delete tiles after chunking the whole shard
327334
tiles_deleted = 0

embed/src/pixelrag_embed/embed_cpu.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ def embed_items(
203203
pooled = pooled / pooled.norm()
204204
embeddings[i] = pooled.cpu().numpy().astype(np.float16)
205205

206-
if (i + 1) % 10 == 0:
207-
logger.info("Embedded %d/%d", i + 1, len(items))
208-
209206
return embeddings
210207

211208

0 commit comments

Comments
 (0)