# export_c_dna.py - dump DNA-DiskChat-2B controller weights (fp32) + a prompt for # the C filter runtime. The codon table is already on disk as codons.u8 (128 B/row). import os, sys, struct, numpy as np, torch os.environ['CUDA_VISIBLE_DEVICES'] = '' sys.path.insert(0, '/root/dna') from model_dna import DnaChat from infer_dna import load_tok CK = os.environ.get('DNA_CK', '/root/dna/ckpt/base.pt') OUT = '/root/dna/ctrl_dna.bin' CODONS = '/root/dna/codons.u8' ck = torch.load(CK, map_location='cpu', weights_only=False) m = DnaChat(**ck['config']) m.load_state_dict({k.replace('_orig_mod.', ''): v for k, v in ck['model'].items()}, strict=True) m.eval() V, D, L, FF, A, Bp = m.vocab, m.d, m.layers, m.ff, m.a, m.b ncod = m.ncod def w(f, t): f.write(np.ascontiguousarray(t.detach().float().numpy().ravel(), dtype=' 1 else 'The capital of France is' ids = [tok.token_to_id('')] + tok.encode(prompt).ids np.asarray(ids, np.uint16).tofile('/root/dna/prompt.u16') print('PROMPT_IDS', len(ids), prompt, flush=True) # PyTorch reference: greedy next-token ids for parity check with the C runtime from infer_dna import load_model, generate mm, _ = load_model('cpu') ref = generate(mm, tok, prompt, n=32, temp=0.0, device='cpu') print('PYTORCH_REF:', ref, flush=True)