[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81319":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":14,"stars7d":14,"stars30d":14,"stars90d":13,"forks30d":13,"starsTrendScore":15,"compositeScore":16,"rankGlobal":8,"rankLanguage":8,"license":8,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":19,"hasPages":17,"topics":20,"createdAt":8,"pushedAt":8,"updatedAt":21,"readmeContent":22,"aiSummary":23,"trendingCount":13,"starSnapshotCount":13,"syncStatus":11,"lastSyncTime":24,"discoverSource":25},81319,"gpt-2-ts","badlogic\u002Fgpt-2-ts","badlogic",null,"TypeScript",45,2,44,0,1,3,38.03,false,"main",true,[],"2026-06-12 04:01:32","# gpt-2-ts\n\nhttps:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F27c98071-38f1-406d-a653-88b91766fe4e\n\nA tiny GPT-2 124M inference implementation in TypeScript.\n\nThe runtime is intentionally simple and C-like: fixed tensor files, `Float32Array` buffers, token-by-token inference, KV cache, top-k sampling, and streaming output.\n\n## Requirements\n\n- Node.js with built-in TypeScript type stripping, tested with Node `v25.2.1`\n- `uv` for the Python conversion tools\n\n## Setup\n\nInstall TypeScript typings\u002Fcompiler:\n\n```bash\nnpm install\n```\n\nDownload and convert OpenAI's original GPT-2 checkpoint:\n\n```bash\ncd convert\nuv sync\nuv run python download_model.py 124M\nuv run python convert.py --model 124M --clean\ncd ..\n```\n\nOther original GPT-2 sizes should also work:\n\n```bash\nuv run python download_model.py 355M   # or 774M, 1558M\nuv run python convert.py --model 355M --clean\n```\n\nThe runtime reads `tensors\u002Fhparams.json`, so model dimensions are not hardcoded. The 1558M model needs many GB of RAM\u002Fdisk.\n\nThis creates local, gitignored directories:\n\n```text\nmodels\u002F   # original OpenAI TensorFlow checkpoint files\ntensors\u002F  # converted .tensor files + tokenizer files\n```\n\n## Run\n\n```bash\nnode gpt-2.ts \"Hello, my name is\" --tokens=50 --top-k=40 --temperature=0.9\n```\n\nStreaming is on by default. Disable it with:\n\n```bash\nnode gpt-2.ts \"Hello\" --tokens=20 --stream=0\n```\n\nOther options:\n\n```text\n--tokens=N          number of new tokens, default 20\n--top-k=K           top-k sampling; use 1 for greedy, default 40\n--temperature=T     sampling temperature, default 0.9\n--stop-eos=0        do not stop on \u003C|endoftext|>\n--stream=0          print only final text\n```\n\n## Check\n\n```bash\nnpm run check\n```\n\n## Tensor format\n\nEach `.tensor` file is a 64-byte fixed little-endian header followed by raw row-major `float32` data:\n\n```c\ntypedef struct {\n    char magic[8];       \u002F\u002F \"GPT2TNS\\0\"\n    uint32_t version;    \u002F\u002F 1\n    uint32_t dtype;      \u002F\u002F 1 = float32\n    uint32_t ndim;\n    uint32_t reserved;\n    uint64_t shape[4];\n    uint64_t nbytes;\n} TensorHeader;\n```\n\nSee `convert\u002FREADME.md` for conversion details.\n","这是一个使用TypeScript编写的轻量级GPT-2 124M模型推理实现。项目核心功能包括基于`Float32Array`的缓冲区、逐token生成文本、KV缓存机制、top-k采样以及流式输出等特性，旨在提供一个简洁且类似C语言风格的运行环境。适用于需要在Node.js环境中进行自然语言处理任务的场景，特别是对于资源有限但又希望利用GPT-2模型能力的情况。通过简单的设置步骤，用户可以下载并转换OpenAI官方提供的GPT-2检查点文件来开始使用，支持多种大小的预训练模型，并可通过调整参数如生成长度、采样策略等定制化输出。","2026-06-11 04:04:36","CREATED_QUERY"]