File size: 1,675 Bytes
324ecd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Record deterministic Space replays from real checkpoint forward passes."""
import json
from pathlib import Path
from beamboot.causal_lm import CausalMachine
from beamboot.os import OperatingMonitor, firmware


def main():
    base = CausalMachine.from_pretrained('artifacts/beamboot-monitor')
    dataset = {}
    cases = [('boot', None), ('help', 'help'), ('version', 'version'),
             ('add_7_8', (7, 8)), ('add_15_3', (15, 3)), ('add_0_0', (0, 0))]
    for name, command in cases:
        runtime = CausalMachine.__new__(CausalMachine)
        runtime.model = base.model
        runtime._reset(base.maximum)
        monitor = OperatingMonitor.__new__(OperatingMonitor)
        monitor.labels, monitor.runtime = firmware()[1], runtime
        monitor.started, monitor.waiting = False, None
        trace = []
        original = runtime.step
        def step():
            result = original()
            trace.append({'pc': result.pc, 'acc': result.acc, 'token': runtime.token,
                          'writes': runtime.writes, 'write': result.write, 'output': result.output})
            return result
        runtime.step = step
        boot = monitor.boot()
        if command is None:
            response = boot
        else:
            trace.clear()
            if isinstance(command, tuple): response = str(monitor.add(*command))
            else: response = getattr(monitor, command)()
        dataset[name] = {'boot': boot, 'response': response, 'trace': trace}
        print(name, len(trace), repr(response), flush=True)
    Path('static-space/traces.json').write_text(json.dumps(dataset, separators=(',', ':')))


if __name__ == '__main__': main()