File size: 4,822 Bytes
5b2d580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
"""Validate the prepared dataset locally; never authenticates or uploads."""
from pathlib import Path
import json,os,hashlib
os.environ['HF_HUB_OFFLINE']='1'
os.environ['HF_DATASETS_OFFLINE']='1'
import pyarrow.parquet as pq
import yaml,datasets,huggingface_hub
from huggingface_hub import DatasetCard

ROOT=Path(__file__).resolve().parents[1]

def main():
    front=ROOT.joinpath('README.md').read_text(encoding='utf-8').split('---',2)[1]
    meta=yaml.safe_load(front)
    assert len(meta['configs'])==8
    assert sum(bool(c.get('default'))for c in meta['configs'])==1
    assert meta['configs'][0]['config_name']=='evaluation'
    assert 'license'not in meta
    card=DatasetCard.load(str(ROOT/'README.md'))
    assert len(card.data.to_dict()['configs'])==8
    source={};records=[];contexts=[];row_counts={}
    for p in sorted((ROOT/'data').glob('*.parquet')):
        rows=pq.read_table(p).to_pylist()
        mirrors=[json.loads(l)for l in (ROOT/'tables_jsonl'/f'{p.stem}.jsonl').read_text().splitlines()]
        assert rows==mirrors
        row_counts[p.stem]=len(rows)
        if p.stem=='contexts':contexts=rows
        else:records.extend(rows)
    context_map={r['context_id']:r for r in contexts}
    assert len(context_map)==74
    total_masks=0;large_masks=0
    for r in records:
        f=r['source_file']
        if f not in source:source[f]=json.loads((ROOT/f).read_text())
        obj=source[f]
        for token in r['source_pointer'].split('/')[1:]:
            token=token.replace('~1','/').replace('~0','~')
            obj=obj[int(token)]if isinstance(obj,list)else obj[token]
        truth=obj['truth_evaluation']
        assert r['oracle_calls']==obj['total_oracle_calls']
        assert r['component_mse']==truth['component_mse']
        assert r['certified']==truth['certified']
        assert r['false_certificate_evaluation_only']==truth['false_certificate_evaluation_only']
        assert r['oracle_calls']==r['specialized_readout_calls']+r['fresh_risk_audit_calls']+r['search_and_screen_calls']
        assert r['context_id']in context_map
        for c in json.loads(r['charged_to_context_ids_json']):assert c in context_map
        masks=r['model_support_masks'];coefs=r['model_coefficients']
        assert len(masks)==len(coefs)==r['model_terms']
        assert dict(zip(masks,coefs))==obj['model']
        for mask in masks:
            assert isinstance(mask,str)and str(int(mask))==mask
            assert 0<=int(mask)<(1<<r['dimension'])
            large_masks+=int(int(mask)>2**64-1);total_masks+=1
    evaluations=[r for r in records if r['phase']=='evaluation']
    warmup=[r for r in records if r['phase']=='warmup']
    assert len(evaluations)==668 and len(warmup)==41
    assert len({r['record_id']for r in records})==709
    assert len({r['teacher_case_id']for r in evaluations})==148
    assert len({r['teacher_case_id']for r in warmup})==21
    assert sum(r['certified']for r in evaluations)==661
    for c in contexts:
        calls=sum(r['oracle_calls']for r in evaluations if r['context_id']==c['context_id'])
        assert c['evaluation_oracle_calls']==calls
        assert c['training_inclusive_calls']==calls+c['charged_training_calls']
    expected={'evaluation':668,'core_evaluation':324,'probe_evaluation':120,'strong_evaluation':192,
              'unified_evaluation':32,'warmup_usages':41,'all_risk_records':709,'contexts':74}
    loaded={}
    # Load the local repository using actual dataset-card configuration, not
    # an independently reconstructed list of files.
    for config in meta['configs']:
        name=config['config_name']
        data=datasets.load_dataset(str(ROOT),name=name)
        assert len(data)==1
        split=list(data)[0]
        assert data[split].num_rows==expected[name]
        loaded[name]={'split':split,'rows':data[split].num_rows,'columns':len(data[split].column_names)}
    default=datasets.load_dataset(str(ROOT))
    assert default['evaluation'].num_rows==668
    archive=ROOT/'release/Nhioryum_Phi_Research_Package.zip'
    sha=hashlib.sha256(archive.read_bytes()).hexdigest()
    assert sha=='925b1b7a917c5a16c25f1ade5a08c9622366cbe3b0e6da828a3e9fbfa7ca8e54'
    result={'local_card_metadata_valid':True,'actual_datasets_local_load':loaded,
        'default_config_load_rows':668,'parquet_jsonl_exact_roundtrip':True,
        'source_pointer_records_verified':len(records),'context_rows_verified':len(contexts),
        'support_masks_verified':total_masks,'support_masks_above_uint64_preserved_as_strings':large_masks,
        'original_archive_sha256':sha,'datasets_version':datasets.__version__,
        'huggingface_hub_version':huggingface_hub.__version__,
        'remote_upload_performed':False,'network_disabled_for_validation':True}
    print(json.dumps(result,indent=2))

if __name__=='__main__':main()