Skip to content
Open
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ See also [github's page](https://github.com/FluxML/Flux.jl/releases) for a compl

## Unreleased

- Fix stack overflow when applying f16/f32/f64 or cpu/gpu to empty structs declared with Flux.@layer.
- Switch to `ParallelTestRunner.jl` for parallel test execution, replacing the previous test runner.

## v0.16.8 (January 2025)
Expand Down
1 change: 1 addition & 0 deletions src/layers/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ end
function _macro_adapt(type)
quote
Adapt.adapt_structure(to, layer::$type) = $fmap($adapt(to), layer)
$Functors.isleaf(::$type) = false
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/layers/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,18 @@ end

@test_throws LoadError @eval Flux.@layer :zzz MacroTest.TwoThirds
@test_throws LoadError @eval Flux.@layer MacroTest.TwoThirds chidren=(a, b)

@testset "empty struct" begin
struct EmptyStruct end
Flux.@layer EmptyStruct
em = EmptyStruct()
# @layer overrides isleaf to false, so fmap decomposes instead of recursing
@test Functors.isleaf(em) == false
@test Flux.f16(em) === em
@test Flux.f32(em) === em
@test Flux.f64(em) === em
@test Flux.cpu(em) === em
@test Flux.gpu(em) === em
end
end

Loading