ml5-library icon indicating copy to clipboard operation
ml5-library copied to clipboard

Convert DataSync() to async

Open joeyklee opened this issue 6 years ago • 4 comments

→ 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

joeyklee avatar Jun 20 '19 19:06 joeyklee

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 :)

nsthorat avatar Jun 20 '19 19:06 nsthorat

Thanks @nsthorat! 🙏 We are all for the de-jank 😂

joeyklee avatar Jun 20 '19 19:06 joeyklee

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!

shiffman avatar Jun 20 '19 20:06 shiffman

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.

lindapaiste avatar Apr 17 '22 00:04 lindapaiste