okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

waveringanaserve: restore the DeepSeek V4.1 server paths, tools and headers removed upstream, keeping the native picture tower firstba8745e13

main
1.6 KiB38 linesraw
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
5    python tools/ds4/tok.py --model ~/models/DSV4 --chat "Why is the sky blue?" [--think]   -> 0,128803,...
6    python 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:
16    ap = argparse.ArgumentParser()
17    ap.add_argument("--model", default=str(pathlib.Path("~/models/DSV4").expanduser()))
18    ap.add_argument("--chat")
19    ap.add_argument("--think", action="store_true", help="thinking mode (the prompt ends with <think>)")
20    ap.add_argument("--text")
21    ap.add_argument("--decode")
22    a = ap.parse_args()
23    from tokenizers import Tokenizer
24    tok = Tokenizer.from_file(str(pathlib.Path(a.model).expanduser() / "tokenizer.json"))
25    if a.decode:
26        ids = [int(x) for x in a.decode.replace(" ", "").strip(",").split(",") if x]
27        print(tok.decode(ids, skip_special_tokens=False))
28        return 0
29    if a.chat is not None:
30        s = "<|begin▁of▁sentence|><|User|>" + a.chat + "<|Assistant|>" + ("<think>" if a.think else "</think>")
31    else:
32        s = a.text or ""
33    print(",".join(str(i) for i in tok.encode(s, add_special_tokens=False).ids))
34    return 0
35
36
37if __name__ == "__main__":
38    sys.exit(main())