[인공지능 기술] WebGPU powered machine learning in the browser with Apache TVM : Apache TVM을 사용하여 브라우저에서 WebGPU 기반 기계 학습
2023.10.12 16:17
[인공지능 기술] WebGPU powered machine learning in the browser with Apache TVM : Apache TVM을 사용하여 브라우저에서 WebGPU 기반 기계 학습
By Tianqi Chen, Jared Roesch, and Jason Knight
TL;DR
Easy ML deployment in the browser with near-native GPU performance and WebAssembly
We introduced support for WASM and WebGPU backends to the Apache TVM deep learning compiler Our initial experiments shows that TVM’s WebGPU backend can get close to native GPU performance when deploying models in the browser.
Introduction — faster browser applications
WebGPU and WebAssembly are two up-and-coming browser standards aimed at making browser based applications as efficient as native applications while retaining hardware portability. WebGPU first builds on top of the lower level graphics API movements to enable more full featured GPU accelerated compute capabilities as compared to its predecessor WebGL, and WebAssembly (WASM) is a similar effort for unlocking CPU based compute capabilities. And best of all, WASM is most likely already enabled in the browser you’re reading this in, with WebGPU coming soon.
For some of the exciting capabilities and use cases behind WASM particularly, please check out Lin Clark’s excellent WASM “skill tree”

WASM’s post MVP skill tree
Leveraging more of these WASM capabilities such as SIMD support and multi-threading as they mature is an exciting area of future work, but let’s see how far we can get with WASM and WASI (standard interfaces) to feed WebGPU compute shaders.
Machine learning in the browser
While efforts like TensorFlow.js and ONNX.js attempt to bring machine learning to the browser, there still exist non-trivial gaps in performance between the web versions and native ones. One of the many reasons behind these gaps are the lack of standard and performant access to the GPU on the web. WebGL lacks important features such as compute shaders and generic storage buffers that are necessary for high performance deep learning.
WebGPU offers the potential to bridge this gap with its first-class compute shader support.
To explore the potential of using WebGPU for deploying machine learning in the browser, we enhanced the deep learning compiler Apache (incubating) TVM to target WASM (for host code that computes the launching parameters and calls into the device launch) and WebGPU (for device execution). Our preliminary results are quite positive — for the first time, we can deploy machine learning applications on the web while still getting near native performance on the GPU.
Please check out our companion Apache TVM technical blog post for the technical details, but in short, we were able to achieve near native GPU performance in the browser through WASM and WebGPU by combining:
-
TVM’s existing SPIR-V code generation capabilities to target WebGPU compute APIs
-
TVM’s existing LLVM backend for it’s WASM generation support
-
A new tvmjs TypeScript runtime
-
WASM’s standard interfaces (WASI) for system library calls (eg malloc, stderr)
-
Chrome’s nightly WebGPU support

One important advantage of the compilation based approach is the reuse of infrastructure. We are able to effortlessly relative to other approaches target the web by reusing the infrastructure for optimizing GPU kernels for native platforms such as CUDA, Metal and OpenCL. If the mapping of the WebGPU API to native APIs is efficient we can expect similar performance with very little work. More importantly, the AutoTVM infrastructure allows us to specialize the compute shaders for specific models, enabling the generation of the best compute shaders for our specific model of interest.
Performance

