Skip to content

Commit

Permalink
Set more sensible default threads count (#196)
Browse files Browse the repository at this point in the history
* Set more sensible default threads count

* Don't care about pre 1.6

* Typo

* add Nothing back into the union
  • Loading branch information
Moelf authored Nov 17, 2023
1 parent 07b3a57 commit 0b4977a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/booster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function Booster(cache::AbstractVector{<:DMatrix};
model_file::AbstractString="",
tree_method::Union{Nothing,AbstractString}=nothing,
validate_parameters::Bool=true,
nthread=Threads.nthreads(),
kw...
)
o = Ref{BoosterHandle}()
Expand All @@ -124,7 +125,7 @@ function Booster(cache::AbstractVector{<:DMatrix};
else
(tree_method=tree_method,)
end
setparams!(b; validate_parameters, tm..., kw...)
setparams!(b; validate_parameters, nthread, tm..., kw...)
b
end
Booster(dm::DMatrix; kw...) = Booster([dm]; kw...)
Expand Down
6 changes: 3 additions & 3 deletions src/dmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,13 @@ function _unsafe_dataiter_reset(ptr::Ptr)
end

function _dmatrix_caching_config_json(;cache_prefix::AbstractString,
nthreads::Union{Integer,Nothing},
nthreads::Union{Integer, Nothing},
missing_value::Float32=NaN32,
)
d = Dict("missing"=>"__NAN_STR__",
"cache_prefix"=>cache_prefix,
)
isnothing(nthreads) || (d["nthreads"] = nthreads)
isnothing(nthreads) || (d["nthreads"] = string(nthreads))
# this is to strip out the special Float32 values to representations it'll accept
nanstr = if isnan(missing_value)
"NaN"
Expand All @@ -603,7 +603,7 @@ end
function DMatrix(itr::DataIterator;
missing_value::Float32=NaN32,
cache_prefix::AbstractString=joinpath(tempdir(),"xgb-cache"),
nthreads::Union{Integer,Nothing}=nothing,
nthreads::Union{Integer, Nothing}=Threads.nthreads(),
kw...
)
o = Ref{DMatrixHandle}()
Expand Down

0 comments on commit 0b4977a

Please sign in to comment.