[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-state-spaces--s4":3,"tool-state-spaces--s4":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":75,"owner_avatar_url":76,"owner_bio":77,"owner_company":77,"owner_location":77,"owner_email":77,"owner_twitter":77,"owner_website":77,"owner_url":78,"languages":79,"stars":105,"forks":106,"last_commit_at":107,"license":108,"difficulty_score":10,"env_os":109,"env_gpu":110,"env_ram":109,"env_deps":111,"category_tags":124,"github_topics":125,"view_count":10,"oss_zip_url":77,"oss_zip_packed_at":77,"status":16,"created_at":129,"updated_at":130,"faqs":131,"releases":160},1047,"state-spaces\u002Fs4","s4","Structured state space sequence models","s4 是一个专注于结构化状态空间序列建模的开源框架，旨在突破传统模型在处理长序列数据时的性能瓶颈。基于 HiPPO 理论，s4 通过结构化状态空间机制，能够在低计算成本下有效捕捉长距离依赖关系，广泛适用于音频、文本及时间序列分析等任务。\n\ns4 主要面向深度学习研究人员与开发者，提供了基于 PyTorch 的灵活训练框架及独立模块。技术亮点在于高效实现了 Cauchy 和 Vandermonde 内核，支持自定义 CUDA 加速或 Pykeops 集成，显著优化了内存占用与计算速度。s4 不仅包含多种变体模型（如 S4D、S4ND 等）的官方实现，还提供了详细的实验复现指南与示例脚本。无论是希望探索序列建模前沿理论，还是需要将高效序列层集成到现有项目中，s4 都能提供坚实的技术支持与便捷的开发体验。","# Structured State Spaces for Sequence Modeling\n\nThis repository provides the official implementations and experiments for models related to [S4](https:\u002F\u002Farxiv.org\u002Fabs\u002F2111.00396),\nincluding [HiPPO](https:\u002F\u002Farxiv.org\u002Fabs\u002F2008.07669), [LSSL](https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.13985), [SaShiMi](https:\u002F\u002Farxiv.org\u002Fabs\u002F2202.09729),\n[DSS](https:\u002F\u002Farxiv.org\u002Fabs\u002F2203.14343), [HTTYH](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.12037), [S4D](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.11893),\nand [S4ND](https:\u002F\u002Farxiv.org\u002Fabs\u002F2210.06583).\n\nProject-specific information for each of these models, including overview of the source code and specific experiment reproductions,\ncan be found under [models\u002F](models\u002F).\n\n\n## Table of Contents\n\nSetting up the environment and porting S4 to external codebases:\n- [Setup](#setup)\n- [Getting Started with S4](#getting-started-with-s4)\n\nUsing this repository for training models:\n- [Training](#training)\n- [Generation](#generation)\n- [Repository Structure](#overall-repository-structure)\n- [Citation](#citation)\n\n### Changelog\nSee [CHANGELOG.md](CHANGELOG.md)\n\n### Roadmap\n- More documentation for training from scratch using this repository\n- Compilation of S4 resources and implementations\n- pip package\n\n\n## Setup\n\n### Requirements\nThis repository requires Python 3.9+ and Pytorch 1.10+.\nIt has been tested up to Pytorch 1.13.1.\nOther packages are listed in [requirements.txt](.\u002Frequirements.txt).\nSome care may be needed to make some of the library versions compatible, particularly torch\u002Ftorchvision\u002Ftorchaudio\u002Ftorchtext.\n\nExample installation:\n```\nconda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia\npip install -r requirements.txt\n```\n\n\n### Structured Kernels\n\nA core operation of S4 are the Cauchy and Vandermonde kernels described in the [paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2111.00396).\nThese are very simple matrix multiplications; a naive implementation of these operation can be found in the [standalone](models\u002Fs4\u002Fs4.py) in the function `cauchy_naive` and `log_vandermonde_naive`.\nHowever, as the paper describes, this has suboptimal memory usage that currently requires a custom kernel to overcome in PyTorch.\n\nTwo more efficient methods are supported. The code will automatically detect if either of these is installed and call the appropriate kernel.\n\n#### Custom CUDA Kernel\n\nThis version is faster but requires manual compilation for each machine environment.\nRun `python setup.py install` from the directory `extensions\u002Fkernels\u002F`.\n\n#### Pykeops\n\nThis version is provided by the [pykeops library](https:\u002F\u002Fwww.kernel-operations.io\u002Fkeops\u002Fpython\u002Finstallation.html).\nInstallation usually works out of the box with `pip install pykeops cmake` which are also listed in the requirements file.\n\n\n## Getting Started with S4\n\n### S4 Module\n\nSelf-contained files for the S4 layer and variants can be found in [models\u002Fs4\u002F](.\u002Fmodels\u002Fs4\u002F),\nwhich includes instructions for calling the module.\n\nSee [notebooks\u002F](notebooks\u002F) for visualizations explaining some concepts behind HiPPO and S4.\n\n### Example Train Script (External Usage)\n\n[example.py](example.py) is a self-contained training script for MNIST and CIFAR that imports the standalone S4 file. The default settings `python example.py` reaches 88% accuracy on sequential CIFAR with a very simple S4D model of 200k parameters.\nThis script can be used as an example for using S4 variants in external repositories.\n\n### Training with this Repository (Internal Usage)\n\nThis repository aims to provide a very flexible framework for training sequence models. Many models and datasets are supported.\n\nThe basic entrypoint is `python -m train`, or equivalently\n```\npython -m train pipeline=mnist model=s4\n```\nwhich trains an S4 model on the Permuted MNIST dataset.\nThis should get to around 90% after 1 epoch which takes 1-3 minutes depending on GPU.\n\nMore examples of using this repository are documented throughout. See [Training](#training) for an overview.\n\n### Optimizer Hyperparameters\n\nOne important feature of this codebase is supporting parameters that require different optimizer hyperparameters.\nIn particular, the SSM kernel is particularly sensitive to the $(A, B)$ (and sometimes $\\Delta$ parameters),\nso the learning rate on these parameters is sometimes lowered and the weight decay is always set to $0$.\n\nSee the method `register` in the model (e.g. [s4d.py](py)) and the function `setup_optimizer` in the training script (e.g. [example.py](example.py)) for an examples of how to implement this in external repos.\n\n\u003C!--\nOur logic for setting these parameters can be found in the `OptimModule` class under `src\u002Fmodels\u002Fsequence\u002Fss\u002Fkernel.py` and the corresponding optimizer hook in `SequenceLightningModule.configure_optimizers` under `train.py`\n-->\n\n\n## Training\n\nThe core training infrastructure of this repository is based on [Pytorch-Lightning](https:\u002F\u002Fpytorch-lightning.readthedocs.io\u002Fen\u002Flatest\u002F) with a configuration scheme based on [Hydra](https:\u002F\u002Fhydra.cc\u002Fdocs\u002Fintro\u002F).\n\nThe main entrypoint is `train.py` and configs are found in `configs\u002F`.\n\n### Data\n\nBasic datasets are auto-downloaded, including MNIST, CIFAR, and Speech Commands.\nAll logic for creating and loading datasets is in [src\u002Fdataloaders](.\u002Fsrc\u002Fdataloaders\u002F) directory.\nThe README inside this subdirectory documents how to download and organize other datasets.\n\n### Models\n\nModels are defined in [src\u002Fmodels](src\u002Fmodels). See the README in this subdirectory for an overview.\n\n\n### Configs and Hyperparameters\nPre-defined configs reproducing end-to-end experiments from the papers are provided, found under project-specific information in [models\u002F](models\u002F), such as for the [original S4 paper](models\u002Fs4\u002Fexperiments.md).\n\nConfigs can also be easily modified through the command line.\nAn example experiment is\n```\npython -m train pipeline=mnist dataset.permute=True model=s4 model.n_layers=3 model.d_model=128 model.norm=batch model.prenorm=True wandb=null\n```\nThis uses the Permuted MNIST task with an S4 model with a specified number of layers, backbone dimension, and normalization type.\n\nSee [configs\u002FREADME.md](configs\u002F) for more detailed documentation about the configs.\n\n\n#### Hydra\n\nIt is recommended to read the [Hydra documentation](https:\u002F\u002Fhydra.cc\u002Fdocs\u002Fintro\u002F) to fully understand the configuration framework. For help launching specific experiments, please file an issue.\n\n\u003C!--\n#### Registries\n\nThis codebase uses a modification of the hydra `instantiate` utility that provides shorthand names of different classes, for convenience in configuration and logging.\nThe mapping from shorthand to full path can be found in `src\u002Futils\u002Fregistry.py`.\n-->\n\n\n### Resuming\n\nEach experiment will be logged to its own directory (generated by Hydra) of the form `.\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002F`. Checkpoints will be saved here inside this folder and printed to console whenever a new checkpoint is created.\nTo resume training, simply point to the desired `.ckpt` file (a PyTorch Lightning checkpoint, e.g. `.\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt`) and append the flag `train.ckpt=\u003Cpath>\u002F\u003Cto>\u002F\u003Ccheckpoint>.ckpt` to the original training command.\n\n### PyTorch Lightning Trainer\n\nThe PTL [Trainer](https:\u002F\u002Fpytorch-lightning.readthedocs.io\u002Fen\u002Fstable\u002Fcommon\u002Ftrainer.html) class controls the overall training loop and also provides many useful pre-defined flags. Some useful examples are explained below.\nThe full list of allowable flags can be found in the PTL documentation, as well as our [trainer configs](configs\u002Ftrainer\u002F). See the default trainer config [configs\u002Ftrainer\u002Fdefault.yaml](configs\u002Ftrainer\u002Fdefault.yaml) for the most useful options.\n\n#### Multi-GPU training\n\nSimply pass in `trainer.gpus=2` to train with 2 GPUs.\n\n#### Inspect model layers\n\n`trainer.weights_summary=full` prints out every layer of the model with their parameter counts. Useful for debugging internals of models.\n\n#### Data subsampling\n`trainer.limit_{train,val}_batches={10,0.1}` trains (validates) on only 10 batches (0.1 fraction of all batches). Useful for testing the train loop without going through all the data.\n\n\n### WandB\n\nLogging with [WandB](https:\u002F\u002Fwandb.ai\u002Fsite) is built into this repository.\nIn order to use this, simply set your `WANDB_API_KEY` environment variable, and change the `wandb.project` attribute of [configs\u002Fconfig.yaml](configs\u002Fconfig.yaml) (or pass it on the command line e.g. `python -m train .... wandb.project=s4`).\n\nSet `wandb=null` to turn off WandB logging.\n\n\n## Generation\n\nAutoregressive generation can be performed with the [generate.py](generate.py) script.\nThis script can be used in two ways after training a model using this codebase.\n\n### Option 1: Checkpoint Path\nThe more flexible option requires the checkpoint path of the trained PyTorch Lightning model.\nThe generation script accepts the same config options as the train script, with a few additional flags that are documented in [configs\u002Fgenerate.yaml](configs\u002Fgenerate.yaml).\nAfter training with `python -m train \u003Ctrain flags>`, generate with\n```\npython -m generate \u003Ctrain flags> checkpoint_path=\u003Cpath\u002Fto\u002Fmodel.ckpt> \u003Cgeneration flags>\n```\nAny of the flags found in the config can be overridden.\n\nNote: This option can be used with either `.ckpt` checkpoints (PyTorch Lightning, which includes information for the Trainer) or `.pt` checkpoints (PyTorch, which is just a model state dict).\n\n### Option 2: Experiment Path\nThe second option for generation does not require passing in training flags again, and instead reads the config from the Hydra experiment folder, along with a PyTorch Lightning checkpoint within the experiment folder.\n\n### Example 1 (Language)\n\nDownload the [WikiText-103 model checkpoint](https:\u002F\u002Fhuggingface.co\u002Fkrandiash\u002Fsashimi-release\u002Ftree\u002Fmain\u002Fcheckpoints), for example to `.\u002Fcheckpoints\u002Fs4-wt103.pt`.\nThis model was trained with the command `python -m train experiment=lm\u002Fs4-wt103`. Note that from the config we can see that the model was trained with a receptive field of length 8192.\n\nTo generate, run\n```\npython -m generate experiment=lm\u002Fs4-wt103 checkpoint_path=checkpoints\u002Fs4-wt103.pt n_samples=1 l_sample=16384 l_prefix=8192 decode=text\n```\nThis generates a sample of length 16384 conditioned on a prefix of length 8192.\n\n### Example 2 (Audio)\n\nLet's train a small SaShiMi model on the SC09 dataset. We can also reduce the number of training and validation batches to get a checkpoint faster:\n```\npython -m train experiment=audio\u002Fsashimi-sc09 model.n_layers=2 trainer.limit_train_batches=0.1 trainer.limit_val_batches=0.1\n```\n\nAfter the first epoch completes, a message is printed indicating where the checkpoint is saved.\n```\nEpoch 0, global step 96: val\u002Floss reached 3.71754 (best 3.71754), saving model to \"\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt\"\n```\n\nOption 1:\n```\npython -m generate experiment=audio\u002Fsashimi-sc09 model.n_layers=2 checkpoint_path=\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt n_samples=4 l_sample=16000\n```\nThis option redefines the full config so that the model and dataset can be constructed.\n\nOption 2:\n```\npython -m generate experiment_path=\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime> checkpoint_path=checkpoints\u002Fval\u002Floss.ckpt n_samples=4 l_sample=16000\n```\nThis option only needs the path to the Hydra experiment folder and the desired checkpoint within.\n\n\n## Overall Repository Structure\n```\nconfigs\u002F         Config files for model, data pipeline, training loop, etc.\ndata\u002F            Default location of raw data\nextensions\u002F      CUDA extensions (Cauchy and Vandermonde kernels)\nsrc\u002F             Main source code for models, datasets, etc.\n  callbacks\u002F     Training loop utilities (e.g. checkpointing)\n  dataloaders\u002F   Dataset and dataloader definitions\n  models\u002F        Model definitions\n  tasks\u002F         Encoder\u002Fdecoder modules to interface between data and model backbone\n  utils\u002F\nmodels\u002F          Model-specific information (code, experiments, additional resources)\nexample.py       Example training script for using S4 externally\ntrain.py         Training entrypoint for this repo\ngenerate.py      Autoregressive generation script\n```\n\n\n## Citation\nIf you use this codebase, or otherwise found our work valuable, please cite S4 and [other relevant papers](models\u002FREADME.md#citations).\n\n```\n@inproceedings{gu2022efficiently,\n  title={Efficiently Modeling Long Sequences with Structured State Spaces},\n  author={Gu, Albert and Goel, Karan and R\\'e, Christopher},\n  booktitle={The International Conference on Learning Representations ({ICLR})},\n  year={2022}\n}\n```\n","# 用于序列建模 (Sequence Modeling) 的结构化状态空间 (Structured State Spaces)\n\n本仓库提供了与 [S4](https:\u002F\u002Farxiv.org\u002Fabs\u002F2111.00396) 相关模型的官方实现和实验，\n包括 [HiPPO](https:\u002F\u002Farxiv.org\u002Fabs\u002F2008.07669)、[LSSL](https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.13985)、[SaShiMi](https:\u002F\u002Farxiv.org\u002Fabs\u002F2202.09729)、\n[DSS](https:\u002F\u002Farxiv.org\u002Fabs\u002F2203.14343)、[HTTYH](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.12037)、[S4D](https:\u002F\u002Farxiv.org\u002Fabs\u002F2206.11893)\n和 [S4ND](https:\u002F\u002Farxiv.org\u002Fabs\u002F2210.06583)。\n\n每个模型的项目特定信息，包括源代码概述和具体实验复现，\n可以在 [models\u002F](models\u002F) 下找到。\n\n\n## 目录\n\n设置环境并将 S4 移植到外部代码库：\n- [设置](#setup)\n- [S4 入门](#getting-started-with-s4)\n\n使用本仓库训练模型：\n- [训练](#training)\n- [生成](#generation)\n- [仓库结构](#overall-repository-structure)\n- [引用](#citation)\n\n### 变更日志\n参见 [CHANGELOG.md](CHANGELOG.md)\n\n### 路线图\n- 更多关于使用本仓库从头开始训练的文档\n- S4 资源和实现的汇编\n- pip 包\n\n\n## 设置\n\n### 要求\n本仓库需要 Python 3.9+ 和 Pytorch 1.10+。\n已测试至 Pytorch 1.13.1。\n其他包列在 [requirements.txt](.\u002Frequirements.txt) 中。\n需要注意使某些库版本兼容，特别是 torch\u002Ftorchvision\u002Ftorchaudio\u002Ftorchtext。\n\n安装示例：\n```\nconda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia\npip install -r requirements.txt\n```\n\n\n### 结构化核函数 (Structured Kernels)\n\nS4 的核心操作是 [论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2111.00396) 中描述的柯西 (Cauchy) 和范德蒙德 (Vandermonde) 核函数 (kernels)。\n这些是非常简单的矩阵乘法；这些操作的朴素实现可以在 [standalone](models\u002Fs4\u002Fs4.py) 中的 `cauchy_naive` 和 `log_vandermonde_naive` 函数中找到。\n然而，正如论文所述，这需要次优的内存使用，目前需要自定义核函数 (kernel) 来在 PyTorch 中克服。\n\n支持两种更高效的方法。代码会自动检测是否安装了其中任何一种并调用相应的核函数。\n\n#### 自定义 CUDA 核函数 (Custom CUDA Kernel)\n\n此版本更快，但需要为每个机器环境手动编译。\n从 `extensions\u002Fkernels\u002F` 目录运行 `python setup.py install`。\n\n#### Pykeops\n\n此版本由 [pykeops 库](https:\u002F\u002Fwww.kernel-operations.io\u002Fkeops\u002Fpython\u002Finstallation.html) 提供。\n安装通常只需 `pip install pykeops cmake` 即可开箱即用，这些也列在 requirements 文件中。\n\n\n## S4 入门\n\n### S4 模块\n\nS4 层及其变体的独立文件可以在 [models\u002Fs4\u002F](.\u002Fmodels\u002Fs4\u002F) 中找到，\n其中包括调用模块的说明。\n\n参见 [notebooks\u002F](notebooks\u002F) 以获取解释 HiPPO 和 S4 背后一些概念的可视化内容。\n\n### 示例训练脚本（外部使用）\n\n[example.py](example.py) 是一个用于 MNIST 和 CIFAR 的独立训练脚本，导入独立的 S4 文件。默认设置 `python example.py` 在顺序 CIFAR 上达到 88% 的准确率，使用的是一个非常简单的 200k 参数的 S4D 模型。\n此脚本可用作在外部仓库中使用 S4 变体的示例。\n\n### 使用本仓库训练（内部使用）\n\n本仓库旨在提供一个非常灵活的框架来训练序列模型。支持许多模型和数据集。\n\n基本入口点是 `python -m train`，或等价于\n```\npython -m train pipeline=mnist model=s4\n```\n这在 Permuted MNIST 数据集上训练一个 S4 模型。\n这应该在 1 个 epoch (训练轮次) 后达到约 90%，根据 GPU 不同需要 1-3 分钟。\n\n更多使用本仓库的示例在整个文档中都有记录。参见 [训练](#training) 以获得概述。\n\n### 优化器超参数 (Optimizer Hyperparameters)\n\n此代码库的一个重要功能是支持需要不同优化器超参数 (optimizer hyperparameters) 的参数。\n特别是，SSM 核函数 (kernel) 对 $(A, B)$（有时是 $\\Delta$ 参数）特别敏感，\n因此这些参数的学习率有时会降低，并且权重衰减 (weight decay) 始终设置为 $0$。\n\n参见模型中的 `register` 方法（例如 [s4d.py](py)）和训练脚本中的 `setup_optimizer` 函数（例如 [example.py](example.py)），以了解如何在外部仓库中实现此功能的示例。\n\n\u003C!--\n我们设置这些参数的逻辑可以在 `src\u002Fmodels\u002Fsequence\u002Fss\u002Fkernel.py` 下的 `OptimModule` 类中找到，相应的优化器钩子 (optimizer hook) 在 `train.py` 下的 `SequenceLightningModule.configure_optimizers` 中\n-->\n\n\n## 训练\n\n本仓库的核心训练基础设施基于 [Pytorch-Lightning](https:\u002F\u002Fpytorch-lightning.readthedocs.io\u002Fen\u002Flatest\u002F)，配置方案基于 [Hydra](https:\u002F\u002Fhydra.cc\u002Fdocs\u002Fintro\u002F)。\n\n主入口点是 `train.py`，配置文件在 `configs\u002F` 中。\n\n### 数据\n\n基本数据集会自动下载，包括 MNIST、CIFAR 和 Speech Commands。\n创建和加载数据集的所有逻辑都在 [src\u002Fdataloaders](.\u002Fsrc\u002Fdataloaders\u002F) 目录中。\n此子目录内的 README 记录了如何下载和组织其他数据集。\n\n### 模型\n\n模型定义在 [src\u002Fmodels](src\u002Fmodels) 中。参见此子目录中的 README 以获得概述。\n\n\n### 配置和超参数\n提供了复现论文中端到端实验的预定义配置，位于 [models\u002F](models\u002F) 中的项目特定信息下，例如 [原始 S4 论文](models\u002Fs4\u002Fexperiments.md)。\n\n配置也可以通过命令行轻松修改。\n一个实验示例是\n```\npython -m train pipeline=mnist dataset.permute=True model=s4 model.n_layers=3 model.d_model=128 model.norm=batch model.prenorm=True wandb=null\n```\n这使用 Permuted MNIST 任务，带有指定层数、主干维度 (backbone dimension) 和归一化类型 (normalization type) 的 S4 模型。\n\n参见 [configs\u002FREADME.md](configs\u002F) 以获取有关配置的更详细文档。\n\n\n#### Hydra\n\n建议阅读 [Hydra 文档](https:\u002F\u002Fhydra.cc\u002Fdocs\u002Fintro\u002F) 以充分了解配置框架。如需帮助启动特定实验，请提交 issue。\n\n\u003C!--\n#### 注册表 (Registries)\n\n此代码库使用了 hydra `instantiate` 实用程序的修改版本，提供了不同类的简称，以便于配置和日志记录。\n从简称到完整路径的映射可以在 `src\u002Futils\u002Fregistry.py` 中找到。\n-->\n\n### 恢复训练\n\n每个实验都将记录到其自己的目录中（由 Hydra (配置管理工具) 生成），格式为 `.\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002F`。检查点（Checkpoints）将保存于此文件夹内，并在创建新检查点时打印到控制台。\n要恢复训练，只需指向所需的 `.ckpt` 文件（PyTorch Lightning (深度学习框架) 检查点，例如 `.\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt`），并将标志 `train.ckpt=\u003Cpath>\u002F\u003Cto>\u002F\u003Ccheckpoint>.ckpt` 附加到原始训练命令后。\n\n### PyTorch Lightning Trainer\n\nPTL [Trainer](https:\u002F\u002Fpytorch-lightning.readthedocs.io\u002Fen\u002Fstable\u002Fcommon\u002Ftrainer.html) 类控制整体训练循环，并提供许多有用的预定义标志。下面解释了一些有用的示例。\n允许的标志完整列表可在 PTL 文档以及我们的 [trainer configs](configs\u002Ftrainer\u002F) 中找到。参见默认训练器配置 [configs\u002Ftrainer\u002Fdefault.yaml](configs\u002Ftrainer\u002Fdefault.yaml) 以获取最有用的选项。\n\n#### 多 GPU 训练\n\n只需传入 `trainer.gpus=2` 即可使用 2 个 GPU (图形处理器) 进行训练。\n\n#### 检查模型层\n\n`trainer.weights_summary=full` 打印出模型的每一层及其参数计数。用于调试模型内部结构。\n\n#### 数据子采样\n`trainer.limit_{train,val}_batches={10,0.1}` 仅在 10 个批次（所有批次的 0.1 比例）上进行训练（验证）。用于在不遍历所有数据的情况下测试训练循环。\n\n\n### WandB\n\n使用 [WandB](https:\u002F\u002Fwandb.ai\u002Fsite) (实验跟踪工具) 记录日志的功能已内置到此仓库中。\n为了使用此功能，只需设置 `WANDB_API_KEY` 环境变量，并更改 [configs\u002Fconfig.yaml](configs\u002Fconfig.yaml) 的 `wandb.project` 属性（或在命令行上传递，例如 `python -m train .... wandb.project=s4`）。\n\n设置 `wandb=null` 以关闭 WandB 日志记录。\n\n\n## 生成\n\n自回归（Autoregressive）生成可以使用 [generate.py](generate.py) 脚本执行。\n在使用此代码库训练模型后，该脚本可以通过两种方式使用。\n\n### 选项 1：检查点路径\n更灵活的选项需要训练好的 PyTorch Lightning 模型的检查点路径。\n生成脚本接受与训练脚本相同的配置选项，还有一些额外的标志记录在 [configs\u002Fgenerate.yaml](configs\u002Fgenerate.yaml) 中。\n使用 `python -m train \u003Ctrain flags>` 训练后，生成使用\n```\npython -m generate \u003Ctrain flags> checkpoint_path=\u003Cpath\u002Fto\u002Fmodel.ckpt> \u003Cgeneration flags>\n```\n配置中的任何标志都可以被覆盖。\n\n注意：此选项可与 `.ckpt` 检查点（PyTorch Lightning，包含 Trainer 信息）或 `.pt` 检查点（PyTorch，仅是模型状态字典）一起使用。\n\n### 选项 2：实验路径\n生成的第二个选项不需要再次传递训练标志，而是从 Hydra 实验文件夹读取配置，以及实验文件夹内的 PyTorch Lightning 检查点。\n\n### 示例 1 (语言)\n\n下载 [WikiText-103 模型检查点](https:\u002F\u002Fhuggingface.co\u002Fkrandiash\u002Fsashimi-release\u002Ftree\u002Fmain\u002Fcheckpoints)，例如到 `.\u002Fcheckpoints\u002Fs4-wt103.pt`。\n此模型是使用命令 `python -m train experiment=lm\u002Fs4-wt103` 训练的。注意从配置中我们可以看到模型是使用长度为 8192 的感受野（Receptive field）训练的。\n\n要生成，运行\n```\npython -m generate experiment=lm\u002Fs4-wt103 checkpoint_path=checkpoints\u002Fs4-wt103.pt n_samples=1 l_sample=16384 l_prefix=8192 decode=text\n```\n这将生成一个长度为 16384 的样本，以长度为 8192 的前缀为条件。\n\n### 示例 2 (音频)\n\n让我们在 SC09 数据集上训练一个小型 SaShiMi 模型。我们还可以减少训练和验证批次的数量以更快地获得检查点：\n```\npython -m train experiment=audio\u002Fsashimi-sc09 model.n_layers=2 trainer.limit_train_batches=0.1 trainer.limit_val_batches=0.1\n```\n\n第一个 Epoch (训练轮次) 完成后，会打印一条消息指示检查点保存的位置。\n```\nEpoch 0, global step 96: val\u002Floss reached 3.71754 (best 3.71754), saving model to \"\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt\"\n```\n\n选项 1：\n```\npython -m generate experiment=audio\u002Fsashimi-sc09 model.n_layers=2 checkpoint_path=\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime>\u002Fcheckpoints\u002Fval\u002Floss.ckpt n_samples=4 l_sample=16000\n```\n此选项重新定义完整配置，以便可以构建模型和数据集。\n\n选项 2：\n```\npython -m generate experiment_path=\u003Crepository>\u002Foutputs\u002F\u003Cdate>\u002F\u003Ctime> checkpoint_path=checkpoints\u002Fval\u002Floss.ckpt n_samples=4 l_sample=16000\n```\n此选项只需要 Hydra 实验文件夹的路径以及其中所需的检查点。\n\n\n## 整体仓库结构\n```\nconfigs\u002F         Config files for model, data pipeline, training loop, etc.\ndata\u002F            Default location of raw data\nextensions\u002F      CUDA extensions (Cauchy and Vandermonde kernels)\nsrc\u002F             Main source code for models, datasets, etc.\n  callbacks\u002F     Training loop utilities (e.g. checkpointing)\n  dataloaders\u002F   Dataset and dataloader definitions\n  models\u002F        Model definitions\n  tasks\u002F         Encoder\u002Fdecoder modules to interface between data and model backbone\n  utils\u002F\nmodels\u002F          Model-specific information (code, experiments, additional resources)\nexample.py       Example training script for using S4 externally\ntrain.py         Training entrypoint for this repo\ngenerate.py      Autoregressive generation script\n```\n\n\n## 引用\n如果您使用此代码库，或发现我们的工作有价值，请引用 S4 和 [其他相关论文](models\u002FREADME.md#citations)。\n\n```\n@inproceedings{gu2022efficiently,\n  title={Efficiently Modeling Long Sequences with Structured State Spaces},\n  author={Gu, Albert and Goel, Karan and R\\'e, Christopher},\n  booktitle={The International Conference on Learning Representations ({ICLR})},\n  year={2022}\n}\n```","# S4 快速上手指南\n\n## 环境准备\n\n在开始使用 S4 之前，请确保您的开发环境满足以下系统要求：\n\n- **Python**: 3.9 或更高版本\n- **PyTorch**: 1.10 或更高版本（本项目已测试至 1.13.1）\n- **其他依赖**: 详见项目根目录下的 `requirements.txt`\n- **硬件**: 推荐使用 NVIDIA GPU 以加速训练（部分内核需要 CUDA 支持）\n\n## 安装步骤\n\n1. **安装 PyTorch 及相关组件**\n   建议使用 Conda 创建环境，并安装兼容版本的 PyTorch 家族库：\n   ```bash\n   conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia\n   ```\n\n2. **安装项目依赖**\n   进入项目目录，安装所需 Python 包：\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n3. **配置高效内核（可选但推荐）**\n   S4 的核心运算涉及 Cauchy 和 Vandermonde 内核。为了优化内存和速度，代码会自动检测以下两种实现之一：\n   - **自定义 CUDA 内核**（速度最快，需编译）：\n     ```bash\n     cd extensions\u002Fkernels\u002F\n     python setup.py install\n     ```\n   - **Pykeops 库**（通常可直接安装）：\n     ```bash\n     pip install pykeops cmake\n     ```\n\n## 基本使用\n\n### 1. 运行独立示例脚本\n仓库提供了自包含的训练脚本 `example.py`，适合快速验证或将 S4 集成到外部代码库。默认设置下在序列 CIFAR 数据集上训练：\n```bash\npython example.py\n```\n*预期结果：使用约 200k 参数的 S4D 模型，准确率可达 88%。*\n\n### 2. 使用仓库框架训练\n本仓库基于 PyTorch-Lightning 和 Hydra 配置系统。以下命令在 Permuted MNIST 数据集上训练 S4 模型：\n```bash\npython -m train pipeline=mnist model=s4\n```\n*预期结果：1 个 epoch 后准确率约为 90%（耗时 1-3 分钟，取决于 GPU）。*\n\n### 3. 自定义超参数\n您可以通过命令行直接修改模型配置。例如，指定层数、维度并关闭 WandB 日志：\n```bash\npython -m train pipeline=mnist dataset.permute=True model=s4 model.n_layers=3 model.d_model=128 model.norm=batch model.prenorm=True wandb=null\n```\n\n*更多配置详情可查阅 `configs\u002F` 目录文档。*","某工业 AI 团队正在开发风力发电机故障预测系统，需要处理长达数万步的振动传感器序列数据，以提前识别潜在机械故障。\n\n### 没有 s4 时\n- 传统 RNN 模型在处理长序列时出现梯度消失，无法捕捉早期的异常振动信号。\n- 尝试使用 Transformer 架构，但二次方复杂度导致显存占用过高，无法在边缘计算设备上部署。\n- 训练速度缓慢，每次超参数调整都需要数小时，研发周期被大幅拉长。\n- 长距离依赖建模效果差，导致对缓慢恶化的故障模式漏报率居高不下，影响生产安全。\n\n### 使用 s4 后\n- s4 利用结构化状态空间机制，完美捕捉长程依赖，早期微弱信号不再丢失。\n- 线性复杂度大幅降低显存需求，模型成功部署至资源受限的边缘网关，推理延迟更低。\n- 集成简单的 Python 接口，内置高效 CUDA 内核加速计算，训练速度提升数倍，迭代效率显著提高。\n- 在长序列分类任务上准确率显著上升，故障识别更精准，维护成本降低。\n\ns4 通过高效的状态空间建模，解决了长序列处理中的性能与效率瓶颈，让长上下文理解变得轻量且精准。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fstate-spaces_s4_577dc18e.png","state-spaces","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fstate-spaces_a1d8a689.png",null,"https:\u002F\u002Fgithub.com\u002Fstate-spaces",[80,84,88,92,96,99,102],{"name":81,"color":82,"percentage":83},"Jupyter Notebook","#DA5B0B",95.8,{"name":85,"color":86,"percentage":87},"Python","#3572A5",4.1,{"name":89,"color":90,"percentage":91},"Cuda","#3A4E3A",0.1,{"name":93,"color":94,"percentage":95},"C++","#f34b7d",0,{"name":97,"color":98,"percentage":95},"C","#555555",{"name":100,"color":101,"percentage":95},"Shell","#89e051",{"name":103,"color":104,"percentage":95},"Makefile","#427819",2875,356,"2026-04-03T05:41:07","Apache-2.0","未说明","推荐 NVIDIA GPU (示例使用 CUDA 11.6)，支持多卡训练，自定义 CUDA 内核需编译",{"notes":112,"python":113,"dependencies":114},"核心算子支持自定义 CUDA 内核（需手动编译）或 Pykeops 库以提升效率；配置管理基于 Hydra 框架；支持 WandB 日志记录；多 GPU 训练可通过 trainer.gpus 参数配置；部分库版本需兼容（特别是 torch 系列）。","3.9+",[115,116,117,118,119,120,121,122,123],"pytorch>=1.10","torchvision","torchaudio","torchtext","pykeops","cmake","pytorch-lightning","hydra-core","wandb",[13],[126,127,128],"state-space-models","sequence-models","pytorch","2026-03-27T02:49:30.150509","2026-04-06T05:32:15.925468",[132,137,141,146,151,155],{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},4663,"将 S4 替换为 S4D 后内存占用显著增加是否正常？","是的，这是预期行为。默认设置下，等效的 S4D 层比 S4 层的内存消耗至少增加 20%。如果遇到 OOM（内存溢出），建议检查 pykeops 版本。pykeops 1.5 在多 GPU 环境下存在缓存问题，建议升级到 pykeops 2.1，它避免了缓存机制且编译更快。","https:\u002F\u002Fgithub.com\u002Fstate-spaces\u002Fs4\u002Fissues\u002F51",{"id":138,"question_zh":139,"answer_zh":140,"source_url":136},4664,"使用 `keops=True` 时遇到梯度 NaN 或缓存问题如何解决？","这可能与 pykeops 版本有关。用户反馈在 `keops=True, mode='nplr'` 时出现梯度问题。维护者确认 pykeops 1.5 存在多 GPU 缓存问题，建议升级到 pykeops 2.1，该版本旨在解决此类问题且不再缓存内核。",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},4665,"在 LRA Pathfinder 数据集上模型无法收敛（Loss 始终为 0.693）怎么办？","这是 PyTorch 1.10 版本的已知 Bug，已在后续版本中修复。如果遇到训练和验证准确率停滞在 0.5 左右且 Loss 不变的情况，请尝试升级 PyTorch 版本。","https:\u002F\u002Fgithub.com\u002Fstate-spaces\u002Fs4\u002Fissues\u002F22",{"id":147,"question_zh":148,"answer_zh":149,"source_url":150},4666,"运行 SaShiMi 生成脚本时提示 `hurwitz` 参数不存在？","代码库已更新，旧参数可能已被移除。请在生成脚本中移除 `hurwitz` 标志覆盖。建议使用当前代码库的最新配置和检查点，并根据需要修改生成脚本中的标志。","https:\u002F\u002Fgithub.com\u002Fstate-spaces\u002Fs4\u002Fissues\u002F32",{"id":152,"question_zh":153,"answer_zh":154,"source_url":150},4667,"加载训练好的模型检查点时报错 `Missing key(s) in state_dict`？","这通常是因为推理配置与训练配置不匹配。例如，设置 `model.layer.postact=null` 会导致模型结构变化从而无法加载 state_dict。请确保生成脚本中的配置参数与训练时保持一致，不要随意移除导致结构变化的参数。",{"id":156,"question_zh":157,"answer_zh":158,"source_url":159},4668,"如何验证 S4 层在卷积模式和递归模式下的输出一致性？","如果发现两种模式输出差异巨大，请检查 `step` 函数（递归模式）。通常在 S4 层之后缺少了一个激活函数（activation）。确保 `step` 函数中包含与 `forward` 函数（卷积模式）相同的激活步骤即可解决不一致问题。","https:\u002F\u002Fgithub.com\u002Fstate-spaces\u002Fs4\u002Fissues\u002F115",[161,164,167,170,173],{"id":162,"version":163,"summary_zh":77,"released_at":77},104157,"v4.1.0",{"id":165,"version":166,"summary_zh":77,"released_at":77},104158,"v4.0.0",{"id":168,"version":169,"summary_zh":77,"released_at":77},104159,"v3.0.0",{"id":171,"version":172,"summary_zh":77,"released_at":77},104160,"v2",{"id":174,"version":175,"summary_zh":77,"released_at":77},104161,"v1"]