Code Monkey home page Code Monkey logo

mediapipe_llm's Introduction

On-device LLM Inference using MediaPipe API

개요

구글 미디어파이프(MediaPipe)는 ML/DL 애플리케이션 생성을 위한 다양한 도구를 제공한다. 2024년 5월 미디어파이프는 온-디바이스에서 대규모언어모델(LLM) 실행을 위한 API를 제공하기 시작하였다. 이제 LLM 서빙을 위한 서버를 구축하지 않더라도 모바일 장치 등에서 맞춤형 언어모델을 실행할 수 있고, 이를 활용한 애플리케이션을 제작하기가 더 쉬워질 것이다.
여기에서는 웹 브라우저에서 MediaPipe LLM API를 실행하는 text-generation 공식예제를 변형하여, 간단한 챗UI에서 LLM모델을 실행시켜본다. 크롬의 하드웨어 가속을 허용한 상태에서 텍스트 생성은 상용 LLM 서비스 모델 못지않게 빠른 사용자 경험을 제공한다.
기타 자세한 내용은 링크를 참조한다.

실행 방식

  1. Kaggle의 Gemma 모델 페이지에서 gemma-2b-it-gpu-int4 모델을 다운로드 받는다.
  2. 터미널 또는 명령 프롬프트 등을 실행하여, 다음 명령어를 이용하여, 간단한 테스트 서버를 실행시킨다.
python -m http.server 8000
  1. Chrome 또는 Edge 처럼 WebGPU 지원이 되는 브라우저를 열고 localhost:8000으로 접속한다.

실행 결과 예시

inference result

참고 사항

  • 다른 모델을 사용할 때는 index.js에서 modelFileName에 해당 모델 파일의 경로를 입력한다.
  • 현재 구글의 Gemma 모델 이외에 Falcon, StableLM, Phi-2 등의 모델을 지원한다.
  • Kaggle의 Gemma 모델이 아닌 위의 모델을 HuggingFace에서 받아서 사용할 경우에는, 해당 TfLite 모델을 MediaPipe에서 사용할 수 있는 형태로 추가 변환이 필요한다.
  • 직접 fine-tuned 모델을 사용할 경우라면, 우선 AI Edge를 이용하여 TfLite 파일로 변환한 후, 위의 과정을 진행한다.
  • 웹 브라우저에서 Inference API를 사용할 때는 WebGPU를 지원하는 브라우저를 사용하여야 한다.
  • 외장 그래픽 카드가 있음에도 추론 속도가 빠르지 않다면, (Windows, Chrome의 경우) 앱별 그래픽카드 설정과 브라우저의 하드웨어 가속 설정을 확인한다.
  • 4bit로 양자화된 gemma-2b 모델(gemma-2b-it-gpu-int4.bin)의 경우, 약 1.5 GB의 GPU메모리를 사용하는 경량 실행이 가능하였다.

참고 링크

mediapipe_llm's People

Contributors

hayunjong83 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.