arXiv:2507.23292cs.LGcs.CL2025-07

让序列模型轻松支持训练与实时生成,避免常见错误。

SequenceLayers: Sequence Processing and Streaming Neural Networks Made Easy

  • 定义显式时序状态,支持逐层与逐步执行
  • 相同输入下逐步推演结果与批量计算一致
  • 适配主流框架,适合构建可靠流式模型

我们提出一种序列建模的神经网络层 API 与库,支持既可分层执行(如教师强制训练)又可逐步执行(如自回归采样)。通过显式定义层在时间上的状态(如 Transformer 的键值缓存、卷积缓冲区、RNN 隐状态),并提供状态演化函数,确保逐步推演结果与无状态分层调用完全一致。该设计使复杂模型即刻具备流式能力,消除大量流式与并行处理中的常见错误,并可在任意深度学习框架中实现。配套提供可组合、声明式的 API 与丰富的层和组合器,帮助从简单可流式组件快速构建生产级模型,同时保证强正确性。当前已在 JAX 与 TensorFlow 2 中实现,代码开源于 https://github.com/google/sequence-layers。

原文摘要 · Abstract (English)

We introduce a neural network layer API and library for sequence modeling, designed for easy creation of sequence models that can be executed both layer-by-layer (e.g., teacher-forced training) and step-by-step (e.g., autoregressive sampling). To achieve this, layers define an explicit representation of their state over time (e.g., a Transformer KV cache, a convolution buffer, an RNN hidden state), and a step method that evolves that state, tested to give identical results to a stateless layer-wise invocation. This and other aspects of the SequenceLayers contract enables complex models to be immediately streamable, mitigates a wide range of common bugs arising in both streaming and parallel sequence processing, and can be implemented in any deep learning library. A composable and declarative API, along with a comprehensive suite of layers and combinators, streamlines the construction of production-scale models from simple streamable components while preserving strong correctness guarantees. Our current implementations of SequenceLayers (JAX, TensorFlow 2) are available at https://github.com/google/sequence-layers.

序列建模流式推理API 设计模型正确性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。