File size: 2,589 Bytes
f764cdf
 
 
 
 
 
 
 
4b10a0d
 
 
 
 
 
 
 
 
 
 
 
 
 
f764cdf
 
 
 
 
 
4b10a0d
 
f764cdf
 
4b10a0d
f764cdf
 
 
 
 
 
 
 
4b10a0d
f764cdf
 
 
 
 
 
 
 
 
 
 
 
4b10a0d
 
f764cdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Immutable configuration and output models for repository sample building."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Mapping


BEGIN_REPO_NAME = "<|begin▁of▁repo▁name|>"
END_REPO_NAME = "<|end▁of▁repo▁name|>"
BEGIN_FILE_NAME = "<|begin▁of▁file▁name|>"
END_FILE_NAME = "<|end▁of▁file▁name|>"
BEGIN_FILE = "<|begin▁of▁file|>"
END_FILE = "<|end▁of▁file|>"
SPECIAL_TOKENS = (
    BEGIN_REPO_NAME,
    END_REPO_NAME,
    BEGIN_FILE_NAME,
    END_FILE_NAME,
    BEGIN_FILE,
    END_FILE,
)


@dataclass(frozen=True, slots=True)
class BuildConfig:
    """Controls deterministic repository sample construction.

    ``max_tokens`` is enforced with the supplied tokenizer, or the pinned
    DeepSeek V4 Flash Base tokenizer by default.
    """

    max_tokens: int = 8_192
    min_tokens: int = 1
    max_file_tokens: int | None = None
    include_weak_edges: bool = False
    metadata_only_vendor: bool = True
    metadata_only_generated: bool = True
    target_context: bool = False
    max_targets_per_repo: int = 32
    max_dependency_depth: int = 3
    utf8_bytes_per_token: float = 3.0

    def __post_init__(self) -> None:
        if self.max_tokens < 64:
            raise ValueError("max_tokens must be at least 64")
        if self.min_tokens < 0 or self.min_tokens > self.max_tokens:
            raise ValueError("min_tokens must be between 0 and max_tokens")
        if self.max_file_tokens is not None and self.max_file_tokens < 1:
            raise ValueError("max_file_tokens must be positive")
        if self.max_targets_per_repo < 0:
            raise ValueError("max_targets_per_repo must be non-negative")
        if self.max_dependency_depth < 0:
            raise ValueError("max_dependency_depth must be non-negative")
        if self.utf8_bytes_per_token <= 0:
            raise ValueError("utf8_bytes_per_token must be positive")


@dataclass(frozen=True, slots=True)
class SampleFile:
    """Provenance for one repository file represented in a sample."""

    path: str
    relation: str
    content_policy: str
    role: str = "unknown"
    language: str | None = None
    bytes: int = 0
    part: int = 1
    parts: int = 1


@dataclass(frozen=True, slots=True)
class Sample:
    """One rendered training document and its complete provenance."""

    sample_id: str
    repo_id: str
    revision_id: str
    kind: str
    text: str
    files: tuple[SampleFile, ...]
    token_count: int
    metadata: Mapping[str, Any] = field(default_factory=dict)