Add Control v2 incremental experiment results (evidence, visuals, 42 fixed samples)
a64600b verified Download method_v2/evidence/code/suite/tests/test_control.py from CharlesZhang-USTC/snf_experiments: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/CharlesZhang-USTC/snf_experiments/resolve/main/method_v2/evidence/code/suite/tests/test_control.py
- Command line
-
hf download hf://CharlesZhang-USTC/snf_experiments/method_v2/evidence/code/suite/tests/test_control.py
-
curl -L -o test_control.py https://huggingface.co/CharlesZhang-USTC/snf_experiments/resolve/main/method_v2/evidence/code/suite/tests/test_control.py
1.72 kB
| import unittest | |
| import torch | |
| from suite.control import gate,masked_decode | |
| class ControlTests(unittest.TestCase): | |
| def test_zero_support_is_untouched(self): | |
| s=torch.tensor([0.,.2,0.,1.]) | |
| for soft in [True,False]: | |
| for p in [0.,.01,.1,.5,1.]:self.assertTrue(torch.equal(gate(s,p,.2,soft)[s==0],torch.zeros(2))) | |
| def test_soft_zero_endpoint_is_continuous(self): | |
| self.assertLess(float(gate(torch.tensor([1e-8]),0.,.1)),1e-6) | |
| def run_order(self,arm,alpha=0.,ref=None): | |
| if ref is None:ref=torch.arange(12).reshape(1,12)%3 | |
| mask=torch.tensor([0.]*4+[1.]*4+[0.]*4);trace=[] | |
| def predict(ids): | |
| logits=torch.zeros(1,12,3);logits[:,:,0]=.3 | |
| logits[:,:,1]+=((ids==1).float().sum()/12) | |
| return logits | |
| out,commit=masked_decode(predict,ref,mask,3,6,dict(seed=2,alpha=alpha,arm=arm),trace) | |
| return out,commit,trace | |
| def test_permutations_preserve_compute_counts(self): | |
| traces=[self.run_order(a)[2] for a in ['confidence','target_first','target_last','random']] | |
| self.assertTrue(all([t['newly_committed'] for t in ts]==[t['newly_committed'] for t in traces[0]] for ts in traces)) | |
| for ts in traces:self.assertEqual(sum(t['newly_committed'] for t in ts),12) | |
| def test_alpha_zero_independent_of_reference(self): | |
| a=self.run_order('confidence',0.)[0];b=self.run_order('confidence',0.,torch.ones(1,12,dtype=torch.long)*2)[0] | |
| self.assertTrue(torch.equal(a,b)) | |
| def test_commit_is_complete(self): | |
| _,c,tr=self.run_order('target_last',.5);self.assertTrue(bool((c>=0).all()));self.assertTrue(all(t['gate_outside_max']==0 for t in tr)) | |
| if __name__=='__main__':unittest.main() | |