Skip to content

Commit d8fe3b7

Browse files
committed
test(MLDataDevices): migrate to ParallelTestRunners
1 parent 26359fd commit d8fe3b7

File tree

13 files changed

+116
-114
lines changed

13 files changed

+116
-114
lines changed

.buildkite/testing_mldatadevices.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ steps:
77
version: "{{matrix.julia}}"
88
- JuliaCI/julia-test#v1:
99
project: "lib/MLDataDevices"
10-
test_args: "BACKEND_GROUP={{matrix.group}}"
10+
test_args: "--BACKEND_GROUP={{matrix.group}}"
1111
- JuliaCI/julia-coverage#v1:
1212
codecov: true
1313
dirs:
@@ -34,7 +34,7 @@ steps:
3434
# version: "{{matrix.julia}}"
3535
# - JuliaCI/julia-test#v1:
3636
# project: "lib/MLDataDevices"
37-
# test_args: "BACKEND_GROUP=AMDGPU"
37+
# test_args: "--BACKEND_GROUP=AMDGPU"
3838
# - JuliaCI/julia-coverage#v1:
3939
# codecov: true
4040
# dirs:
@@ -59,7 +59,7 @@ steps:
5959
version: "{{matrix.julia}}"
6060
- JuliaCI/julia-test#v1:
6161
project: "lib/MLDataDevices"
62-
test_args: "BACKEND_GROUP=Metal"
62+
test_args: "--BACKEND_GROUP=Metal"
6363
- JuliaCI/julia-coverage#v1:
6464
codecov: true
6565
dirs:
@@ -85,7 +85,7 @@ steps:
8585
version: "{{matrix.julia}}"
8686
- JuliaCI/julia-test#v1:
8787
project: "lib/MLDataDevices"
88-
test_args: "BACKEND_GROUP=oneAPI"
88+
test_args: "--BACKEND_GROUP=oneAPI"
8989
- JuliaCI/julia-coverage#v1:
9090
codecov: true
9191
dirs:

.github/workflows/CI_MLDataDevices.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
julia_version: "1.12"
3434
project: "lib/MLDataDevices"
35-
test_args: "BACKEND_GROUP=${{ matrix.group }}"
35+
test_args: "--BACKEND_GROUP=${{ matrix.group }}"
3636
os: ${{ matrix.os }}
3737

3838
downgrade:
@@ -48,4 +48,4 @@ jobs:
4848
julia_version: "1.11"
4949
project: "lib/MLDataDevices"
5050
downgrade_testing: true
51-
test_args: "BACKEND_GROUP=${{ matrix.group }}"
51+
test_args: "--BACKEND_GROUP=${{ matrix.group }}"

lib/MLDataDevices/ext/GPUArraysSparseArraysExt.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ Adapt.adapt_storage(::CPUDevice, rng::GPUArrays.RNG) = Random.default_rng()
1111
Internal.get_device(rng::GPUArrays.RNG) = Internal.get_device(rng.state)
1212
Internal.get_device_type(rng::GPUArrays.RNG) = Internal.get_device_type(rng.state)
1313

14-
for (T1, T2) in (
15-
(:AbstractGPUSparseMatrixCSC, :SparseMatrixCSC),
16-
(:AbstractGPUSparseVector, :SparseVector),
17-
)
14+
for (T1, T2) in
15+
((AbstractGPUSparseMatrixCSC, SparseMatrixCSC), (AbstractGPUSparseVector, SparseVector))
1816
@eval begin
1917
Adapt.adapt_storage(::CPUDevice{Missing}, x::$(T1)) = $(T2)(x)
2018
Adapt.adapt_storage(::CPUDevice{Nothing}, x::$(T1)) = $(T2)(x)

