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

AlphaZero is not precompiling on Ubuntu with Julia version 1.10.8 #223

Open
MendeBadra opened this issue Jan 23, 2025 · 6 comments
Open

Comments

@MendeBadra
Copy link

I followed the instructions on the doc site and on the README file but can't seem to make it work.

$ julia --project -e 'import Pkg; Pkg.instantiate()' --startup-file=no    
The latest version of Julia in the `release` channel is 1.11.3+0.x64.linux.gnu. You currently have `1.11.2+0.x64.linux.gnu` 
installed. Run:                                                                                                             
                                                                                                                            
  juliaup update                                                                                                            
                                                                                                                            
in your terminal shell to install Julia 1.11.3+0.x64.linux.gnu and update the `release` channel to that version.            
┌ Warning: The active manifest file is an older format with no julia version entry. Dependencies may have been resolved with
 a different julia version.                                                                                                 
└ @ /media/razydave/HDD/MendeFolder/New/AlphaZero.jl/Manifest.toml:0                                                        
Precompiling project...                                                                                                     
  ✗ FillArrays                                                                                                              
  ✗ StaticArrays                                                                                                            
  ✗ Compat                                                                                                                  
  ✗ DataStructures                                                                                                          
  ✗ ChainRulesCore                                                                                                          
  ✗ DiffResults                                                                                                             
  ✗ Contour                                                                                                                 
  ✗ ColorSchemes                                                                                                            
  ✗ GeometryBasics                                                                                                          
  ✗ SortingAlgorithms                                                                                                       
  ✗ GPUCompiler                                                                                                             
  ✗ QuadGK                                                                                                                  
  ✗ ChainRules                                                                                                              
  ✗ SpecialFunctions                                                                                                        
  ✗ NNlib                                                                                                                   
  ✗ PlotUtils                                                                                                               
  ✗ StatsFuns                                                                                                               
  ✗ ForwardDiff                                                                                                             
  ✗ PlotThemes                                                                                                              
  ✗ RecipesPipeline                                                                                                         
  ✗ CUDA                                                                                                                    
  ✗ Zygote                                                                                                                  
  ✗ NNlibCUDA                                                       
  ✗ StatsBase                                                                                                               
  ✗ Distributions
  ✗ Plots
  ✗ Flux
  ✗ AlphaZero
  0 dependencies successfully precompiled in 55 seconds. 173 already precompiled.

The following 8 direct dependencies failed to precompile:

Plots 

Failed to precompile Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80] to "/home/razydave/.julia/compiled/v1.11/Plots/jl_vrVo3X".
WARNING: could not import Base.@_pure_meta into StaticArrays
ERROR: LoadError: too many parameters for type AbstractTriangular
Stacktrace:
 [1] top-level scope
   @ ~/.julia/packages/StaticArrays/rKBnO/src/traits.jl:96
 [2] include(mod::Module, _path::String)
   @ Base ./Base.jl:557
 [3] include(x::String)
   @ StaticArrays ~/.julia/packages/StaticArrays/rKBnO/src/StaticArrays.jl:1
 [4] top-level scope
   @ ~/.julia/packages/StaticArrays/rKBnO/src/StaticArrays.jl:104
 [5] include
   @ ./Base.jl:557 [inlined]
 [6] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, lo
ad_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
   @ Base ./loading.jl:2881
 [7] top-level scope
 [7] top-level scope
   @ stdin:6
in expression starting at /home/razydave/.julia/packages/StaticArrays/rKBnO/src/traits.jl:96
in expression starting at /home/razydave/.julia/packages/StaticArrays/rKBnO/src/StaticArrays.jl:1
in expression starting at stdin:6
ERROR: LoadError: Failed to precompile StaticArrays [90137ffa-7385-5640-81b9-e52037218182] to "/home/razydave/.julia/compile
d/v1.11/StaticArrays/jl_xF8e8G".
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool; flags
::Cmd, cacheflags::Base.CacheFlags, reasons::Dict{String, Int64}, loadable_exts::Nothing)
    @ Base ./loading.jl:3174
  [3] (::Base.var"#1110#1111"{Base.PkgId})()
    @ Base ./loading.jl:2579
  [4] mkpidlock(f::Base.var"#1110#1111"{Base.PkgId}, at::String, pid::Int32; kwopts::@Kwargs{stale_age::Int64, wait::Bool})
    @ FileWatching.Pidfile ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/FileWatching/src/pidfile.j
