Skip to content

Commit

Permalink
fix: adapt to upcoming reactant changes (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Feb 24, 2025
1 parent a979d4f commit 8509073
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/MLDataDevices/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLDataDevices"
uuid = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "1.6.10"
version = "1.6.11"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
26 changes: 6 additions & 20 deletions lib/MLDataDevices/ext/MLDataDevicesReactantExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module MLDataDevicesReactantExt

using Adapt: Adapt
using MLDataDevices: MLDataDevices, Internal, ReactantDevice, CPUDevice, get_device_type
using MLDataDevices: MLDataDevices, Internal, ReactantDevice, CPUDevice
using Random: Random
using Reactant: Reactant, XLA, ConcreteRArray, ConcreteRNumber, TracedRArray,
TracedRNumber
Expand Down Expand Up @@ -32,25 +32,11 @@ end
Internal.unsafe_free_internal!(::Type{ReactantDevice}, x::AbstractArray) = nothing

# Device Transfer
function Adapt.adapt_storage(
dev::ReactantDevice, x::AbstractArray{<:Reactant.ReactantPrimitive})
@warn "ReactantDevice got an array on device: $(get_device_type(x)). We will have to \
transfer this via CPU." maxlog=1
return Adapt.adapt(dev, Adapt.adapt(CPUDevice(), x))
end

function Adapt.adapt_storage(dev::ReactantDevice, x::Array{<:Reactant.ReactantPrimitive})
client = dev.client === missing ? XLA.default_backend[] : dev.client
device = dev.device === missing ? nothing : dev.device
return ConcreteRArray(x; client, device)
end

# XXX: Check for client and device and use faster implementation if possible
function Adapt.adapt_storage(dev::ReactantDevice, x::ConcreteRArray)
dev.client === missing && dev.device === missing && return x
@warn "Fetching `client` and `device` from a ConcreteRArray hasn't been implemented \
yet. Using slow fallback path." maxlog=1
return Adapt.adapt(dev, Adapt.adapt(CPUDevice(), x))
function Adapt.adapt_storage(dev::ReactantDevice, x::AbstractArray)
kwargs = (;)
dev.client === missing || (kwargs = (; kwargs..., client=dev.client))
dev.device === missing || (kwargs = (; kwargs..., device=dev.device))
return ConcreteRArray(x; kwargs...)
end

Adapt.adapt_storage(::CPUDevice, ::Reactant.ConcreteRNG) = Random.default_rng()
Expand Down
1 change: 1 addition & 0 deletions lib/MLDataDevices/src/public.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end
struct MetalDevice <: AbstractGPUDevice end
struct oneAPIDevice <: AbstractGPUDevice end

# TODO: We need to rethink how to store the client and device. what about sharding??
@kwdef struct ReactantDevice{C, D} <: AbstractAcceleratorDevice
client::C = missing
device::D = missing
Expand Down

2 comments on commit 8509073

@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 register subdir=lib/MLDataDevices

@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/125702

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 MLDataDevices-v1.6.11 -m "<description of version>" 85090738848efb6ec3320c557ca81aa6ca6aacd8
git push origin MLDataDevices-v1.6.11

Please sign in to comment.