Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-train/blob/main/tests/omegallm/tok/ratio.sh # aien-train AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-train / tests / omegallm / tok / ratio.sh` 63 lines ยท 3100 bytes Raw Blame History 1 #!/bin/sh 2 # Own BPE compression measurement: train ollm-tok merges on a prefix of a training text, then 3 # encode a public-domain sample and a held-out text, prove both round trips exact, and print the 4 # byte and token counts (the ratio bytes/tokens is computed outside this script). 5 # 6 # BIN=path/to/ollm-tok TRAIN=text V=8192 MAXBYTES=`100000000` PD=pg1342.txt HELD=valid.txt \ 7 # sh tests/omegallm/tok/ratio.sh 8 # 9 # PD is Project Gutenberg eBook #1342 (Pride and Prejudice, public domain in the USA), fetched by the 10 # operator from https://www.gutenberg.org/cache/epub/1342/pg1342.txt and checked by sha256 below; 11 # only the text between the START and END lines is encoded. It is never committed. A missing or 12 # different PD file gives NOT_RUN for that sample. HELD (optional) is any held-out text. 13 # Environment: WORK (scratch, default scratch-tok-ratio beside the clone; keep it under a private 14 # directory when TRAIN is private), CORES (default 18-19), MODE (raw or chat, default raw). 15 # Runs at nice 10 inside bwrap with no network; only WORK is writable. 16 set -u 17 here=$(cd "$(dirname "$0")" && pwd) 18 BIN=${BIN:?set BIN} 19 TRAIN=${TRAIN:?set TRAIN} 20 V=${V:-8192} 21 MAXBYTES=${MAXBYTES:-0} 22 PD=${PD:-} 23 HELD=${HELD:-} 24 MODE=${MODE:-raw} 25 WORK=${WORK:-$here/../../../../scratch-tok-ratio} 26 CORES=${CORES:-18-19} 27 PDSHA=`3f6bb9d6f78e0293b56acd4714dd68cb7d6d1d293402031ce9d5a216bcaf9d75` 28 if [ -z "${TOK_RATIO_PINNED:-}" ]; then 29 mkdir -p "$WORK" 30 WORK=$(cd "$WORK" && pwd) 31 export TOK_RATIO_PINNED=1 WORK BIN TRAIN V MAXBYTES PD HELD MODE 32 exec taskset -c "$CORES" nice -n 10 bwrap --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp \ 33 --bind "$WORK" "$WORK" --unshare-net --die-with-parent -- sh "$0" "$@" 34 fi 35 cd "$WORK" || exit 2 36 echo "tok-ratio: bin sha256=$(sha256sum "$BIN" | cut -c1-16) mode=$MODE V=$V maxbytes=$MAXBYTES train_bytes=$(wc -c < "$TRAIN")" 37 /usr/bin/time -f "TIME toktrain %e s %M KiB" "$BIN" toktrain "$MODE" "$TRAIN" merges.bin "$V" "$MAXBYTES" || { echo "FAIL toktrain exit $?"; exit 1; } 38 echo "MERGES sha256=$(sha256sum merges.bin | cut -d' ' -f1) bytes=$(wc -c < merges.bin)" 39 fail=0 40 sample() { 41 _n=$1 _f=$2 42 /usr/bin/time -f "TIME tokenc $_n %e s" "$BIN" tokenc "$MODE" merges.bin "$_f" "$_n.tok" || { echo "FAIL $_n tokenc"; fail=1; return; } 43 "$BIN" tokdec merges.bin "$_n.tok" "$_n.back" >/dev/null || { echo "FAIL $_n tokdec"; fail=1; return; } 44 if cmp -s "$_f" "$_n.back"; then 45 echo "MEASURED $_n bytes=$(wc -c < "$_f") tokens=$(( $(wc -c < "$_n.tok") / 2 )) round_trip=PASS" 46 else 47 echo "FAIL $_n round trip"; fail=1 48 fi 49 rm -f "$_n.back" 50 } 51 if [ -n "$PD" ] && [ -r "$PD" ] && [ "$(sha256sum "$PD" | cut -d' ' -f1)" = "$PDSHA" ]; then 52 sed -n '/^\*\*\* START OF THE PROJECT GUTENBERG EBOOK/,/^\*\*\* END OF THE PROJECT GUTENBERG EBOOK/p' "$PD" \ 53 | sed '1d;$d' > pd-body.txt 54 sample pg1342-body pd-body.txt 55 else 56 echo "NOT_RUN pg1342-body: PD sample absent or not sha256 $PDSHA" 57 fi 58 if [ -n "$HELD" ] && [ -r "$HELD" ]; then 59 sample held "$HELD" 60 else 61 echo "NOT_RUN held: no HELD text" 62 fi 63 [ "$fail" = 0 ]