lib/MLDataDevices/test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LuxTestUtils = "ac9de150-d08f-4546-94fb-7472b5760531"
1212
MLDataDevices = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40"
1313
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
1414
OneHotArrays = "0b1bfda6-eb8a-41d2-88d8-f5af5cad476f"
15+
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
1516
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1617
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1718
Reactant = "3c362404-f566-11ee-1572-e11a4b42c853"
@@ -38,6 +39,7 @@ ForwardDiff = "0.10.36, 1"
3839
Functors = "0.5"
3940
MLUtils = "0.4.4"
4041
OneHotArrays = "0.2.5"
42+
ParallelTestRunner = "2.1"
4143
Pkg = "1.10"
4244
Random = "1.10"
4345
Reactant = "0.2.170"

lib/MLDataDevices/test/amdgpu_tests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using MLDataDevices, Random, Test
22
using ArrayInterface: parameterless_type
33

4-
@testset "CPU Fallback" begin
4+
include("common.jl")
5+
6+
@test_in_separate_process "CPU Fallback" begin
7+
using MLDataDevices, Test
8+
59
@test !MLDataDevices.functional(AMDGPUDevice)
610
@test cpu_device() isa CPUDevice
711
@test gpu_device() isa CPUDevice

lib/MLDataDevices/test/common.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Pkg: Pkg
2+
using Test: @test, @testset
3+
4+
macro test_in_separate_process(testname, expr)
5+
tmpfile = tempname() * ".jl"
6+
open(tmpfile, "w") do io
7+
println(io, expr)
8+
end
9+
project_path = dirname(Pkg.project().path)
10+
11+
run_cmd = `$(Base.julia_cmd()) --color=yes --project=$(project_path) --startup-file=no --code-coverage=user $(tmpfile)`
12+
13+
return quote
14+
@testset $(testname) begin
15+
try
16+
run($run_cmd)
17+
@test true
18+
catch
19+
@test false
20+
end
21+
end
22+
end
23+
end

lib/MLDataDevices/test/cuda_tests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using MLDataDevices, Random, Functors, Test
22
using ArrayInterface: parameterless_type
33

4-
@testset "CPU Fallback" begin
4+
include("common.jl")
5+
6+
@test_in_separate_process "CPU Fallback" begin
7+
using MLDataDevices, Test
8+
59
@test !MLDataDevices.functional(CUDADevice)
610
@test cpu_device() isa CPUDevice
711
@test gpu_device() isa CPUDevice

lib/MLDataDevices/test/eltype_tests.jl

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
@testitem "Device Eltype Functionality" setup = [SharedTestSetup] tags = [:misc] begin
2-
using MLDataDevices, Random, Test
1+
using MLDataDevices, Random, Test
32

3+
@testset "Device Eltype Functionality" begin
44
@testset "CPU Device with Eltype" begin
55
# Test default behavior (missing eltype)
66
cpu_default = cpu_device()
77
@test cpu_default isa CPUDevice{Missing}
88

99
# Test eltype=nothing (preserve type)
10-
cpu_preserve = cpu_device(; eltype=nothing)
10+
cpu_preserve = cpu_device(nothing)
1111
@test cpu_preserve isa CPUDevice{Nothing}
1212

1313
# Test specific eltype
14-
cpu_f32 = cpu_device(; eltype=Float32)
14+
cpu_f32 = cpu_device(Float32)
1515
@test cpu_f32 isa CPUDevice{Float32}
1616

17-
cpu_f64 = cpu_device(; eltype=Float64)
17+
cpu_f64 = cpu_device(Float64)
1818
@test cpu_f64 isa CPUDevice{Float64}
1919

2020
# Test invalid eltype
21-
@test_throws ArgumentError cpu_device(eltype=Int)
22-
@test_throws ArgumentError cpu_device(eltype=String)
21+
@test_throws MethodError cpu_device(Int)
22+
@test_throws MethodError cpu_device(String)
2323
end
2424

2525
@testset "CPU Device Array Conversion" begin
@@ -34,13 +34,13 @@
3434
@test y_f64 == x_f64
3535

