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

mark stop, skip, @epochs as deprecated #2027

Merged
merged 5 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 17 additions & 1 deletion src/optimise/train.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct SkipException <: Exception end
Call `Flux.skip()` in a callback to indicate when a callback condition is met.
This will trigger the train loop to skip the current data point and not update with the calculated gradient.

!!! note
`Flux.skip()` will be removed from Flux 0.14

# Examples
```julia
cb = function ()
Expand All @@ -46,6 +49,9 @@ end
```
"""
function skip()
Base.depwarn("""Flux.skip() will be removed from Flux 0.14.
It never worked as described,
mcabbott marked this conversation as resolved.
Show resolved Hide resolved
and should be replaced with `continue` in an ordinary `for` loop.""", :skip)
throw(SkipException())
end

Expand All @@ -58,6 +64,9 @@ struct StopException <: Exception end
Call `Flux.stop()` in a callback to indicate when a callback condition is met.
This will trigger the train loop to stop and exit.

!!! note
`Flux.stop()` will be removed from Flux 0.14. It should be replaced with `break` in an ordinary `for` loop.

# Examples
```julia
cb = function ()
Expand All @@ -66,6 +75,8 @@ end
```
"""
function stop()
Base.depwarn("""Flux.stop() will be removed from Flux 0.14.
It should be replaced with `break` in an ordinary `for` loop.""", :stop)
throw(StopException())
end

Expand Down Expand Up @@ -140,8 +151,11 @@ end
Run `body` `N` times. Mainly useful for quickly doing multiple epochs of
training in a REPL.

!!! note
The macro `@epochs` will be removed from Flux 0.14. Please just write an ordinary `for` loop.

# Examples
```jldoctest
```julia
julia> Flux.@epochs 2 println("hello")
[ Info: Epoch 1
hello
Expand All @@ -150,6 +164,8 @@ hello
```
"""
macro epochs(n, ex)
Base.depwarn("""The macro `@epochs` will be removed from Flux 0.14.
Just write an ordinary for loop.""", Symbol("@epochs"), force=true)
mcabbott marked this conversation as resolved.
Show resolved Hide resolved
:(@progress for i = 1:$(esc(n))
@info "Epoch $i"
$(esc(ex))
Expand Down
9 changes: 6 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ julia> loss() = rand();
julia> trigger = Flux.patience(() -> loss() < 1, 3);


julia> Flux.@epochs 10 begin
julia> for i in 1:10
@info "Epoch \$i"
trigger() && break
end
[ Info: Epoch 1
Expand Down Expand Up @@ -658,7 +659,8 @@ julia> loss = let l = 0
julia> es = Flux.early_stopping(loss, 3);


julia> Flux.@epochs 10 begin
julia> for i in 1:10
@info "Epoch \$i"
es() && break
end
[ Info: Epoch 1
Expand Down Expand Up @@ -699,7 +701,8 @@ julia> f = let v = 10
julia> trigger = Flux.plateau(f, 3; init_score=10, min_dist=18);


julia> Flux.@epochs 10 begin
julia> for i in 1:10
@info "Epoch \$i"
trigger() && break
end
[ Info: Epoch 1
Expand Down