Convert DataSync() to async
→ Description 📝
- want to suggest an update 💡
Based on our conversations with @nsthorat - we should start thinking about making our data conversions from GPU to CPU async in the coming future.
Some bg info: https://meowni.ca/posts/on-tfjs-datasync/
cc/ @shiffman @yining1023
Just to recap that conversation:
- dataSync() and arraySync() makes your UI janky. Doing this at the library level means user code will have no opportunity to de-jank. Prefer data() and array()
- In WebGPU & WASM backend we will have no ability to support dataSync() because of the fundamentals of those backends so it's good to switch now
If you have any questions let me know :)
Thanks @nsthorat! 🙏
We are all for the de-jank 😂
At the moment, I think the only place we are actively using dataSync() is ml5.sentiment with the predict() function. That should definitely change to a callback / promise to match the rest of the API anyway!
I am also using dataSync() liberally with my tf.js neuro-evolution examples so that will be something to look at as I begin working on integrating those into ml5!
I'm seeing 19 uses of dataSync() and 4 or arraySync(). Some can be fixed without too much pain BUT a bunch are inside of tf.tidy() expressions, which have to be synchronous. So we would have to break those up into multiple parts (using multiple tf.tidy()s for the synchronous parts) and do some manual disposing.