import unittest from transformers import BeamForCausalLM from beamboot import tinylm from beamboot.os import firmware from beamboot.unified import UnifiedMonitor, ALPHABET class FirmwareTests(unittest.TestCase): def test_default_firmware_unchanged_and_lm_fits_rom(self): base, lm = firmware()[0], firmware(lm=True)[0] self.assertEqual(len(base), 184) self.assertLessEqual(len(lm), 256) self.assertNotIn('lm_first', firmware()[1]) class UnifiedMonitorTests(unittest.TestCase): @classmethod def setUpClass(cls): cls.mon = UnifiedMonitor() cls.boot = cls.mon.boot() def test_single_stock_model_runs_monitor_and_net(self): mon = self.mon self.assertIsInstance(mon.runtime.model, BeamForCausalLM) self.assertEqual(mon.runtime.model.config.num_hidden_layers, 3) self.assertEqual(self.boot, 'BEAM>\n') self.assertEqual(mon.version(), 'BEAMBOOT 0.1\n') self.assertEqual(mon.add(7, 8), 15) # lm: the firmware (in model weights) dispatches the command; the chars # come from the model's own 42-token-per-char trace, matching the reference. out = mon.lm('a', 3) self.assertEqual(out, 'LM:bcd\n') self.assertEqual(len(mon.last_trace), 42*3) self.assertEqual([ALPHABET.index(c) for c in out[3:-1]], tinylm.reference(mon.net, 0, 3)) # the OS keeps working after the net ran in the same KV cache self.assertEqual(mon.add(9, 9), 2) self.assertEqual(mon.help(), '1 HELP 2 VER 3 ADD\n') out = mon.lm('f', 2) self.assertEqual(out, 'LM:gh\n') self.assertEqual(mon.add(3, 4), 7) def test_rejects_bad_arguments(self): with self.assertRaises(ValueError): self.mon.lm('z', 3) with self.assertRaises(ValueError): self.mon.lm('a', 11) if __name__ == '__main__': unittest.main()