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

Stack cache and acceleration #767

Closed
wants to merge 6 commits into from
Closed

Conversation

olivierlabayle
Copy link
Collaborator

@olivierlabayle olivierlabayle commented May 12, 2022

Following up on: #759

This adds two fields to the Stack to enable/disable submachines caching and the network's acceleration:

  • cache: Whether submachines will be caching data or not.
  • acceleration: Acceleration mode of the learning network.

added by @ablaom: This PR allows one to train a learning network node using multithreading, as in fit!(node, acceleration=CPUThreads()).

@olivierlabayle olivierlabayle marked this pull request as draft May 12, 2022 16:53
@olivierlabayle olivierlabayle mentioned this pull request May 12, 2022
4 tasks
@codecov-commenter
Copy link

codecov-commenter commented May 15, 2022

Codecov Report

Merging #767 (dd2478b) into dev (4d1ed14) will increase coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #767      +/-   ##
==========================================
+ Coverage   85.85%   85.96%   +0.11%     
==========================================
  Files          36       36              
  Lines        3451     3471      +20     
==========================================
+ Hits         2963     2984      +21     
+ Misses        488      487       -1     
Impacted Files Coverage Δ
src/composition/learning_networks/machines.jl 91.95% <100.00%> (ø)
src/composition/learning_networks/nodes.jl 71.24% <100.00%> (+1.37%) ⬆️
src/composition/models/stacking.jl 94.66% <100.00%> (+0.14%) ⬆️
src/resampling.jl 91.60% <0.00%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d1ed14...dd2478b. Read the comment docs.

@ablaom
Copy link
Member

ablaom commented May 16, 2022

@olivierlabayle This is great, thank you.

Since this adds CPUThreads as an option for training any learning network node, it's probably prudent to add some more tests for this. I would like to see that the CPUThreads analogue of these tests also a pass:

## EXTRA TESTS FOR TRAINING SEQUENCE

Note that @test_mach_sequence already provides a list of multiple acceptable training sequences, to handle case of asynchronous training. So they "should" pass.

Probably we can just wrap these tests in an @test_accelerated block, as we have elsewhere, but exclude CPUProcesses.

I don't think we need to check both options give same results. You already do this for Stack. What do you think?

Copy link
Member

@ablaom ablaom left a comment

Choose a reason for hiding this comment

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

My comments and test suggestions not withstanding, I'm already happy with this "draft" PR.

@olivierlabayle
Copy link
Collaborator Author

@ablaom Thank you for this early review. I had indeed only marked this as a draft because I wanted to be a bit more thorough about the testing of the new multithreading feature.

I will need to have a proper look at the @test_accelerated and @test_mach_sequence macros that you suggest. If the models in the sequence are completely deterministic I think I should make sure the results are concordent at least to some extent.

@olivierlabayle
Copy link
Collaborator Author

I have incremented the testset you suggested with CPUThreads() as a resource for the custom learning network. Unfortunately, I couldn't make use of the @testset_accelerated macro with the exclude keyword. Besides, what is the advantage over the classic @testset for accel in accelerations end? (This is what I have used)

@olivierlabayle olivierlabayle marked this pull request as ready for review May 19, 2022 00:17
@ablaom
Copy link
Member

ablaom commented May 19, 2022

Besides, what is the advantage over the classic @testset for accel in accelerations end? (This is what I have used)

👍🏾 Probably that macro was written before that syntax was available?? I didn't know about it myself.

Copy link
Member

@ablaom ablaom left a comment

Choose a reason for hiding this comment

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

I'm happy with this, @olivierlabayle

I'm going to recommend that @OkonSamuel also reviews this, as he is more familiar with multithreading issues. He is pretty busy, but I think it's worth getting an expert to look over this.

@ablaom ablaom requested a review from OkonSamuel May 19, 2022 05:24
@ablaom
Copy link
Member

ablaom commented May 30, 2022

Following suggestion of @OkonSamuel we should test multi-threading works for a variety of component models. I am working on some enhancements of MLJTestIntegration.jl to automate such a test, and will check back here when that is ready.

@olivierlabayle
Copy link
Collaborator Author

Following suggestion of @OkonSamuel we should test multi-threading works for a variety of component models. I am working on some enhancements of MLJTestIntegration.jl to automate such a test, and will check back here when that is ready.

Great idea, I'll be waiting then!

@@ -54,7 +58,7 @@ const Stack{modelnames, inp_scitype, tg_scitype} =
ProbabilisticStack{modelnames, inp_scitype, tg_scitype}}

"""
Stack(;metalearner=nothing, resampling=CV(), name1=model1, name2=model2, ...)
Stack(;metalearner=nothing, resampling=CV(), name1=model1, cache=true, acceleration=CPU1(), name2=model2, ...)
Copy link
Member

Choose a reason for hiding this comment

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

This doc-string got a little mangled, with the model1 and model2 being separated. As this has grown passed the length of the line, how about we not list all the options here:

Suggested change
Stack(;metalearner=nothing, resampling=CV(), name1=model1, cache=true, acceleration=CPU1(), name2=model2, ...)
Stack(;metalearner=nothing, name1=model1, name2=model2, keyword_options...)

ablaom added a commit to JuliaAI/MLJTestIntegration.jl that referenced this pull request Jun 9, 2022
add stack_evaluation; needs JuliaAI/MLJBase.jl#767

rm target_scitype arg from stack_evaluation

put stack test into test()

oops

fix some bugs

separate out :accelerated_stack_evaluation test

more tweaks

oops
@ablaom
Copy link
Member

ablaom commented Jun 9, 2022

@olivierlabayle I needed to rebase this and am closing in favour of #785. The rebase includes a fix for the doc string marked above.

@ablaom ablaom closed this Jun 9, 2022
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

Successfully merging this pull request may close these issues.

3 participants