Please support prefetch with python datasets

未关闭
#5,323 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
20/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
python, tensorflow

调研方向

首先检查 tf.data.Dataset 中与 prefetch 和 generator 相关的入口点;该 issue 没有指出仓库文件或测试。使用 Python generator 和 prefetch 重现报告的行为,然后确定受支持的行为和约束。完成这项工作需要达成一致的设计,并提供测试来证明自定义 Python dataset 的准备过程可以进行预取,而不会阻塞 accelerator 工作。

由索引模型根据 Issue 内容生成。

描述

enhancement

Is your feature request related to a problem? Please describe.
There's a tremendous performance difference between datasets which are fully tensor end-to-end and datasets where some data wrangling happens in Python.

I was hoping to use "prefetch" to prepare data with the CPU while the GPU does work, but unfortunately, this only works if the data preparation is fully tensorflow-ish (? not sure the right term here)

Python IO operations are often exponentially slower and act as a bottleneck and prevent computers from keeping accelerators working at capacity.

Describe the solution you'd like
I wish tf.data.Dataset prefetch was more broadly compatible with prefetching of non-tensorflow vanilla-python data preparations.

Would it be possible for prefetch to use some performant C++ to sidestep Python GIL issues and juggle python data wrangling CPU processes alongside GPU training / inference without depending on such python CPU work happening in the main python driver process? I just want to be able to prefetch custom python datasets. Often there's some prep involved, not every dataset is tensorflow end-to-end.

i.e. instead of (python)->(gpu) what if it were

(python)->(cpp)
(cpp)->(python_prefetch)
(cpp)->(gpu/tpu accelerator)

Since C++ lacks a GIL, it could just run the python generator in a process which is isolated from the main python driver process' GIL, you'd still have a GIL per generator, but that's an easy fix, just run more python processes with different random seeds etc.

Describe alternatives you've considered
Torch DataLoader could be an option but it also seems to be a python-driven solution and therefore not super performant. I tried Threading, but pickling and unpickling overhead in python can be pretty bad. I think maybe C++ could run a background python process to prefetch python data in a more performant way than python could.

Additional context
Broader accessibility of custom dataset prefetching could enable new use-cases for tf.data especially in prototyping or infinite search spaces where it might not make sense to convert entire datasets to tensors in advance.

Apologies if I misunderstand the intricacies involved. I just want to prefetch datasets built from generators. I tried doing this last week but it didn't work, so hopefully I'm not mentioning an issue which is fixed and I missed a way to pull it off. It's hard to provide an example since the code in question is closed-source and quite extensive anyway. For a good example of when this might be handy, consider RL gym envs or datasets which involve making GET requests.

主要语言
Python
星标
4.6k
派生
1.6k
平均合并
14 小时 3 分钟
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tensorflow/datasets 的其他 Issue

查看 tensorflow/datasets 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。