Skip to content

Commit

Permalink
mark stop, skip, @epochs as deprecated (#2027)
Browse files Browse the repository at this point in the history
* mark stop, skip, at-epochs as deprecated

* remove at-epochs from testing

* add removal notes

* typo

* Apply suggestions from code review

Co-authored-by: Brian Chen <[email protected]>

Co-authored-by: Brian Chen <[email protected]>
  • Loading branch information
mcabbott and ToucheSir authored Aug 27, 2022
1 parent bc7b54c commit 6c747f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 16 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,8 @@ end
```
"""
function skip()
Base.depwarn("""Flux.skip() will be removed from Flux 0.14.
and should be replaced with `continue` in an ordinary `for` loop.""", :skip)
throw(SkipException())
end

Expand All @@ -58,6 +63,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 +74,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 +150,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 +163,8 @@ hello
```
"""
macro epochs(n, ex)
Base.depwarn("""The macro `@epochs` will be removed from Flux 0.14.
As an alternative, you can write a simple `for i in 1:epochs` loop.""", Symbol("@epochs"), force=true)
:(@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 @@ -648,7 +648,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 @@ -685,7 +686,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 @@ -726,7 +728,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

0 comments on commit 6c747f3

Please sign in to comment.