python - "No space left on device"拟合 Sklearn 模型时出错

标签 python multithreading scikit-learn ioerror

我正在使用 scikit-learn 拟合包含大量数据的 LDA 模型。相关代码如下:

lda = LatentDirichletAllocation(n_topics = n_topics, 
                                max_iter = iters,
                                learning_method = 'online',
                                learning_offset = offset,
                                random_state = 0,
                                evaluate_every = 5,
                                n_jobs = 3,
                                verbose = 0)
lda.fit(X)

(我想这里唯一可能相关的细节是我正在使用多个作业。)

一段时间后,我收到“设备上没有剩余空间”错误,即使磁盘上有足够的空间和大量可用内存。我在两台不同的计算机上(在我的本地计算机和远程服务器上)尝试了多次相同的代码,首先使用 python3,然后使用 python2,每次都以同样的错误结束。

如果我在较小的数据样本上运行相同的代码,一切正常。

整个堆栈跟踪:

Failed to save <type 'numpy.ndarray'> to .npy file:
Traceback (most recent call last):
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/externals/joblib/numpy_pickle.py", line 271, in save
    obj, filename = self._write_array(obj, filename)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/externals/joblib/numpy_pickle.py", line 231, in _write_array
    self.np.save(filename, array)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.py", line 491, in save
    pickle_kwargs=pickle_kwargs)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/numpy/lib/format.py", line 584, in write_array
    array.tofile(fp)
IOError: 275500 requested and 210934 written


IOErrorTraceback (most recent call last)
<ipython-input-7-6af7e7c9845f> in <module>()
      7                                 n_jobs = 3,
      8                                 verbose = 0)
----> 9 lda.fit(X)

/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/decomposition/online_lda.pyc in fit(self, X, y)
    509                     for idx_slice in gen_batches(n_samples, batch_size):
    510                         self._em_step(X[idx_slice, :], total_samples=n_samples,
--> 511                                       batch_update=False, parallel=parallel)
    512                 else:
    513                     # batch update

/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/decomposition/online_lda.pyc in _em_step(self, X, total_samples, batch_update, parallel)
    403         # E-step
    404         _, suff_stats = self._e_step(X, cal_sstats=True, random_init=True,
--> 405                                      parallel=parallel)
    406 
    407         # M-step

/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/decomposition/online_lda.pyc in _e_step(self, X, cal_sstats, random_init, parallel)
    356                                               self.mean_change_tol, cal_sstats,
    357                                               random_state)
--> 358             for idx_slice in gen_even_slices(X.shape[0], n_jobs))
    359 
    360         # merge result

/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.pyc in __call__(self, iterable)
    808                 # consumption.
    809                 self._iterating = False
--> 810             self.retrieve()
    811             # Make sure that we get a last message telling us we are done
    812             elapsed_time = time.time() - self._start_time

/home/ubuntu/anaconda2/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.pyc in retrieve(self)
    725                 job = self._jobs.pop(0)
    726             try:
--> 727                 self._output.extend(job.get())
    728             except tuple(self.exceptions) as exception:
    729                 # Stop dispatching any new job in the async callback thread

/home/ubuntu/anaconda2/lib/python2.7/multiprocessing/pool.pyc in get(self, timeout)
    565             return self._value
    566         else:
--> 567             raise self._value
    568 
    569     def _set(self, i, obj):

IOError: [Errno 28] No space left on device

最佳答案

LatentDirichletAllocation 也有同样的问题。看来,您的共享内存已用完(运行 df -h 时的 /dev/shm)。尝试将 JOBLIB_TEMP_FOLDER 环境变量设置为不同的值:例如,设置为 /tmp。就我而言,它已经解决了这个问题。

或者只是增加共享内存的大小,如果您对正在训练 LDA 的机器拥有适当的权限。

关于python - "No space left on device"拟合 Sklearn 模型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40115043/

相关文章:

C++11 多线程在神经网络中的性能非常低

python - 如何优化大型数据集的标签编码(sci-kit learn)

python - GridSearchCV(sklearn) 中的多个估计器

python - 使用 Scikit Learn 的 DictVectorizer 时 toarray 中的 MemoryError

python - 如何使用 python wsgi 应用程序读取 Json 对象

python - Django - 将变量从函数 View 传递到 html 模板

python - 为什么 Nose 看不到我的任何环境变量?

python - PYTHON中如何对Mysql进行转义

java - 横向滚动背景移出框架

multithreading - ConcurrentHashMap 与 ConcurrentSkipListMap 说明