Download code/tests/test_pilot_core.py from PratikBuilds/modelclinic-experiment-001: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/datasets/PratikBuilds/modelclinic-experiment-001/resolve/main/code/tests/test_pilot_core.py
- Command line
-
hf download hf://datasets/PratikBuilds/modelclinic-experiment-001/code/tests/test_pilot_core.py
-
curl -L -o test_pilot_core.py https://huggingface.co/datasets/PratikBuilds/modelclinic-experiment-001/resolve/main/code/tests/test_pilot_core.py
2.54 kB
| import sys,json,tempfile,unittest | |
| from pathlib import Path | |
| sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src')) | |
| from pilot_core import * | |
| ROOT=Path(__file__).resolve().parents[1] | |
| class PilotCoreTests(unittest.TestCase): | |
| def setUp(self):self.c=read_json(ROOT/'experiments/pilot_001_config.json');self.q=read_jsonl(ROOT/'experiments/math500_pilot_20.jsonl') | |
| def test_configuration_and_heldout(self): | |
| self.assertTrue(validate(self.c,self.q)); c=dict(self.c); c['calibration_prompts']=[self.q[0]['problem']];self.assertRaises(AssertionError,validate,c,self.q) | |
| def test_prompt_condition_alignment_and_thinking(self): | |
| a=prompt(self.q[0],self.c);self.assertEqual(a,prompt(self.q[0],self.c));self.assertFalse(thinking('base_no_thinking'));self.assertTrue(all(thinking(c) for c in self.c['conditions'] if c!='base_no_thinking')) | |
| def test_resume_and_hash(self): | |
| h=fingerprint(self.c,self.q);r={'run_hash':h,'source_row':65,'condition':'edited','seed':1};self.assertIn((65,'edited',1),completed([r],h));self.assertRaises(ValueError,completed,[r,r],h);self.assertRaises(ValueError,completed,[r],'other') | |
| with tempfile.TemporaryDirectory() as d: | |
| p=Path(d)/'r.jsonl';append_record(p,r);self.assertEqual(read_jsonl(p),[r]) | |
| def test_loop_and_limits(self): | |
| self.assertTrue(loop_metrics([1,2,3,4]*12)['loop_detected']);self.assertFalse(loop_metrics(list(range(40)))['loop_detected']);c=dict(self.c);c['max_new_tokens']=99999;self.assertRaises(AssertionError,validate,c,self.q) | |
| if __name__=='__main__':unittest.main() | |
| class TestPairing(unittest.TestCase): | |
| def test_all_conditions_have_identical_question_and_config(self): | |
| c=read_json(ROOT/'experiments/pilot_001_config.json'); qs=read_jsonl(ROOT/'experiments/math500_pilot_20.jsonl'); pairs=[(q,k) for q in qs for k in c['conditions']] | |
| self.assertEqual(len(pairs),120) | |
| for q in qs: | |
| self.assertEqual(len({prompt(q,c) for a,k in pairs if a['source_row']==q['source_row']}),1) | |
| self.assertEqual(sum(not thinking(k) for q,k in pairs),20) | |
| def test_fingerprint_detects_changes(self): | |
| c=read_json(ROOT/'experiments/pilot_001_config.json');qs=read_jsonl(ROOT/'experiments/math500_pilot_20.jsonl'); d=dict(c);d['max_new_tokens']+=1;self.assertNotEqual(fingerprint(c,qs),fingerprint(d,qs)) | |
| class TestEos(unittest.TestCase): | |
| def test_model_eos_can_differ_from_tokenizer(self): | |
| self.assertTrue(stopped_on_eos([1,248044],[248044,248046]));self.assertFalse(stopped_on_eos([1,42],[248044,248046]));self.assertFalse(stopped_on_eos([],248044)) | |