File size: 591 Bytes
17e10c6 | 1 2 3 4 5 6 7 8 9 10 11 | import json
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("openbmb/MiniCPM5-1B")
rows = [json.loads(l) for l in open("data_native/mt_train.jsonl", encoding="utf-8")]
lens = sorted(len(tok(tok.apply_chat_template(r["messages"], tools=r["tools"], tokenize=False), add_special_tokens=False)["input_ids"]) for r in rows)
def p(q): return lens[min(len(lens)-1, int(len(lens)*q))]
print("n", len(lens), "p50", p(.5), "p75", p(.75), "p90", p(.9), "p95", p(.95), "max", lens[-1])
for cap in (1024, 1280, 1536):
print(cap, "keeps", sum(1 for x in lens if x <= cap))
|