GPT-2 small language model (int8) for the AI text detector =========================================================== Used by: /ai-detector and /ar/ai-detector ("language-model signals", English text only). Runs on the device with ONNX Runtime Web; the files are served from this site and cached in the browser's Cache Storage ("gpt2-lm-v1"). No text is sent anywhere. Files ----- gpt2-lm-int8.onnx.part0 .. part7 one ONNX model split into 8 byte ranges (each under 17 MB); the worker concatenates them. Total 128,772,319 bytes, SHA-256 1870762c0f2c6aa818b544d05736495a1a1468289c473a0fd5ca891fab55d661 gpt2-bpe.txt GPT-2 byte-level BPE vocabulary: 50,256 base64 tokens, line number = token id (rank); <|endoftext|> is 50256. Weights and licence ------------------- Model: GPT-2 small (124M parameters) by OpenAI, https://github.com/openai/gpt-2 Licence: "Modified MIT License" (MIT permission text plus a non-binding request about generated content; this tool does not generate text). See LICENSE-gpt2-MIT.txt. Source of the ONNX file: the ONNX Model Zoo, onnx/models (Apache-2.0), validated/text/machine_comprehension/gpt-2/model/gpt2-lm-head-10.onnx (PyTorch GPT-2 with LM head exported to ONNX, opset 10; 664,871,060 bytes, SHA-256 12fbb1ec2d2d70c8ebd21a290a348a4109447b98582af64c6f93b6526d5c8f35). See LICENSE-onnx-models-Apache-2.0.txt. Vocabulary: the GPT-2 BPE ranks (OpenAI, MIT) as packaged in the npm package js-tiktoken 1.0.21 (MIT), dist/ranks/gpt2.js, rewritten one token per line. Modifications (scripts/gpt2/convert.py, Python onnx 1.23 + onnxruntime 1.30; reproducible) ----------------------------------------------------------------------- 1. Kept only the logits output (the 12 key/value "present" outputs are dropped) and shared one causal-mask buffer instead of 12 identical copies. 2. Gemm -> MatMul + Add; opset 10 -> 13 (onnx.version_converter). 3. Weight-only int8: every transformer MatMul weight is stored as int8 with one float scale per output column and turned back into float32 by Cast + Mul, which ONNX Runtime constant-folds when the model loads (so it computes in float32; about 0.5 GB of memory). 4. The token embedding and the LM head are tied in GPT-2; they now share ONE int8 matrix (block-wise, 32 values per float16 scale), used by the embedding Gather and by the LM head as Gemm(transB=1). The position embedding is int8 with one scale per row. 5. A negative-log-likelihood head replaces the logits output: inputs `input1` (token ids, [1, 1, T]) and `targets` ([1, 1, T]); output `nll` ([1, 1, T]) = -log p(target | prefix) via LogSoftmax + GatherElements, so the 50,257-way logits never leave the model. Check (Python onnxruntime, one thread, 35 English test passages): per-token NLL correlates at least 0.9966 with the unmodified float32 model; per-text perplexity is within -1.3% .. +3.9% of the float32 value.