l:95
  [5] #mkpidlock#6
    @ ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/FileWatching/src/pidfile.jl:90 [inlined]
  [6] trymkpidlock(::Function, ::Vararg{Any}; kwargs::@Kwargs{stale_age::Int64})
    @ FileWatching.Pidfile ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/FileWatching/src/pidfile.j
l:116
  [7] #invokelatest#2
    @ ./essentials.jl:1057 [inlined]
  [8] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [9] maybe_cachefile_lock(f::Base.var"#1110#1111"{Base.PkgId}, pkg::Base.PkgId, srcpath::String; stale_age::Int64)
    @ Base ./loading.jl:3698
 [10] maybe_cachefile_lock
    @ ./loading.jl:3695 [inlined]
 [11] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2565
 [12] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2388
 [13] #invoke_in_world#3

The error is truncated here.

@MendeBadra
Copy link
Author

I also followed the instruction on README.md and I got this error:

ulia +1.10 --project -e 'import Pkg; Pkg.instantiate()' --startup-file=no  
                                                                                                                            
    Updating registry at `~/.julia/registries/General.toml`                                                                 
ERROR: Unsatisfiable requirements detected for package GPUCompiler [61eb1bfa]:                                              
 GPUCompiler [61eb1bfa] log:                                                                                                
 ├─possible versions are: 0.1.0-1.1.0 or uninstalled                                                                        
 ├─restricted by compatibility requirements with CUDA [052768ef] to versions: [0.11.1-0.12.9, 0.13.3-0.17.3]                
 │ └─CUDA [052768ef] log:                                                                                                   
 │   ├─possible versions are: 0.1.0-5.6.1 or uninstalled                                                                    
 │   └─restricted to versions 3 by AlphaZero [8ed9eb0b], leaving only versions: 3.0.0-3.13.1                                
 │     └─AlphaZero [8ed9eb0b] log:                                                                                          
 │       ├─possible versions are: 0.5.5 or uninstalled                                                                      
 │       └─AlphaZero [8ed9eb0b] is fixed to version 0.5.5                                                                   
 └─restricted by julia compatibility requirements to versions: 0.22.0-1.1.0 or uninstalled — no versions left               
Stacktrace:                                                                                                                 
  [1] propagate_constraints!(graph::Pkg.Resolve.Graph, sources::Set{Int64}; log_events::Bool)                               
    @ Pkg.Resolve ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Resolve/graphtype.jl:1072  
  [2] propagate_constraints! (repeats 2 times)                                                                              
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Resolve/graphtype.jl:1008 [inlined]    
  [3] simplify_graph!(graph::Pkg.Resolve.Graph, sources::Set{Int64}; clean_graph::Bool)                                     
    @ Pkg.Resolve ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Resolve/graphtype.jl:1533  
  [4] simplify_graph! (repeats 2 times)                                                                                     
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Resolve/graphtype.jl:1532 [inlined]    
  [5] resolve_versions!(env::Pkg.Types.EnvCache, registries::Vector{Pkg.Registry.RegistryInstance}, pkgs::Vector{Pkg.Types.PackageSpec}, julia_version::VersionNumber, installed_only::Bool)
    @ Pkg.Operations ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Operations.jl:414       
  [6] up(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}, level::Pkg.Types.UpgradeLevel; skip_writing_project::Bool, preserve::Nothing)
    @ Pkg.Operations ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Operations.jl:1553      
  [7] up                                                                                                                    
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/Operations.jl:1535 [inlined]           
  [8] up(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; level::Pkg.Types.UpgradeLevel, mode::Pkg.Types.PackageMode, preserve::Nothing, update_registry::Bool, skip_writing_project::Bool, kwargs::@Kwargs{})                    
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:351                                                                                         [9] up                                        
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:326 [inlined]                                                                                     
 [10] up                                       
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:164 [inlined]                                                                                     
 [11] instantiate(ctx::Pkg.Types.Context; manifest::Nothing, update_registry::Bool, verbose::Bool, platform::Base.BinaryPlatforms.Platform, allow_build::Bool, allow_autoprecomp::Bool, kwargs
::@Kwargs{})
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1132                                                                                      
 [12] instantiate                              
    @ ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1108 [inlined]                                                                                    
 [13] instantiate(; kwargs::@Kwargs{})                                                         
    @ Pkg.API ~/.julia/juliaup/julia-1.10.8+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1107        
 [14] top-level scope
    @ none:1

