ENOMEM huggingface system_error ai_generated partial

OSError:无法对数据集文件进行内存映射:[Errno 12] 无法分配内存

OSError: Unable to mmap dataset file: [Errno 12] Cannot allocate memory

ID: huggingface/dataset-memory-mapping-failure

其他格式: JSON · Markdown 中文 · English
75%修复率
85%置信度
1证据数
2023-08-15首次发现

版本兼容性

版本状态引入弃用备注
datasets>=2.10.0 active
Linux kernel >=5.4 active
Python>=3.8 active

根因分析

系统没有足够的虚拟内存地址空间来对数据集文件进行内存映射,通常是由于文件过大或系统 ulimit 限制所致。

English

The system does not have enough virtual memory address space to memory-map the dataset file, often due to large file size or system ulimit restrictions.

generic

官方文档

https://huggingface.co/docs/datasets/v2.14.0/en/loading#memory-mapping

解决方案

  1. 通过将数据集文件分割成更小的分片来减小文件大小,然后再加载。使用 `datasets.load_dataset('path/to/dataset', split='train[:50%]')` 加载一半数据。
  2. 在Linux上使用 `sysctl -w vm.max_map_count=2000000` 增加系统的 vm.max_map_count。这增加了允许的内存映射区域数量。
  3. 使用 `load_dataset(..., streaming=True)` 通过流式传输数据块来避免对整个文件进行内存映射。

无效尝试

常见但无效的做法:

  1. 90% 失败

    The error is about virtual memory address space, not physical RAM. Adding RAM does not fix address space exhaustion.

  2. 80% 失败

    The error occurs during mmap of the original dataset file, not cache. Disabling caching may cause other issues and does not fix the mmap failure.

  3. 95% 失败

    This error is about mmap, not mlock. The ulimit for locked memory is unrelated to virtual memory mapping limits.