Skip to content

Fuse document iterate and extract stages - #1458

Merged
sarahyurick merged 20 commits into
NVIDIA-NeMo:mainfrom
sarahyurick:fuse_iterate_extract
Feb 6, 2026
Merged

Fuse document iterate and extract stages#1458
sarahyurick merged 20 commits into
NVIDIA-NeMo:mainfrom
sarahyurick:fuse_iterate_extract

Conversation

@sarahyurick

@sarahyurick sarahyurick commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Closes #780.

This change allows the following improvements:

Configuration Runtime
Fusion + Ray Data executor 27m 49.1s
No Fusion + Ray Data executor 29m 33.1s
Fusion + Xenna executor 54m 4.2s
No Fusion + Xenna executor 66m 6.8s

Common Crawl benchmarks with url_limit=16 and num_cpus=8

Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>


@dataclass
class DocumentIterateExtractStage(ProcessingStage[FileGroupTask, DocumentBatch]):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to opinions about where this class should live and/or any file restructuring ideas.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>
Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Sarah Yurick <sarahyurick@gmail.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ayushdg ayushdg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tiny stories tutorial (and possibly some other small places) may still have references to the iterate and extract stage separately. beyond that the PR should be good to go

@sarahyurick

Copy link
Copy Markdown
Contributor Author

The tiny stories tutorial (and possibly some other small places) may still have references to the iterate and extract stage separately. beyond that the PR should be good to go

@ayushdg hi thanks, I checked the tutorials and found that they do not need updated. This is because the TinyStories tutorial, etc. only access the abstract classes DocumentIterator and DocumentExtractor which are not modified by this PR, and do not interact with DocumentIterateStage or DocumentExtractStage at all.

Lmk if I am missing anything.

@ayushdg

ayushdg commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Lmk if I am missing anything.

Nope I missed that. In that case we should be good to go! Thanks a lot @sarahyurick

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +101 to +103
for record_dict in iterator_result:
if self.record_limit and record_count >= self.record_limit:
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Record counts wrong
record_limit is enforced based on record_count, but record_count is only incremented after a record is kept (i.e., after extract() and after extracted is None filtering). With an extractor that filters heavily, this will iterate/extract far more than record_limit input records per file (and potentially do a lot more work/memory) before record_count reaches the limit. This is triggered when extractor is set and can return None (e.g., content filters).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A record is only added to the result after extraction. This means that the record count is correct.

@greptile-apps

greptile-apps Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (2)

nemo_curator/stages/text/download/base/iterator.py
Empty batch lacks schema
When records is empty (empty task.data, iterate() returns None, all files error, or all records filtered), pd.DataFrame(records) creates a DataFrame with no columns. Downstream stages/tests that rely on declared outputs (e.g., expecting the filename column or extractor output columns) will hit KeyError when accessing missing columns. Consider constructing an empty DataFrame with the expected columns from self.outputs()[1] when records is empty.


docs/about/concepts/text/data-acquisition-concepts.md
Incorrect API description
This section says the iterator’s yielded list[dict] is converted to a DataFrame and “passed to Extractor”, and later states “DocumentExtractor works on a Pandas DataFrame”. In the current implementation, DocumentIterateExtractStage calls extractor.extract(record_dict) per-record (a dict), not on a DataFrame. As written, this doc is describing a different API/behavior than users will actually get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Download and Extract - Consider merging iterate and extract to a single stage

2 participants