CUDA11.2环境下执行dataset.map时报dill._dill无stack属性错误怎么办?
解决
AttributeError: module 'dill._dill' has no attribute 'stack'问题 问题背景
在Colab环境(CUDA 11.2)中执行以下代码时触发错误:
train_dataset = train_dataset.map( process_data_to_model_inputs, batched=True, batch_size=batch_size, remove_columns=["article", "abstract", "section_names"], )
错误信息:
AttributeError: module 'dill._dill' has no attribute 'stack'
已尝试pip install dill==0.3.4但问题未解决。
解决方案
卸载并重新安装指定版本的dill
旧版本dill存在兼容性问题,卸载后安装更稳定的适配版本:pip uninstall -y dill pip install dill==0.3.5.1强制重启Colab运行时
安装完成后,点击Colab顶部菜单栏「Runtime」→「Restart runtime」,确保新安装的dill被加载,避免使用缓存的旧版本文件。固定transformers/datasets与dill的兼容版本
如果上述方法无效,尝试安装经过验证的兼容版本组合:pip install transformers==4.21.0 datasets==2.4.0 dill==0.3.5.1临时绕开dill序列化逻辑
在map方法中添加load_from_cache_file=False参数,禁用缓存加载,直接跳过dill的序列化步骤:train_dataset = train_dataset.map( process_data_to_model_inputs, batched=True, batch_size=batch_size, remove_columns=["article", "abstract", "section_names"], load_from_cache_file=False )
内容的提问来源于stack exchange,提问作者JenHao Yang
相关产品推荐
相关产品推荐

