nemo_curator.stages.deduplication.semantic.kmeans
nemo_curator.stages.deduplication.semantic.kmeans
Module Contents
Classes
Data
API
Bases: ProcessingStage[FileGroupTask, _EmptyTask], DeduplicationIO
KMeans clustering stage that requires RAFT for distributed processing.
Computes the L2 distance to nearest centroid to each embedding in the DataFrame. Embeddings are normalized. For cosine we’ll need to normalize the centroids as well.
Pass 1: sample files at the actor level, read embeddings, fit KMeans, and (on actor 0) save centroids.
Returns: float
Wall-clock seconds spent reading sampled files (for the combined
Pass 2: load each full group, predict labels, write results.
Returns: list[_EmptyTask]
(results, pass2_read_time, total_rows). The orchestrator combines
Single-pass approach: loads all groups simultaneously.
Requires peak GPU memory = sum(all groups’ data). Only suitable when the total dataset fits in GPU memory.
Memory-efficient two-pass approach for large datasets.
Pass 1 (_fit_pass): samples fit_data_fraction of the actor’s files (across all groups), re-chunks them into memory-bounded fit_groups, reads only the embedding column, fits the KMeans model, and saves centroids if cache_path is set. IO and GPU memory in Pass 1 scale with fit_data_fraction. Pass 2 (_predict_write_pass): loads each (full) original group one at a time, predicts labels, writes, then frees GPU memory before loading the next group.
Peak GPU memory ≈ max(fit_data_fraction x actor_rows, one_group_size) x embedding_dim x 4 bytes, instead of total_data x embedding_dim x 4 bytes.
Read a group of files into a cudf DataFrame.
Process a batch of FileGroupTasks using distributed RAFT KMeans.
In RAFT mode, each actor processes its assigned tasks, but the KMeans model is trained cooperatively across all actors using RAFT communication.
When fit_data_fraction is set, uses a memory-efficient two-pass approach: Pass 1: samples files at the actor level, reads only the embedding column from those files Pass 2: loads each (full) original group one at a time for prediction and writing Otherwise, loads all groups simultaneously (original behavior).
Bases: CompositeStage[_EmptyTask, _EmptyTask]
KMeans clustering stage that requires RAFT for distributed processing.
KMeans clustering stage that requires RAFT for distributed processing.
Initialize parent class after dataclass initialization.