Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: incorrect activation usage
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Jul 23, 2024
1 parent e8f8484 commit d179933
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/impl/activation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@ end
_fast_activation(::typeof(identity), x::AbstractArray) = x

@stable default_mode="disable" function _fast_activation::F, x::AbstractArray) where {F}
y = similar(x, Core.Compiler._return_type(σ, Tuple{eltype(x)}))
_fast_activation!(internal_operation_mode(x), y, σ, x)
return y
return _fast_activation(internal_operation_mode(x), σ, x)
end

function CRC.rrule(cfg::RuleConfig{>:HasReverseMode}, ::typeof(_fast_activation),
σ::F, x::AbstractArray{T}) where {F, T}
return CRC.rrule_via_ad(cfg, broadcast, σ, x)
end

_fast_activation(opmode, σ::F, x::AbstractArray) where {F} = broadcast(σ, x)

function _fast_activation(opmode::LoopedArrayOp, σ::F, x::AbstractArray) where {F}
RT = Core.Compiler._return_type(σ, Tuple{eltype(x)})
y = similar(x, ifelse(isconcretetype(RT), RT, eltype(x)))
_fast_activation!(opmode, y, σ, x)
return y
end

_fast_activation!(::typeof(identity), x::AbstractArray) = nothing

@stable default_mode="disable" function _fast_activation!::F, x::AbstractArray) where {F}
Expand Down
2 changes: 1 addition & 1 deletion src/impl/bias_activation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function __apply_bias_activation_cached!!(
if can_setindex(x)
opmode = internal_operation_mode((x, bias))
if opmode isa LoopedArrayOp
bc = Broadcast.instantiate(Broadcast.broadcasted(σ +, x, bias_))
bc = Broadcast.instantiate(Broadcast.broadcasted(+, x, bias_))
@simd ivdep for I in eachindex(bc)
@inbounds x[I] = bc[I]
end
Expand Down

2 comments on commit d179933

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

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 v0.3.31 -m "<description of version>" d1799333aad78bf91b952d0618350e30073b3750
git push origin v0.3.31

Please sign in to comment.