[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-google-research--prompt-tuning":3,"tool-google-research--prompt-tuning":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 真正成长为懂上",155373,2,"2026-04-14T11:34:08",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[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},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"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":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":76,"owner_email":76,"owner_twitter":76,"owner_website":77,"owner_url":78,"languages":79,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":92,"env_os":93,"env_gpu":94,"env_ram":95,"env_deps":96,"category_tags":107,"github_topics":108,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":112,"updated_at":113,"faqs":114,"releases":115},7480,"google-research\u002Fprompt-tuning","prompt-tuning","Original Implementation of Prompt Tuning from Lester, et al, 2021","prompt-tuning 是谷歌研究团队开源的代码库，完整复现了 2021 年 EMNLP 论文中提出的“提示微调”（Prompt Tuning）技术。在大模型时代，传统的全量微调需要更新数十亿参数，不仅计算成本高昂，还难以部署。prompt-tuning 巧妙地解决了这一痛点：它保持预训练模型主体参数冻结不变，仅通过学习和优化少量可训练的“提示向量”，就能让模型适应下游任务。这种方法在大幅降低显存占用和训练时间的同时，依然能取得与全量微调相媲美的性能，极大地提升了参数效率。\n\n该项目基于 T5X、Flax 和 JAX 生态构建，提供了从环境搭建、模型训练到推理预测的完整流程，并支持在云 TPU 上高效运行。代码库中包含了详细的配置示例、演示脚本以及部分已发布的模型检查点，方便用户快速上手复现实验结果。由于其高度专业化的技术栈和对底层深度学习框架的依赖，prompt-tuning 主要面向人工智能研究人员、算法工程师及希望探索参数高效微调技术的开发者。对于想要在不消耗巨大算力的前提下挖掘大模型潜力，或深入研究提示学习机制的专业人士来说，这是一个极具参考价值的基准实现。","# Prompt Tuning\n\nThis is the code to reproduce the experiments from the EMNLP 2021 paper \"The\nPower of Scale for Parameter-Efficient Prompt Tuning\"\n[(Lester et al., 2021)](https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243\u002F).\n\nThese models are built on [T5X](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x), which\ndefines the model and training loop;\n[Flaxformer](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fflaxformer), which defines the actual\nmodel computation; [Flax](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fflax), which defines the low\nlevel model layers; and [Jax](https:\u002F\u002Fgithub.com\u002Fjax-ml\u002Fjax), which provides the\nactual execution. Details of our implementation can be found\n[here](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fimplementation.md).\n\n## Table of Contents\n\n*   [Installation](#installation)\n*   [Training a Prompt](#training-a-prompt)\n    *   [Training a Prompt on a Pod Slice](#training-a-prompt-on-a-pod-slice)\n    *   [Custom Dependencies](#custom-dependencies)\n*   [Inference with a Prompt](#inference-with-a-prompt)\n*   [Model Configuration](#model-configuration)\n*   [Prompt Initialization](#prompt-initialization)\n*   [Released Model Checkpoints](#released-model-checkpoints)\n*   [Released Prompts](#released-prompts)\n*   [Extra Resources](#extra-resources)\n*   [ How to Cite](#how-to-cite)\n\n## Installation\n\n1.  Follow the first 3 steps in the\n    [T5X installation instructions](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x#installation)\n    to create a cloud TPU VM. Also follow step 5 and create a Google Cloud\n    Storage (GCS) bucket. We will read and write data to this bucket using a URI\n    formatted like `gs:\u002F\u002F{bucket-name}\u002Fpath\u002Fto\u002Fitem\u002Fin\u002Fbucket`. This is where we\n    will store cached datasets as well as model checkpoints and results. For\n    ease of reference, some of the most common cloud commands for interacting\n    with the TPU VMs are\n\n```sh\n# Create a Cloud TPU VM\n$ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n    --zone ${ZONE} \\\n    --accelerator-type v3-8 \\\n    --version v2-alpha\n\n# SSH into a Cloud TPU VM\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} --zone ${ZONE}\n\n# Delete a Cloud TPU VM\n$ gcloud alpha compute tpus tpu-vm delete ${TPU_NAME} --zone ${ZONE}\n```\n\n2.  You should now be at the command-line of the TPU VM instance. Clone the\n    Prompt Tuning repository.\n\n```sh\ngit clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\ncd prompt-tuning\n```\n\n3.  Install the Prompt Tuning library.\n\n```sh\npython3 -m pip install .[tpu] -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\nIf you run into an error where pip tries to install earlier and earliler\nversions of dependencies (TensorFlow for example) until it tries to install\nversion `0.0.0` and then fails try adding `--use-deprecated=legacy-resolver` to\nthe install command. This error is related to required versions betweens\ndependencies and the behavior is often called backtracking. If you use the\nflag, it is possible that incompatible versions of libraries may be installed\nand you should look out for warnings about mismatches in the output of the\ninstall command.\n\n*Note:* If you plan to hack on the internals of prompt tuning and need an\neditable install (so changes in the cloned code are used when you run training)\nrun `pip` with the `-e` flag and you may need to delete the `pyproject.toml`\nfile if you are getting errors during installation.\n\nTo run the tests, install the package with the `[test]` (`python3 -m pip install\n.[test] ...`) option and then run `python3 -m pytest` from the root of the\ncloned repository.\n\n## Training a Prompt\n\nTraining a prompt is similar to\n[fine-tuning a model with T5X](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x\u002Fblob\u002Fmain\u002FREADME.md#fine-tuning);\nthe main difference is that we have our own set of Prompt Tuning configuration\nfiles to use.\n\nWe provide a demo script (`prompt_tuning\u002Fscripts\u002Fsst2-demo.sh`) that has all the\nrequired parts for training a prompt. You can use this as a starting point, or\nset `MODEL_DIR` and `TFDS_DATA_DIR` environment variables with paths to your\nGoogle Cloud Storage bucket to run this script directly.\n\n```sh\n.\u002Fprompt-tuning\u002Fprompt_tuning\u002Fscripts\u002Fsst2-demo.sh\n```\n\nTo help with iteration speed, we tend to specify a lot more options the command\nline rather than bundling all of the configuration into a single gin file. A few\noptions of note:\n\n*   `--gin_search_paths` :: a comma separated list of directories to use as path\n    prefixes for gin files. We can use `prompt_tuning.scripts.find_module\n    ${module}` to find the install location of libraries that bundle\n    configurations with them.\n*   `--gin_file` :: The gin file to load. We tend to use paths relative starting\n    with the library they are installed with, i.e.\n    `prompt_tuning\u002Fconfigs\u002Fmodels\u002Ft5_1_1_base_prompt.gin` over\n    `models\u002Ft5_1_1_base_prompt.gin` to avoid any confusion. Using the flag\n    multiple time can be used to specify multiple gin files that will get merged\n    together. Any configurations options set in multiple files will use the\n    value from the last file in the list.\n*   `--gin.{PARAM}={VALUE}` :: This general override flag will set `PARAM` to\n    `VALUE`. This can be used to easily set configuration options without\n    requiring them to be actual command line arguments. For example.\n    `--gin.utils.SaveCheckpointConfig.keep=20` will save the last 20\n    checkpoints.\n\n### Training a Prompt on a Pod Slice\n\nAs models get larger, xl and xxl for example, they do not fit on the 8 TPUs that\ncome with a single TPU VM. In these cases we will need a slice of a TPU pod\n(more information about TPU architecture and available configurations can be\nfound [here](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Fsystem-architecture-tpu-vm)). The\nmain difference between training a prompt on a single TPU VM and on a Pod slice\nis that we now have multiple TPU VMs and will run the same SPMD JAX each VM,\nthis page has more information on\n[multi-host](https:\u002F\u002Fjax.readthedocs.io\u002Fen\u002Flatest\u002Fmulti_process.html) JAX\nprograms. [This guide](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Fjax-pods) gives a quick\nintroduction to running JAX programs on a TPU Pod slice, but we will hit main\npoints here.\n\n1.  Create a TPU Pod slice.\n    [This page](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Ftypes-zones#us) lists which\n    accelerator types are available in which zones. This is the same as\n    creating a TPU VM above, except that we are requesting 32 TPUs instead of\n    8.\n\n```sh\n$ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n    --zone ${ZONE} \\\n    --accelerator-type v3-32 \\\n    --version v2-alpha\n```\n\n2.  Install the Prompt Tuning library. Given that we now have 4 TPU VM, each one\n    has 8 of out TPUs, we want to forgo ssh'ing directly into the VM, as we\n    would need to do that for each host. Instead, the Google Cloud SSH command\n    allows use to specify a command to run with the `--command=` flag and that\n    it should be run on all our VMs (called workers) with `--worker=all`.\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\"git clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning && cd prompt-tuning && \"\npython3 -m pip install . -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\n3.  Write the script to train your prompt. We included a demo script\n    (`\u002Fprompt_tuning\u002Fscripts\u002Fsst2-xxl-demo.sh`) the trains an prompt to solve\n    the [SST2](https:\u002F\u002Fnlp.stanford.edu\u002Fsentiment\u002F) dataset using T5 1.1 lm100k\n    XXL. You can use this as a starting point or just fill in the paths to your\n    Google Cloud Storage bucket to specify where you want to save your results\n    (`MODEL_DIR`) and where to cache TFDS data (`TFDS_DATA_DIR`), or set them as\n    environment variables.\n\n4.  Copy your training script each worker. If this is your first time running\n    `scp` you may get error, run the `ssh-add \u002F...\u002F.ssh\u002Fgoogle_compute_engine`\n    command from the error message and try again.\n\n```sh\n$ gcloud alpha compute tpus tpu-vm scp sst2-xxl-demo.sh ${TPU_NAME}: \\\n  --zone=${ZONE}\n  --worker=all\n```\n\n5.  Execute your training script.\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\".\u002Fsst2-xxl-demo.sh\"\n```\n\nIf one of the workers has an error during training, you will be left with\nprocesses that are using the TPUs on the other workers. This will stop you from\nrestarting your job until those processes a terminated and release the TPU. The\nfollowing command should end all these processes. You may see the `kill` command\nman page come back from the worker who had the initial error.\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\"sudo lsof -t \u002Fdev\u002Faccel0 | xargs kill -9\"\n```\n\n### Custom Dependencies\n\nTo train prompts using custom parts, like your own dataset, follow the\n[T5X Instructions on Custom Components](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x#custom-components)\n\nIf you package your code as a pip-installable python package, you won't be bound\nto a single directory, and you can use `python3 -m\nprompt_tuning.scripts.find_module {your_module}` to help set the\n`gin_search_paths` so that gin configs bundled in your library are findable.\n*Note:* If you do plan to bundle gin configs in an installable package, make\nsure that the directories that contain the config files have an `__init__.py` as\ngin requires files to be in a python package.\n\nIf parts of your custom components are gin configurable, they need to be\nexplicitly imported in your gin files; if they end up getting imported after the\ngin files are parsed, they will cause an error. If none of your dependencies\ncontain gin configurables, you can avoid writing a gin file by passing\n`--gin.MIXTURE_OR_TASK_MODULE=\"'path.to.your.module'`. This will automatically\nimport your module and is convenient for when all you are doing is swapping out\ndatasets.\n\n\n## Inference with a Prompt\n\nOur suggested way to do inference with a prompt is to load the original\ncheckpoint used to initialize the model, and the prompt from a file. As\nexplained in this section about\n[partial loading](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fimplementation.md#partial-loading)\nT5X supports loading some model parameters while initializing others from\nscratch. We use this in conjunction with the `from_array` prompt initializer to\nreload the frozen parameters from the original checkpoint and the prompt file a\nfile. The\n[`configs\u002Fruns\u002Fprompt_eval.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fruns\u002Fprompt_eval.gin)\nsets up this configuration for you; you just have to supply a `PROMPT_FILE`. If\nyour model was trained with any of the `prompts\u002F` config files, you can remove\nthem from the arguments to the evaluation script.\n\nThe included `sst2-demo-eval.sh` script shows an example of doing evaluation\nthis way. All that is needed is to set `EVAL_DIR` and `TFDS_DATA_DIR`\nenvironment variables to the paths to store the output of evaluation and the\ntensorflow datasets cache respectivly.\n\nIn T5X, the evaluation script assumes that your dataset has labels and outputs\nthe final results from your dataset's metric functions. The inference script\ndoes not require labels and instead outputs your model's prediction. We\ninclude an analogous\n[`prompt_infer.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fruns\u002Fprompt_infer.gin)\nfile to use with the inference script.\n\nIf you want to do inference or evaluation with the t5x checkpoint that is\nproduced from a prompt tuning training run, you can use the `(eval|infer).gin`\nconfig from T5X directly. You will need to update the\n`utils.RestoreChekcpointConfig` though. You should set `path` to the new\ncheckpoint, `assignment_map=()` and `fallback_to_scratch=False`.\n\n## Model Configuration\n\nAll model, training, evaluation, saving, restoring, etc. configuration is done\nvia gin. See\n[the gin-config repository](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fgin-config#readme) for a\ngeneral introduction to gin and\n[this primer](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x\u002Fblob\u002Fmain\u002Fgin-primer.md)\n\nWe follow the T5X configuration layout:\n\n*   `runs\u002F` :: contains configs for the actual training of model. This is where\n    things like dataset and evaluation configuration go.\n*   `architectures\u002F` :: contains configs for how the model works. This is where\n    things like encoder-decoder vs decoder-only and embedding sharing are\n    configured.\n*   `models\u002F` :: contains configs that set model specific parameters like the\n    number of layers or the size of the embedding table. It also configures\n    things like the T5X model wrapper used.\n  *   `models\u002Fdecoding\u002F` :: contains easy to use configs to swap out how the\n      model generates text during inference, includes configs for beam search\n      and nucleus sampling.\n  *   `models\u002Fsizes\u002F` :: contains the various settings to create models of\n      different sizes, these are combined with the default versions to create a\n      sized version, for example,`t5_1_1_prompt.gin` + `sizes\u002Flarge.gin`\n      creates a T5 1.1 Large model. Some common combinations already available\n      as gin files with the right includes (`t5_1_1_large_prompt.gin` for our\n      example above). _Note:_ These size files need to come __after__ the main\n      model file.\n*   `prompts\u002F` :: Our extra directory contains configs that set the `PROMPT` gin\n    variable, allowing for easy switching of the prompt initialization based\n    which prompt file is added as a `--gin_file` argument (it needs to come\n    after the `models\u002F` gin file),\n\n### Order of gin config files\n\nWhen specifying `--gin_file` arguments in the command line, the order matters.\nThe general order in which the gin files must be specified is:\n\n1.  `models\u002F*.gin`\n1.  `prompts\u002F*.gin`\n1.  `models\u002Fsizes\u002F*.gin*`\n1.  `models\u002Fdecoding\u002F*.gin`\n1.  `runs\u002F*.gin`\n\n\n### Required Fields\n\nT5X has some required fields like `MIXTURE_OR_TASK_NAME` or\n`TASK_FEATURE_LENGTHS`. We add two more:\n\n*   `PROMPT_LENGTH` :: The length of the prompt we are using, this is used in a\n    few different places to we require it as a gin macro we can reference in\n    multiple places and ensure the values are in sync.\n*   `PROMPT` :: This is the configuration of the actual prompt module that will\n    be used in the Flaxformer `PromptX` subclasses.\n\n*Note:* Prompt Tuning does not currently support packing of examples. This means\nthat our max target length only need to be long enough to fit the target for\neach example. This means our `targets` key in the `TASK_FEATURE_LENGTHS` mapping\ncan be much shorter, for example around 4 for many SuperGLUE\n[(Wang et al., 2019)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1905.00537) tasks, compared to 62\nwhich is what the P5X default is.\n\n## Prompt Initialization\n\nThere are several options for the initialization of the prompt parameter. We\nsupport the various methods in section 3.2 our\n[paper](https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243.pdf), as well as\ninitialization from a file. The latter allows one to do things like train on\nBoolQ starting from a prompt learned on MNLI.\n\nAll initializers follow the flax initializer API of being a parameterized\nfunction that returns a closure over the initialization function. The actual\ninitialization function always has the signature of\n\n```python\ndef initializer(rng: Array, shape: Sequence[int]) -> Array:\n  ...\n```\n\nWe provide each initialization scheme as a gin configuration file in the\n`configs\u002Fprompts` directory. They can be used by including the gin file with the\n`--gin_file=path\u002Fto\u002Fconfigs\u002Fprompts\u002Fscheme.gin`. This file needs to come\n**after** the main model file, otherwise the default (random uniform) method\nwill overwrite the one you selected. Some of these initialization methods will\nrequire you to set extra gin values either though an override flag of in one of\nyour gin files.\n\n**Random Uniform**\n\nA standard, random initialization similar to what people have used for embedding\ninitialization. This is the default and no gin file is required. The scale of\nthe random values can be adjusted by overridding\n`prompt_init\u002Flinen.initializers.uniform.scale=N`.\n\n**Sampled Vocab**\n\nSample a token embedding to use as initialization for each prompt position with\nthe `from_sample_of_embeddings` initializer. You can limit the sampling to the\nfirst `n` embeddings with the\n`prompt_init\u002Fprompts.from_samples_of_embeddings.population_size` parameter.\n\nThis can be used with\n[`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab.gin).\nThis method uses the embedding table extracted from the initial model\ncheckpoint. You can also provide your own embedding file with\n[`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab_numpy.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab_numpy.gin).\nThis method requires that you provide a value for `EMBEDDING_FILE` that is a\nnumpy array of the model's embedding table. This can be extracted from a model\ncheckpoint using\n[prompt_tuning.scripts.extract_variable](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fscripts\u002Fextract_variable.py).\n\n**Class Label**\n\nWe support initializing prompt timesteps with the embedding of class labels\n(a.k.a. *verbalizers*) via the `from_embedded_list` initializer. Users providing\na list of words (class labels) to use. Each words is tokenized by a provided\nvocab; embedded with a provided vocab table; aggregated, if need be, across\nsub-tokens; and used to initialize a prompt time-step. If the provided tokens\ndon't cover the full prompt length, the missing tokens are initialized using\nthe provided fall back initializer.\n\nWe can match the paper, where unfilled prompt tokens are filled by sampling from\nthe embedding table, by composing this initialization with the one above. It can\nbe used with\n[`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels.gin).\nThis requires setting `CLASS_LABELS`, which is a list of the words that you want\nto embed as prompt initialization. You can also provide your own embedding file\n(which is the same as above) with\n[`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels_numpy.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels_numpy.gin).\nThis additionally requires setting `EMBEDDING_FILE`.\n\n**From String**\n\nWe also support initializing a prompt with the embedding of some string, often\nused to start from a discrete prompt or a task description. This uses the\n`from_embedded_string` initializer. The string is tokenized by the provided\nvocabulary, each token is looked up in the provided embedding table, and the\nresulting embedded representation of the string is used as a prompt\ninitialization. If the provided tokens don't cover the full prompt length, the\nmissing tokens are initialized using the provided fall back initializer.\n\n_Note:_ The vocabulary just converts the string into a sequence of ids, you\nwill need to ensure that the string matches the result of any text formatting\n(spaces around punctuation, etc.) that your SeqIO task does.\n\n**From File**\n\nYou can also load a prompt from a file with the `from_array` initializer to\nenable transfer across tasks. This is done with\n[`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_file.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_file.gin).\nThis requires setting `PROMPT_FILE` with a path to the Numpy file with the\nprompt to load. Numpy versions of the prompt are emitted by default when training,\nbut the prompt can also be extracted with the script mentioned above.\n\n## Released Model Checkpoints\n\nWe have released T5X native checkpoints of the T5 1.1 checkpoints that have had\n100K steps of language model adaptation.\n\n*   **t5_1_1_lm100k_small** (~77 million parameters):\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_small\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_small\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_base** (~250 million parameters):\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_base\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_base\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_large** (~800 million parameters):\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_large\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_large\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_xl** (~3 billion parameters):\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xl\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xl\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_xxl** (~11 billion parameters):\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xxl\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xxl\u002Fcheckpoint_1100000)\n\nThese are converted from the public\n[Mesh TensorFlow checkpoints](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ftext-to-text-transfer-transformer\u002Fblob\u002Fmain\u002Freleased_checkpoints.md#lm-adapted-t511lm100k).\n\n## Released Prompts\n\nWe have released pretrained prompts on a variety of tasks, and plan to add to\nthem over time.\n\nPrompts can be found in the\n[`pretrained_prompts`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fpretrained_prompts)\ndirectory. From there each sub-directory groups prompts by the model they were\ntrained for. The easiest way to reference these prompts that are bundled with\nthe library is:\n\n```sh\n  --PROMPT_FILE=`python3 -m prompt_tuning.scripts.find_module prompt_tuning`\u002Fpretrained_prompts\u002F{MODEL_SIZE}\u002F{PROMPT}.npy\n```\n\nDue to the inherent randomness of parallel computation, there are a few settings\nthat need to match between training and evaluation to get the exact same\nnumbers. Each model sub-directory has a `README.md` the specifies what these\nsettings should be. The most important settings to match are batch size, TPU\ntopology, and model parallelism partitioning. The tables include the scores you\nshould expect to see if you use these prompts in `t5x.eval`\n\n\n## Extra Resources\n\nThis is a collection of additional resources about Prompt Tuning.\n\n*   Presentations:\n    *   EMNLP:\n        [Video](https:\u002F\u002Fblester125.com\u002Fpresentations\u002Fprompt-tuning-emnlp-2021.html)\n        [Slides](https:\u002F\u002Fblester125.com\u002Fstatic\u002Fpresentations\u002Fslides\u002FPrompt-Tuning-Presentation-EMNLP-2021.pdf)\n        [Poster](https:\u002F\u002Fblester125.com\u002Fstatic\u002Fpresentations\u002Fposters\u002FPrompt-Tuning-EMNLP-2021-Poster.pdf)\n\n\n## How to Cite\n\nIf you use this work as a jumping off point, please cite\n\n```bibtex\n@inproceedings{lester-etal-2021-power,\n    title = \"The Power of Scale for Parameter-Efficient Prompt Tuning\",\n    author = \"Lester, Brian  and\n      Al-Rfou, Rami  and\n      Constant, Noah\",\n    booktitle = \"Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing\",\n    month = nov,\n    year = \"2021\",\n    address = \"Online and Punta Cana, Dominican Republic\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243\",\n    doi = \"10.18653\u002Fv1\u002F2021.emnlp-main.243\",\n    pages = \"3045--3059\",\n}\n```\n\n## Note\n\nThis is not an officially supported Google product.\n","# 提示调优\n\n这是用于复现 EMNLP 2021 论文《参数高效提示调优的规模效应》\n[(Lester 等, 2021)](https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243\u002F) 中实验的代码。\n\n这些模型基于 [T5X](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x) 构建，其中 T5X 定义了模型和训练循环；\n[Flaxformer](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fflaxformer) 定义了实际的模型计算；[Flax](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fflax) 定义了底层模型层；而 [Jax](https:\u002F\u002Fgithub.com\u002Fjax-ml\u002Fjax) 则提供了实际的执行。我们的实现细节可以在此处找到：\n[这里](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fimplementation.md)。\n\n## 目录\n\n*   [安装](#installation)\n*   [训练提示](#training-a-prompt)\n    *   [在 Pod 分片上训练提示](#training-a-prompt-on-a-pod-slice)\n    *   [自定义依赖项](#custom-dependencies)\n*   [使用提示进行推理](#inference-with-a-prompt)\n*   [模型配置](#model-configuration)\n*   [提示初始化](#prompt-initialization)\n*   [发布的模型检查点](#released-model-checkpoints)\n*   [发布的提示](#released-prompts)\n*   [额外资源](#extra-resources)\n*   [如何引用](#how-to-cite)\n\n## 安装\n\n1.  按照 [T5X 安装说明](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x#installation) 中的前三个步骤创建一个云端 TPU 虚拟机。同时按照第 5 步创建一个 Google Cloud Storage (GCS) 存储桶。我们将使用类似 `gs:\u002F\u002F{bucket-name}\u002Fpath\u002Fto\u002Fitem\u002Fin\u002Fbucket` 的 URI 格式从该存储桶读取和写入数据。我们将在其中存储缓存的数据集以及模型检查点和结果。为了便于参考，以下是一些与 TPU 虚拟机交互的常用云命令：\n\n```sh\n# 创建云端 TPU 虚拟机\n$ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n    --zone ${ZONE} \\\n    --accelerator-type v3-8 \\\n    --version v2-alpha\n\n# SSH 到云端 TPU 虚拟机\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} --zone ${ZONE}\n\n# 删除云端 TPU 虚拟机\n$ gcloud alpha compute tpus tpu-vm delete ${TPU_NAME} --zone ${ZONE}\n```\n\n2.  现在您应该已经进入了 TPU 虚拟机实例的命令行界面。克隆提示调优仓库。\n\n```sh\ngit clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\ncd prompt-tuning\n```\n\n3.  安装提示调优库。\n\n```sh\npython3 -m pip install .[tpu] -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\n如果您遇到 pip 尝试安装越来越旧的依赖版本（例如 TensorFlow），直到尝试安装版本 `0.0.0` 并失败的错误，请在安装命令中添加 `--use-deprecated=legacy-resolver`。此错误与依赖项之间的所需版本有关，这种行为通常被称为回溯。如果使用该标志，可能会安装不兼容的库版本，因此您应注意安装命令输出中的版本不匹配警告。\n\n*注意：* 如果您计划修改提示调优的内部实现并需要可编辑的安装（以便在运行训练时使用克隆代码中的更改），请使用 `-e` 标志运行 `pip`；如果在安装过程中出现错误，您可能需要删除 `pyproject.toml` 文件。\n\n要运行测试，请使用 `[test]` 选项安装包（`python3 -m pip install .[test] ...`），然后从克隆仓库的根目录运行 `python3 -m pytest`。\n\n## 训练提示\n\n训练提示类似于\n[T5X 微调模型](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x\u002Fblob\u002Fmain\u002FREADME.md#fine-tuning)；\n主要区别在于我们有自己的提示调优配置文件集可供使用。\n\n我们提供了一个演示脚本 (`prompt_tuning\u002Fscripts\u002Fsst2-demo.sh`)，其中包含了训练提示所需的所有部分。您可以将其作为起点，或者设置 `MODEL_DIR` 和 `TFDS_DATA_DIR` 环境变量，指向您的 Google Cloud Storage 存储桶路径，直接运行此脚本。\n\n```sh\n.\u002Fprompt-tuning\u002Fprompt_tuning\u002Fscripts\u002Fsst2-demo.sh\n```\n\n为了提高迭代速度，我们倾向于在命令行中指定更多选项，而不是将所有配置打包到单个 gin 文件中。值得注意的几个选项：\n\n*   `--gin_search_paths` :: 以逗号分隔的目录列表，用作 gin 文件的路径前缀。我们可以使用 `prompt_tuning.scripts.find_module ${module}` 来查找包含配置的库的安装位置。\n*   `--gin_file` :: 要加载的 gin 文件。我们倾向于使用相对于其安装库的路径，例如使用 `prompt_tuning\u002Fconfigs\u002Fmodels\u002Ft5_1_1_base_prompt.gin` 而不是 `models\u002Ft5_1_1_base_prompt.gin`，以避免混淆。多次使用该标志可以指定多个 gin 文件，这些文件将被合并在一起。如果在多个文件中设置了相同的配置选项，则会采用列表中最后一个文件的值。\n*   `--gin.{PARAM}={VALUE}` :: 这个通用覆盖标志会将 `PARAM` 设置为 `VALUE`。这可用于轻松设置配置选项，而无需将其作为实际的命令行参数。例如，\n    `--gin.utils.SaveCheckpointConfig.keep=20` 将保存最近的 20 个检查点。\n\n### 在 TPU Pod 分片上训练提示\n\n随着模型规模的增大，例如 XL 和 XXL 模型，它们已经无法容纳在单个 TPU 虚拟机所配备的 8 个 TPU 上。在这种情况下，我们需要使用 TPU Pod 的一个分片（有关 TPU 架构和可用配置的更多信息，请参阅 [此处](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Fsystem-architecture-tpu-vm)）。在单个 TPU 虚拟机上与在 Pod 分片上训练提示的主要区别在于，我们现在有多个 TPU 虚拟机，并且将在每个虚拟机上运行相同的 SPMD JAX 程序。本页面提供了关于 [多主机](https:\u002F\u002Fjax.readthedocs.io\u002Fen\u002Flatest\u002Fmulti_process.html) JAX 程序的更多信息。[这篇指南](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Fjax-pods)简要介绍了如何在 TPU Pod 分片上运行 JAX 程序，但我们在此处将重点概述主要步骤。\n\n1. 创建 TPU Pod 分片。\n   [此页面](https:\u002F\u002Fcloud.google.com\u002Ftpu\u002Fdocs\u002Ftypes-zones#us)列出了哪些地区提供哪种类型的加速器。这与上述创建 TPU 虚拟机的过程相同，只是我们请求的是 32 个 TPU 而不是 8 个。\n\n```sh\n$ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n    --zone ${ZONE} \\\n    --accelerator-type v3-32 \\\n    --version v2-alpha\n```\n\n2. 安装 Prompt Tuning 库。由于我们现在有 4 个 TPU 虚拟机，每个虚拟机拥有 8 个 TPU，因此我们不希望通过 SSH 直接登录到每个虚拟机来执行操作。相反，Google Cloud 的 SSH 命令允许我们使用 `--command=` 标志指定要在所有虚拟机（称为工作节点）上运行的命令，并通过 `--worker=all` 参数实现这一点。\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\"git clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning && cd prompt-tuning && \"\npython3 -m pip install . -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\n3. 编写用于训练提示的脚本。我们提供了一个演示脚本 (`\u002Fprompt_tuning\u002Fscripts\u002Fsst2-xxl-demo.sh`)，该脚本使用 T5 1.1 lm100k XXL 模型来训练提示以解决 [SST2](https:\u002F\u002Fnlp.stanford.edu\u002Fsentiment\u002F) 数据集问题。您可以将其用作起点，或者只需填写指向您 Google Cloud Storage 存储桶的路径，以指定保存结果的位置 (`MODEL_DIR`) 和缓存 TFDS 数据的位置 (`TFDS_DATA_DIR`)，也可以将这些路径设置为环境变量。\n\n4. 将您的训练脚本复制到每个工作节点。如果您是第一次使用 `scp`，可能会遇到错误。请按照错误消息中的说明运行 `ssh-add \u002F...\u002F.ssh\u002Fgoogle_compute_engine` 命令，然后重试。\n\n```sh\n$ gcloud alpha compute tpus tpu-vm scp sst2-xxl-demo.sh ${TPU_NAME}: \\\n  --zone=${ZONE}\n  --worker=all\n```\n\n5. 执行您的训练脚本。\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\".\u002Fsst2-xxl-demo.sh\"\n```\n\n如果其中一个工作节点在训练过程中出现错误，其他工作节点上的 TPU 将被占用而无法释放。这将阻止您重新启动作业，直到这些进程被终止并释放 TPU。以下命令应能终止所有这些进程。您可能会从最初出错的工作节点返回 `kill` 命令的手册页。\n\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\"sudo lsof -t \u002Fdev\u002Faccel0 | xargs kill -9\"\n```\n\n### 自定义依赖项\n\n要使用自定义组件（如您自己的数据集）训练提示，请遵循 [T5X 关于自定义组件的说明](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x#custom-components)。\n\n如果您将自己的代码打包成可使用 pip 安装的 Python 包，则不必局限于单个目录，并且可以使用 `python3 -m prompt_tuning.scripts.find_module {your_module}` 来帮助设置 `gin_search_paths`，以便找到您库中捆绑的 gin 配置文件。*注意：* 如果您计划将 gin 配置文件捆绑到可安装的包中，请确保包含配置文件的目录具有 `__init__.py` 文件，因为 gin 要求文件必须位于 Python 包中。\n\n如果您的自定义组件的部分内容可以通过 gin 进行配置，则需要在 gin 文件中显式导入；如果它们是在解析 gin 文件之后才被导入，将会导致错误。如果您所有的依赖项都不包含可配置的 gin 设置，则可以通过传递 `--gin.MIXTURE_OR_TASK_MODULE=\"'path.to.your.module'\"` 来避免编写 gin 文件。这将自动导入您的模块，非常适合仅需更换数据集的情况。\n\n\n## 使用提示进行推理\n\n我们建议的使用提示进行推理的方法是加载用于初始化模型的原始检查点，并从文件中加载提示。正如本节关于 [部分加载](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fimplementation.md#partial-loading) 中所解释的那样，T5X 支持在初始化时加载部分模型参数，而其他参数则从头开始初始化。我们将此功能与 `from_array` 提示初始化器结合使用，以从原始检查点和提示文件中重新加载冻结的参数。[configs\u002Fruns\u002Fprompt_eval.gin](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fruns\u002Fprompt_eval.gin) 文件为您设置了此配置；您只需提供 `PROMPT_FILE` 即可。如果您的模型是使用任何 `prompts\u002F` 配置文件训练的，您可以将其从评估脚本的参数中移除。\n\n随附的 `sst2-demo-eval.sh` 脚本展示了以这种方式进行评估的示例。您只需设置 `EVAL_DIR` 和 `TFDS_DATA_DIR` 环境变量，分别指向存储评估输出和 TensorFlow 数据集缓存的路径即可。\n\n在 T5X 中，评估脚本假定您的数据集包含标签，并根据数据集的指标函数输出最终结果。而推理脚本则不需要标签，而是直接输出模型的预测结果。我们还提供了一个类似的 [prompt_infer.gin](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fruns\u002Fprompt_infer.gin) 文件，供与推理脚本一起使用。\n\n如果您希望使用由提示微调训练生成的 T5X 检查点进行推理或评估，可以直接使用 T5X 中的 `(eval|infer).gin` 配置文件。不过，您需要更新 `utils.RestoreChekcpointConfig`。应将 `path` 设置为新的检查点，`assignment_map=()`，并设置 `fallback_to_scratch=False`。\n\n## 模型配置\n\n所有关于模型、训练、评估、保存、恢复等的配置均通过 gin 完成。有关 gin 的通用介绍，请参阅\n[gin-config 仓库](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fgin-config#readme)，以及\n[这篇入门指南](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ft5x\u002Fblob\u002Fmain\u002Fgin-primer.md)。\n\n我们遵循 T5X 的配置布局：\n\n*   `runs\u002F` :: 包含用于实际训练模型的配置。数据集和评估相关的配置通常放在这里。\n*   `architectures\u002F` :: 包含模型架构相关的配置。例如，编码器-解码器架构与纯解码器架构的选择，以及嵌入共享等设置。\n*   `models\u002F` :: 包含设置模型特定参数的配置，如层数或嵌入表的大小。此外，还配置所使用的 T5X 模型封装器等。\n    *   `models\u002Fdecoding\u002F` :: 提供易于使用的配置，用于在推理过程中切换文本生成方式，包括束搜索和核采样等配置。\n    *   `models\u002Fsizes\u002F` :: 包含用于创建不同规模模型的各种设置。这些设置会与默认版本结合，形成特定规模的模型，例如，`t5_1_1_prompt.gin` + `sizes\u002Flarge.gin` 可以创建一个 T5 1.1 Large 模型。一些常用组合已作为包含正确引入语句的 gin 文件提供（如上例中的 `t5_1_1_large_prompt.gin`）。_注意：_ 这些规模文件必须__位于__主模型文件之后。\n*   `prompts\u002F` :: 我们的额外目录包含用于设置 `PROMPT` gin 变量的配置，从而可以通过添加不同的提示文件作为 `--gin_file` 参数来轻松切换提示初始化方式（该文件需置于 `models\u002F` gin 文件之后）。\n\n### gin 配置文件的顺序\n\n在命令行中指定 `--gin_file` 参数时，文件的顺序非常重要。gin 文件的一般指定顺序如下：\n\n1.  `models\u002F*.gin`\n1.  `prompts\u002F*.gin`\n1.  `models\u002Fsizes\u002F*.gin`\n1.  `models\u002Fdecoding\u002F*.gin`\n1.  `runs\u002F*.gin`\n\n### 必填字段\n\nT5X 有一些必填字段，如 `MIXTURE_OR_TASK_NAME` 或 `TASK_FEATURE_LENGTHS`。我们又增加了两个必填字段：\n\n*   `PROMPT_LENGTH` :: 我们所使用的提示长度。由于该值会在多个地方使用，因此我们将其定义为一个 gin 宏，以便在多处引用并确保各处数值一致。\n*   `PROMPT` :: 这是实际提示模块的配置，将在 Flaxformer 的 `PromptX` 子类中使用。\n\n*注：* 目前，提示调优不支持示例打包。这意味着我们的最大目标长度只需足够容纳每个示例的目标即可。因此，在 `TASK_FEATURE_LENGTHS` 映射中，`targets` 键的值可以显著缩短，例如对于许多 SuperGLUE [(Wang et al., 2019)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1905.00537) 任务，可以设为约 4，而 P5X 的默认值则是 62。\n\n## 提示初始化\n\n提示参数的初始化有多种选项。我们支持我们在论文 [3.2 节](https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243.pdf) 中介绍的各种方法，同时也支持从文件中进行初始化。后者允许用户例如从 MNLI 上学到的提示开始，在 BoolQ 数据集上进行训练。\n\n所有初始化器都遵循 Flax 初始化器 API，即它们是带参数的函数，返回一个关于初始化函数的闭包。实际的初始化函数总是具有以下签名：\n\n```python\ndef initializer(rng: Array, shape: Sequence[int]) -> Array:\n  ...\n```\n\n我们将每种初始化方案都提供为 `configs\u002Fprompts` 目录下的 gin 配置文件。可以通过使用 `--gin_file=path\u002Fto\u002Fconfigs\u002Fprompts\u002Fscheme.gin` 来包含 gin 文件来使用这些配置。该文件需要**位于**主模型文件**之后**，否则默认的（随机均匀）方法会覆盖您选择的方法。其中一些初始化方法可能需要您通过覆盖标志或在其中一个 gin 文件中设置额外的 gin 值。\n\n**随机均匀**\n\n这是一种标准的随机初始化，类似于人们用于嵌入初始化的方式。这是默认设置，无需任何 gin 文件。随机值的尺度可以通过覆盖 `prompt_init\u002Flinen.initializers.uniform.scale=N` 来调整。\n\n**采样词汇表**\n\n使用 `from_sample_of_embeddings` 初始化器，为每个提示位置采样一个标记嵌入作为初始化。您可以使用 `prompt_init\u002Fprompts.from_samples_of_embeddings.population_size` 参数将采样限制为前 `n` 个嵌入。\n\n这可以与 [`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab.gin) 一起使用。这种方法使用从初始模型检查点中提取的嵌入表。您也可以通过 [`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab_numpy.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_sampled_vocab_numpy.gin) 提供您自己的嵌入文件。此方法要求您提供一个名为 `EMBEDDING_FILE` 的值，该值是一个包含模型嵌入表的 numpy 数组。这可以通过使用 [prompt_tuning.scripts.extract_variable](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fscripts\u002Fextract_variable.py) 从模型检查点中提取。\n\n**类标签**\n\n我们支持通过 `from_embedded_list` 初始化器，使用类标签（又称“表述词”）的嵌入来初始化提示时间步。用户可以提供一个要使用的单词列表（类标签）。每个单词由提供的词汇表进行分词；使用提供的词汇表嵌入；如有必要，跨子标记进行聚合；然后用于初始化提示的一个时间步。如果提供的标记未能覆盖整个提示长度，则缺失的标记将使用提供的后备初始化器进行初始化。\n\n为了与论文中的做法保持一致——未填充的提示标记通过从嵌入表中采样来填充——我们可以将此初始化方法与上述方法组合使用。它可以与 [`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels.gin) 一起使用。这需要设置 `CLASS_LABELS`，即您希望嵌入作为提示初始化的单词列表。您还可以通过 [`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels_numpy.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_class_labels_numpy.gin) 提供您自己的嵌入文件（与上述相同）。此外，还需要设置 `EMBEDDING_FILE`。\n\n**来自字符串**\n\n我们还支持使用某个字符串的嵌入来初始化提示，通常用于从离散提示或任务描述开始。这使用 `from_embedded_string` 初始化器。字符串由提供的词汇表进行分词，每个标记在提供的嵌入表中查找，最终得到的字符串嵌入表示被用作提示初始化。如果提供的标记未能覆盖整个提示长度，则缺失的标记将使用提供的后备初始化器进行初始化。\n\n*注意：* 词汇表只是将字符串转换为一系列 ID，您需要确保字符串与您的 SeqIO 任务所执行的任何文本格式化（如标点符号周围的空格等）相匹配。\n\n**从文件**\n\n您还可以使用 `from_array` 初始化器从文件中加载提示，以实现跨任务的迁移。这可以通过 [`--gin_file=prompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_file.gin`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fconfigs\u002Fprompts\u002Ffrom_file.gin) 来完成。这需要设置 `PROMPT_FILE`，指定包含要加载提示的 Numpy 文件的路径。默认情况下，训练时会输出提示的 Numpy 版本，但也可以使用上述脚本提取提示。\n\n## 已发布的模型检查点\n\n我们发布了经过 10 万步语言模型适应的 T5 1.1 检查点的 T5X 原生检查点。\n\n*   **t5_1_1_lm100k_small**（约 7700 万个参数）：\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_small\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_small\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_base**（约 2.5 亿个参数）：\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_base\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_base\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_large**（约 8 亿个参数）：\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_large\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_large\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_xl**（约 30 亿个参数）：\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xl\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xl\u002Fcheckpoint_1100000)\n*   **t5_1_1_lm100k_xxl**（约 110 亿个参数）：\n    [gs:\u002F\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xxl\u002Fcheckpoint_1100000](https:\u002F\u002Fconsole.cloud.google.com\u002Fstorage\u002Fbrowser\u002Ft5-data\u002Fpretrained_models\u002Ft5x\u002Ft5_1_1_lm100k_xxl\u002Fcheckpoint_1100000)\n\n这些检查点是从公开的 [Mesh TensorFlow 检查点](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Ftext-to-text-transfer-transformer\u002Fblob\u002Fmain\u002Freleased_checkpoints.md#lm-adapted-t511lm100k) 转换而来的。\n\n## 已发布的提示词\n\n我们已在多种任务上发布了预训练的提示词，并计划随着时间的推移继续增加更多内容。\n\n提示词位于\n[`pretrained_prompts`](https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\u002Ftree\u002Fmain\u002Fprompt_tuning\u002Fpretrained_prompts)\n目录中。该目录下的每个子目录按其对应的预训练模型进行分组。引用随库一起打包的这些提示词最简单的方式是：\n\n```sh\n  --PROMPT_FILE=`python3 -m prompt_tuning.scripts.find_module prompt_tuning`\u002Fpretrained_prompts\u002F{MODEL_SIZE}\u002F{PROMPT}.npy\n```\n\n由于并行计算固有的随机性，在训练和评估过程中需要确保若干设置完全一致，才能得到完全相同的数值结果。每个模型子目录都包含一个 `README.md` 文件，其中详细说明了这些必须匹配的设置。最重要的几个设置包括：批量大小、TPU 拓扑结构以及模型并行化的划分方式。表格中列出了在使用这些提示词运行 `t5x.eval` 时应预期获得的分数。\n\n\n## 其他资源\n\n这里收集了一些关于提示词微调的额外资源。\n\n*   演示文稿：\n    *   EMNLP：\n        [视频](https:\u002F\u002Fblester125.com\u002Fpresentations\u002Fprompt-tuning-emnlp-2021.html)\n        [幻灯片](https:\u002F\u002Fblester125.com\u002Fstatic\u002Fpresentations\u002Fslides\u002FPrompt-Tuning-Presentation-EMNLP-2021.pdf)\n        [海报](https:\u002F\u002Fblester125.com\u002Fstatic\u002Fpresentations\u002Fposters\u002FPrompt-Tuning-EMNLP-2021-Poster.pdf)\n\n\n## 如何引用\n\n如果您将本工作作为起点，请引用以下文献：\n\n```bibtex\n@inproceedings{lester-etal-2021-power,\n    title = \"参数高效的提示词微调中的规模效应\",\n    author = \"Lester, Brian  and\n      Al-Rfou, Rami  and\n      Constant, Noah\",\n    booktitle = \"2021年自然语言处理经验方法会议论文集\",\n    month = nov,\n    year = \"2021\",\n    address = \"线上及多米尼加共和国蓬塔卡纳\",\n    publisher = \"计算语言学协会\",\n    url = \"https:\u002F\u002Faclanthology.org\u002F2021.emnlp-main.243\",\n    doi = \"10.18653\u002Fv1\u002F2021.emnlp-main.243\",\n    pages = \"3045--3059\",\n}\n```\n\n## 注意事项\n\n本项目并非 Google 官方支持的产品。","# Prompt Tuning 快速上手指南\n\n本指南基于 Google Research 开源的 `prompt-tuning` 项目，帮助开发者快速复现 EMNLP 2021 论文中的参数高效提示微调实验。该项目主要依赖 TPU 环境运行。\n\n## 环境准备\n\n*   **硬件要求**：推荐使用 Google Cloud TPU VM（至少 v3-8 配置）。对于超大模型（如 XXL），需要 TPU Pod Slice（多主机环境）。\n*   **软件依赖**：\n    *   Python 3\n    *   Google Cloud SDK (`gcloud`)\n    *   JAX, Flax, Flaxformer, T5X\n*   **存储要求**：需要创建一个 Google Cloud Storage (GCS) Bucket，用于存放数据集缓存、模型检查点和结果。路径格式为 `gs:\u002F\u002F{bucket-name}\u002Fpath\u002Fto\u002Fitem`。\n\n## 安装步骤\n\n### 1. 创建并连接 TPU VM\n使用 `gcloud` 命令创建 TPU 虚拟机并 SSH 登录：\n\n```sh\n# 创建 Cloud TPU VM (以 v3-8 为例)\n$ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n    --zone ${ZONE} \\\n    --accelerator-type v3-8 \\\n    --version v2-alpha\n\n# SSH 登录到 TPU VM\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} --zone ${ZONE}\n```\n\n### 2. 克隆代码库\n在 TPU VM 命令行中克隆仓库：\n\n```sh\ngit clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning\ncd prompt-tuning\n```\n\n### 3. 安装依赖库\n安装 Prompt Tuning 库及其 TPU 依赖。\n*注意：若遇到依赖版本回溯错误（backtracking error），请添加 `--use-deprecated=legacy-resolver` 标志。*\n\n```sh\npython3 -m pip install .[tpu] -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\n*(可选) 如果需要开发模式安装（修改代码即时生效）：*\n```sh\n# 可能需要先删除 pyproject.toml 以避免安装错误\nrm pyproject.toml\npython3 -m pip install -e .[tpu] -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\n```\n\n## 基本使用\n\n### 训练一个 Prompt\n训练流程与 T5X 微调类似，但需使用专用的配置文件。项目提供了针对 SST-2 数据集的演示脚本。\n\n**前置设置**：\n确保已设置环境变量指向你的 GCS Bucket：\n*   `MODEL_DIR`: 保存模型检查点和结果的目录。\n*   `TFDS_DATA_DIR`: 缓存 TensorFlow Datasets 的目录。\n\n**运行演示脚本**：\n```sh\n.\u002Fprompt-tuning\u002Fprompt_tuning\u002Fscripts\u002Fsst2-demo.sh\n```\n\n**关键参数说明**：\n*   `--gin_search_paths`: 指定 gin 配置文件的搜索路径前缀。\n*   `--gin_file`: 加载具体的 gin 配置文件（支持合并多个文件）。\n*   `--gin.{PARAM}={VALUE}`: 直接覆盖配置参数。例如 `--gin.utils.SaveCheckpointConfig.keep=20` 表示保留最近 20 个检查点。\n\n### 多主机训练 (TPU Pod Slice)\n对于无法放入单台 VM (8 TPU) 的大模型（如 XL, XXL），需使用 TPU Pod Slice。\n\n1.  **创建 Pod Slice** (例如 32 TPU):\n    ```sh\n    $ gcloud alpha compute tpus tpu-vm create ${TPU_NAME} \\\n        --zone ${ZONE} \\\n        --accelerator-type v3-32 \\\n        --version v2-alpha\n    ```\n\n2.  **在所有 Worker 上安装代码**:\n    ```sh\n    $ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n      --zone ${ZONE} \\\n      --worker=all \\\n      --command=\"git clone --branch=main https:\u002F\u002Fgithub.com\u002Fgoogle-research\u002Fprompt-tuning && cd prompt-tuning && python3 -m pip install . -f https:\u002F\u002Fstorage.googleapis.com\u002Fjax-releases\u002Flibtpu_releases.html\"\n    ```\n\n3.  **分发训练脚本**:\n    ```sh\n    $ gcloud alpha compute tpus tpu-vm scp sst2-xxl-demo.sh ${TPU_NAME}: \\\n      --zone=${ZONE} \\\n      --worker=all\n    ```\n\n4.  **执行训练**:\n    ```sh\n    $ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n      --zone ${ZONE} \\\n      --worker=all \\\n      --command=\".\u002Fsst2-xxl-demo.sh\"\n    ```\n\n*(故障处理)* 若训练中断导致 TPU 被占用，可使用以下命令清理进程：\n```sh\n$ gcloud alpha compute tpus tpu-vm ssh ${TPU_NAME} \\\n  --zone ${ZONE} \\\n  --worker=all \\\n  --command=\"sudo lsof -t \u002Fdev\u002Faccel0 | xargs kill -9\"\n```\n\n### 推理与评估\n\n**评估 (Evaluation)**:\n加载原始模型检查点和训练好的 Prompt 文件进行评估。需设置 `EVAL_DIR` 和 `TFDS_DATA_DIR`。\n```sh\n# 示例脚本参考\n.\u002Fprompt_tuning\u002Fscripts\u002Fsst2-demo-eval.sh\n```\n配置核心在于使用 `configs\u002Fruns\u002Fprompt_eval.gin` 并指定 `PROMPT_FILE`。\n\n**纯推理 (Inference)**:\n如果不需标签，仅需模型预测输出，使用 `configs\u002Fruns\u002Fprompt_infer.gin` 配置。\n\n**直接使用 T5X 检查点**:\n若想对训练生成的完整 T5X 检查点进行推理，可直接使用 T5X 原生的 `(eval|infer).gin`，但需更新恢复配置：\n*   `path`: 指向新检查点路径\n*   `assignment_map=()`\n*   `fallback_to_scratch=False`","某电商公司的算法团队需要在资源有限的云 TPU 集群上，快速为数十个垂直品类（如美妆、数码、家居）定制专属的情感分析模型，以实时监控用户评论风向。\n\n### 没有 prompt-tuning 时\n- **算力成本高昂**：传统全量微调（Full Fine-tuning）需要更新 T5 大模型的全部参数，每次训练都需占用大量显存和计算资源，导致多任务并行时预算迅速超支。\n- **部署维护繁琐**：每个品类都需要保存一份完整的模型权重副本，存储压力巨大，且上线新模型时的推理服务配置极其复杂。\n- **迭代周期漫长**：由于训练数据加载和参数更新耗时久，从数据准备到模型验证往往需要数天，无法应对突发的舆情热点。\n- **小样本效果差**：在部分新品类缺乏标注数据的情况下，全量微调极易过拟合，模型泛化能力严重不足。\n\n### 使用 prompt-tuning 后\n- **参数效率极致**：prompt-tuning 仅训练极少量的软提示（Soft Prompts）向量，冻结了主干网络，使单卡显存占用降低数个数量级，同等硬件下可并行训练更多任务。\n- **存储与部署轻量化**：只需保存微小的 Prompt 检查点而非整个模型，存储空间节省超过 99%，切换不同品类任务仅需热加载对应的 Prompt 向量。\n- **敏捷开发落地**：训练速度显著提升，团队可在几小时内完成从数据输入到模型验证的闭环，迅速响应业务需求变化。\n- **小样本表现优异**：得益于预训练模型的强大泛化性，prompt-tuning 在少样本场景下依然保持高准确率，有效解决了冷启动难题。\n\nprompt-tuning 通过“冻结主干、只调提示”的参数高效策略，让大模型在低资源环境下实现了低成本、快节奏的多任务定制化落地。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fgoogle-research_prompt-tuning_bbffb750.png","google-research","Google Research","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fgoogle-research_c23b2adf.png","",null,"https:\u002F\u002Fresearch.google","https:\u002F\u002Fgithub.com\u002Fgoogle-research",[80,84],{"name":81,"color":82,"percentage":83},"Python","#3572A5",99.1,{"name":85,"color":86,"percentage":87},"Shell","#89e051",0.9,698,64,"2026-04-14T00:59:47","Apache-2.0",5,"Linux","不依赖 NVIDIA GPU，必需 Google Cloud TPU (v3-8, v3-32 等)，基于 JAX\u002Flibtpu 运行","未说明 (取决于 TPU 实例配置及模型大小，大型模型如 XXL 需 TPU Pod 切片)",{"notes":97,"python":98,"dependencies":99},"该工具专为 Google Cloud TPU 环境设计，不支持本地 GPU 运行。安装需通过 gcloud 创建 Cloud TPU VM，并使用特定的 JAX libtpu 源进行安装。数据存储和检查点需使用 Google Cloud Storage (GCS)。训练大型模型（如 XL, XXL）需要 TPU Pod 切片（多主机分布式训练）。","3.8+",[100,101,102,103,104,105,106],"jax","flax","flaxformer","t5x","tensorflow-datasets","gin-config","libtpu",[35,14],[64,109,110,100,101,111],"nlp","machine-learning","language-model","2026-03-27T02:49:30.150509","2026-04-15T03:24:53.989287",[],[]]