Skip to content

Commit

Permalink
Update to Flux v0.13 (#18)
Browse files Browse the repository at this point in the history
* update for Flux v0.13

* work on either flux version

* rm Flux comparison test; clean up test file

* don't need this

* only test Flux 0.12 on v1.5

* fix

* update version; rm comment

* Update digits.jl
  • Loading branch information
ericphanson authored May 25, 2022
1 parent 50bda07 commit c142a48
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,37 @@ on:
- 'Project.toml'
jobs:
test:
name: Julia ${{ matrix.version }} - Legolas ${{ matrix.legolas-version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
name: Julia ${{ matrix.version }} - Legolas ${{ matrix.legolas-version }} - Flux ${{ matrix.flux-version }} - ${{ github.event_name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
legolas-version:
- '0.2'
- '0.3'
flux-version:
- '0.12'
- '0.13'
version:
- '1.5' # earliest supported version
- '1' # current release
os:
- ubuntu-latest
arch:
- x64
include:
- version: '1.5' # earliest supported version
legolas-version: '0.2'
flux-version: '0.12'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- name: "Install Legolas version"
arch: x64
- name: "Install Legolas and Flux"
shell: julia --color=yes --project=. {0}
run: |
using Pkg
Pkg.add(Pkg.PackageSpec(; name="Legolas", version="${{ matrix.legolas-version }}"))
Pkg.add([Pkg.PackageSpec(; name="Legolas", version="${{ matrix.legolas-version }}"),
Pkg.PackageSpec(; name="Flux", version="${{ matrix.flux-version }}")])
- uses: actions/cache@v2
with:
path: ~/.julia/artifacts
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Manifest.toml
test/my_model.model.arrow
my_model.model.arrow
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LegolasFlux"
uuid = "eb5f792d-d1b1-4535-bae3-d5649ec7daa4"
authors = ["Beacon Biosignals, Inc."]
version = "0.1.5"
version = "0.1.6"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand All @@ -11,7 +11,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Arrow = "1, 2"
Flux = "0.12"
Flux = "0.12, 0.13"
Functors = "0.2.6"
Legolas = "0.1, 0.2, 0.3"
Tables = "1"
Expand Down
2 changes: 1 addition & 1 deletion examples/digits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function train_model!(m; N = N_train)
loss = (x, y) -> crossentropy(m(x), y)
opt = ADAM()
evalcb = throttle(() -> @show(accuracy(m, tX, tY)), 5)
Flux.@epochs 1 Flux.train!(loss, params(m), Iterators.take(train, N), opt; cb=evalcb)
Flux.@epochs 1 Flux.train!(loss, Flux.params(m), Iterators.take(train, N), opt; cb=evalcb)
return accuracy(m, tX, tY)
end

Expand Down
68 changes: 36 additions & 32 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using LegolasFlux
using Test
using Flux, LegolasFlux
using LegolasFlux: Weights, FlatArray, ModelRow
using Flux: params
using Arrow
using Random
using StableRNGs
Expand All @@ -15,34 +16,32 @@ function test_weights()
return [reshape(Float32.(1:prod(s)), s) for s in shapes]
end

# This simple model should work with both Flux's `params/loadparams!` and
# our `weights/load_weights!`. The only difference is in layers with `!isempty(other_weights(layer))`.
@testset "using ($get_weights, $load_weights)" for (get_weights, load_weights) in [(fetch_weights, load_weights!, params, Flux.loadparams!)]
@testset "Roundtripping simple model" begin
try
# quick test with `missing` weights.
model_row = ModelRow(; weights=missing)
write_model_row("my_model.model.arrow", model_row)
rt = read_model_row("my_model.model.arrow")
@test isequal(model_row, rt)

# quick test with `missing` weights.
model_row = ModelRow(; weights=missing)
write_model_row("my_model.model.arrow", model_row)
rt = read_model_row("my_model.model.arrow")
@test isequal(model_row, rt)

my_model = make_my_model()
load_weights(my_model, test_weights())

model_row = ModelRow(; weights=collect(get_weights(my_model)))
write_model_row("my_model.model.arrow", model_row)
my_model = make_my_model()
load_weights!(my_model, test_weights())

model_row = ModelRow(; weights=collect(fetch_weights(my_model)))
write_model_row("my_model.model.arrow", model_row)

fresh_model = make_my_model()
fresh_model = make_my_model()

model_row = read_model_row("my_model.model.arrow")
weights = collect(model_row.weights)
load_weights(fresh_model, weights)
model_row = read_model_row("my_model.model.arrow")
weights = collect(model_row.weights)
load_weights!(fresh_model, weights)

@test collect(params(fresh_model)) == weights == test_weights()
@test collect(params(fresh_model)) == weights == test_weights()

@test all(x -> eltype(x) == Float32, weights)

rm("my_model.model.arrow")
@test all(x -> eltype(x) == Float32, weights)
finally
rm("my_model.model.arrow")
end
end

struct MyArrayModel
Expand All @@ -51,16 +50,20 @@ end
Flux.@functor MyArrayModel

@testset "Non-numeric arrays ignored" begin
m = MyArrayModel([Dense(1, 10), Dense(10, 10), Dense(10, 1)])
weights = fetch_weights(m)
@test length(weights) == 6

model_row = ModelRow(; weights=collect(weights))
write_model_row("my_model.model.arrow", model_row)

new_model_row = read_model_row("my_model.model.arrow")
new_weights = collect(new_model_row.weights)
@test new_weights == weights
try
m = MyArrayModel([Dense(1, 10), Dense(10, 10), Dense(10, 1)])
weights = fetch_weights(m)
@test length(weights) == 6

model_row = ModelRow(; weights=collect(weights))
write_model_row("my_model.model.arrow", model_row)

new_model_row = read_model_row("my_model.model.arrow")
new_weights = collect(new_model_row.weights)
@test new_weights == weights
finally
rm("my_model.model.arrow")
end
end

@testset "Errors" begin
Expand Down Expand Up @@ -97,6 +100,7 @@ end
end
testmode!(model)
w = fetch_weights(model)

p = collect(params(model))
output = model(x)

Expand Down

2 comments on commit c142a48

@ericphanson
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/61010

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.6 -m "<description of version>" c142a4843faac9469aae2802c17f23afd1f43c46
git push origin v0.1.6

Please sign in to comment.