Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass in RNG to shuffle #1188

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/WeightInitializers/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WeightInitializers"
uuid = "d49dbf32-c5c2-4618-8acc-27bb2598ef2d"
authors = ["Avik Pal <avikpal@mit.edu> and contributors"]
version = "1.0.4"
version = "1.0.5"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion lib/WeightInitializers/src/WeightInitializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module WeightInitializers
using ArgCheck: @argcheck
using GPUArraysCore: @allowscalar
using LinearAlgebra: LinearAlgebra, Diagonal, qr
using Random: Random, AbstractRNG, shuffle
using Random: Random, AbstractRNG
using SpecialFunctions: SpecialFunctions, erfinv # TODO: Move to Ext in v2.0
using Statistics: Statistics, std

Expand Down
14 changes: 13 additions & 1 deletion lib/WeightInitializers/src/initializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,19 @@ function sparse_init(rng::AbstractRNG, ::Type{T}, dims::Integer...;
sparse_array .*= T(std)
fill!(view(sparse_array, 1:num_zeros, :), zero(T))

return @allowscalar mapslices(shuffle, sparse_array; dims=1)
if applicable(Random.rng_native_52, rng)
@inbounds for i in axes(sparse_array, 2)
@allowscalar Random.shuffle!(rng, view(sparse_array, :, i))
end
else
@warn "`rng` is not supported by `Random.shuffle!`. Ignoring the `rng` for \
shuffle." maxlog=1
@inbounds for i in axes(sparse_array, 2)
@allowscalar Random.shuffle!(view(sparse_array, :, i))
end
end

return sparse_array
end

"""
Expand Down
Loading