From de540d3d4f6c00da6d3621608f4af07804ff0561 Mon Sep 17 00:00:00 2001 From: hardik-xi11 Date: Thu, 2 Apr 2026 16:52:21 +0530 Subject: [PATCH 1/2] fix overflow error on empty struct --- src/layers/macro.jl | 1 + test/layers/macro.jl | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/layers/macro.jl b/src/layers/macro.jl index f430d33102..4961841798 100644 --- a/src/layers/macro.jl +++ b/src/layers/macro.jl @@ -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 diff --git a/test/layers/macro.jl b/test/layers/macro.jl index ab83c5cf0b..2c8b646e11 100644 --- a/test/layers/macro.jl +++ b/test/layers/macro.jl @@ -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 From 7118e7cc597e101ea87d1a71ebf71870af7ef606 Mon Sep 17 00:00:00 2001 From: hardik-xi11 Date: Thu, 9 Apr 2026 16:01:32 +0530 Subject: [PATCH 2/2] add entry in news.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c3c88b1faf..1c903e81fa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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)