onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

[WIP] [tracking] Improve Sequence operator handling

Open Copilot opened this issue 8 months ago • 0 comments

Analyzing sequence operator handling efficiency improvements in ONNX Runtime

Overview: The current sequence operator implementation relies heavily on tensor copies as noted in the TODO comment. This PR aims to improve efficiency by reducing unnecessary tensor copying through better use of move semantics and avoiding redundant allocations.

Plan:

  • [x] Analyze current sequence operator implementation and identify inefficiencies
  • [x] Understand the current test structure and codebase organization
  • [x] Optimize SequenceInsert to reduce tensor copying where possible
  • [x] Optimize SequenceConstruct to use move semantics when appropriate
  • [x] Add CreateTensorOrtValue function to enable direct OrtValue creation with move semantics
  • [ ] Create performance benchmark tests to measure current copying overhead
  • [ ] Investigate SequenceAt optimization opportunities (limited due to operational requirements)
  • [ ] Run existing tests to ensure no regression
  • [ ] Validate performance improvements with benchmarks

Key optimizations implemented:

  • Added CreateTensorOrtValue() function that creates OrtValue directly with move semantics instead of creating Tensor first then converting
  • Updated SequenceInsert and SequenceConstruct to use the optimized function
  • This reduces the number of copy operations and temporary object creation
  • Maintains compatibility with DataTransferManager for cross-EP support

Note: SequenceErase is already well-optimized as it avoids copying non-erased tensors. SequenceAt requires copying due to operational requirements but uses efficient DataTransferManager.

Fixes #18355.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jun 14 '25 16:06 Copilot