I am surprised that I could not see a concise way to run a tf.data API on the GPU. I understand that the data pipelines can run on CPU so that it can happen in parallel (with pre-fetching), allowing the GPU to run actual model and train it.
However, my pre-processing is extremely parallel and computationally intensive. While I can technically write the pre-processing as the first layer in my model, I would really not prefer to do this to prevent training data leakage into my model.
Any pointers is appreciated for this. The closest I found was https://towardsdatascience.com/overcoming-data-preprocessing-bottlenecks-with-tensorflow-data-service-nvidia-dali-and-other-d6321917f851, which involves using nvidia DALI frameworks.
Here are some critical points:
- I have already tried enforcing device placement with
tf.device('...'). - I dont want to prefectch the data into the device but rather run the whole data pipeline on GPU.
- Preferably, if my computation is more, I want to save my dataset as a
tfrecords, so that I can load it directly. This can be done withtf.data.experimental.savefor now, but it again it uses CPU!