[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-VHellendoorn--Code-LMs":3,"tool-VHellendoorn--Code-LMs":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",143909,2,"2026-04-07T11:33:18",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,"2026-04-06T11:32:50",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":77,"owner_email":77,"owner_twitter":72,"owner_website":78,"owner_url":79,"languages":80,"stars":89,"forks":90,"last_commit_at":91,"license":92,"difficulty_score":10,"env_os":93,"env_gpu":94,"env_ram":95,"env_deps":96,"category_tags":103,"github_topics":104,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":108,"updated_at":109,"faqs":110,"releases":143},5079,"VHellendoorn\u002FCode-LMs","Code-LMs","Guide to using pre-trained large language models of source code","Code-LMs 是一个专注于源代码预训练大语言模型的资源指南与模型库，旨在帮助开发者和研究人员轻松使用针对编程任务优化的 AI 模型。它核心解决了通用语言模型在代码生成、补全及理解任务上表现不足的问题，提供了如 PolyCoder 等经过大规模代码数据训练的专用模型。\n\n该项目特别适合软件开发者、AI 研究人员以及对代码智能感兴趣的技术人员使用。用户可以直接通过 Hugging Face 快速加载不同参数量（从 1.6 亿到 27 亿参数）的 PolyCoder 模型，进行函数自动补全、算法生成等实验；也可以利用其提供的基于 GPT-NeoX 修改版的工具链，复现论文中的评估结果或进行深度微调。\n\nCode-LMs 的独特亮点在于其对代码特定语法的深度优化，例如在分词器中专门支持了制表符和换行符的处理，这对于保持代码格式规范至关重要。此外，项目不仅提供了便捷的 API 调用示例，还开源了完整的训练检查点、评估脚本以及配套的 Docker 镜像，极大地降低了复现前沿代码大模型研究的门槛，让用户无需从零开始即可探索代码生成的无限可能。","# Large Models of Source Code\nI occasionally train and publicly release large neural language models on programs, including [PolyCoder](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169.pdf). Here, I describe how to use these.\n\n## October 2022 - PolyCoder is available on Huggingface!\nThanks to [@NinedayWang](https:\u002F\u002Fgithub.com\u002FNinedayWang), PolyCoder is available on the Huggingface Hub!\n\nThe available models are:\n* `NinedayWang\u002FPolyCoder-160M`\n* `NinedayWang\u002FPolyCoder-0.4B`\n* `NinedayWang\u002FPolyCoder-2.7B`\n\nTo use in Huggingface, simply run (requires the newest version of `transformers`: `pip install transformers==4.23.0` ):\n```python\nimport transformers\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\nfrom packaging import version\nassert version.parse(transformers.__version__) >= version.parse(\"4.23.0\")\n\ntokenizer = AutoTokenizer.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\nmodel = AutoModelForCausalLM.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\n```\n\nThe model can be used, for example, by:\n```python\nprompt = '''def binarySearch(arr, left, right, x):\n    mid = (left +'''\ninput_ids = tokenizer.encode(prompt, return_tensors='pt')\nresult = model.generate(input_ids, max_length=50, num_beams=4, num_return_sequences=4)\nfor res in result:\n    print(tokenizer.decode(res))\n```\n\n## Table of Contents\n1. [Setup](#getting-started)\n2. [Models (incl. PolyCoder)](#models)\n3. [Datasets](#datasets)\n4. [Evaluation](#evaluation)\n5. [How to cite](#citation)\n\n\n## Getting Started\nAll current models were trained using the [GPT NeoX toolkit](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox). First, download a pretrained checkpoint as described below and then use this either with [a Docker image](#via-docker) or through our fork of this toolkit [from source](#from-source) to [generate code](#code-generation) or [replicate our evaluation](#evaluation).\n\n### Retrieving Checkpoints\nCheckpoint files for training PolyCoder are hosted on this [public Zenodo repository](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556). See [this section](#models) for details on currently available models. Model checkpoints range up to 6GB, which is also the amount of GPU memory they require to run (running on CPU is neither tested nor recommended). Download and untar a checkpoint file (in this case for a 2.7B parameter model trained for 150K steps) to a directory called `checkpoints\u002F`, using:\n\n```\nmkdir checkpoints\ncd checkpoints\nwget https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F2-7B-150K.tar\ntar -xvf 2-7B-150K.tar\n```\n\n### From Source\nWe maintain a public fork of the NeoX repository [here](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox), which includes the (minor) changes we made to the codebase to allow for tabs & newlines in the tokenization, and also includes instructions for running the perplexity and HumanEval tasks. Note that this repository uses [a forked version](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Flm-evaluation-harness) of the LM Evaluation Harness with the code benchmark from [our work](#citation).\n\nBuilding this repository should match the process for GPT-NeoX almost exactly. You may also use the Docker image mentioned next, but mounting a checkout of the latest version of this fork over the `\u002Fgpt-neox` directory inside the container. Once set up `generate.py` entrypoint (described [below](#code-generation)) for free-form code generation, or use one of the commands [here](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox#a-modified-version-for-polycoder-code-pretraining) to calculate perplexity and HumanEval results as in [the paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169).\n\n### Via Docker\nA *base* Docker image containing a slightly modified version of the [gpt-neox repository](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox) is [available via DockerHub](https:\u002F\u002Fhub.docker.com\u002Frepository\u002Fdocker\u002Fvhellendoorn\u002Fcode-lms-neox):\n```\ndocker pull vhellendoorn\u002Fcode-lms-neox:base\n```\n\nThis image can be used together with a checkpoint file hosted on this [public Zenodo repository](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556). The base Docker image size is 5.4GB. Once a checkpoint has been retrieved, start the container with the following commands (substituting another GPU device index if needed):\n```\nnvidia-docker run --rm -it -e NVIDIA_VISIBLE_DEVICES=0 --shm-size=1g --ulimit memlock=-1 --mount type=bind,src=$PWD\u002Fcheckpoints,dst=\u002Fgpt-neox\u002Fcheckpoints vhellendoorn\u002Fcode-lms-neox:base\n```\n\n### Code Generation\nThe following command can be used to generate code from a prompt:\n```\nsudo .\u002Fdeepy.py generate.py configs\u002Ftext_generation.yml checkpoints\u002Fconfigs\u002Flocal_setup.yml checkpoints\u002Fconfigs\u002F2-7B.yml\n```\n**Note:** if not using the 2.7B parameter model, replace the final config file with the appropriate model size (e.g., `small` = 160M parameters, `medium` = 405M).\n\nOnce the checkpoint has been loaded, you can feed it an example such as `def return1():\\n  \"\"\"Returns 1.\"\"\"\\n  ` (note the whitespace tokens) and watch it predict `return 1` (and then probably a bunch of other `returnX` methods, depending on the sample).\n\nThe modifications to gpt-neox mentioned above center around the need to allow tabs and newlines in the prompt input. For the _interactive_ mode, these can be added using their escaped versions (`\\t`, `\\n`); when using file-based input, the project will read the entire file instead of treating each line as a prompt. By default, the command below will create an interactive prompt and return relatively short outputs (256 tokens) with a sampling temperature of 0.5; this behavior can be changed in `\u002Fgpt-neox\u002Fcheckpoints\u002Fconfigs\u002Ftext_generation.yml`.\n\nA lower temperature (e.g., 0.2) will produce more consistent and plausible (to the model) predictions; a higher temperature such as the default may be useful for generating and evaluating many candidates (see [our paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169) for recommendations). For the latter setting, consider switching to the `input-file` mode and providing an entire snippet (without escaping whitespace) in the corresponding file\n\n## Multi-lingual Models\u003Ca name=\"models\">\u003C\u002Fa>\nSeveral models have been trained on a [large corpus](#data-characteristics) of code spanning 12 programming languages. This includes a 2.7B parameter model (nick-named **PolyCoder**, trained for 100K and 150K steps), a 405M parameter model (100K & 150K steps) and a 160M parameter model (150K steps).\n\n### Available Models\nAll models are available [at a public Zenodo repository](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556), in the form of `.tar` files with fairly self-explanatory names (e.g., 2-7B-100K => a 2.7B parameter model trained for 100K steps). Currently available models include:\n\n* **[GPT2 - 2.7B](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F2-7B-150K.tar):** A 32 layer, 2,560 dimensional Transformer model, trained with a batch size of 128 sequences (256K tokens). Models available both at 100K and at 150K steps steps.\n  * Note that GPT-Neox' [default config](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002F2-7B.yml) for this model was modified to reduce the number of training steps (and learning rate decay steps accordingly) to 160K, down from 320K, to better match the available training resources. Hence, this model may not have reached its peak performance.\n* **[GPT2 - 0.4B](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F0-4B-150K.tar):** A 24 layer, 1,024 dimensional Transformer model based on the [`medium` config](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002Fmedium.yml), trained with 256K tokens per batch.\n* **[GPT2 - 160M](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F160M-150K.tar):** A 12 layer, 768 dimensional Transformer model based on the [`small` config](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002Fsmall.yml), trained with 256K tokens per batch.\n\n### Training Process\nTraining was done on 4 to 8 NVIDIA RTX 8000 GPUs, largely following the standard config values, except also enabling \"scaled-upper-triang-masked-softmax-fusion\" and \"bias-gelu-fusion\" for performance and slightly changing the batch size (see [model details](#available-models)), data split (changed to 98.9%, 0.1%, 1%), initial loss scale (2^16), and print\u002Feval intervals.\n\nThe below image shows the loss curve of the various models' training process in terms of validation loss.\n![image](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FVHellendoorn_Code-LMs_readme_8e767fe8a895.png)\n\n### Caveats\nThe trained models come with a few minor known limitations:\n- This model was not trained to solve programming problems and may not perform well on a benchmark such as [HumanEval](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fhuman-eval). Models like Codex (powering Copilot) are pretrained on natural language, which may boost their ability to interpret NL prompts; this model only learned language from comments in code.\n- The model appears to start generating a random new file once it reaches the (predicted) end of the current one. It is possible that the end-of-document token was not properly added to the training data.\n- Whitespace is **very important** to the model, since no preprocessing was done on the input files. For instance, the following snippet will yield poor predictions, because in Java we would never expect an instance-method at the top-level, as is indicated by the single level of (`\\t`) indentation of the two lines within this method:\n```\npublic int getTotalWeight(List\u003CInteger> weights) {\\n\\t\u002F\u002F Sum weights in parallel.\\n\\treturn \n```\nAdjusting the indentation makes it predict more reasonable continuations:\n```\npublic int getTotalWeight(List\u003CInteger> weights) {\\n\\t\\t\u002F\u002F Sum weights in parallel.\\n\\t\\treturn \n```\nThe Codex model discusses controlling for this to increase usability; this may be worth doing in a future version of the model.\n\n\n## Datasets\n\n### 249GB Multi-Lingual Corpus\nThis is the corpus used to train PolyCoder. \n\nThe datasets were cloned overnight on October 9-10, 2021. To mine a similar training set, see [Data](https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Ftree\u002Fmain\u002FData).\n\nThe list of file paths can be downloaded from: [https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Findex.zip](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Findex.zip). \nEach row in the file is the file path along with its SHA-256 hash, to ease deduplication. That is, the hashes allow checking if files from any future test set were already contained in the training set.\n\nThe data collection and filtering process is described in detail in [the paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169.pdf) and below. The final, filtered dataset statistics are:\n\n|Language|Repositories|Size(GB)|Files|\n|------|-----|-----|-------|\n|C | 10,749 | 55G | 3,037,112 |\n|C# | 9,511 | 21G | 2,514,494 |\n|C++ | 13,726 | 52G | 4,289,506 |\n|Go | 12,371 | 15G | 1,416,789 |\n|Java | 15,044 | 41G | 5,120,129 |\n|JavaScript | 25,144 | 22G | 1,774,174 |\n|PHP | 9,960 | 13G | 1,714,058 |\n|Python | 25,446 | 16G | 1,550,208 |\n|Ruby | 5,826 | 4.1G | 674,343 |\n|Rust | 4,991 | 3.5G | 304,842 |\n|Scala | 1,497 | 1.8G | 245,100 |\n|TypeScript | 12,830 | 9.2G | 1,441,926 |\n\n### Data Collection & Filtering\nI cloned the most popular repositories for 12 popular programming languages with at least 50 stars (stopping at ~25K per language) from GitHub in October 2021. For each project, each file belonging to the majority-language of that project was extracted, yielding the training set below (after cleaning). This initial, unfiltered dataset spanned 631GB and 38.9M files.\n\nNext, similar to Codex and CodeParrot, very large (>1MB) and very short (\u003C100 tokens) files were filtered out, reducing the dataset to 424GB. Files were then deduplicated based on a hash of their content, which reduced the number of files by another 30% or so, leaving 249GB of data and 24.1M files. No tokenization filters were applied; the model processes entire files including all comments. A code-specific vocabulary was constructed on a random 5% subset of the files above.\n\n## Evaluation\nPlease find detailed instructions for replicating our perplexity and HumanEval results on [our public fork](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox#a-modified-version-for-polycoder-code-pretraining) of the NeoX repository. This in turn leverages [our extension](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Flm-evaluation-harness) of the LM Evaluation Harness.\n\n### Evaluating Codex\nTo download the test sets that we used in the paper (12 programming languages), use:\n```\nwget https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Funseen_test_sets.tar.gz\ntar -xvzf unseen_test_sets.tar.gz\n```\n\nTo get perplexity results on these samples using Codex' API, use:\n```\nexport OPENAI_API_KEY=\u003CYOUR OPEN AI API KEY>\npython3 -u Evaluation\u002Feval_codex_all.py --dirs Code-sampled100\n```\nWhere `\u003CYOUR OPEN AI API KEY>` is a private string that can be obtained by signing up for [OpenAI's beta](https:\u002F\u002Fbeta.openai.com\u002Faccount\u002Fapi-keys).\n\nAs of **March 2022**, getting an API Key is free for 3 months, and afterwards a credit card needs to be entered. However, even after entering a credit card, using our evaluation script does not lead to any costs.\n\n### Results - HumanEval\nThese are PolyCoder's results on the [HumanEval benchmark](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fhuman-eval):\n\n|Model|Pass@1|Pass@10|Pass@100|\n|------|-----|-----|-------|\n|PolyCoder (160M) | 2.13% | 3.35% | 4.88% |\n|PolyCoder (400M) | 2.96% | 5.29% | 11.59% |\n|PolyCoder (2.7B) | 5.59% | 9.87% | 17.68% |\n| CodeParrot (110M) | 3.80% | 6.57% | 12.78% |\n| CodeParrot (1.5B) | 3.58% | 8.03% | 14.96% | \n| GPT-Neo (125M) | 0.75% | 1.88% | 2.97% | \n| GPT-Neo (1.3B) | 4.79% | 7.47% | 16.30% | \n| GPT-Neo (2.7B) | 6.41% | 11.27% | 21.37% | \n| GPT-J (6B) | 11.62% | 15.74% | 27.74% | \n| Codex (300M) | 13.17% | 20.37% | 36.27% | \n| Codex (2.5B) | 21.36% | 35.42% | 59.50% | \n| Codex (12B) | 28.81% | 46.81% | 72.31% | \n\n\n### Results - Multilingual Language Modeling\nThese are the perplexity results of PolyCoder on the [multilingual test sets](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Funseen_test_sets.tar.gz):\n\n|Language| Perplexity |\n|------|-----|\n|C | 2.3464 |\n|C# | 2.5832 |\n|C++ | 2.9189 |\n|Go | 2.567 |\n|Java | 2.9194 |\n|JavaScript | 3.0611 |\n|PHP | 3.6954 |\n|Python | 3.1767 |\n|Ruby | 3.9742 |\n|Rust | 3.2449 |\n|Scala | 3.8735 |\n|TypeScript | 3.6143 |\n\nA comparison with the other models is available in Figure 6 in the paper:\n![image](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FVHellendoorn_Code-LMs_readme_eae4a1a7b7ff.png)\n\n## Citation\n\n[A Systematic Evaluation of Large Language Models of Code](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169)\n\n```\n@article{xu2022systematic,\n  title={A Systematic Evaluation of Large Language Models of Code},\n  author={Xu, Frank F and Alon, Uri and Neubig, Graham and Hellendoorn, Vincent J},\n  journal={arXiv preprint arXiv:2202.13169},\n  year={2022}\n}\n```\n","# 源代码大型模型\n我偶尔会训练并公开发布用于程序的大型神经语言模型，其中包括 [PolyCoder](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169.pdf)。在此，我将介绍如何使用这些模型。\n\n## 2022年10月——PolyCoder已在Huggingface上线！\n感谢 [@NinedayWang](https:\u002F\u002Fgithub.com\u002FNinedayWang)，PolyCoder现已在Huggingface Hub上可用！\n\n目前可用的模型有：\n* `NinedayWang\u002FPolyCoder-160M`\n* `NinedayWang\u002FPolyCoder-0.4B`\n* `NinedayWang\u002FPolyCoder-2.7B`\n\n要在Huggingface中使用，只需运行以下代码（需要最新版本的 `transformers`：`pip install transformers==4.23.0`）：\n```python\nimport transformers\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\nfrom packaging import version\nassert version.parse(transformers.__version__) >= version.parse(\"4.23.0\")\n\ntokenizer = AutoTokenizer.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\nmodel = AutoModelForCausalLM.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\n```\n\n例如，可以这样使用该模型：\n```python\nprompt = '''def binarySearch(arr, left, right, x):\n    mid = (left +'''\ninput_ids = tokenizer.encode(prompt, return_tensors='pt')\nresult = model.generate(input_ids, max_length=50, num_beams=4, num_return_sequences=4)\nfor res in result:\n    print(tokenizer.decode(res))\n```\n\n## 目录\n1. [准备工作](#getting-started)\n2. [模型（包括 PolyCoder）](#models)\n3. [数据集](#datasets)\n4. [评估](#evaluation)\n5. [如何引用](#citation)\n\n\n## 准备工作\n当前所有模型均使用 [GPT NeoX 工具包](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox) 训练而成。首先，请按照下文所述下载预训练检查点，然后可通过 [Docker 镜像](#via-docker) 或通过我们对该工具包的分支 [从源码编译](#from-source) 来进行 [代码生成](#code-generation) 或 [复现我们的评估](#evaluation)。\n\n### 获取检查点\n用于训练 PolyCoder 的检查点文件托管在这个 [公共 Zenodo 仓库](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556) 中。有关当前可用模型的详细信息，请参阅 [本节](#models)。模型检查点大小可达 6GB，这也是它们运行所需的显存容量（既未测试过也不建议在 CPU 上运行）。请下载并解压一个检查点文件（此处以训练了 15 万步的 27 亿参数模型为例），将其放置于名为 `checkpoints\u002F` 的目录中，操作如下：\n```\nmkdir checkpoints\ncd checkpoints\nwget https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F2-7B-150K.tar\ntar -xvf 2-7B-150K.tar\n```\n\n### 从源码编译\n我们在 [这里](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox) 维护了一个 NeoX 仓库的公开分支，其中包含了我们对代码库所做的（少量）修改，以支持分词时处理制表符和换行符，并且还包括运行困惑度和 HumanEval 任务的说明。请注意，此仓库使用的是 [lm-evaluation-harness 的一个分支版本](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Flm-evaluation-harness)，其中包含来自 [我们的工作](#citation) 的代码基准测试。\n\n构建此仓库的过程应与 GPT-NeoX 几乎完全一致。您也可以使用接下来提到的 Docker 镜像，但需将该分支的最新版本挂载到容器内的 `\u002Fgpt-neox` 目录下。设置完成后，即可运行 `generate.py` 入口脚本（详见 [下方](#code-generation)）进行自由格式的代码生成，或使用 [此处](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox#a-modified-version-for-polycoder-code-pretraining) 的命令来计算困惑度和 HumanEval 结果，正如 [论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169) 中所描述的那样。\n\n### 通过 Docker\n一个包含略微修改过的 [gpt-neox 仓库](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox) 的 *基础* Docker 镜像，已通过 [DockerHub](https:\u002F\u002Fhub.docker.com\u002Frepository\u002Fdocker\u002Fvhellendoorn\u002Fcode-lms-neox) 提供：\n```\ndocker pull vhellendoorn\u002Fcode-lms-neox:base\n```\n\n此镜像可与托管在 [公共 Zenodo 仓库](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556) 中的检查点文件一起使用。基础 Docker 镜像大小为 5.4GB。获取检查点后，可使用以下命令启动容器（如有需要，可替换其他 GPU 设备编号）：\n```\nnvidia-docker run --rm -it -e NVIDIA_VISIBLE_DEVICES=0 --shm-size=1g --ulimit memlock=-1 --mount type=bind,src=$PWD\u002Fcheckpoints,dst=\u002Fgpt-neox\u002Fcheckpoints vhellendoorn\u002Fcode-lms-neox:base\n```\n\n### 代码生成\n以下命令可用于根据提示生成代码：\n```\nsudo .\u002Fdeepy.py generate.py configs\u002Ftext_generation.yml checkpoints\u002Fconfigs\u002Flocal_setup.yml checkpoints\u002Fconfigs\u002F2-7B.yml\n```\n**注意：** 如果不使用 27 亿参数模型，请将最后一个配置文件替换为相应模型尺寸的文件（例如，“small”表示 1.6 亿参数，“medium”表示 4.05 亿参数）。\n\n加载检查点后，您可以输入类似 `def return1():\\n  \"\"\"Returns 1.\"\"\"\\n` 的示例（注意其中的空白标记），观察它预测出 `return 1`（然后可能还会生成许多其他 `returnX` 方法，具体取决于样本内容）。\n\n上述对 gpt-neox 的修改主要围绕允许在提示输入中使用制表符和换行符的需求。对于 _交互式_ 模式，可以使用转义版本（`\\t`、`\\n`）；而在使用文件输入时，程序会读取整个文件，而不是将每行视为一个单独的提示。默认情况下，以下命令会创建一个交互式提示，并以 0.5 的采样温度返回相对较短的输出（256 个标记）；这一行为可在 `\u002Fgpt-neox\u002Fcheckpoints\u002Fconfigs\u002Ftext_generation.yml` 中更改。\n\n较低的温度（如 0.2）会产生更一致且对模型而言更合理的预测；而较高的温度（如默认值）则可能有助于生成和评估大量候选结果（有关建议，请参阅 [我们的论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169)）。对于后者，可以考虑切换到“输入文件”模式，并在相应的文件中提供完整的代码片段（无需转义空白字符）。\n\n## 多语言模型\u003Ca name=\"models\">\u003C\u002Fa>\n多个模型是在涵盖 12 种编程语言的 [大型语料库](#data-characteristics) 上训练而成的。其中包括一个 27 亿参数的模型（昵称为 **PolyCoder**，分别训练了 10 万和 15 万步）、一个 4.05 亿参数的模型（10 万和 15 万步）以及一个 1.6 亿参数的模型（15 万步）。\n\n### 可用模型\n所有模型均可在 [公共 Zenodo 仓库](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556) 中找到，以 `.tar` 文件的形式提供，文件名较为直观易懂（例如，2-7B-100K 表示一个参数量为 27 亿、训练步数为 10 万的模型）。目前可用的模型包括：\n\n* **[GPT2 - 2.7B](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F2-7B-150K.tar)：** 一个 32 层、隐藏层维度为 2,560 的 Transformer 模型，采用 128 条序列（共 25.6 万 token）的批量大小进行训练。提供了训练步数分别为 10 万和 15 万的版本。\n  * 需要注意的是，针对该模型，GPT-Neox 的 [默认配置](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002F2-7B.yml) 被修改为将训练步数（以及学习率衰减步数）从 32 万减少至 16 万，以更好地匹配现有的训练资源。因此，该模型可能尚未达到其最佳性能。\n* **[GPT2 - 0.4B](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F0-4B-150K.tar)：** 一个 24 层、隐藏层维度为 1,024 的 Transformer 模型，基于 [`medium` 配置](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002Fmedium.yml)，每批次使用 25.6 万 token 进行训练。\n* **[GPT2 - 160M](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F160M-150K.tar)：** 一个 12 层、隐藏层维度为 768 的 Transformer 模型，基于 [`small` 配置](https:\u002F\u002Fgithub.com\u002FEleutherAI\u002Fgpt-neox\u002Fblob\u002Fmain\u002Fconfigs\u002Fsmall.yml)，每批次使用 25.6 万 token 进行训练。\n\n### 训练过程\n训练在 4 至 8 张 NVIDIA RTX 8000 GPU 上进行，基本沿用了标准配置参数，同时启用了“scaled-upper-triang-masked-softmax-fusion”和“bias-gelu-fusion”以提升性能，并略微调整了批量大小（详见 [模型详情](#available-models)）、数据划分比例（调整为 98.9%、0.1%、1%）、初始损失缩放系数（2^16）以及打印和评估间隔。\n\n下图展示了各模型验证损失随训练步数的变化曲线：\n![image](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FVHellendoorn_Code-LMs_readme_8e767fe8a895.png)\n\n### 注意事项\n这些训练好的模型存在一些已知的小限制：\n- 本模型并未专门针对编程问题进行训练，因此在类似 [HumanEval](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fhuman-eval) 的基准测试中表现可能不佳。像 Codex（Copilot 的核心模型）这样的模型是基于自然语言预训练的，这有助于它们更好地理解自然语言提示；而本模型仅从代码注释中学习语言。\n- 当模型生成到当前文件的“预期”末尾时，似乎会随机生成一个新的文件。这可能是由于训练数据中未正确添加文档结束标记所致。\n- 对于该模型而言，空格 **非常重要**，因为输入文件未经过任何预处理。例如，以下代码片段会导致较差的预测结果，因为在 Java 中我们通常不会期望在顶级作用域中出现实例方法，而这两行代码却显示为同一层级的缩进：\n```\npublic int getTotalWeight(List\u003CInteger> weights) {\\n\\t\u002F\u002F Sum weights in parallel.\\n\\treturn \n```\n适当调整缩进后，模型就能预测出更合理的续写内容：\n```\npublic int getTotalWeight(List\u003CInteger> weights) {\\n\\t\\t\u002F\u002F Sum weights in parallel.\\n\\t\\treturn \n```\nCodex 模型曾讨论过如何通过控制这些问题来提高实用性，未来版本的模型或许可以考虑这一点。\n\n\n## 数据集\n\n### 249GB 多语言语料库\n这是用于训练 PolyCoder 的语料库。\n\n这些数据集于 2021 年 10 月 9 日至 10 日夜间完成克隆。若需挖掘类似的训练集，请参阅 [Data](https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Ftree\u002Fmain\u002FData)。\n\n文件路径列表可从以下链接下载：[https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Findex.zip](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Findex.zip)。文件中的每一行包含文件路径及其 SHA-256 哈希值，便于去重。也就是说，通过哈希值可以检查未来测试集中是否存在已在训练集中出现过的文件。\n\n数据收集与筛选过程在 [论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169.pdf) 中有详细描述，最终筛选后的数据集统计如下：\n\n|语言|仓库数量|大小（GB）|文件数量|\n|------|-----|-----|-------|\n|C | 10,749 | 55G | 3,037,112 |\n|C# | 9,511 | 21G | 2,514,494 |\n|C++ | 13,726 | 52G | 4,289,506 |\n|Go | 12,371 | 15G | 1,416,789 |\n|Java | 15,044 | 41G | 5,120,129 |\n|JavaScript | 25,144 | 22G | 1,774,174 |\n|PHP | 9,960 | 13G | 1,714,058 |\n|Python | 25,446 | 16G | 1,550,208 |\n|Ruby | 5,826 | 4.1G | 674,343 |\n|Rust | 4,991 | 3.5G | 304,842 |\n|Scala | 1,497 | 1.8G | 245,100 |\n|TypeScript | 12,830 | 9.2G | 1,441,926 |\n\n### 数据收集与筛选\n2021 年 10 月，我从 GitHub 上克隆了 12 种流行编程语言中至少拥有 50 颗星的最受欢迎仓库（每种语言约克隆 2.5 万个），并提取了每个项目中属于其主流语言的所有文件，从而得到了下面的训练集（经过清理之后）。这一初始未过滤的数据集总大小为 631GB，包含 3890 万个文件。\n\n随后，类似于 Codex 和 CodeParrot 的做法，我们过滤掉了超大文件（超过 1MB）和超短文件（少于 100 个 token），使数据集规模缩减至 424GB。接着，我们根据文件内容的哈希值对文件进行去重，进一步减少了约 30% 的文件数量，最终得到 249GB 的数据和 2410 万个文件。我们没有应用任何分词过滤器；模型直接处理整个文件，包括所有注释。此外，我们还在上述文件的随机 5% 子集中构建了一个专用于代码的词汇表。\n\n## 评估\n有关如何复现我们的困惑度和 HumanEval 结果的详细说明，请参阅 NeoX 仓库的 [我们的公开分支](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox#a-modified-version-for-polycoder-code-pretraining)。该分支又利用了我们对 LM Evaluation Harness 的扩展版 [我们的扩展](https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Flm-evaluation-harness)。\n\n### 评估 Codex\n要下载我们在论文中使用的测试集（涵盖 12 种编程语言），请使用以下命令：\n```\nwget https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Funseen_test_sets.tar.gz\ntar -xvzf unseen_test_sets.tar.gz\n```\n\n若要使用 Codex 的 API 在这些样本上获得困惑度结果，请执行以下命令：\n```\nexport OPENAI_API_KEY=\u003CYOUR OPEN AI API KEY>\npython3 -u Evaluation\u002Feval_codex_all.py --dirs Code-sampled100\n```\n其中 `\u003CYOUR OPEN AI API KEY>` 是一个私密字符串，可通过注册 [OpenAI 的测试版](https:\u002F\u002Fbeta.openai.com\u002Faccount\u002Fapi-keys) 获取。\n\n截至 **2022 年 3 月**，获取 API 密钥前 3 个月是免费的，之后则需要绑定信用卡。不过，即使绑定了信用卡，使用我们的评估脚本也不会产生任何费用。\n\n### 结果 - HumanEval\n以下是 PolyCoder 在 [HumanEval 基准测试](https:\u002F\u002Fgithub.com\u002Fopenai\u002Fhuman-eval)上的表现：\n\n|模型|通过率@1|通过率@10|通过率@100|\n|------|-----|-----|-------|\n|PolyCoder (160M) | 2.13% | 3.35% | 4.88% |\n|PolyCoder (400M) | 2.96% | 5.29% | 11.59% |\n|PolyCoder (2.7B) | 5.59% | 9.87% | 17.68% |\n| CodeParrot (110M) | 3.80% | 6.57% | 12.78% |\n| CodeParrot (1.5B) | 3.58% | 8.03% | 14.96% | \n| GPT-Neo (125M) | 0.75% | 1.88% | 2.97% | \n| GPT-Neo (1.3B) | 4.79% | 7.47% | 16.30% | \n| GPT-Neo (2.7B) | 6.41% | 11.27% | 21.37% | \n| GPT-J (6B) | 11.62% | 15.74% | 27.74% | \n| Codex (300M) | 13.17% | 20.37% | 36.27% | \n| Codex (2.5B) | 21.36% | 35.42% | 59.50% | \n| Codex (12B) | 28.81% | 46.81% | 72.31% | \n\n\n### 结果 - 多语言语言建模\n以下是 PolyCoder 在 [多语言测试集](https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002Funseen_test_sets.tar.gz)上的困惑度结果：\n\n|语言| 困惑度 |\n|------|-----|\n|C | 2.3464 |\n|C# | 2.5832 |\n|C++ | 2.9189 |\n|Go | 2.567 |\n|Java | 2.9194 |\n|JavaScript | 3.0611 |\n|PHP | 3.6954 |\n|Python | 3.1767 |\n|Ruby | 3.9742 |\n|Rust | 3.2449 |\n|Scala | 3.8735 |\n|TypeScript | 3.6143 |\n\n与其他模型的对比见论文中的图 6：\n![image](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FVHellendoorn_Code-LMs_readme_eae4a1a7b7ff.png)\n\n## 引用\n\n[代码大型语言模型的系统性评估](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2202.13169)\n\n```\n@article{xu2022systematic,\n  title={A Systematic Evaluation of Large Language Models of Code},\n  author={Xu, Frank F and Alon, Uri and Neubig, Graham and Hellendoorn, Vincent J},\n  journal={arXiv preprint arXiv:2202.13169},\n  year={2022}\n}\n```","# Code-LMs (PolyCoder) 快速上手指南\n\nCode-LMs 是一系列在源代码上训练的大型神经语言模型，其中最著名的是 **PolyCoder**。该模型支持 12 种编程语言，适用于代码生成任务。本指南将帮助您快速部署并使用 Hugging Face 版本或本地源码版本。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux (推荐) 或 macOS\n- **GPU**: 推荐使用 NVIDIA GPU。\n  - 运行 2.7B 模型至少需要 **6GB** 显存。\n  - 运行 0.4B 模型约需 2-3GB 显存。\n  - *注意：官方未测试也不推荐在 CPU 上运行。*\n- **内存**: 建议系统内存大于 16GB。\n\n### 前置依赖\n- Python 3.8+\n- Git\n- Docker (可选，用于容器化部署)\n- NVIDIA Driver 和 CUDA Toolkit (若使用 GPU)\n\n## 安装步骤\n\n本项目提供两种主要使用方式：通过 **Hugging Face Transformers**（推荐，最简单）或通过 **源码\u002FDocker**（适合复现评估或自定义生成）。\n\n### 方案一：通过 Hugging Face 使用（推荐）\n\n这是最快捷的方式，无需下载大型检查点文件，直接利用 `transformers` 库加载。\n\n1. **安装依赖**\n   确保安装指定版本的 `transformers` 库：\n   ```bash\n   pip install transformers==4.23.0 packaging torch\n   ```\n   *(国内用户可使用清华源加速：`pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple transformers==4.23.0 packaging torch`)*\n\n2. **验证安装**\n   无需额外配置，直接在 Python 中导入即可。可用模型包括：\n   - `NinedayWang\u002FPolyCoder-160M`\n   - `NinedayWang\u002FPolyCoder-0.4B`\n   - `NinedayWang\u002FPolyCoder-2.7B`\n\n### 方案二：通过 Docker 或源码使用（高级）\n\n如果您需要复现论文中的评估结果或使用特定的生成配置，请使用此方案。\n\n#### 选项 A：使用 Docker (推荐)\n1. **拉取镜像**\n   ```bash\n   docker pull vhellendoorn\u002Fcode-lms-neox:base\n   ```\n   *(国内用户若无法连接 DockerHub，请配置阿里云或腾讯云镜像加速器)*\n\n2. **下载模型检查点**\n   从 Zenodo 下载所需模型（以 2.7B 为例）：\n   ```bash\n   mkdir checkpoints\n   cd checkpoints\n   wget https:\u002F\u002Fzenodo.org\u002Frecord\u002F6363556\u002Ffiles\u002F2-7B-150K.tar\n   tar -xvf 2-7B-150K.tar\n   cd ..\n   ```\n   *(注：若下载速度慢，可尝试使用多线程下载工具如 `aria2c`)*\n\n3. **启动容器**\n   将本地检查点目录挂载到容器中：\n   ```bash\n   nvidia-docker run --rm -it -e NVIDIA_VISIBLE_DEVICES=0 --shm-size=1g --ulimit memlock=-1 --mount type=bind,src=$PWD\u002Fcheckpoints,dst=\u002Fgpt-neox\u002Fcheckpoints vhellendoorn\u002Fcode-lms-neox:base\n   ```\n\n#### 选项 B：从源码构建\n克隆修改后的 GPT-NeoX 仓库：\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Ffrankxu2004\u002Fgpt-neox.git\ncd gpt-neox\n# 按照仓库内的 README 安装依赖并配置环境\n```\n\n## 基本使用\n\n### 1. 使用 Hugging Face 进行代码生成\n\n以下示例展示如何使用 PolyCoder-2.7B 模型根据提示词生成代码。\n\n```python\nimport transformers\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\nfrom packaging import version\n\n# 版本检查\nassert version.parse(transformers.__version__) >= version.parse(\"4.23.0\")\n\n# 加载模型和分词器\ntokenizer = AutoTokenizer.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\nmodel = AutoModelForCausalLM.from_pretrained(\"NinedayWang\u002FPolyCoder-2.7B\")\n\n# 将模型移至 GPU (如果可用)\nif torch.cuda.is_available():\n    model.to(\"cuda\")\n\n# 定义提示词 (注意保持缩进格式)\nprompt = '''def binarySearch(arr, left, right, x):\n    mid = (left +'''\n\n# 编码输入\ninput_ids = tokenizer.encode(prompt, return_tensors='pt')\nif torch.cuda.is_available():\n    input_ids = input_ids.to(\"cuda\")\n\n# 生成代码\n# num_beams=4 表示束搜索宽度，num_return_sequences=4 表示返回 4 个候选结果\nresult = model.generate(input_ids, max_length=50, num_beams=4, num_return_sequences=4)\n\n# 解码并打印结果\nfor res in result:\n    print(tokenizer.decode(res))\n```\n\n### 2. 使用命令行生成 (Docker\u002F源码模式)\n\n如果您使用的是 Docker 或源码部署，可以使用提供的脚本进行交互式生成。\n\n**命令示例：**\n```bash\nsudo .\u002Fdeepy.py generate.py configs\u002Ftext_generation.yml checkpoints\u002Fconfigs\u002Flocal_setup.yml checkpoints\u002Fconfigs\u002F2-7B.yml\n```\n\n**使用说明：**\n- **交互模式**：启动后，您可以输入包含转义字符的提示词（例如使用 `\\t` 代表制表符，`\\n` 代表换行符）。\n- **文件模式**：修改配置文件 `\u002Fgpt-neox\u002Fcheckpoints\u002Fconfigs\u002Ftext_generation.yml` 可切换到文件输入模式，直接读取完整代码片段。\n- **温度参数 (Temperature)**：\n  - 默认值较高，适合生成多样化的候选代码用于评估。\n  - 若需更稳定、合理的预测，建议在配置中将 temperature 设为 `0.2`。\n\n### 重要提示\n- **缩进敏感**：PolyCoder 对空白字符（空格、制表符）非常敏感。请确保输入提示词的缩进符合目标语言的语法规范，否则可能导致生成质量下降。\n- **模型局限**：该模型仅在代码及其注释上训练，未专门针对自然语言指令微调。对于复杂的自然语言需求描述，其表现可能不如 Codex 等模型。","某初创公司的后端工程师需要在深夜紧急修复一个遗留系统中的复杂二分查找算法，且必须确保新代码符合项目特定的编码风格。\n\n### 没有 Code-LMs 时\n- 工程师需手动查阅大量文档和旧代码库来回忆算法细节，耗时费力且容易出错。\n- 通用代码助手生成的代码往往缺乏对特定边界条件（如整数溢出）的处理，导致后续调试成本高昂。\n- 生成的代码风格与公司现有的缩进、命名规范不一致，需要人工逐行调整才能合并。\n- 面对非主流编程语言或特定领域的逻辑实现，通用模型经常产生幻觉或无法编译的代码片段。\n- 在离线或内网环境下，无法调用云端大模型辅助编程，开发进度被迫停滞。\n\n### 使用 Code-LMs 后\n- 直接输入函数签名和部分逻辑，Code-LMs 基于 PolyCoder 模型瞬间补全了完整的二分查找实现，包含正确的中间值计算逻辑。\n- 模型在训练时学习了海量真实代码库，自动添加了防止整数溢出的健壮性检查，显著降低了运行时错误风险。\n- 生成的代码天然契合开源社区的通用规范，且可通过微调适配特定风格，大幅减少了代码审查后的修改工作。\n- 凭借在多种编程语言上的预训练能力，Code-LMs 能准确理解并生成冷门语言或特定领域逻辑，提供可立即运行的解决方案。\n- 支持本地部署和离线运行，工程师无需联网即可利用高性能模型加速开发，保障了数据安全与开发连续性。\n\nCode-LMs 通过将通用的代码理解能力转化为具体的生产力，让开发者从繁琐的样板代码编写中解放出来，专注于核心业务逻辑的创新。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FVHellendoorn_Code-LMs_807d1d46.png","VHellendoorn","Vincent Hellendoorn","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FVHellendoorn_4013c2eb.png","AI4SE Researcher, Assistant Prof. at CMU","Carnegie Mellon University",null,"vhellendoorn.github.io","https:\u002F\u002Fgithub.com\u002FVHellendoorn",[81,85],{"name":82,"color":83,"percentage":84},"Python","#3572A5",88.8,{"name":86,"color":87,"percentage":88},"Shell","#89e051",11.2,1842,265,"2026-03-31T00:56:08","MIT","Linux","必需 NVIDIA GPU。训练使用 4-8 张 NVIDIA RTX 8000。推理 2.7B 模型需约 6GB 显存。通过 Docker 运行需支持 nvidia-docker (CUDA 环境)。","未说明",{"notes":97,"python":95,"dependencies":98},"1. 官方明确不建议在 CPU 上运行模型。2. 提供两种运行方式：使用提供的 Docker 镜像（推荐）或从源码编译特定的 gpt-neox 分支。3. 模型检查点文件最大约 6GB，托管在 Zenodo 上。4. 该模型对代码中的空白字符（空格、制表符）非常敏感，输入格式不当会导致预测效果差。5. 模型主要基于代码注释学习自然语言，可能在纯自然语言提示的编程任务（如 HumanEval）上表现不如 Codex。",[99,100,101,102],"transformers==4.23.0","gpt-neox (forked version)","lm-evaluation-harness (forked version)","packaging",[14,35],[105,106,107],"gpt-2","deep-learning","source-code","2026-03-27T02:49:30.150509","2026-04-07T22:49:53.141167",[111,116,121,126,131,135,139],{"id":112,"question_zh":113,"answer_zh":114,"source_url":115},23088,"在 Docker 中运行 PolyCoder 时遇到 CUDA CUBLAS_STATUS_EXECUTION_FAILED 错误怎么办？","这通常是因为 Docker 容器内部的 CUDA 版本与宿主机的 PyTorch 包不匹配。解决方案是在容器内重新安装与 Docker 镜像 CUDA 版本一致的 PyTorch。例如，如果 Docker 使用 CUDA 11.1，请运行以下命令（注意需要在容器内使用 sudo）：\npip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Ftorch_stable.html\n此外，请确保挂载检查点文件时路径正确：应将 `checkpoints-160M` 文件夹直接挂载到 `\u002Fgpt-neox\u002Fcheckpoints`，而不是包含子文件夹的路径。","https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Fissues\u002F23",{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},23089,"输入超过 1 个 token 时代码生成失败，但在单 token 输入时正常，如何解决？","这个问题通常与 CUDA 版本兼容性有关，特别是在使用 Singularity 或自定义 Docker 配置时。维护者建议升级 Docker 镜像中的 CUDA 版本（例如升级到 CUDA 11.5）并重新构建镜像。如果无法修改镜像，可以尝试基于原始仓库重新构建环境，确保 CUDA 驱动和 PyTorch 版本完全兼容。有用户通过重新基于（rebase）Docker 镜像解决了该问题。","https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Fissues\u002F30",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},23090,"运行 Hugging Face 示例时报错 'Failed to import transformers.models.gpt_neox.modeling_gpt_neox' 怎么办？","这通常是 `transformers` 库安装问题或执行方式不当导致的，尤其是在 Windows 系统上。尝试不要直接运行脚本文件，而是通过 Python 解释器调用模块。例如，使用 `python -m your_script` 或在交互式环境中导入。同时建议检查 `transformers` 版本（如 4.23.0），并确保在 Conda 虚拟环境中运行以避免依赖冲突。","https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Fissues\u002F40",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},23091,"PolyCoder 模型是否已发布到 Hugging Face Hub？如果没有，如何自行转换使用？","官方团队目前暂无足够人力直接将模型上传至 Hugging Face Hub，但提供了两种替代方案：\n1. 利用 Hugging Face `transformers` 库最近添加的 GPT-NeoX 20B 支持（PR #16659），尝试直接将 PolyCoder 的检查点替换到 NeoX 20B 的配置中，可能无需额外转换即可运行。\n2. 使用第三方仓库 [minimal-gpt-neox-20b](https:\u002F\u002Fgithub.com\u002Fzphang\u002Fminimal-gpt-neox-20b)，它提供了纯 PyTorch 方式加载 20B 检查点的方法，同样适用于 PolyCoder 的检查点。\n如果社区成员愿意协助转换，维护者非常欢迎并提供技术支持。","https:\u002F\u002Fgithub.com\u002FVHellendoorn\u002FCode-LMs\u002Fissues\u002F26",{"id":132,"question_zh":133,"answer_zh":134,"source_url":115},23092,"Docker 容器中挂载检查点文件时路径应该如何设置？","挂载检查点文件时，不应将包含版本号的子文件夹（如 `checkpoints-160M`）整体挂载，而应将该文件夹内的内容直接挂载到容器内的 `\u002Fgpt-neox\u002Fcheckpoints` 目录。例如，在运行命令的 `-v` 或 `--mount` 参数中，源路径应为 `...\u002Fcheckpoints-160M`，目标路径应为 `\u002Fgpt-neox\u002Fcheckpoints`，确保容器内该目录下直接包含检查点文件，而不是多一层子目录。",{"id":136,"question_zh":137,"answer_zh":138,"source_url":125},23093,"在 Windows 上运行 PolyCoder 的 Hugging Face 实现遇到问题，有什么建议？","Windows 用户可能会遇到兼容性问题。建议首先使用 Conda 创建独立的虚拟环境来隔离依赖。其次，尝试不要直接双击或通过文件资源管理器运行脚本，而是在命令行中使用 `python` 命令显式调用，或使用模块执行方式（`python -m`）。有用户反馈，改变调用方式（invoke instead of running directly）解决了奇怪的导入错误。",{"id":140,"question_zh":141,"answer_zh":142,"source_url":120},23094,"如何在没有 root 权限的集群上使用 Singularity 运行 PolyCoder？","在没有 root 权限的集群上，可以使用 Singularity 替代 Docker。关键步骤包括：\n1. 将镜像中的 `\u002Fgpt-neox` 目录复制出来，以便以读写模式绑定挂载（bind-mount）。\n2. 使用 `--writable-tmpfs` 参数启动容器以获得可写文件系统。\n3. 确保正确绑定挂载检查点目录和工作目录。\n示例命令：\nsingularity shell --nv -B $PWD\u002Fgpt-neox:\u002Fgpt-neox -B $PWD\u002Fcheckpoints-0-4B:\u002Fgpt-neox\u002Fcheckpoints --writable-tmpfs code-lms-neox_base.sif\n如果遇到崩溃，可能需要重新构建镜像以匹配集群的 CUDA 版本。",[]]