如何在 OSX 上使用多线程安装 XGBoost

2024-05-07

我正在尝试按照指南在我的 mac (osx 10.12.1) 上安装 xgboosthere http://xgboost.readthedocs.io/en/latest/build.html#building-on-osx但我遇到了一些问题。


Step1

获取带有 openmp 支持的 gcc-6.x.xbrew install gcc --without-multilib

Terminal

Ben$ brew install gcc --without-multilib
Error: gcc-5.3.0 already installed
To install this version, first `brew unlink gcc`

Ben$ brew unlink gcc
Unlinking /usr/local/Cellar/gcc/5.3.0... 1288 symlinks removed

Ben$ brew install gcc --without-multilib
[26 minutes later]
==> Summary
????  /usr/local/Cellar/gcc/6.2.0: 1,358 files, 238.3M, built in 26 minutes 20 seconds

Step2

克隆存储库git clone --recursive https://github.com/dmlc/xgboost

Terminal

Ben$ git clone --recursive https://github.com/dmlc/xgboost
Cloning into 'xgboost'...
remote: Counting objects: 18754, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 18754 (delta 1), reused 0 (delta 0), pack-reused 18733
Receiving objects: 100% (18754/18754), 6.23 MiB | 3.74 MiB/s, done.
Resolving deltas: 100% (11347/11347), done.
Checking connectivity... done.
Submodule 'dmlc-core' (https://github.com/dmlc/dmlc-core) registered for path 'dmlc-core'
Submodule 'rabit' (https://github.com/dmlc/rabit) registered for path 'rabit'
Cloning into '/Users/Ben/xgboost/dmlc-core'...
Cloning into '/Users/Ben/xgboost/rabit'...
Submodule path 'dmlc-core': checked out 'f35f14f30835af238257b979cc1fac3e41ff3291'
Submodule path 'rabit': checked out 'a9a2a69dc1144180a43f7d2d1097264482be7817'

Step3

使用以下命令构建cd xgboost; cp make/config.mk ./config.mk; make -j4

注意:如果您使用 OSX El Capitan,brew 将安装 gcc 最新版本 gcc-6。所以你可能需要修改Makefile#L46并将gcc-5更改为gcc-6。之后,在 make/config.mk 中将 gcc-5/g++-5 更改为 gcc-6/g++-6,然后使用以下命令进行构建

嗯。不完全确定在这里做什么。我看到里面有一个名为“Makefile”的文件xgboost/。在里面我看到很多我不明白的东西,但这些线看起来相关

生成文件(片段)

# on Mac OS X, force brew gcc-6, since the Xcode c++ fails anyway
# it is useful for pip install compiling-on-the-fly
OS := $(shell uname)
ifeq ($(OS), Darwin)
export CC = $(if $(shell which gcc-6),gcc-6,$(if $(shell which gcc-mp-6), gcc-mp-6, clang))
export CXX = $(if $(shell which g++-6),g++-6,$(if $(shell which g++-mp-6),g++-mp-6, clang++))
endif

忽略这一点并继续前进......

Terminal

Ben$ cd xgboost; cp make/config.mk ./config.mk; make -j4
[Tons of log output. Appears to finish succesfully]
...
g++-6 -std=c++0x -Wall -O3 -msse2  -Wno-unknown-pragmas -funroll-loops -Iinclude   -Idmlc-core/include -Irabit/include -fPIC -fopenmp -shared -o lib/libxgboost.so build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a -pthread -lm  -fopenmp 

第四步(说明here http://xgboost.readthedocs.io/en/latest/build.html#r-package-installation?)

如果您想使用最新的 xgboost 版本并且已经 编译xgboost,使用library(devtools); install('xgboost/R-package')手动安装 xgboost 软件包(相应地将路径更改为 你编译 xgboost 的地方)。

新 R 会话

library(devtools)
install("/Users/Ben/xgboost/R-package")

Installing xgboost
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  '/Users/Ben/xgboost/R-package' --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library' --install-tests 

* installing *source* package ‘xgboost’ ...
** libs
g++-5 -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -I../..//dmlc-core/include -I../..//rabit/include -I../../ -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=1 -DDMLC_DISABLE_STDIN=1 -DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1 -DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_ -I/usr/local/opt/llvm/include   -fopenmp  -fPIC  -Wall -mtune=core2 -g -O2 -c xgboost_R.cc -o xgboost_R.o
make: g++-5: No such file or directory
make: *** [xgboost_R.o] Error 1
ERROR: compilation failed for package ‘xgboost’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/xgboost’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/xgboost’
Error: Command failed (1)

失败:(我哪里出错了?


更新的解决方案

截至 2019 年 3 月,R 版本 3.5.3,xgboost 版本 0.82.0.1,自从我的旧答案以来,事情已经发生了变化。以下步骤基于安装指南在这里 https://xgboost.readthedocs.io/en/latest/build.html,但略有不同。

  1. brew install cmake or brew upgrade cmake (cmake --version对我来说显示 3.14.0)
  2. brew install gcc or brew upgrade gcc(注意安装的 gcc 版本。它应该位于/usr/local/bin。我得到 gcc 8.3.0 (gcc-8 --version))
  3. cd some/unimportant/directory
  4. git clone --recursive https://github.com/dmlc/xgboost
  5. cd xgboost/
  6. mkdir build
  7. cd build
  8. CC=gcc-8 CXX=g++-8 cmake .. -DR_LIB=ON
  9. make -j4
  10. sudo make install

现在重新启动/刷新 RStudio,它应该已安装

在 R 中测试

set.seed(222)
N <- 2*10^5
p <- 350
x <- matrix(rnorm(N  * p), ncol = p)
y <- rnorm(N)

system.time(mymodel <- xgboost(
  # nthread = 4,
  data = x,
  label = y, 
  nrounds = 5, 
  objective = "reg:linear", 
  tree_method = "exact",
  max_depth = 10,
  min_child_weight = 1, 
  eta = 1, 
  subsample = 0.66, 
  colsample_bytree = 0.33
))

# Tested on 2018 MPB, xgboost version 0.82.0.1, multi-threaded version
# nthread = default:   7.4 seconds (elapsed)
# nthread = 1:        24.0 seconds (elapsed)
# nthread = 2:        13.7 seconds (elapsed)
# nthread = 4:         7.5 seconds (elapsed)

旧答案

令人惊奇的是,在 StackOverflow 上写下你的问题通常会直接引导你找到答案。花了几个小时后,我发现我需要更改这三行~/.R/Makevars

CC=gcc-5
CXX=g++-5
CXX1X = g++-5

to

CC=gcc-6
CXX=g++-6
CXX1X = g++-6

另外,我最终从“drat”存储库安装了 xgboost

install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc")
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 OSX 上使用多线程安装 XGBoost 的相关文章

  • 尽管浮点数相同,但它们并不相等? [复制]

    这个问题在这里已经有答案了 下面的程序输出This No is not same 当两个数字相同时为什么会这样做 void main float f 2 7 if f 2 7 printf This No is same else prin
  • C语言中没有循环可以打印数组吗?

    例如 在Python中 如果我们将一个列表作为数组 它会直接用一行代码打印整个数组 有什么办法可以用C语言实现同样的事情吗 简短回答 No 对表格上几乎所有问题的简短回答 用 C 语言做 X 工作能像用 Python 一样简单吗 No 长答
  • 多线程 - 比单线程慢

    当我使用多个线程而不是单线程运行程序时 它会变慢 不是应该更快吗 该程序应该遍历从起始目录开始的所有目录 并查找并打印所有名为 X 的文件 代码如下 while done pthread mutex lock lock if list is
  • Swift 上的 USB 连接委托

    Swift 中是否有一个代表可以让我的班级知道何时通过计算机的 USB 插入新设备 我想知道我的程序何时可以使用新设备 Eric Aya 的答案已经相当不错了 但这里有一个 Swift 3 的改编 我把大部分丑陋的东西包裹在一个USBWat
  • 根据 Active Directory 策略检查密码[重复]

    这个问题在这里已经有答案了 我有一个允许用户更改其 AD 密码的前端 有没有办法获取特定用户及其属性 长度 复杂性 的密码策略 例如细粒度 有没有办法根据此特定策略检查字符串 xyz121 编辑 我不想检查活动目录中存储的当前密码 我想检查
  • 解释 survreg 中的威布尔参数

    我正在尝试使用从 R 中的 survreg 估计的参数生成逆威布尔分布 我的意思是 对于给定的概率 这将是在 MS Excel 中实现的小型模拟模型中的随机数 返回使用我的参数预计出现故障 的时间 我理解逆威布尔分布的一般形式是 X b l
  • 为什么 rand() 总是返回相同的值? [复制]

    这个问题在这里已经有答案了 可能的重复 在C中生成随机数 https stackoverflow com questions 3067364 generating random numbers in c 使用 rand 生成随机数 http
  • 重定向 std::cout

    我需要一个类 在其对象的生命周期内将一个 ostream 重定向到另一个 ostream 经过一番修补后 我想出了这个 include
  • 如果我重新分配并且新大小为 0,会发生什么情况。这与释放等效吗?

    给出以下代码 int a NULL a calloc 1 sizeof a printf d n a a realloc a 0 printf d n a return 0 它返回 4078904 0 这个 realloc 相当于 free
  • 如果项目包含多个文件夹,如何使用 Add-Migration

    我想Add Migration使用我的 DbContext 但出现错误 The term add migration is not recognized as the name of a cmdlet function script fil
  • Code::Blocks 中的调试似乎不起作用 - 缺少调试符号

    我正在尝试在 Code Blocks 中调试程序 我跟着本指南 http wiki codeblocks org index php title Debugging with Code Blocks and 这个短视频 http www y
  • 如何阻止 Control-I 在 CoreWindow 范围内的 UWP 文本框中插入选项卡?

    当我在 UWP 应用程序中有一个 TextBox 时 对我来说 奇怪的行为 在 Windows 10 中创建通用的空白应用程序 UWP 应用程序 使用以下代码将文本框添加到默认网格
  • 模板定义中的友元函数

    我的问题有点相关this https stackoverflow com questions 1297609 overloading friend operator for template class one 我想重载某些类的运算符 te
  • 如何在 SQLite 中检查数据库是否存在 C#

    我目前正在用 C 编写一个应用程序 并使用 sqlite 作为嵌入式数据库 我的应用程序在启动时创建一个新数据库 但如何让它检查数据库是否存在 如果它确实存在 我如何让它使用它 如果不存在如何创建一个新数据库 这是我到目前为止所拥有的 pr
  • 如何使 WinForms UserControl 填充其容器的大小

    我正在尝试创建一个多布局主屏幕应用程序 我在顶部有一些按钮链接到应用程序的主要部分 例如模型中每个实体的管理窗口 单击这些按钮中的任何一个都会在面板中显示关联的用户控件 面板包含用户控件 而用户控件又包含用户界面 WinForms User
  • C# 模式匹配

    我对 C 有点陌生 我正在寻找一个字符串匹配模式来执行以下操作 我有一个像这样的字符串 该书将在 唐宁街 11 号接待处 并将由主要医疗保健人员参加 我需要创建一个 span 标签来使用 startIndex 和 length 突出显示一些
  • Web API 2.0 使用 pascalcase 模型接收驼峰式命名的 JSON 数据

    我正在尝试对我的 Web API 进行 PUT 调用 我在 WebApiConfig cs 中设置了以下内容 以处理以驼峰形式将数据发送回我的 Web 项目 config Formatters JsonFormatter Serialize
  • 使用 SparkR 1.5 从 RStudio 中的 hdfs 读取大文件(纯文本、xml、json、csv)的选项

    我是 Spark 新手 想知道除了下面的选项之外是否还有其他选项可以使用 SparkR 从 RStudio 读取存储在 hdfs 中的数据 或者我是否正确使用它们 数据可以是任何类型 纯文本 csv json xml 或任何包含关系表的数据
  • 如何创建实体集或模型而不在数据库中创建相应的表 - 实体框架

    我的 sqlserver 数据库中有一个存储过程 它返回多个结果集 我正在使用 msdn 中的以下链接从实体框架中的 SP 读取多个结果集 https msdn microsoft com en us library jj691402 v
  • 有没有办法在 C# 中仅通过文件名查找文件?

    我们现在使用绝对路径或相对路径在 C 应用程序中查找文件 如果文件位于当前工作目录下或 路径 之一下 有没有办法仅通过名称查找文件 使用绝对路径不好 使用相对路径也不够好 因为我们可能通过重命名或移动项目文件夹来更改项目结构 如果我们的代码

随机推荐