Skip to content
Open
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
12 changes: 7 additions & 5 deletions ext/ReactantNNlibExt/Implementations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ for (jlop, hloop) in (
@eval $(jlop)(x::TracedRNumber) = @opcall $(hloop)(x)
end

Reactant.MLIR.IR.DUMP_MLIR_ALWAYS[] = true

function NNlib.softmax!(out::AnyTracedRArray{T,N}, x::AbstractArray; dims=1) where {T,N}
x = T.(Reactant.materialize_traced_array(x))
max_ = maximum(x; dims)
diff = exp.(x .- max_)
# TOOD: re-enable conditional once https://github.com/EnzymeAD/Reactant.jl/issues/1581
# fixed
# @trace if all(isfinite, max_)
@. out = diff
# else
# @. out = ifelse(isinf(max_), ifelse(isinf(x), T(1), T(0)), diff)
# end
@trace if all(isfinite, max_)
@. out = diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@. out = diff
@. out = diff

else
@. out = ifelse(isinf(max_), ifelse(isinf(x), T(1), T(0)), diff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@. out = ifelse(isinf(max_), ifelse(isinf(x), T(1), T(0)), diff)
@. out = ifelse(isinf(max_), ifelse(isinf(x), T(1), T(0)), diff)

end
out ./= sum(out; dims)
return out
end
Expand Down
Loading