简体   繁体   English

需要减少 R 中神经网络 package 使用的线程

[英]Need to reduce threads used by neuralnet package in R

I have a large linux server running rstudio (R version 4.0.5) that I share with 6 other people.我有一个运行 rstudio(R 版本 4.0.5)的大型 linux 服务器,我与其他 6 人共享。 It has 56 cores.它有 56 个内核。 By design, no programmer is supposed to use more than 8 cores on jobs that will take a long time.按照设计,任何程序员都不应该在需要很长时间的工作上使用超过 8 个内核。 I am using neuralnet, and it completely consumes all available cores.我正在使用神经网络,它完全消耗了所有可用的内核。 I need to be able to lock this down to 8 cores.我需要能够将其锁定为 8 个内核。

packages like xgboost have the ability to limit threads.像 xgboost 这样的包具有限制线程的能力。 I have not been able to find anything similar for the package neuralnet.我无法为 package 神经网络找到类似的东西。 Is there an alternate way of thread limiting or does the package neuralnet have a way of limiting threads that I am not aware of?是否有另一种线程限制方法,或者 package 神经网络是否有一种我不知道的限制线程的方法?

here is as script you can use, I did not write this script, I found it on this post: Error in plot.nn: weights were not calculated I have altered the script so that it will converge这是您可以使用的脚本,我没有编写此脚本,我在这篇文章中找到了它: plot.nn 中的错误:未计算权重我已经更改了脚本,以便它会收敛


install.packages("tidyverse", dependencies = TRUE)
install.packages("neuralnet", dependencies = TRUE)
install.packages("plyr", dependencies = TRUE)

library(tidyverse)
library(neuralnet)
library(plyr)


CreditCardnn <- read.csv("https://raw.githubusercontent.com/621-Group2/Final-Project/master/UCI_Credit_Card.csv")


#Normalize dataset
maxValue <- apply(CreditCardnn, 2, max)
minValue <- apply(CreditCardnn, 2, min)

CreditCardnn <- as.data.frame(scale(CreditCardnn, center = minValue, scale = maxValue - minValue))

#Rename to target variable
colnames(CreditCardnn)[25] <- "target"


smp <- floor(0.70 * nrow(CreditCardnn))
set.seed(4784)

CreditCardnn$ID <- NULL
train_index <- sample(seq_len(nrow(CreditCardnn)), size = smp, replace = FALSE)

train_nn <- CreditCardnn[train_index, ]
test_nn <- CreditCardnn[-train_index, ]

allVars <- colnames(CreditCardnn)
predictorVars <- allVars[!allVars%in%'target']
predictorVars <- paste(predictorVars, collapse = "+")
f <- as.formula(paste("target~", predictorVars, collapse = "+"))

nueralModel <- neuralnet(formula = f, 
                         data = train_nn, 
                         hidden = c(4,2), 
                         linear.output = T, 
                         lifesign = 'full',
                         stepmax = 1e6)

plot(nueralModel)

Update 1: 1.27.2022更新 1:1.27.2022

Here is my session info.这是我的 session 信息。 I does appear that BLAS might be doing this I am not using DataTables我确实似乎 BLAS 可能正在这样做我没有使用 DataTables

R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux 8.3 (Ootpa)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.3.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plyr_1.8.6       neuralnet_1.44.6 forcats_0.5.1    stringr_1.4.0    dplyr_1.0.7      purrr_0.3.4      readr_2.0.0      tidyr_1.1.4     
 [9] tibble_3.1.3     ggplot2_3.3.5    tidyverse_1.3.1 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       cellranger_1.1.0 pillar_1.6.2     compiler_4.0.5   dbplyr_2.1.1     tools_4.0.5      jsonlite_1.7.2   lubridate_1.7.10
 [9] lifecycle_1.0.0  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.11     reprex_2.0.1     cli_3.0.1        rstudioapi_0.13  DBI_1.1.1       
[17] haven_2.4.3      xml2_1.3.2       withr_2.4.2      httr_1.4.2       fs_1.5.0         generics_0.1.0   vctrs_0.3.8      hms_1.1.0       
[25] grid_4.0.5       tidyselect_1.1.1 glue_1.4.2       R6_2.5.0         fansi_0.5.0      readxl_1.3.1     tzdb_0.1.2       modelr_0.1.8    
[33] magrittr_2.0.1   backports_1.2.1  scales_1.1.1     ellipsis_0.3.2   rvest_1.0.1      assertthat_0.2.1 colorspace_2.0-2 utf8_1.2.2      
[41] stringi_1.6.2    munsell_0.5.0    broom_0.7.9      crayon_1.4.1    