I got this dependency error several times now.

@jonathan-laurent
Copy link
Owner

I never tested AlphaZero.jl on Julia 1.10 indeed and so the instructions might need updating. What's likely happening here is that some compat bounds specified in the project file are not compatible with 1.10 anymore. Could you try and install the latest versions of all dependencies and see if it works? If it does and the test suite passes, I would be interested in knowing what libraries need updating.

@MendeBadra
Copy link
Author

I believe Knet package needs updating. I have created a new empty environment and tried installing packages to it.

(AlphaZero.jl) pkg> st
Status `/media/razydave/HDD/MendeFolder/AlphaZero.jl/Project.toml` (empty project)

(AlphaZero.jl) pkg> add ArgParse CUDA Colors CommonRLInterface Crayons DataStructures Distributed Distributions Documenter ExprTools Flux Format JSON3 Knet LinearAlgebra LoggingExtras Plots ProgressMeter Random Requires Serialization Setfield StaticArrays Statistics ThreadPools Zygote

   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Knet [1902f260]:
 Knet [1902f260] log:
 ├─possible versions are: 1.0.0-1.4.10 or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions: 1.0.0-1.4.10
 ├─restricted by compatibility requirements with CuArrays [3a865a2d] to versions: [1.0.0-1.2.3, 1.3.7-1.4.10] or uninstalled, leaving only versions: [1.0.0-1.2.3, 1.3.7-1.4.10]
 │ └─CuArrays [3a865a2d] log:
 │   ├─possible versions are: 0.2.1-2.2.2 or uninstalled
 │   ├─restricted by compatibility requirements with Statistics [10745b16] to versions: 0.2.1-1.7.3 or uninstalled
 │   │ └─Statistics [10745b16] log:
 │   │   ├─possible versions are: 1.10.0 or uninstalled
 │   │   └─restricted to versions * by an explicit requirement, leaving only versions: 1.10.0
 │   └─restricted by julia compatibility requirements to versions: uninstalled
 ├─restricted by compatibility requirements with CUDAapi [3895d2a7] to versions: 1.3.7-1.4.10 or uninstalled, leaving only versions: 1.3.7-1.4.10
 │ └─CUDAapi [3895d2a7] log:
 │   ├─possible versions are: 0.5.0-4.0.0 or uninstalled
 │   └─restricted by julia compatibility requirements to versions: uninstalled
 └─restricted by compatibility requirements with CUDA [052768ef] to versions: 1.0.0-1.3.6 or uninstalled — no versions left
   └─CUDA [052768ef] log:
     ├─possible versions are: 0.1.0-5.6.1 or uninstalled
     ├─restricted to versions * by an explicit requirement, leaving only versions: 0.1.0-5.6.1
     ├─restricted by compatibility requirements with Statistics [10745b16] to versions: [2.3.0, 2.5.0-5.6.1] or uninstalled, leaving only versions: [2.3.0, 2.5.0-5.6.1]
     │ └─Statistics [10745b16] log: see above
     └─restricted by compatibility requirements with GPUCompiler [61eb1bfa] to versions: 5.0.0-5.6.1 or uninstalled, leaving only versions: 5.0.0-5.6.1
       └─GPUCompiler [61eb1bfa] log:
         ├─possible versions are: 0.1.0-1.1.0 or uninstalled
         ├─restricted by compatibility requirements with CUDA [052768ef] to versions: [0.3.0-0.7.3, 0.8.1-0.10.0, 0.11.1-0.12.9, 0.13.3-0.21.4, 0.24.0-1.1.0]
         │ └─CUDA [052768ef] log: see above
         └─restricted by julia compatibility requirements to versions: 0.22.0-1.1.0 or uninstalled, leaving only versions: 0.24.0-1.1.0

(AlphaZero.jl) pkg> 

Without the Knet package installed, the precompilation happens without any problems.

@jonathan-laurent
Copy link
Owner

Interesting, thanks. It would be worth looking at Knet's issues or creating a new one to see if the Knet compat bounds can simply be lifted without consequences or if there is a deep reason for those bounds.

Also, AlphaZero.jl supports both a Flux and a Knet backend. If you use the Flux backend, it should be possible to get rid of the Knet imports altogether. Now that Pkg supports preferences and weak dependencies, it should even be possible to make both Knet and Flux weak dependencies, which are selected based on user preferences. I would take a PR implementing this solution.

@MendeBadra
Copy link
Author

