From 4061b2add0d218d85e48c9368f0dac19e83cad3f Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sun, 16 Jun 2024 12:57:25 -0700 Subject: [PATCH] Run doctests in the test CI --- .github/workflows/CI.yml | 4 ++-- .github/workflows/CompatHelper.yml | 5 ++++- Project.toml | 6 +++++- docs/Project.toml | 30 ++++++++++++++++++++++++------ docs/make.jl | 13 +------------ src/transform/flux.jl | 10 +++++----- test/qa_tests.jl | 15 +++++++++++++++ 7 files changed, 56 insertions(+), 27 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d15d43a5e8..0f0713386e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -20,7 +20,7 @@ concurrency: jobs: ci: - name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }} + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.test_group }} if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }} runs-on: ${{ matrix.os }} strategy: @@ -128,7 +128,7 @@ jobs: downgrade: if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }} && github.base_ref == github.event.repository.default_branch - name: Downgrade Julia ${{ matrix.version }} - ${{ github.event_name }} + name: Downgrade Julia ${{ matrix.version }} - ${{ matrix.test_group }} runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 675f43163c..866d4fbe0e 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -1,11 +1,14 @@ name: CompatHelper + on: schedule: - cron: 0 0 * * * workflow_dispatch: + permissions: contents: write pull-requests: write + jobs: CompatHelper: runs-on: ubuntu-latest @@ -31,7 +34,7 @@ jobs: - name: "Run CompatHelper" run: | import CompatHelper - subdirs = [""] + subdirs = ["", "docs"] append!(subdirs, joinpath.(("examples",), filter(p -> isdir(joinpath("examples", p)), readdir("examples")))) CompatHelper.main(; subdirs) shell: julia --color=yes {0} diff --git a/Project.toml b/Project.toml index 046bd96b02..b9deaa5867 100644 --- a/Project.toml +++ b/Project.toml @@ -74,6 +74,7 @@ ChainRulesCore = "1.23" ComponentArrays = "0.15.11" ConcreteStructs = "0.2.3" ConstructionBase = "1.5" +Documenter = "1.4" DynamicExpressions = "0.16, 0.17" Enzyme = "0.12.12" ExplicitImports = "1.1.1" @@ -95,6 +96,7 @@ MLUtils = "0.4.3" MPI = "0.20.19" MacroTools = "0.5.13" Markdown = "1.10" +Metalhead = "0.9.3" NCCL = "0.1.1" OhMyThreads = "0.5.1" Optimisers = "0.3" @@ -119,6 +121,7 @@ julia = "1.10" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2" ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" DynamicExpressions = "a40a106e-89c9-4ca8-8020-a735e8728b6b" Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" @@ -131,6 +134,7 @@ LuxCUDA = "d0bbae9a-e099-4d5b-a835-1c6931763bda" LuxTestUtils = "ac9de150-d08f-4546-94fb-7472b5760531" MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54" MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" +Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc" NCCL = "3fe64909-d7a1-4096-9b7d-7a0f12cf0f6b" Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -144,4 +148,4 @@ Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["Aqua", "ComponentArrays", "DynamicExpressions", "Enzyme", "ExplicitImports", "FiniteDifferences", "Flux", "ForwardDiff", "Logging", "LuxAMDGPU", "LuxCUDA", "LuxTestUtils", "MLUtils", "MPI", "NCCL", "Optimisers", "Pkg", "ReTestItems", "ReverseDiff", "SimpleChains", "StableRNGs", "Statistics", "Test", "Tracker", "Zygote"] +test = ["Aqua", "ComponentArrays", "Documenter", "DynamicExpressions", "Enzyme", "ExplicitImports", "FiniteDifferences", "Flux", "ForwardDiff", "Logging", "LuxAMDGPU", "LuxCUDA", "LuxTestUtils", "MLUtils", "MPI", "Metalhead", "NCCL", "Optimisers", "Pkg", "ReTestItems", "ReverseDiff", "SimpleChains", "StableRNGs", "Statistics", "Test", "Tracker", "Zygote"] diff --git a/docs/Project.toml b/docs/Project.toml index 705e90c50a..7ac1d1164a 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -6,9 +6,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365" -DynamicExpressions = "a40a106e-89c9-4ca8-8020-a735e8728b6b" FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" -Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" @@ -19,16 +17,36 @@ LuxCore = "bb33d45b-7691-41d6-9220-0943567d0623" LuxDeviceUtils = "34f89e08-e1d5-43b4-8944-0b49ac560553" LuxLib = "82251201-b29d-42c6-8e01-566dec8acb11" LuxTestUtils = "ac9de150-d08f-4546-94fb-7472b5760531" -Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc" Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" -SimpleChains = "de6bee2f-e2f4-4ec7-b6ed-219cc6f6e9e5" WeightInitializers = "d49dbf32-c5c2-4618-8acc-27bb2598ef2d" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] -Boltz = "0.3.7" +ADTypes = "1.3" +Adapt = "4" +Boltz = "0.3.8" +ChainRulesCore = "1.24" +ComponentArrays = "0.15" +Documenter = "1.4" +DocumenterVitepress = "0.1.1" +FiniteDiff = "2.23.1" +ForwardDiff = "0.10.36" +LinearAlgebra = "1.10" +Literate = "2.18.0" +Lux = "0.5.53" +LuxAMDGPU = "0.2.3" +LuxCUDA = "0.3.2" +LuxCore = "0.1.15" LuxDeviceUtils = "0.1.21" +LuxLib = "0.3.26" +LuxTestUtils = "0.1.15" +Optimisers = "0.3.3" +Pkg = "1.10" +Printf = "1.10" +Random = "1.10" +WeightInitializers = "0.1.7" +Zygote = "0.6.70" +julia = "1.10" diff --git a/docs/make.jl b/docs/make.jl index 69755a3e62..6469b7c72f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -3,17 +3,6 @@ using Lux, LuxCore, LuxLib, WeightInitializers, Boltz using LuxTestUtils, LuxDeviceUtils using LuxAMDGPU, LuxCUDA -# Doctest Imports -doctestexpr = quote - using SimpleChains: static - using Flux: Flux - using Metalhead: Metalhead - using DynamicExpressions - using Adapt, Lux, Random, Optimisers, Zygote -end - -DocMeta.setdocmeta!(Lux, :DocTestSetup, doctestexpr; recursive=true) - #! format: off pages = [ @@ -93,7 +82,7 @@ deploy_decision = Documenter.deploy_folder(deploy_config; repo="github.com/LuxDL makedocs(; sitename="Lux.jl Documentation", authors="Avik Pal et al.", clean=true, - doctest=true, + doctest=false, # We test it in the CI, no need to run it here modules=[Lux, LuxCore, LuxLib, WeightInitializers, Boltz, LuxTestUtils, LuxDeviceUtils, LuxAMDGPU, LuxCUDA], linkcheck=true, diff --git a/src/transform/flux.jl b/src/transform/flux.jl index 6514fb0e00..4c369d7038 100644 --- a/src/transform/flux.jl +++ b/src/transform/flux.jl @@ -22,20 +22,20 @@ Convert a Flux Model to Lux Model. ## Example ```jldoctest -julia> import Flux, Metalhead +julia> import Flux julia> using Adapt, Lux, Random -julia> m = Metalhead.ResNet(18); +julia> m = Flux.Chain(Flux.Dense(2 => 3, relu), Flux.Dense(3 => 2)); -julia> m2 = adapt(FromFluxAdaptor(), m.layers); # or FromFluxAdaptor()(m.layers) +julia> m2 = adapt(FromFluxAdaptor(), m); # or FromFluxAdaptor()(m.layers) -julia> x = randn(Float32, 224, 224, 3, 2); +julia> x = randn(Float32, 2, 32); julia> ps, st = Lux.setup(Random.default_rng(), m2); julia> size(first(m2(x, ps, st))) -(1000, 2) +(2, 32) ``` """ @kwdef struct FromFluxAdaptor <: AbstractToLuxAdaptor diff --git a/test/qa_tests.jl b/test/qa_tests.jl index 30d608c140..becefd19ed 100644 --- a/test/qa_tests.jl +++ b/test/qa_tests.jl @@ -22,3 +22,18 @@ end ignore=(:inputsize, :setup, :testmode, :trainmode, :update_state, :AbstractRNG)) === nothing end + +@testitem "doctests: Quality Assurance" tags=[:others] begin + using Documenter + + doctestexpr = quote + using SimpleChains: static + using Flux: Flux + using Metalhead: Metalhead + using DynamicExpressions + using Adapt, Lux, Random, Optimisers, Zygote + end + + DocMeta.setdocmeta!(Lux, :DocTestSetup, doctestexpr; recursive=true) + doctest(Lux; manual=false) +end