Skip to content

Commit 79822aa

Browse files
author
intern_nem_dev_1
committed
Pin FinePDFs revision for long-document seeds
1 parent a9b324b commit 79822aa

7 files changed

Lines changed: 148 additions & 5 deletions

File tree

src/nemotron/recipes/data/sdg/long-document/01-seed-dataset-preparation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
logging.getLogger("fsspec").setLevel(logging.WARNING)
8686

8787
FINEPDFS_REPO = "HuggingFaceFW/finepdfs"
88+
FINEPDFS_REVISION = "220bac3acbf07789502c621d2d33952f51ac7f86"
8889

8990

9091
class SeedConfig(BaseModel):
@@ -105,6 +106,11 @@ class SeedConfig(BaseModel):
105106
default="eng_Latn",
106107
description="FinePDFs language subset (e.g. eng_Latn, fra_Latn).",
107108
)
109+
finepdfs_revision: str = Field(
110+
default=FINEPDFS_REVISION,
111+
pattern=r"[0-9a-f]{40}",
112+
description="Pinned FinePDFs dataset revision SHA for reproducible seed inputs.",
113+
)
108114
timeout: int = Field(
109115
default=20,
110116
ge=0,
@@ -195,15 +201,17 @@ def run_seed(cfg: SeedConfig) -> None:
195201
output_dir.mkdir(parents=True, exist_ok=True)
196202

197203
log.info(
198-
"Streaming %d documents from %s (subset=%s)",
204+
"Streaming %d documents from %s (subset=%s, revision=%s)",
199205
cfg.num_docs,
200206
FINEPDFS_REPO,
201207
cfg.subset,
208+
cfg.finepdfs_revision,
202209
)
203210

204211
ds = load_dataset(
205212
FINEPDFS_REPO,
206213
name=cfg.subset,
214+
revision=cfg.finepdfs_revision,
207215
split="train",
208216
streaming=True,
209217
)

src/nemotron/recipes/data/sdg/long-document/config/01-seed.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
output_dir: ./seed_data
88
num_docs: 10
99
subset: eng_Latn
10+
finepdfs_revision: 220bac3acbf07789502c621d2d33952f51ac7f86
1011
timeout: 20
1112
dpi: 144
1213
max_pages: 50
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
from __future__ import annotations
2+
3+
import ast
4+
import re
5+
from pathlib import Path
6+
7+
import yaml
8+
9+
REPO_ROOT = Path(__file__).resolve().parents[3]
10+
SEED_SCRIPT = REPO_ROOT / "src/nemotron/recipes/data/sdg/long-document/01-seed-dataset-preparation.py"
11+
SEED_CONFIG = REPO_ROOT / "src/nemotron/recipes/data/sdg/long-document/config/01-seed.yaml"
12+
EXPECTED_REPO = "HuggingFaceFW/finepdfs"
13+
EXPECTED_REVISION = "220bac3acbf07789502c621d2d33952f51ac7f86"
14+
15+
16+
def _module_tree() -> ast.Module:
17+
return ast.parse(SEED_SCRIPT.read_text(encoding="utf-8"))
18+
19+
20+
def _module_string_constant(tree: ast.Module, name: str) -> str:
21+
for node in tree.body:
22+
if not isinstance(node, ast.Assign):
23+
continue
24+
if not any(isinstance(target, ast.Name) and target.id == name for target in node.targets):
25+
continue
26+
assert isinstance(node.value, ast.Constant)
27+
assert isinstance(node.value.value, str)
28+
return node.value.value
29+
raise AssertionError(f"missing module constant {name}")
30+
31+
32+
def _field_default_name(tree: ast.Module, field_name: str) -> str:
33+
for node in ast.walk(tree):
34+
if not isinstance(node, ast.AnnAssign):
35+
continue
36+
if not isinstance(node.target, ast.Name) or node.target.id != field_name:
37+
continue
38+
assert isinstance(node.value, ast.Call)
39+
assert isinstance(node.value.func, ast.Name)
40+
assert node.value.func.id == "Field"
41+
for keyword in node.value.keywords:
42+
if keyword.arg != "default":
43+
continue
44+
assert isinstance(keyword.value, ast.Name)
45+
return keyword.value.id
46+
raise AssertionError(f"missing SeedConfig field {field_name}")
47+
48+
49+
def _load_dataset_call(tree: ast.Module) -> ast.Call:
50+
for node in ast.walk(tree):
51+
if not isinstance(node, ast.Call):
52+
continue
53+
if isinstance(node.func, ast.Name) and node.func.id == "load_dataset":
54+
return node
55+
raise AssertionError("missing load_dataset call")
56+
57+
58+
def _keyword_value(call: ast.Call, name: str) -> ast.expr:
59+
for keyword in call.keywords:
60+
if keyword.arg == name:
61+
return keyword.value
62+
raise AssertionError(f"missing load_dataset keyword {name}")
63+
64+
65+
def test_finepdfs_seed_source_defaults_to_pinned_revision() -> None:
66+
tree = _module_tree()
67+
68+
assert _module_string_constant(tree, "FINEPDFS_REPO") == EXPECTED_REPO
69+
revision = _module_string_constant(tree, "FINEPDFS_REVISION")
70+
assert revision == EXPECTED_REVISION
71+
assert re.fullmatch(r"[0-9a-f]{40}", revision)
72+
assert _field_default_name(tree, "finepdfs_revision") == "FINEPDFS_REVISION"
73+
74+
75+
def test_finepdfs_load_dataset_threads_revision_from_config() -> None:
76+
call = _load_dataset_call(_module_tree())
77+
78+
assert isinstance(call.args[0], ast.Name)
79+
assert call.args[0].id == "FINEPDFS_REPO"
80+
81+
name_value = _keyword_value(call, "name")
82+
assert isinstance(name_value, ast.Attribute)
83+
assert isinstance(name_value.value, ast.Name)
84+
assert name_value.value.id == "cfg"
85+
assert name_value.attr == "subset"
86+
87+
revision_value = _keyword_value(call, "revision")
88+
assert isinstance(revision_value, ast.Attribute)
89+
assert isinstance(revision_value.value, ast.Name)
90+
assert revision_value.value.id == "cfg"
91+
assert revision_value.attr == "finepdfs_revision"
92+
93+
94+
def test_finepdfs_default_config_exposes_same_revision_pin() -> None:
95+
config = yaml.safe_load(SEED_CONFIG.read_text(encoding="utf-8"))
96+
97+
assert config["finepdfs_revision"] == EXPECTED_REVISION
98+
assert re.fullmatch(r"[0-9a-f]{40}", config["finepdfs_revision"])
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# intern_nem_dev_1 - 状态
22

3-
<!-- METADATA:STATUS=Working,TASK=task162_long_document_public_docs_path_portability_s1,ROLE=dev,SESSION=1 -->
3+
<!-- METADATA:STATUS=Working,TASK=task164_long_document_finepdfs_revision_pin_s1,ROLE=dev,SESSION=1 -->
44

55
| 字段 ||
66
|------|-----|
77
| Name | intern_nem_dev_1 |
88
| Status | Working |
9-
| Current Task | task162_long_document_public_docs_path_portability_s1 |
10-
| PR | https://github.com/songCNMS/Nemotron/pull/269 |
9+
| Current Task | task164_long_document_finepdfs_revision_pin_s1 |
10+
| PR | pending |
1111
| Session | 1 |
12-
| Recent Progress | Opened PR #269 for task162; public long-document SDG docs now use NEMO_RUN_DIR-relative seed examples and focused static docs checks passed |
12+
| Recent Progress | Started task164 from origin/main a9b324bf28cd6cb0470b58eec47fd17336fdec0f; adding offline/static FinePDFs revision pin coverage |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# task164_long_document_finepdfs_revision_pin_s1
2+
3+
<!-- METADATA:STATUS=InProgress,ASSIGNEE=intern_nem_dev_1,SESSION=1 -->
4+
5+
## Scope
6+
7+
- Pin long-document SDG FinePDFs seed loading to revision `220bac3acbf07789502c621d2d33952f51ac7f86`.
8+
- Keep `HuggingFaceFW/finepdfs`, subset behavior, and downstream stage semantics unchanged.
9+
- Add focused static/AST tests that do not call `load_dataset` or download PDFs.
10+
11+
## Boundaries
12+
13+
- No live `load_dataset`, PDF downloads, seed generation, `--serve`, endpoints, train/eval, W&B, cluster jobs, deploy, artifact operations, main push, or self-merge.
14+
- Scope is limited to the seed script/config, focused static tests, and task/status docs.
15+
16+
## Status
17+
18+
- Base: `a9b324bf28cd6cb0470b58eec47fd17336fdec0f`
19+
- Branch: `intern_nem_dev_1/task164_long_document_finepdfs_revision_pin_s1`
20+
- PR: pending
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# History Log
2+
3+
<!-- METADATA:SESSION=1 -->
4+
5+
## Session 1 - 2026-05-29
6+
7+
- Started task164 from `origin/main` at `a9b324bf28cd6cb0470b58eec47fd17336fdec0f`.
8+
- Added a default FinePDFs revision pin and config-threaded `load_dataset(..., revision=...)` path.
9+
- Added focused AST/static tests for the repo id, exact revision SHA, config field/default, `load_dataset` revision keyword, and YAML default.
10+
- Ran focused pytest, py_compile, Ruff, structured AST probe, added-line live-surface scan, and `git diff --check` without calling `load_dataset` or running seed generation.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Task Knowledge
2+
3+
<!-- METADATA:SESSION=1 -->
4+
5+
- FinePDFs seed loading must use repo `HuggingFaceFW/finepdfs` pinned to lowercase 40-character SHA `220bac3acbf07789502c621d2d33952f51ac7f86`.
6+
- Task validation must remain offline/static; do not call `load_dataset`, download PDFs, or run the seed stage.

0 commit comments

Comments
 (0)