Skip to content

Add RAII wrappers for ORT Model Editor API types#1953

Merged
baijumeswani merged 8 commits into
mainfrom
resolve_remaining_graph_issues
Feb 3, 2026
Merged

Add RAII wrappers for ORT Model Editor API types#1953
baijumeswani merged 8 commits into
mainfrom
resolve_remaining_graph_issues

Conversation

@qjia7
Copy link
Copy Markdown
Contributor

@qjia7 qjia7 commented Jan 26, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds RAII (Resource Acquisition Is Initialization) wrappers for ONNX Runtime Model Editor API types and refactors the graph builder code to use these wrappers for improved resource management. Additionally, it removes mutex protection from the graph session cache based on the assumption that ort-genai execution is single-threaded.

Changes:

  • Added RAII wrapper structs (OrtGraph, OrtModel, OrtValueInfo, OrtNode) in onnxruntime_api.h following the existing OrtOpAttr pattern
  • Removed SessionCache struct and mutex from graph_session_cache_ in generators.h, replacing it with a simple unordered_map
  • Refactored graph_builder.cpp Build() function to use std::unique_ptr for automatic resource cleanup instead of manual try/catch blocks

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/models/onnxruntime_api.h Adds RAII wrapper structs for OrtGraph, OrtModel, OrtValueInfo, and OrtNode with custom delete operators for automatic cleanup
src/generators.h Removes SessionCache struct with mutex, replaces with simple unordered_map based on single-threaded execution assumption
src/models/graph_executor.cpp Removes mutex include and simplifies cache access after SessionCache removal
src/models/graph_builder.cpp Refactors Build() to use RAII patterns with std::unique_ptr instead of manual try/catch exception handling

Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/generators.h Outdated
Comment thread src/models/graph_builder.cpp
Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/models/graph_builder.cpp Outdated
@qjia7 qjia7 marked this pull request as ready for review January 27, 2026 08:53
@qjia7
Copy link
Copy Markdown
Contributor Author

qjia7 commented Jan 27, 2026

@baijumeswani This is the follow-up PR to resolve your remaining comments in #1895. The pipeline failures may not related with my changes. My another PR #1952 meets the similar issue after I rebase the code to latest without any code changes. However, it passed before.

@kunal-vaishnavi
Copy link
Copy Markdown
Contributor

@baijumeswani This is the follow-up PR to resolve your remaining comments in #1895. The pipeline failures may not related with my changes. My another PR #1952 meets the similar issue after I rebase the code to latest without any code changes. However, it passed before.

The pipeline failures are because Hugging Face released transformers v5 and it has some bugs. I have a fix for the CIs in this PR. You can pin the version like this in the meantime.

Comment thread src/generators.h Outdated
Comment thread src/models/graph_builder.cpp Outdated
@qjia7 qjia7 requested a review from baijumeswani January 30, 2026 07:25
Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/models/graph_builder.cpp Outdated
@qjia7 qjia7 marked this pull request as draft February 2, 2026 03:39
@qjia7 qjia7 marked this pull request as ready for review February 2, 2026 05:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/models/graph_builder.cpp
Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/models/graph_builder.cpp Outdated
Comment thread src/models/graph_builder.cpp
Comment thread src/models/graph_builder.cpp
Comment thread src/models/graph_builder.cpp Outdated
Copy link
Copy Markdown
Collaborator

@baijumeswani baijumeswani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment. Otherwise looks good.

@baijumeswani baijumeswani enabled auto-merge (squash) February 3, 2026 02:26
@baijumeswani baijumeswani merged commit 8dcb154 into main Feb 3, 2026
15 checks passed
@baijumeswani baijumeswani deleted the resolve_remaining_graph_issues branch February 3, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants