Closed ldeso closed 1 month ago
Force-pushed to pass the method ambiguity check, also moved the tests to the "Miscellaneous Layers" test item.
Does this need to be a separate layer? We can just use multiple dispatch to combine with the Embedding layer
I created a separate pull request with multiple dispatch to let you compare (#670). While the solution with multiple dispatch results in less code, it also requires a modification of the Embedding struct which might be a bit risky (even though it passes all tests).
https://github.com/LuxDL/Lux.jl/pull/670 supersedes this
Lux currently offers an Embedding layer that calls the NNlib.gather method with linear indices as arguments.
This pull request adds a CartesianEmbedding layer that allows using the other NNlib.gather method with Cartesian indices as arguments. This eliminates the need to convert manually from linear to Cartesian indices to use NNlib.gather, which significantly improves performance and reduce the number of allocations, especially on the GPU.
Example
Closes #670