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

Let connection in Parallel be a layer #377

Open
vpuri3 opened this issue Aug 4, 2023 · 0 comments
Open

Let connection in Parallel be a layer #377

vpuri3 opened this issue Aug 4, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@vpuri3
Copy link
Contributor

vpuri3 commented Aug 4, 2023

This seems to be a common use of Parallel/ BranchLayer containers:

Chain(
  BranchLayer(chain1, chain2),       # x -> (f(x), g(x))
  Parallel(nothing, chain3, chain4), # (x1, x2) -> (f(x1), g(x2))
  fusion                             # (y1, y2) -> z eg Bilinear layer
)

an easier syntax for the last two layers would be Parallel(fusion, chain1, chain2) which entails allowing connection in Parallel to be a Lux layer. Likely adding an if C <: AbstractExplicitLayer statement here.

if C == Nothing
push!(calls, :($(y_symbols[N + 1]) = tuple($(Tuple(y_symbols[1:N])...))))
else
push!(calls, :($(y_symbols[N + 1]) = connection($(Tuple(y_symbols[1:N])...))))
end

Similarly, BranchLayer can be extended with kwarg fusion like BranchLayer(layers...; fusion = nothing) with behaviour x -> fusion(f(x), g(x)). This is equivalent to

Chain(
  BranchLayer(chain1, chain2), # x -> (f(x), g(x))
  fusion,                 # (x1, x2) -> z
)

The default can be set to the current behaviour (x -> (f(x), g(x))) with fusion = nothing.

@avik-pal avik-pal added the enhancement New feature or request label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants