Google Touts Web-Based Machine Learning with TensorFlow.js
To find out more about TensorFlow.js and how web developers use it in their projects, I spoke to Jason Mayes, who leads the Developer Relations team for Web ML at Google. “Web ML” is a broader term that basically means using ML inside the browser (or on Node.js). But the main part of Mayes’ remit is the TensorFlow.js team, so I began by asking him about the main use cases for ML on the web.
Why Do ML over the Web?
Another privacy use case is human-computer interaction. “With some of our models, we can do body pose estimation, or body segmentation, face keypoint estimation, all that kind of stuff,” Mayes said.
Lower latency is another reason to do ML in the browser, according to Mayes. “Some of these models can run over 120 frames per second in the browser, on an NVIDIA 1070 let’s say,” he said. “So that’s kind of [an] old generation graphics card and [yet it’s] still pushing some decent performance there.”
Cost was his third reason, “because you’re not having to hire and run expensive GPUs and CPUs in the cloud and keep them running 24/7 to provide a service.”
How JS ML Compares to Python ML
However, this begs the question of how TensorFlow.js compares to using TensorFlow in its more familiar Python environment?
He mentioned that HuggingFace, one of the leading NLP service companies, runs its ML workloads in TensorFlow.js for the speed benefits.
“Python is actually not very efficient at running,” he continued. “It’s good for academia, for trying things out — it’s got a lot of libraries to use out of the box. But I think we’ll have the same thing replicated in our own community going forward, and you’ll see the performance benefits.”
As another example of this in action, he pointed to LinkedIn. “If you go to a LinkedIn web page on your mobile phone, that’s actually delivered by a TensorFlow.js model on the backend running in Node,” he said. This resulted in a “15% performance gain over their Python equivalent model, which means they save millions of dollars a month by just doing that.”
More Speed: WebGL and WebAssembly
As with many other leading web applications, TensorFlow.js is making use of the latest hardware acceleration technologies. WebGL and WebAssembly are both in production, while WebGPU is in testing.
“We’ve got WebGL to do graphics card acceleration,” he explained. “Essentially, using textures and shaders to do mathematical operations — which is a bit of a hack, but it works. And then we’ve also got WebAssembly to go faster on the CPU. We’ve also got the new emerging WebGPU standard, which is currently behind a flag in Chrome Canary and other browsers, but eventually, it will become the thing in browsers to use. And I think we’re seeing around 2x-plus performance [gain] in WebGPU — bear in mind, with WebGL right now we’re getting hundreds of frames per second already.”
More about Web ML
TensorFlow.js is clearly the main web-based ML tool at Google, but I asked Mayes what else comes under the umbrella term “Web ML”?
“So Google’s obviously heavily invested in ML and from my perspective, working on this Web ML side, it offers a unique selling point — if you will — to our [ML] ecosystem… currently, there’s no PyTorch.js, for example,” he said, referencing Meta’s ML platform.
Google offers what Mayes calls “a path to the web” for machine learning, “which researchers and others can embrace, to get those benefits that we spoke about before.”
He also works with “other teams [at Google] that might touch on web-based deployments of machine learning, like the MediaPipe models that are also able to run in the web browser.” He’s referencing an open source project called MediaPipe, for using ML in “live and streaming media.”
TensorFlow.js has been growing “3x year-on-year” according to Mayes. It’s only going to get bigger, as ML and AI apps continue to ramp up in popularity. Indeed, just this week Google itself released a ChatGPT competitor called Bard. I asked Mayes how big he thinks web-based ML tools like Tensorflow.js will get?
“I think Web ML is the real Web3,” he said, echoing a catchphrase he has been using on social media. “I’m not saying crypto is bad or anything, but I think […] it’s like a teenager trying to find itself right now. And I think Web ML can have an impact on industries [and] companies right now.”
“I believe that if we continue on this 3x path of growth, we could be the most widely used form of ML in the future within the TensorFlow ecosystem. That’s my personal belief. But if we continue this growth upward, I don’t see why not — because there are a lot more JS developers out there.”
To keep that momentum going, Mayes said that Google is “always looking for interesting models we can port from Google research to the web, to make it easier to use.”
If you’re a developer interested in learning more about web-based ML, check out this series of tutorials featuring Jason Mayes.