Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions benchmarking/scripts/exact_dedup_identification_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@
import argparse
import time
from pathlib import Path
from typing import Any
from typing import Any, Literal

from loguru import logger
from utils import write_benchmark_results

from nemo_curator.stages.deduplication.exact.workflow import ExactDeduplicationWorkflow


def _parse_memory_arg(value: str) -> int | Literal["auto"] | None:
"""Parse a memory argument that can be an int, 'auto', or None."""
if value.lower() == "none":
return None
if value.lower() == "auto":
return "auto"
return int(value)


def run_exact_duplicate_identification_benchmark( # noqa: PLR0913
input_path: str,
output_path: str,
Expand All @@ -37,6 +46,9 @@ def run_exact_duplicate_identification_benchmark( # noqa: PLR0913
input_blocksize: str = "2GiB",
assign_id: bool = True,
id_field: str | None = None,
total_nparts: int | None = None,
rmm_pool_size: int | Literal["auto"] | None = "auto",
spill_memory_limit: int | Literal["auto"] | None = "auto",
) -> dict[str, Any]:
"""Run the exact duplicate identification benchmark and collect comprehensive metrics."""

Expand All @@ -56,6 +68,9 @@ def run_exact_duplicate_identification_benchmark( # noqa: PLR0913
input_blocksize=input_blocksize,
assign_id=assign_id,
id_field=id_field,
total_nparts=total_nparts,
rmm_pool_size=rmm_pool_size,
spill_memory_limit=spill_memory_limit,
)
workflow_result = workflow.run(initial_tasks=None)
run_time_taken = time.perf_counter() - run_start_time
Expand Down Expand Up @@ -86,6 +101,9 @@ def run_exact_duplicate_identification_benchmark( # noqa: PLR0913
"input_blocksize": input_blocksize,
"assign_id": assign_id,
"id_field": id_field,
"total_nparts": total_nparts,
"rmm_pool_size": rmm_pool_size,
"spill_memory_limit": spill_memory_limit,
},
"metrics": {
"is_success": success,
Expand Down Expand Up @@ -126,7 +144,21 @@ def main() -> int:
default=None,
help="Existing id field name if not automatically assigning a new id",
)

parser.add_argument(
"--total-nparts",
type=int,
default=None,
help="Total number of output partitions",
)
parser.add_argument(
"--rmm-pool-size", type=_parse_memory_arg, default="auto", help="Size of the RMM GPU memory pool in bytes"

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.

Huh, I never realized type is used as a function here. Nice!

)
parser.add_argument(
"--spill-memory-limit",
type=_parse_memory_arg,
default="auto",
help="Device memory limit in bytes for spilling to host",
)
args = parser.parse_args()

logger.info("=== Exact Duplicate Identification Benchmark Starting ===")
Expand All @@ -141,6 +173,9 @@ def main() -> int:
input_blocksize=args.input_blocksize,
assign_id=args.assign_id,
id_field=args.id_field,
total_nparts=args.total_nparts,
rmm_pool_size=args.rmm_pool_size,
spill_memory_limit=args.spill_memory_limit,
)

except Exception as e:
Expand Down
20 changes: 19 additions & 1 deletion nemo_curator/stages/deduplication/exact/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__( # noqa: PLR0913
id_field: str | None = None,
text_field: str = "text",
perform_removal: bool = False,
total_nparts: int | None = None,
rmm_pool_size: int | Literal["auto"] | None = "auto",
spill_memory_limit: int | Literal["auto"] | None = "auto",
env_vars: dict[str, Any] | None = None,
):
"""
Expand Down Expand Up @@ -97,6 +100,16 @@ def __init__( # noqa: PLR0913
Field containing the text to deduplicate.
perform_removal: bool
Whether to remove the duplicates from the original dataset.
total_nparts: int | None = None
Total number of output partitions. If None, will be set automatically by the executor.
rmm_pool_size: int | Literal["auto"] | None = "auto"
Size of the RMM GPU memory pool in bytes.
If "auto", the memory pool is set to 90% of the free GPU memory.
If None, the memory pool is set to 50% of the free GPU memory that can expand if needed.
spill_memory_limit: int | Literal["auto"] | None = "auto"
Device memory limit in bytes for spilling to host.
If "auto", the limit is set to 80% of the RMM pool size.
If None spilling is disabled.
env_vars: dict[str, Any] | None = None
Environment variables to pass to the pipeline.
"""
Expand All @@ -112,6 +125,9 @@ def __init__( # noqa: PLR0913
self.assign_id = assign_id
self.id_field = id_field
self.perform_removal = perform_removal
self.total_nparts = total_nparts
self.rmm_pool_size = rmm_pool_size
self.spill_memory_limit = spill_memory_limit

self.env_vars = env_vars

Expand Down Expand Up @@ -150,7 +166,9 @@ def _create_identification_pipeline(self, num_input_tasks: int) -> Pipeline:
assign_id=self.assign_id,
id_field=self.id_field,
# Matches previous implementation to write out to 1/3 the number of input tasks
total_nparts=max(1, num_input_tasks // 3),
total_nparts=max(1, num_input_tasks // 3) if self.total_nparts is None else self.total_nparts,
Comment thread
ayushdg marked this conversation as resolved.
Resolved
rmm_pool_size=self.rmm_pool_size,
spill_memory_limit=self.spill_memory_limit,
),
],
)
Expand Down
3 changes: 3 additions & 0 deletions tests/stages/deduplication/exact/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def test_no_dedup(self, exact_no_dedup_data_jsonl: list[FileGroupTask], tmpdir:
text_field="content",
perform_removal=False,
input_path=str(tmpdir),
total_nparts=2,
rmm_pool_size=None,
spill_memory_limit="auto",
)
result = workflow.run(initial_tasks=exact_no_dedup_data_jsonl)
assert result.pipeline_tasks
Expand Down
Loading