Skip to content

[tmva][sofie] Don't copy the Session in the RDataFrame Python tutorial - #23624

Merged
guitargeek merged 3 commits into
root-project:masterfrom
guitargeek:sofie-rdf-fixup
Oct 7, 2026
Merged

guitargeek merged 3 commits into
root-project:masterfrom
guitargeek:sofie-rdf-fixup

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

Follows up on 0878949.

The TMVA_SOFIE_RDataFrame.py tutorial initialized its vector of Sessions with an initializer list, which copies the Session. A generated Session holds raw pointers into its own weight vectors and intermediate memory pool, so the copy still pointed to the buffers of the temporary Session, which were freed right after. The inference then read the weights from freed memory and wrote the intermediate tensors into it.

This silently gave wrong results, and on macOS 27 it crashed with SIGTRAP because the system allocator detects the heap corruption.

Construct the Session in place with emplace_back instead.

Comment thread tutorials/machine_learning/TMVA_SOFIE_RDataFrame.py Outdated
@silverweed

Copy link
Copy Markdown
Contributor

Shouldn't the Session be non-copyable if this footgun exists?

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Test Results

    24 files      24 suites   3d 23h 45m 47s ⏱️
 3 883 tests  3 881 ✅ 0 💤  2 ❌
83 111 runs  83 094 ✅ 0 💤 17 ❌

For more details on these failures, see this check.

Results for commit f22aa69.

♻️ This comment has been updated with latest results.

The RooONNXFunc stored the SOFIE Session in a std::any, which requires
copy-constructible types. Since the copy constructor and copy assignment
of the SOFIE-emitted Session classes should be deleted, we can't use it
anymore.

Use a std::shared_ptr<void> instead, which also type-erases the deleter
but doesn't require the stored type to be copyable.
Follows up on 0878949.

The TMVA_SOFIE_RDataFrame.py tutorial initialized its vector of Sessions
with an initializer list, which copies the Session. A generated Session
holds raw pointers into its own weight vectors and intermediate memory
pool, so the copy still pointed to the buffers of the temporary Session,
which were freed right after. The inference then read the weights from
freed memory and wrote the intermediate tensors into it.

This silently gave wrong results, and on macOS 27 it crashed with
SIGTRAP because the system allocator detects the heap corruption.

Construct the Session in place with emplace_back instead.
Some data members of the session classes are pointers to memory owned by
the session class, so the session can't be trivially copied.

Instead of implementing a proper copy constructor and copy assignment,
just delete them because they are also not needed.

@vepadulano vepadulano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this fix!

@guitargeek
guitargeek merged commit 92792ac into root-project:master Oct 7, 2026
30 of 33 checks passed
@guitargeek
guitargeek deleted the sofie-rdf-fixup branch October 7, 2026 13:25
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