Skip to content

Enable multiple dispatch for compact layers#14

Open
MilesCranmer wants to merge 1 commit intoFluxML:masterfrom
MilesCranmer:master
Open

Enable multiple dispatch for compact layers#14
MilesCranmer wants to merge 1 commit intoFluxML:masterfrom
MilesCranmer:master

Conversation

@MilesCranmer
Copy link
Contributor

@MilesCranmer MilesCranmer commented Jul 16, 2023

This is just an idea to make CompactLayer have a type parameter S::Symbol which lets you use multiple dispatch on the output of @compact. This addresses @darsnack's point in #12 (reply in thread).

Here's an example:

model1 = @compact(W=randn(32)) do x
  W .* x
end

model2 = @compact(MyCustomLayer, W=randn(32)) do x
  W .* x
end

my_custom_function(::CompactLayer) = 1
my_custom_function(::CompactLayer{:MyCustomLayer}) = 2

my_custom_function(model1) # 1
my_custom_function(model2) # 2

It also prints the symbol as you would expect:

julia> model2 = @compact(MyCustomLayer, W=randn(32)) do x
         W .* x
       end
@compact(
  MyCustomLayer,
  W = randn(32),                        # 32 parameters
) do x 
    W .* x
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant