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

Incorrect adapt usage leads to non-concrete elements #883

Open
avik-pal opened this issue Aug 21, 2024 · 0 comments
Open

Incorrect adapt usage leads to non-concrete elements #883

avik-pal opened this issue Aug 21, 2024 · 0 comments
Labels

Comments

@avik-pal
Copy link
Member

Currently several places in the codebase uses this pattern:

adapt(eltypeθ,
   hcat(vec(map(points -> collect(points), Iterators.product(span...)))...))

But, adapt doesn't work with eltype, for example:

julia> adapt(Float32, rand(2, 3))
2×3 Matrix{Float64}:
 0.0893353  0.197801   0.457015
 0.796801   0.0334906  0.255498

This causes adapt to simply ignore the eltype and constructs non-concrete array types, which eventually leads to issues like https://github.com/SciML/NeuralPDE.jl/actions/runs/10485955321/job/29043160310?pr=882#step:6:1231 (matrix multiplication with non-concrete elements).

Lux does have mechanisms to catch these. While not perfect, activating the following preferences will throw errors whenever a "bad" type is being propagated. I don't turn these on by default, since they can have some overhead but for testing purposes these should be set to "error" on CI.

using Preferences

Preferences.set_preferences!("Lux", "eltype_mismatch_handling" => "error")

Preferences.set_preferences!("LuxLib", "instability_check" => "error")
Preferences.set_preferences!("LuxCore", "instability_check" => "error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants