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

bumped version #25

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 6 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NeuralAttentionlib"
uuid = "12afc1b8-fad6-47e1-9132-84abc478905f"
authors = ["chengchingwen <adgjl5645@hotmail.com>"]
version = "0.2.12"
version = "0.2.13"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -11,21 +11,19 @@ GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
NNlibCUDA = "a00861dc-f156-4864-bf3c-e6376f28a68d"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"

[compat]
Adapt = "3.3"
CUDA = "3, 4"
Adapt = "4"
CUDA = "5"
ChainRulesCore = "1.3"
GPUArrays = "8"
GPUArrays = "8, 9, 10"
GPUArraysCore = "0.1"
NNlib = "0.7, 0.8"
NNlibCUDA = "0.2"
NNlib = "0.7, 0.8, 0.9"
Requires = "1.1"
Static = "0.7, 0.8"
julia = "1.6"
julia = "1.8"

[extras]
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Expand Down
1 change: 0 additions & 1 deletion src/NeuralAttentionlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import GPUArraysCore
using ChainRulesCore

using NNlib
using NNlibCUDA

using Requires

Expand Down
10 changes: 6 additions & 4 deletions src/functional/layernorm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ _x_y2(x, y) = (x, x * y)
function _normalize(inN::T, ϵ::T, x::T, mean_M2_::Tuple{Int32, T, T}) where T
_, μ, M2 = mean_M2_
v = M2 * inN
σ₀ = sqrt(v)
σ = max(σ₀, ϵ)
# σ₀ = sqrt(v .+ ϵ)
# σ = max(σ₀, ϵ)
σ = sqrt(v .+ ϵ)
return (x - μ) / σ
end

function _normalize(inN::Float16, ϵ::Float16, x::Float16, mean_M2_::Tuple{Int32, Float32, Float32})
_, μ, M2 = mean_M2_
v = Float16(M2) * inN
σ₀ = sqrt(v)
σ = max(σ₀, ϵ)
# σ₀ = sqrt(v)
# σ = max(σ₀, ϵ)
σ = sqrt(v .+ ϵ)
return Float16(Float32(x) - μ) / σ
end

Expand Down
2 changes: 1 addition & 1 deletion src/mask/mask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Base.@propagate_inbounds Base.getindex(m::M, I::Integer...) where {M <: Union{<:
Base.@propagate_inbounds Base.getindex(m::MaskIndexer, i::CartesianIndex) = m[Tuple(i)]
Base.@propagate_inbounds Base.getindex(m::MaskIndexer, I::Tuple) = m[I...]

Adapt.adapt(to::CUDA.Adaptor, m::AbstractArrayMask) = Indexer{typeof(m)}(map(Base.Fix1(Adapt.adapt, to), GetIndexer(m).__fields))
Adapt.adapt(to::CUDA.KernelAdaptor, m::AbstractArrayMask) = Indexer{typeof(m)}(map(Base.Fix1(Adapt.adapt, to), GetIndexer(m).__fields))

randomness(::AbstractMask) = static(false)
require_dest(::AbstractMask) = static(false)
10 changes: 5 additions & 5 deletions src/mask/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AttenMask(m::FlipMask) = FlipMask(AttenMask(m.mask))
Base.:!(m::AbstractMask) = FlipMask(m)
Base.:!(m::FlipMask) = m.mask

Adapt.adapt(to::CUDA.Adaptor, m::FlipMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask),))
Adapt.adapt(to::CUDA.KernelAdaptor, m::FlipMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask),))
adapt_structure(to, x::FlipMask) = FlipMask(adapt(to, x.mask))
GetIndexer(m::FlipMask, dest_size = nothing) = Indexer{typeof(m)}((mask = GetIndexer(m.mask, dest_size),), dest_size)

Expand Down Expand Up @@ -43,7 +43,7 @@ Base.:|(::Nothing, m::AbstractMask) = nothing
Base.:&(m::AbstractMask, ::Nothing) = m
Base.:&(::Nothing, m::AbstractMask) = m

Adapt.adapt(to::CUDA.Adaptor, m::CombinedMask) = Indexer{typeof(m)}((f = adapt(to, m.f),
Adapt.adapt(to::CUDA.KernelAdaptor, m::CombinedMask) = Indexer{typeof(m)}((f = adapt(to, m.f),
masks = map(Base.Fix1(adapt, to), m.masks)))
adapt_structure(to, x::CombinedMask) = CombinedMask(x.f, adapt(to, x.masks))
GetIndexer(m::CombinedMask, dest_size = nothing) = Indexer{typeof(m)}((m.f, masks = map(Base.Fix2(GetIndexer, dest_size), m.masks)))
Expand Down Expand Up @@ -101,7 +101,7 @@ function BatchedMask(mask)
return BatchedMask(mask, batch_dim)
end

Adapt.adapt(to::CUDA.Adaptor, m::BatchedMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask), batch_dim = static(m.batch_dim)))
Adapt.adapt(to::CUDA.KernelAdaptor, m::BatchedMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask), batch_dim = static(m.batch_dim)))
adapt_structure(to, x::BatchedMask) = BatchedMask(adapt(to, x.mask), x.batch_dim)
GetIndexer(m::BatchedMask, dest_size = nothing) = Indexer{typeof(m)}((mask = GetIndexer(m.mask, dest_size), batch_dim = static(m.batch_dim)))

Expand Down Expand Up @@ -138,7 +138,7 @@ end

AttenMask(r::RepeatMask) = RepeatMask(AttenMask(r.mask), r.num)

Adapt.adapt(to::CUDA.Adaptor, m::RepeatMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask), num = m.num))
Adapt.adapt(to::CUDA.KernelAdaptor, m::RepeatMask) = Indexer{typeof(m)}((mask = adapt(to, m.mask), num = m.num))
adapt_structure(to, x::RepeatMask) = RepeatMask(adapt(to, x.mask), x.num)
GetIndexer(m::RepeatMask, dest_size = nothing) = Indexer{typeof(m)}((mask = GetIndexer(m.mask, dest_size), num = m.num))

Expand Down Expand Up @@ -176,7 +176,7 @@ struct BiSequenceMask{QM<:AbstractMask, KM<:AbstractMask} <: AbstractWrapperMask
k_mask::KM
end

Adapt.adapt(to::CUDA.Adaptor, m::BiSequenceMask) = Indexer{typeof(m)}((q_mask = adapt(to, m.q_mask), k_mask = adapt(to, m.k_mask)))
Adapt.adapt(to::CUDA.KernelAdaptor, m::BiSequenceMask) = Indexer{typeof(m)}((q_mask = adapt(to, m.q_mask), k_mask = adapt(to, m.k_mask)))
adapt_structure(to, x::BiSequenceMask) = BiSequenceMask(adapt(to, x.q_mask), adapt(to, x.k_mask))

bi_dest_size(::Nothing, is_q) = nothing
Expand Down