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

Use new public feature #2342

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.14.6"
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
Expand Down Expand Up @@ -38,6 +39,7 @@ AMDGPU = "0.5, 0.6"
Adapt = "3.0"
CUDA = "4, 5"
ChainRulesCore = "1.12"
Compat = "4.10.0"
Functors = "0.4"
MLUtils = "0.4"
MacroTools = "0.5"
Expand Down
46 changes: 46 additions & 0 deletions src/Flux.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Flux

using Base: tail
using Compat: @compat # for @compat public
using Preferences
using LinearAlgebra, Statistics, Random # standard lib
using MacroTools, Reexport, ProgressLogging, SpecialFunctions
Expand Down Expand Up @@ -30,6 +31,15 @@ export Chain, Dense, Embedding, Maxout, SkipConnection, Parallel, PairwiseFusion
fmap, cpu, gpu, f32, f64, f16, rand32, randn32, zeros32, ones32,
testmode!, trainmode!

@compat(public, ( # mark unexported symbols as API, on Julia 1.11
# modules
Losses,
# layers
Bilinear, Scale, dropout,
# utils
outputsize, state,
))

include("optimise/Optimise.jl")
using .Optimise
export Descent, Adam, Momentum, Nesterov, RMSProp,
Expand All @@ -47,6 +57,10 @@ using Adapt, Functors, OneHotArrays
include("utils.jl")
include("functor.jl")

@compat public onehot, onehotbatch, onecold, # from OneHotArrays
functor, @functor, # from Functors
setup, update!, destructure, freeze!, adjust!, params, trainable # from Optimise/Train/Optimisers

# Pirate error to catch a common mistake.
Functors.functor(::Type{<:MLUtils.DataLoader}, x) = error("`DataLoader` does not support Functors.jl, thus functions like `Flux.gpu` will not act on its contents.")

Expand All @@ -69,5 +83,37 @@ include("deprecations.jl")
include("losses/Losses.jl")
using .Losses

@compat(public, (
# init
glorot_uniform,
glorot_normal,
Comment on lines +91 to +94
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called the macro with brackets just to allow comments like this. But eventual syntax is just public glorot_uniform, glorot_normal like using, for which this isn't possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will express a slight personal preference for this over the indent-only syntax on L60-62, but the best way to settle the debate might be to see what the auto-formatter outputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All now switched to this format.

kaiming_uniform,
kaiming_normal,
truncated_normal,
orthogonal,
sparse_init,
identity_init,

# Losses
binary_focal_loss,
binarycrossentropy,
crossentropy,
dice_coeff_loss,
focal_loss,
hinge_loss,
huber_loss,
kldivergence,
label_smoothing,
logitbinarycrossentropy,
logitcrossentropy,
mae,
mse,
msle,
poisson_loss,
siamese_contrastive_loss,
squared_hinge_loss,
tversky_loss,
))


end # module
Loading