Skip to content

[Python][ML] Add device param to RDataLoader's .as_torch()#22013

Merged
dpiparo merged 2 commits intoroot-project:masterfrom
siliataider:rdataloader
Apr 22, 2026
Merged

[Python][ML] Add device param to RDataLoader's .as_torch()#22013
dpiparo merged 2 commits intoroot-project:masterfrom
siliataider:rdataloader

Conversation

@siliataider
Copy link
Copy Markdown
Contributor

@siliataider siliataider commented Apr 22, 2026

This Pull request:

Changes or fixes:

as_torch() now supports an optional device argument, allowing batches to be placed directly on the target device without a separate .to(device) call after the iteration:

train = ROOT.Experimental.RDataLoader(df, ...)

for x, y in train.as_torch(device="cuda"):
   ...

Proposed as an alternative to

for x, y in train.as_torch():
    x = x.to("cuda")
    y = y.to("cuda")
    ...

The implementation directly passes device to torch.as_tensor(device) which handles the transfer. Default is None.

@siliataider siliataider self-assigned this Apr 22, 2026
@siliataider siliataider added in:ML Everything under ROOT/ML in:Python Interface labels Apr 22, 2026
@siliataider siliataider added this to the 6.40.00-rc1 milestone Apr 22, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

Test Results

    22 files      22 suites   3d 7h 46m 56s ⏱️
 3 845 tests  3 844 ✅  1 💤 0 ❌
76 827 runs  76 809 ✅ 18 💤 0 ❌

Results for commit 1cdfa0f.

♻️ This comment has been updated with latest results.

@siliataider
Copy link
Copy Markdown
Contributor Author

Failures unrelated to the changes of this PR, will be fixed by root-project/root-ci-images#112

Copy link
Copy Markdown
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@siliataider
Copy link
Copy Markdown
Contributor Author

@dpiparo This PR is ready to merge!

@dpiparo dpiparo merged commit 0f3116e into root-project:master Apr 22, 2026
54 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in:ML Everything under ROOT/ML in:Python Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants