okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ba8745e13
main
1# Copyright (c) 2026 Peasant Smith and the Project Maya contributors (MIT; https://github.com/mw00/project-maya, v1.1.17). 2# Ported into Strata (third_party/project-maya/NOTICE.md, LICENSE); changes are in the git history of this file. 3"""tools/ds4/tok.py - token ids for maya-ds4's --ids, and text back from its output (DeepSeek-V4.1's tokenizer). 4 5python tools/ds4/tok.py --model ~/models/DSV4 --chat "Why is the sky blue?" [--think] -> 0,128803,... 6python tools/ds4/tok.py --model ~/models/DSV4 --decode 18033,1 -> text 7""" 8from __future__import annotations 9 10import argparse 11import pathlib 12import sys 13 14 15def main ()-> int : 16ap = argparse .ArgumentParser () 17ap .add_argument ("--model" ,default = str (pathlib .Path ("~/models/DSV4" ).expanduser ())) 18ap .add_argument ("--chat" ) 19ap .add_argument ("--think" ,action = "store_true" ,help = "thinking mode (the prompt ends with <think>)" ) 20ap .add_argument ("--text" ) 21ap .add_argument ("--decode" ) 22a = ap .parse_args () 23from tokenizers import Tokenizer 24tok = Tokenizer .from_file (str (pathlib .Path (a .model ).expanduser ()/ "tokenizer.json" )) 25if a .decode : 26ids = [int (x )for x in a .decode .replace (" " ,"" ).strip ("," ).split ("," )if x ] 27tok .decode (ids ,skip_special_tokens = False )) 28return 0 29if a .chat is not None : 30s = "<|begin▁of▁sentence|><|User|>" + a .chat + "<|Assistant|>" + ("<think>" if a .think else "</think>" ) 31else : 32s = a .text or "" 33"," .join (str (i )for i in tok .encode (s ,add_special_tokens = False ).ids )) 34return 0 35 36 37if __name__ == "__main__" : 38sys .exit (main ())