|
| 1 | +# Copyright The Marin Authors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# Copyright 2025 The Marin Authors |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | +from iris.logging import configure_logging |
| 7 | +from marin.processing.classification.deduplication.fuzzy import dedup_fuzzy_document |
| 8 | +import os |
| 9 | +from typing import TypeVar |
| 10 | +from marin.execution.step_runner import StepRunner |
| 11 | +from marin.processing.classification.deduplication.exact import dedup_exact_paragraph |
| 12 | +from fray.v2 import ResourceConfig |
| 13 | +from iris.marin_fs import marin_temp_bucket, region_from_metadata, check_path_in_region |
| 14 | +from marin.execution.step_spec import StepSpec |
| 15 | + |
| 16 | +import logging |
| 17 | + |
| 18 | +logger = logging.getLogger(__name__) |
| 19 | + |
| 20 | +T = TypeVar("T") |
| 21 | + |
| 22 | + |
| 23 | +def assert_not_none(value: T | None) -> T: |
| 24 | + assert value is not None |
| 25 | + return value |
| 26 | + |
| 27 | + |
| 28 | +def exect_dedup_steps_10BT() -> list[StepSpec]: |
| 29 | + raw_data_step = StepSpec( |
| 30 | + name="raw_fineweb_edu", |
| 31 | + override_output_path="gs://marin-eu-west4/raw/fineweb-edu-87f0914", |
| 32 | + ) |
| 33 | + |
| 34 | + # assert we are not reading cross-region |
| 35 | + check_path_in_region(raw_data_step.name, raw_data_step.output_path, assert_not_none(region_from_metadata())) |
| 36 | + |
| 37 | + dedup_step = StepSpec( |
| 38 | + name="exact_dedup", |
| 39 | + output_path_prefix=marin_temp_bucket(ttl_days=1, prefix="rav"), |
| 40 | + deps=[raw_data_step], |
| 41 | + fn=lambda op: dedup_exact_paragraph( |
| 42 | + input_paths=os.path.join(raw_data_step.output_path, "sample/10BT"), |
| 43 | + output_path=op, |
| 44 | + max_parallelism=1024, |
| 45 | + ), |
| 46 | + ) |
| 47 | + |
| 48 | + return [raw_data_step, dedup_step] |
| 49 | + |
| 50 | + |
| 51 | +def exact_dedup_steps() -> list[StepSpec]: |
| 52 | + raw_data_step = StepSpec( |
| 53 | + name="raw_nemotron", |
| 54 | + override_output_path="gs://marin-eu-west4/raw/nemotro-cc-eeb783/", |
| 55 | + ) |
| 56 | + |
| 57 | + # assert we are not reading cross-region |
| 58 | + check_path_in_region(raw_data_step.name, raw_data_step.output_path, assert_not_none(region_from_metadata())) |
| 59 | + |
| 60 | + dedup_step = StepSpec( |
| 61 | + name="exact_dedup_high_medium_1", |
| 62 | + output_path_prefix=marin_temp_bucket(ttl_days=2, prefix="rav"), |
| 63 | + deps=[raw_data_step], |
| 64 | + fn=lambda op: dedup_exact_paragraph( |
| 65 | + input_paths=[ |
| 66 | + os.path.join(raw_data_step.output_path, "contrib/Nemotron/Nemotron-CC/data-jsonl/quality=high"), |
| 67 | + os.path.join(raw_data_step.output_path, "contrib/Nemotron/Nemotron-CC/data-jsonl/quality=medium-high"), |
| 68 | + ], |
| 69 | + output_path=op, |
| 70 | + max_parallelism=2048, |
| 71 | + ), |
| 72 | + ) |
| 73 | + |
| 74 | + return [raw_data_step, dedup_step] |
| 75 | + |
| 76 | + |
| 77 | +def fuzzy_dedup_steps() -> list[StepSpec]: |
| 78 | + raw_data_step = StepSpec( |
| 79 | + name="raw_nemotron", |
| 80 | + override_output_path="gs://marin-eu-west4/raw/nemotro-cc-eeb783/", |
| 81 | + ) |
| 82 | + |
| 83 | + # assert we are not reading cross-region |
| 84 | + check_path_in_region(raw_data_step.name, raw_data_step.output_path, assert_not_none(region_from_metadata())) |
| 85 | + |
| 86 | + dedup_step = StepSpec( |
| 87 | + name="fuzzy_dedup_full", |
| 88 | + output_path_prefix=marin_temp_bucket(ttl_days=2, prefix="rav"), |
| 89 | + deps=[raw_data_step], |
| 90 | + fn=lambda op: dedup_fuzzy_document( |
| 91 | + input_paths=[ |
| 92 | + os.path.join(raw_data_step.output_path, "contrib/Nemotron/Nemotron-CC/data-jsonl/quality=high"), |
| 93 | + os.path.join(raw_data_step.output_path, "contrib/Nemotron/Nemotron-CC/data-jsonl/quality=medium-high"), |
| 94 | + ], |
| 95 | + output_path=op, |
| 96 | + max_parallelism=2048, |
| 97 | + worker_resources=ResourceConfig(cpu=5, ram="32g", disk="5g"), |
| 98 | + ), |
| 99 | + ) |
| 100 | + |
| 101 | + return [raw_data_step, dedup_step] |
| 102 | + |
| 103 | + |
| 104 | +if __name__ == "__main__": |
| 105 | + configure_logging(logging.INFO) |
| 106 | + StepRunner().run(exact_dedup_steps()) |
0 commit comments