We ran a quick experiment comparing the execution of a full Mobilenet execution via TVM’s WebGPU backend and native targets that use native GPU runtimes (Metal and OpenCL). We find that WebGPU get’s quite close to matching the performance of Metal. Assuming Chrome WebGPU’s runtime targets Metal instead of OpenCL on the MacOS, we can safely assume there is little to no performance loss when targeting the GPU through the browser here.
We also expect further performance boosts by applying AutoTVM tuning on the GPU being used by the browser since these results are based off previously auto-tuned schedules from a GTX 1080 Ti, which is quite different from the Intel graphics GPU. To make this easier, we expect our upcoming improvements to the uTVM runtime (stay tuned to this blog for an update in the next 1–2 weeks) for embedded microcontrollers will help make autotuning easier in the browser since WASM targets share many similarities to embedded devices.
Looking to the Future
Our results suggest many interesting opportunities for machine learning on the web. Notably, WebGPU is an API that is still evolving and its implications could go beyond web applications. For example one could target native APIs of WebGPU as it matures and becomes standardized through WASI, enabling standalone WASM applications that make use of WebGPU.
The TVM community is also actively working on a Rust based runtime that would enable much more robust WASM support and enable easier interaction with projects like wgpu, and the Rust WASM ecosystem. As an open source project, we are looking for contributors who can bring in new ideas and help push the project in these exciting directions.
The proposed approach provides effective machine learning support for most WASM’s application scenarios. The close to native performance could also unlock better federated learning capabilities on the browser. The same compiled package should also be able to run on native WASM executors to provide sandbox for the applications.
Show me the Details/Code
-
Detailed technical version of this blog post
-
Example project for image classification
-
Apache TVM on github
Acknowledgement
We would like to thank the emscripten project for providing the WASM compilation infrastructures as well as the JS library support on the web. We would also like to thank the WebGPU community for various helpful discussions. Thanks to Fletcher Haynes for valuable feedback on the post.
[출처] https://octoml.ai/blog/webgpu-powered-machine-learning-in-the-browser-with-apache-tvm/
Apache TVM을 사용하여 브라우저에서 WebGPU 기반 기계 학습
저자: Tianqi Chen, Jared Roesch, Jason Knight
TL;DR
거의 기본 GPU 성능과 WebAssembly를 갖춘 브라우저에서 쉽게 ML 배포
Apache TVM 딥 러닝 컴파일러 에 WASM 및 WebGPU 백엔드에 대한 지원을 도입했습니다 . 초기 실험에 따르면 브라우저에 모델을 배포할 때 TVM의 WebGPU 백엔드가 기본 GPU 성능에 근접 할 수 있는 것으로 나타났습니다.
소개 — 더 빠른 브라우저 애플리케이션
WebGPU 와 WebAssembly 는 하드웨어 이식성을 유지하면서 브라우저 기반 애플리케이션을 기본 애플리케이션만큼 효율적으로 만드는 것을 목표로 하는 두 가지 최신 브라우저 표준입니다. WebGPU는 먼저 낮은 수준의 그래픽 API 움직임을 기반으로 구축되어 이전 WebGL에 비해 더 많은 기능을 갖춘 GPU 가속 컴퓨팅 기능을 지원하며 WebAssembly(WASM)는 CPU 기반 컴퓨팅 기능을 잠금 해제하기 위한 유사한 노력입니다. 무엇보다도 WASM은 이 글을 읽고 있는 브라우저에서 이미 활성화되어 있을 가능성이 높으며 WebGPU도 곧 출시될 예정입니다 .
특히 WASM의 흥미로운 기능과 사용 사례에 대해서는 Lin Clark의 우수한 WASM "스킬 트리"를 확인하세요.

WASM의 포스트 MVP 스킬 트리
SIMD 지원 및 멀티스레딩과 같은 WASM 기능이 성숙해짐에 따라 더 많이 활용하는 것은 미래 작업의 흥미로운 영역이지만 WebGPU 컴퓨팅 셰이더에 공급하기 위해 WASM 및 WASI(표준 인터페이스)를 통해 얼마나 멀리까지 갈 수 있는지 살펴보겠습니다.
브라우저에서의 머신러닝
TensorFlow.js 및 ONNX.js와 같은 노력이 기계 학습을 브라우저에 도입하려고 시도하는 동안 웹 버전과 기본 버전 사이에는 여전히 성능 차이가 적지 않습니다. 이러한 격차의 원인 중 하나는 웹에서 GPU에 대한 표준 및 성능 액세스가 부족하기 때문입니다. WebGL에는 고성능 딥 러닝에 필요한 컴퓨팅 셰이더 및 일반 스토리지 버퍼와 같은 중요한 기능이 부족합니다.
WebGPU는 최고 수준의 컴퓨팅 셰이더 지원을 통해 이러한 격차를 해소할 수 있는 잠재력을 제공합니다.
브라우저에 기계 학습을 배포하기 위해 WebGPU를 사용할 수 있는 가능성을 탐색하기 위해 WASM(실행 매개변수를 계산하고 장치 실행을 호출하는 호스트 코드용) 및 WebGPU(장치용)를 대상으로 딥 러닝 컴파일러 Apache(인큐베이팅) TVM을 향상했습니다. 실행). 우리의 예비 결과는 매우 긍정적입니다. 처음으로 GPU에서 기본 성능에 거의 근접하면서 웹에 기계 학습 애플리케이션을 배포할 수 있었습니다.
기술적 세부 사항은 함께 제공되는 Apache TVM 기술 블로그 게시물을 확인하세요 . 간단히 말해서 우리는 다음을 결합하여 WASM 및 WebGPU를 통해 브라우저에서 거의 기본 GPU 성능을 달성할 수 있었습니다.
-
WebGPU 컴퓨팅 API를 대상으로 하는 TVM의 기존 SPIR-V 코드 생성 기능
-
WASM 생성 지원을 위한 TVM의 기존 LLVM 백엔드
-
새로운 tvmjs TypeScript 런타임
-
시스템 라이브러리 호출(예: malloc, stderr)을 위한 WASM의 표준 인터페이스(WASI)
-
Chrome의 야간 WebGPU 지원