3636
# Test nothing eltype (preserve)
37-
cpu_preserve = cpu_device(; eltype=nothing)
37+
cpu_preserve = cpu_device(nothing)
3838
y_f64_preserve = cpu_preserve(x_f64)
3939
@test eltype(y_f64_preserve) === Float64
4040
@test y_f64_preserve == x_f64
4141

4242
# Test specific eltype conversion
43-
cpu_f32 = cpu_device(; eltype=Float32)
43+
cpu_f32 = cpu_device(Float32)
4444
y_f32 = cpu_f32(x_f64)
4545
@test eltype(y_f32) === Float32
4646
@test y_f32 Float32.(x_f64)
@@ -57,55 +57,6 @@
5757
@test y_complex ComplexF32.(x_complex)
5858
end
5959

60-
@testset "GPU Device Creation with Eltype" begin
61-
# Test default behavior
62-
try
63-
gpu_default = gpu_device(; eltype=nothing)
64-
@test MLDataDevices.get_eltype(gpu_default) === Nothing
65-
catch e
66-
if e isa MLDataDevices.Internal.DeviceSelectionException
67-
@test_skip "No functional GPU available"
68-
else
69-
rethrow()
70-
end
71-
end
72-
73-
try
74-
gpu_f32 = gpu_device(; eltype=Float32)
75-
@test MLDataDevices.get_eltype(gpu_f32) === Float32
76-
catch e
77-
if e isa MLDataDevices.Internal.DeviceSelectionException
78-
@test_skip "No functional GPU available"
79-
else
80-
rethrow()
81-
end
82-
end
83-
end
84-
85-
@testset "Reactant Device with Eltype" begin
86-
# Test eltype parameter
87-
reactant_default = reactant_device(; eltype=nothing)
88-
@test reactant_default isa CPUDevice{Nothing} # Falls back to CPU since Reactant not loaded
89-
90-
reactant_f32 = reactant_device(; eltype=Float32)
91-
@test reactant_f32 isa CPUDevice{Float32} # Falls back to CPU since Reactant not loaded
92-
end
93-
94-
@testset "Helper Functions" begin
95-
cpu_f32 = cpu_device(; eltype=Float32)
96-
cpu_f64 = cpu_device(; eltype=Float64)
97-
cpu_nothing = cpu_device(; eltype=nothing)
98-
99-
# Test get_eltype
100-
@test MLDataDevices.get_eltype(cpu_f32) === Float32
101-
@test MLDataDevices.get_eltype(cpu_f64) === Float64
102-
@test MLDataDevices.get_eltype(cpu_nothing) === Nothing
103-
104-
# Test with_eltype
105-
cpu_new = MLDataDevices.with_eltype(cpu_f32, Float64)
106-
@test MLDataDevices.get_eltype(cpu_new) === Float64
107-
end
108-
10960
@testset "Device Constructor Backward Compatibility" begin
11061
# Test that old constructors still work
11162
cpu_old = CPUDevice()

lib/MLDataDevices/test/metal_tests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using MLDataDevices, Random, Test
22
using ArrayInterface: parameterless_type
33

4-
@testset "CPU Fallback" begin
4+
include("common.jl")
5+
6+
@test_in_separate_process "CPU Fallback" begin
7+
using MLDataDevices, Test
8+
59
@test !MLDataDevices.functional(MetalDevice)
610
@test cpu_device() isa CPUDevice
711
@test gpu_device() isa CPUDevice

lib/MLDataDevices/test/oneapi_tests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using MLDataDevices, Random, Test
22
using ArrayInterface: parameterless_type
33

4-
@testset "CPU Fallback" begin
4+
include("common.jl")
5+
6+
@test_in_separate_process "CPU Fallback" begin
7+
using MLDataDevices, Test
8+
59
@test !MLDataDevices.functional(oneAPIDevice)
610
@test cpu_device() isa CPUDevice
711
@test gpu_device() isa CPUDevice

0 commit comments

Comments
 (0)