update 2: 1.27.2022更新 2:1.27.2022

it was BLAS.那是布拉斯。 I set the thread count to 8 and it fixed the issue.我将线程数设置为 8,它解决了这个问题。 Thank you everyone for helping.谢谢大家的帮助。 I have an updated script below for any future viewers to see what was done:我在下面有一个更新的脚本,供以后的观众查看做了什么:

install.packages("tidyverse", dependencies = TRUE)
install.packages("neuralnet", dependencies = TRUE)
install.packages("plyr", dependencies = TRUE)
install.packages("RhpcBLASctl", dependencies = TRUE)

library(tidyverse)
library(neuralnet)
library(plyr)
library(RhpcBLASctl)

CreditCardnn <- read.csv("https://raw.githubusercontent.com/621-Group2/Final-Project/master/UCI_Credit_Card.csv")


#Normalize dataset
maxValue <- apply(CreditCardnn, 2, max)
minValue <- apply(CreditCardnn, 2, min)

CreditCardnn <- as.data.frame(scale(CreditCardnn, center = minValue, scale = maxValue - minValue))

#Rename to target variable
colnames(CreditCardnn)[25] <- "target"


smp <- floor(0.70 * nrow(CreditCardnn))
set.seed(4784)

CreditCardnn$ID <- NULL
train_index <- sample(seq_len(nrow(CreditCardnn)), size = smp, replace = FALSE)

train_nn <- CreditCardnn[train_index, ]
test_nn <- CreditCardnn[-train_index, ]

allVars <- colnames(CreditCardnn)
predictorVars <- allVars[!allVars%in%'target']
predictorVars <- paste(predictorVars, collapse = "+")
f <- as.formula(paste("target~", predictorVars, collapse = "+"))

threads <- 8
blas_set_num_threads(threads)
omp_set_num_threads(threads)

nueralModel <- neuralnet(formula = f, 
                         data = train_nn, 
                         hidden = c(4,2), 
                         linear.output = T, 
                         lifesign = 'full',
                         stepmax = 1e6)

plot(nueralModel)

Check this answer here on stackoverflow.在stackoverflow上检查这个答案 It might be just what you were looking for!它可能正是您想要的!

It uses caret to specify the number of cores.它使用插入符号来指定核心数。

install.packages("tidyverse", dependencies = TRUE)
install.packages("neuralnet", dependencies = TRUE)
install.packages("plyr", dependencies = TRUE)
install.packages("RhpcBLASctl", dependencies = TRUE)

library(tidyverse)
library(neuralnet)
library(plyr)
library(RhpcBLASctl)

CreditCardnn <- read.csv("https://raw.githubusercontent.com/621-Group2/Final-Project/master/UCI_Credit_Card.csv")


#Normalize dataset
maxValue <- apply(CreditCardnn, 2, max)
minValue <- apply(CreditCardnn, 2, min)

CreditCardnn <- as.data.frame(scale(CreditCardnn, center = minValue, scale = maxValue - minValue))

#Rename to target variable
colnames(CreditCardnn)[25] <- "target"


smp <- floor(0.70 * nrow(CreditCardnn))
set.seed(4784)

CreditCardnn$ID <- NULL
train_index <- sample(seq_len(nrow(CreditCardnn)), size = smp, replace = FALSE)

train_nn <- CreditCardnn[train_index, ]
test_nn <- CreditCardnn[-train_index, ]

allVars <- colnames(CreditCardnn)
predictorVars <- allVars[!allVars%in%'target']
predictorVars <- paste(predictorVars, collapse = "+")
f <- as.formula(paste("target~", predictorVars, collapse = "+"))

threads <- 8
blas_set_num_threads(threads)
omp_set_num_threads(threads)

nueralModel <- neuralnet(formula = f, 
                         data = train_nn, 
                         hidden = c(4,2), 
                         linear.output = T, 
                         lifesign = 'full',
                         stepmax = 1e6)

plot(nueralModel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM