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
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.
官方文档
https://huggingface.co/docs/datasets/v2.14.0/en/loading#memory-mapping解决方案
-
通过将数据集文件分割成更小的分片来减小文件大小,然后再加载。使用 `datasets.load_dataset('path/to/dataset', split='train[:50%]')` 加载一半数据。 -
在Linux上使用 `sysctl -w vm.max_map_count=2000000` 增加系统的 vm.max_map_count。这增加了允许的内存映射区域数量。
-
使用 `load_dataset(..., streaming=True)` 通过流式传输数据块来避免对整个文件进行内存映射。
无效尝试
常见但无效的做法:
-
90% 失败
The error is about virtual memory address space, not physical RAM. Adding RAM does not fix address space exhaustion.
-
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.
-
95% 失败
This error is about mmap, not mlock. The ulimit for locked memory is unrelated to virtual memory mapping limits.