Hi, I will be looking to take a stab at this. However, when I said it precompiled fine, I used latest version of Flux with some Functors.jl tweak. I can run 'collect-four' example and self play section but after finishing the self play following error occurred. I guess that the latest version of Flux.jl now took upon "explicit style" where you don't pass params as argument to the Flux.update! function.

julia> resume!(session)                                                                        
Starting iteration 1                                                                           
                                                                                               
  Starting self-play                                                                           
                                                                                               
        Progress: 100%|████████████████████████████████████████████████████| Time: 1:12:40     
                                                                                               
    Generating 28 samples per second on average                                                
    Average exploration depth: 4.4                                                             
    MCTS memory footprint per worker: 11.80MB                                                  
    Experience buffer size: 121,012 (91,154 distinct boards)                                   
                                                                                               
  Starting learning                                                                            
                                                                                               
    Optimizing the loss                                                                        
                                                                                               
         Loss       Lv       Lp     Lreg     Linv       Hp    Hpnet                            
       2.3085   1.1895   0.8373   0.1638   0.1177   1.3078   1.5026 
ERROR: Invalid input to `update!`.                                                                                                                                                            
 `update!(state, model, grad)` needs `state = Flux.setup(opt, model)`.                                                                                                                        
                                                                                                                                                                                              
Stacktrace:                                                                                                                                                                                   
  [1] error(s::String)                                                                                                                                                                        
    @ Base ./error.jl:35                                                                                                                                                                      
  [2] update!(opt::Optimisers.Adam, model::Zygote.Params{Zygote.Buffer{Any, Vector{Any}}}, grad::Zygote.Grads)                                                                                
    @ Flux ~/.julia/packages/Flux/BkG8S/src/deprecations.jl:134                                                                                                                               
  [3] train!(callback::AlphaZero.var"#119#121"{Vector{…}}, nn::ResNet, opt::AlphaZero.Network.Adam, loss::Function, data::Base.Iterators.Take{Base.Iterators.Stateful{…}}, n::Int64)          
    @ AlphaZero.FluxLib /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/networks/flux.jl:84                                                                                                  
  [4] batch_updates!(tr::AlphaZero.Trainer, n::Int64)                                                                                                                                         
    @ AlphaZero /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/learning.jl:132                                                                                                              
  [5] macro expansion                                                                                                                                                                         
    @ ./timing.jl:581 [inlined]                                                                                                                                                               
  [6] learning_step!(env::Env{AlphaZero.Examples.ConnectFour.GameSpec, ResNet, @NamedTuple{…}}, handler::Session{Env{…}})                                                                     
    @ AlphaZero /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/training.jl:224                                                                                                              
  [7] macro expansion                                                                                                                                                                         
    @ ./timing.jl:581 [inlined]                                                                                                                                                               
  [8] macro expansion                                                                                                                                                                         
    @ /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/report.jl:267 [inlined]                                                                                                                
  [9] train!(env::Env{AlphaZero.Examples.ConnectFour.GameSpec, ResNet, @NamedTuple{…}}, handler::Session{Env{…}})                                                                             
    @ AlphaZero /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/training.jl:327                                                                                                              
 [10] resume!(session::Session{Env{AlphaZero.Examples.ConnectFour.GameSpec, ResNet, @NamedTuple{board::StaticArraysCore.SMatrix{7, 6, UInt8, 42}, curplayer::UInt8}}})                        
    @ AlphaZero.UserInterface /media/razydave/HDD/MendeFolder/AlphaZero.jl/src/ui/session.jl:316                                                                                              
 [11] top-level scope                                                                                                                                                                         
    @ REPL[21]:1                                                                                                                                                                              
Some type information was truncated. Use `show(err)` to see complete types.

As far as I understand, the code in src/networks/flux.jl line:83 need to be rewritten in order to be compliant with Flux 0.16.2?

I don't really have much experience in writing structs with julia so, I don't quite understand what model should be in the function state = Flux.setup(opt, model). In the function in line 83, does nn::FluxNetwork count as model? However, when I tried state = Flux.setup(optimiser, nn) it returned an error also. And when I make these changes, I had to run the self-play phase again and again and had to wait 1 or 2 hours, how can I skip this phase?

@jonathan-laurent
Copy link
Owner

Thanks for looking into this. I'd be happy to accept a PR if you manage to update the Flux backend.

You can look at the test suite to run a very quick training session on a toy environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants