File size: 2,068 Bytes
5d32603 | 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 | from copy import deepcopy
from dataclasses import dataclass
import json
from pathlib import Path
import random
from omegaconf import OmegaConf
from rich import print
from refined_v4.data import atomic_json,load_rows,write_rows,signature
from . import ROOT,TASKS
from .data import documents
@dataclass
class Config:
source: str=str(ROOT/'variants/diverse-completion-v1')
root: str=str(ROOT/'variants/diverse-native-v1')
tokens: int=2097152
seed: int=6719
def build(config: Config):
source,root=Path(config.source),Path(config.root)
root.mkdir(parents=True,exist_ok=True)
if (root/'dataset.json').exists():
saved=json.loads((root/'dataset.json').read_text())
if saved['sft_tokens']!=config.tokens:
raise ValueError('Frozen native corpus budget differs')
return saved
if not (root/'data').exists():
(root/'data').symlink_to(source/'data',target_is_directory=True)
report=deepcopy(json.loads((source/'dataset.json').read_text()))
report.update(source=str(source),sft_tokens=config.tokens,source_revision='diverse-native-code-v1',
objective='Pack 2–4 independent native reference programs per document; all input predictions are supervised.')
for task in TASKS:
rows=load_rows(root,task,'sft')
corpus=documents(rows,config.tokens,random.Random(config.seed))
path=root/'sft'/task/'train.jsonl.gz'
write_rows(path,corpus)
report['tasks'][task].update(sft_sha256=signature(path),documents=len(corpus),
input_prediction_tokens=config.tokens,supervised_suffix_tokens=None,
sft_objective='All prediction tokens, with explicitly configured implementation-ending weights.')
atomic_json(root/'data-build-progress.json',report)
atomic_json(root/'dataset.json',report)
print('[green]Diverse native few-shot corpus ready[/green]',config.tokens,flush=True)
return report
if __name__=='__main__':
build(OmegaConf.to_object(OmegaConf.merge(OmegaConf.structured(Config),OmegaConf.from_cli())))
|