Skip to content

NaN caused by tanh_fast #407

Closed
Closed
@zhubonan

Description

@zhubonan

FluxML/Flux.jl#1776 subsitutes tanh by tanh_fast, howeer, the latter gives NaN for large numbers:

I am on Julia 1.7.2 and Flux 0.13.

using Flux

julia> tanh_fast(1e10)
NaN

julia> tanh_fast(-1e10)
-1.0

julia> d = Dense(1=>1, tanh)
Dense(1 => 1, tanh)  # 2 parameters

julia> d([-1.e16])
1-element Vector{Float64}:
 NaN

julia> d([1.e16])
1-element Vector{Float64}:
 -1.0

NaN would then propagate down the network....

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions