-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from Evovest/perf-depth
Perf depth
- Loading branch information
Showing
17 changed files
with
309 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "EvoTrees" | ||
uuid = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5" | ||
authors = ["jeremiedb <[email protected]>"] | ||
version = "0.15.1" | ||
version = "0.15.2" | ||
|
||
[deps] | ||
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using Statistics | ||
using StatsBase:sample | ||
using Base.Threads:@threads | ||
using BenchmarkTools | ||
using Revise | ||
using EvoTrees | ||
using Profile | ||
|
||
nobs = Int(1e6) | ||
num_feat = Int(100) | ||
nrounds = 200 | ||
nthread = Base.Threads.nthreads() | ||
x_train = rand(nobs, num_feat) | ||
y_train = rand(size(x_train, 1)) | ||
|
||
config = EvoTreeRegressor(; | ||
loss=:mse, | ||
nrounds=200, | ||
lambda=0.0, | ||
gamma=0.0, | ||
eta=0.05, | ||
max_depth=10, | ||
min_weight=1.0, | ||
rowsample=0.5, | ||
colsample=0.5, | ||
nbins=64, | ||
tree_type="binary", | ||
rng=123 | ||
) | ||
|
||
################################ | ||
# high-level | ||
################################ | ||
_device = EvoTrees.GPU | ||
@time EvoTrees.fit_evotree(config; x_train, y_train, device = "gpu") | ||
|
||
@time m, cache = EvoTrees.init(config, x_train, y_train); | ||
@time EvoTrees.grow_evotree!(m, cache, config) | ||
@btime EvoTrees.grow_evotree!(m, cache, config) | ||
|
||
Profile.clear() | ||
# Profile.init() | ||
Profile.init(n = 10^5, delay = 0.01) | ||
# @profile m, cache = EvoTrees.init(config, x_train, y_train); | ||
@profile EvoTrees.grow_evotree!(m, cache, config) | ||
Profile.print() | ||
|
||
################################ | ||
# mid-level | ||
################################ | ||
@time m, cache = EvoTrees.init(config, x_train, y_train); | ||
@time EvoTrees.grow_evotree!(m, cache, config) | ||
# compute gradients | ||
@time m, cache = EvoTrees.init(config, x_train, y_train); | ||
@time EvoTrees.update_grads!(cache.∇, cache.pred, cache.y, config) | ||
# subsample rows | ||
@time cache.nodes[1].is = EvoTrees.subsample(cache.is_in, cache.is_out, cache.mask, config.rowsample, config.rng) | ||
# subsample cols | ||
EvoTrees.sample!(config.rng, cache.js_, cache.js, replace=false, ordered=true) | ||
L = EvoTrees._get_struct_loss(m) | ||
# instantiate a tree then grow it | ||
tree = EvoTrees.Tree{L,1}(config.max_depth) | ||
grow! = config.tree_type == "oblivious" ? EvoTrees.grow_otree! : EvoTrees.grow_tree! | ||
@time EvoTrees.grow_tree!( | ||
tree, | ||
cache.nodes, | ||
config, | ||
cache.∇, | ||
cache.edges, | ||
cache.js, | ||
cache.out, | ||
cache.left, | ||
cache.right, | ||
cache.x_bin, | ||
cache.feattypes, | ||
cache.monotone_constraints | ||
) | ||
|
||
using ProfileView | ||
ProfileView.@profview EvoTrees.grow_tree!( | ||
tree, | ||
cache.nodes, | ||
config, | ||
cache.∇, | ||
cache.edges, | ||
cache.js, | ||
cache.out, | ||
cache.left, | ||
cache.right, | ||
cache.x_bin, | ||
cache.feattypes, | ||
cache.monotone_constraints | ||
) | ||
|
||
################################ | ||
# end mid-level | ||
################################ | ||
|
||
|
||
@time m_evo = grow_tree!(params_evo; x_train, y_train, device, print_every_n=100); | ||
|
||
@info "train - no eval" | ||
@time m_evo = fit_evotree(params_evo; x_train, y_train, device, print_every_n=100); | ||
|
||
|
||
offset = 0 | ||
feat = 15 | ||
cond_bin = 32 | ||
@time l, r = split_set_threads!(out, left, right, 𝑖, X_bin, feat, cond_bin, offset, 2^14); | ||
@btime split_set_threads!($out, $left, $right, $𝑖, $X_bin, $feat, $cond_bin, $offset, 2^14); | ||
@code_warntype split_set_1!(left, right, 𝑖, X_bin, feat, cond_bin, offset) | ||
|
||
offset = 0 | ||
feat = 15 | ||
cond_bin = 32 | ||
lid1, rid1 = split_set_threads!(out, left, right, 𝑖, X_bin, feat, cond_bin, offset) | ||
offset = 0 | ||
feat = 14 | ||
cond_bin = 12 | ||
lid2, rid2 = split_set_threads!(out, left, right, lid1, X_bin, feat, cond_bin, offset) | ||
offset = + length(lid1) | ||
feat = 14 | ||
cond_bin = 12 | ||
lid3, rid3 = split_set_threads!(out, left, right, rid1, X_bin, feat, cond_bin, offset) | ||
|
||
lid1_ = deepcopy(lid1) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using EvoTrees | ||
|
||
module LearnAPI | ||
|
||
abstract type Config end | ||
abstract type Learner end | ||
abstract type Model end | ||
|
||
function fit(config::Config; kwargs...) | ||
return nothing | ||
end | ||
function fit(config::Config, data; kwargs...) | ||
return nothing | ||
end | ||
function init(config::Config, data; kwargs...) | ||
return nothing | ||
end | ||
# function fit!(learner::Learner) | ||
# return nothing | ||
# end | ||
|
||
function predict(model::Model, x) | ||
return x | ||
end | ||
function predict!(p, model::Model, x) | ||
return nothing | ||
end | ||
|
||
function isiterative(m) end | ||
|
||
end #module | ||
|
||
struct EvoLearner | ||
params | ||
end | ||
|
||
# 1 args fit: all needed supplemental info passed through kwargs: risk of having fragmentation of naming convention, hard to follow | ||
m = LearnAPI.fit(config::Config; kwargs) | ||
m = LearnAPI.fit(config::EvoTrees.EvoTypes; x_train=xt, y_train=yt) | ||
m = LearnAPI.fit(config::EvoTrees.EvoTypes; x_train=xt, y_train=yt, x_eval=xe, y_eval=ye) | ||
|
||
# 2 args fit: forces the notion of input data on which training is performed. May facilitates dispatch/specialisation on various supported data typees | ||
m = LearnAPI.fit(config::Config, data; kwargs) | ||
m = LearnAPI.fit(config::EvoTrees.EvoTypes, (x_train, y_train)) | ||
m = LearnAPI.fit(config::EvoTrees.EvoTypes, (x_train, y_train); x_eval=xe, y_eval=ye) | ||
m = LearnAPI.fit(config::EvoTrees.EvoTypes, df::DataFrame) | ||
|
||
# Iterative models | ||
import .LearnAPI: isiterative | ||
LearnAPI.isiterative(m::EvoTree) = true | ||
|
||
# 2 args model initialization | ||
# Here a EvoTreeLearner is returned: a comprehensive struct that includes the config, the model, and cache/state | ||
m = LearnAPI.init(config::Config, data::DataFrame; kwargs) | ||
m = LearnAPI.init(config::EvoTrees.EvoTypes, df::DataFrame; x_eval=xe, y_eval=ye) | ||
|
||
LearnAPI.fit!(m::EvoTree) | ||
LearnAPI.fit!(m::EvoTree, data) | ||
|
||
# LearnAPI.fit!(m, config::EvoTrees.EvoTypes; kwargs) | ||
LearnAPI.predict(m::EvoTrees.EvoTypes, x) | ||
|
||
config = EvoTreeRegressor() | ||
# m, cache = LearnAPI.init() | ||
|
||
# should be possible to have model that specify feature treatment upfront at the Config level? | ||
# Or rather have those passed at the fitted level? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
897ffca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
897ffca
There was a problem hiding this comment.
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/88979
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: