Skip to content

Commit

Permalink
fix: don't support pre-moving the data
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 3, 2024
1 parent aafe0d3 commit d8c1129
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 1 addition & 4 deletions ext/MLDataDevicesMLUtilsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using MLDataDevices: MLDataDevices, AbstractDevice, CPUDevice, CUDADevice, AMDGP
MetalDevice, oneAPIDevice, XLADevice, DeviceIterator
using MLUtils: MLUtils, DataLoader

for dev in (CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, oneAPIDevice)
for dev in (CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, oneAPIDevice, XLADevice)
@eval function (D::$(dev))(dataloader::DataLoader)
if dataloader.parallel
if dataloader.buffer
Expand All @@ -28,9 +28,6 @@ for dev in (CPUDevice, CUDADevice, AMDGPUDevice, MetalDevice, oneAPIDevice)
end
end

# XXX: Doing it in parallel leads to deadlocks
(D::XLADevice)(dataloader::DataLoader) = DeviceIterator(D, dataloader)

function eachobsparallel(dev::AbstractDevice, data)
return MLUtils.Loader(1:MLUtils.numobs(data)) do ch, i
obs = MLUtils.getobs(data, i)
Expand Down
12 changes: 10 additions & 2 deletions test/iterator_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ end
@testset "DataLoader: parallel=$parallel" for parallel in (true, false)
@info "Testing DataLoader with parallel=$parallel"
X = rand(Float64, 3, 33)
pre = DataLoader(dev(X); batchsize=13, shuffle=false, parallel)
post = DataLoader(X; batchsize=13, shuffle=false, parallel) |> dev
if dev_type === XLADevice
pre = post # XXX: deadlocks and other shenanigans
else
pre = DataLoader(dev(X); batchsize=13, shuffle=false, parallel)
end

for epoch in 1:2
prev_pre, prev_post = nothing, nothing
Expand All @@ -86,8 +90,12 @@ end
end

Y = rand(Float64, 1, 33)
pre = DataLoader((; x=dev(X), y=dev(Y)); batchsize=13, shuffle=false, parallel)
post = DataLoader((; x=X, y=Y); batchsize=13, shuffle=false, parallel) |> dev
if dev_type === XLADevice
pre = post # XXX: deadlocks and other shenanigans
else
pre = DataLoader((; x=dev(X), y=dev(Y)); batchsize=13, shuffle=false, parallel)
end

for epoch in 1:2
prev_pre, prev_post = nothing, nothing
Expand Down

2 comments on commit d8c1129

@avik-pal
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/116544

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" d8c112982ba574c4323766388d883146cb0e7e98
git push origin v1.2.0

Please sign in to comment.