컴파일 기반 접근 방식의 중요한 이점 중 하나는 인프라를 재사용한다는 것입니다. 우리는 CUDA, Metal 및 OpenCL과 같은 기본 플랫폼에 대해 GPU 커널을 최적화하기 위한 인프라를 재사용함으로써 다른 접근 방식 에 비해 웹을 대상으로 하는 작업을 쉽게 수행할 수 있습니다 . WebGPU API를 네이티브 API로 매핑하는 것이 효율적이라면 거의 작업하지 않고도 비슷한 성능을 기대할 수 있습니다. 더 중요한 것은 AutoTVM 인프라를 통해 특정 모델에 대한 컴퓨팅 셰이더를 전문화하여 특정 관심 모델에 가장 적합한 컴퓨팅 셰이더를 생성할 수 있다는 것입니다.
성능

우리는 TVM의 WebGPU 백엔드와 네이티브 GPU 런타임(Metal 및 OpenCL)을 사용하는 네이티브 대상을 통해 전체 Mobilenet 실행 실행을 비교하는 빠른 실험을 실행했습니다. 우리는 WebGPU가 Metal의 성능과 거의 일치한다는 것을 알았습니다. Chrome WebGPU의 런타임이 MacOS의 OpenCL 대신 Metal을 대상으로 한다고 가정하면 여기에서 브라우저를 통해 GPU를 대상으로 할 때 성능 손실이 거의 또는 전혀 없다고 안전하게 가정할 수 있습니다.
또한 이러한 결과는 Intel 그래픽 GPU와 상당히 다른 GTX 1080 Ti의 이전 자동 조정 일정을 기반으로 하기 때문에 브라우저에서 사용되는 GPU에 AutoTVM 조정을 적용하면 성능이 더욱 향상될 것으로 예상 됩니다 . 이를 더 쉽게 만들기 위해 내장형 마이크로컨트롤러에 대한 uTVM 런타임의 향후 개선 사항(향후 1~2주 내에 업데이트를 위해 이 블로그를 계속 지켜봐 주시기 바랍니다)은 WASM 타겟이 내장형과 많은 유사점을 공유하므로 브라우저에서 자동 조정을 더 쉽게 만드는 데 도움이 될 것으로 기대합니다. 장치.
미래를 바라보며
우리의 결과는 웹에서 기계 학습을 위한 많은 흥미로운 기회를 제시합니다. 특히 WebGPU는 여전히 진화하고 있는 API이며 그 의미는 웹 애플리케이션을 넘어설 수 있습니다. 예를 들어 WebGPU가 성숙해지고 WASI를 통해 표준화됨에 따라 WebGPU의 기본 API를 대상으로 하여 WebGPU를 활용하는 독립형 WASM 애플리케이션을 활성화할 수 있습니다.
TVM 커뮤니티는 또한 훨씬 더 강력한 WASM 지원을 가능하게 하고 wgpu 및 Rust WASM 생태계와 같은 프로젝트와의 더 쉬운 상호 작용을 가능하게 하는 Rust 기반 런타임 에 적극적으로 노력하고 있습니다 . 오픈 소스 프로젝트로서 우리는 새로운 아이디어를 가져오고 프로젝트를 이러한 흥미로운 방향으로 추진하는 데 도움을 줄 수 있는 기여자를 찾고 있습니다.
제안된 접근 방식은 대부분의 WASM 애플리케이션 시나리오에 효과적인 기계 학습 지원을 제공합니다. 기본 성능에 가까워지면 브라우저에서 더 나은 연합 학습 기능을 활용할 수도 있습니다. 동일한 컴파일된 패키지는 기본 WASM 실행기에서도 실행되어 애플리케이션에 샌드박스를 제공할 수 있어야 합니다.
세부정보/코드를 보여주세요.
-
이 블로그 게시물의 자세한 기술 버전
-
이미지 분류를 위한 예시 프로젝트
-
github의 Apache TVM
승인
웹에서 WASM 컴파일 인프라와 JS 라이브러리 지원을 제공한 emscripten 프로젝트에 감사드립니다. 또한 다양한 유용한 토론을 해주신 WebGPU 커뮤니티에도 감사의 말씀을 전하고 싶습니다. 게시물에 귀중한 피드백을 주신 Fletcher Haynes에게 감사드립니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.

