📗
smiley book
  • Smiley Books
  • AI
    • Readme
    • openai-whisper
      • 샘플 실행해보기
      • GPU 서버 준비하기
      • API로 whisper를 외부에 오픈하기
      • 프롬프트 지원
      • 실시간 message chat
      • 화면 이쁘게 만들기와 로그인
      • 파이썬 가상환경
      • 실시간 voice chat
      • fine tunning(미세 조정) 으로 성능 올리기
      • app에서 api를 호출하여 실시간으로 텍스트로 바꿔보기
    • ollama - llm을 쉽게 내컴에서 실행
      • ollama webui
      • ollama docker
    • stable diffusion
      • SDXL - text to image
      • SD-webui
    • ChatGPT
      • 답변이 끊길때
      • 역할을 정하자
      • 구체적인 질문
      • 결과형태를 지정
      • 프롬프트를 여러줄로 사용하자.
      • 마틴 파울러 글 번역본
    • Prompt Engineering
    • Auto-GPT
    • Gemini
      • google ai studio
      • gemini-api
      • embedding guide
    • Huggingface
      • huggingface 사용법
      • huggingface nlp 공부중
    • kaggle
      • download dataset
    • langchain
      • langchain을 공부하며 정리
      • basic
      • slackbot
      • rag
      • document-loader
      • website-loader
      • confluence
      • memory
      • function-call
      • langsmith
      • agent-toolkit
  • Ansible
    • templates vs files and jinja2
    • dynamic inventory
    • limit 옵션 강제하기
    • limit 사용후 gather_fact 문제
  • AWS
    • AWS CLI
    • EKS
      • cluster manage
      • ALB Controller
      • external-dns
      • fargate
    • ECR
    • S3
    • Certificate Manager
  • Azure
    • Azure AD OAuth Client Flow
  • Container
    • Registry
    • 빌드시에 env값 설정하기
  • DB
    • PXC
      • Operator
      • PMM
      • 삭제
      • GTID
      • Cross Site Replication
    • Mssql
    • Mysql
  • dotnet
    • Thread Pool
    • Connection Pool
    • Thread Pool2
  • Devops
    • Recommendation
  • GIT
    • Basic
    • Submodule
  • GitHub
    • Repository
    • GitHub Action
    • GitHub PR
    • Self Hosted Runner
    • GitHub Webhook
  • GitLab
    • CI/CD
    • CI/CD Advance
    • Ssl renew
    • CI/CD Pass env to other job
  • Go Lang
    • 개발 환경 구축
    • multi os binary build
    • kubectl같은 cli만들기
    • azure ad cli
    • embed static file
    • go study
      • pointer
      • module and package
      • string
      • struct
      • goroutine
  • Kubernetes
    • Kubernetes는 무엇인가
    • Tools
    • Install with kubespray
    • Kubernetes hardening guidance
    • 11 ways not to get hacked
    • ArgoCD
      • Install
      • CLI
      • Repository
      • Apps
      • AWS ALB 사용
      • Notification slack
      • Backup / DR
      • Ingress
      • 2021-11-16 Github error
      • Server Config
      • auth0 인증 추가(oauth,OIDC)
    • Extension
      • Longhorn pvc
      • External dns
      • Ingress nginx
      • Cert Manager
      • Kube prometheus
    • Helm
      • Subchart
      • Tip
    • Loki
    • Persistent Volume
    • TIP
      • Job
      • Pod
      • Log
  • KAFKA
    • raft
  • KVM
    • kvm cpu model
  • Linux
    • DNS Bind9
      • Cert-Manager
      • Certbot
      • Dynamic Update
      • Log
    • Export and variable
    • Grep 사용법
  • Modeling
    • C4 model introduce
    • Mermaid
    • reference
  • Monitoring
    • Readme
    • 0. What is Monitoring
    • 1. install prometheus and grafana
    • 2. grafana provisioning
    • 3. grafana dashboard
    • 4. grafana portable dashboard
    • 5. prometheus ui
    • 6. prometheus oauth2
    • Prometheus
      • Metric type
      • basic
      • rate vs irate
      • k8s-prometheus
    • Grafana
      • Expolorer
    • Node Exporter
      • advance
      • textfile collector
  • Motivation
    • 3 Simple Rule
  • OPENNEBULA
    • Install(ansible)
    • Install
    • Tip
    • Windows vm
  • Reading
    • comfort zone
    • 배려
    • elon musk 6 rule for insane productivity
    • Feynman Technique
    • how to interview - elon musk
    • 경청
    • Readme
  • Redis
    • Install
    • Master-slave Architecture
    • Sentinel
    • Redis Cluster
    • Client programming c#
  • SEO
    • Readme
  • Security
    • criminalip.io
      • criminalip.io
  • Stock
    • robinhood-python
  • Terraform
    • moved block
    • output
  • vault
    • Readme
  • VS Code
    • dev container
    • dev container on remote server
  • Old fashione trend
    • curity
    • MAAS
      • Install maas
      • Manage maas
      • Tip
Powered by GitBook
On this page
  • os install
  • partition
  • software
  • GPU 설정
  • Install Nvidia kernel module
  • Install Nvidia container runtime
  • Testing
  • gpu 사용량
  • 성능테스트

Was this helpful?

  1. AI
  2. openai-whisper

GPU 서버 준비하기

Previous샘플 실행해보기NextAPI로 whisper를 외부에 오픈하기

Last updated 2 years ago

Was this helpful?

앞에 문서에서는 데스크탑에 잇는 cpu만 사용해서 프로그램을 실행하엿다 만약 large모델을 사용하게 되면 시간이 많이 소요된다. gpu를 사용해보자.

os install

centos 79 사용

그래픽 카드로 1080ti를 설치

저는 a100이나 tesla4 가 없어서 이걸로 햇습니다. 이걸 사용하시는걸 추천드립니다.

여기를 참고하면 이제 large 모델도 사용할수가 있을거같다. large_v2모델이 나왔다. 현재는 v2가 large인듯 하다.

partition

/boot - 1G
/swap - 8G
/ - 나머지

software

내 컴퓨터에서 gpu서버에 접속하기 위해 실행

vi /etc/hosts
192.168.1.49 whisper

ssh-copy-id whisper

gpu서버 에서 다음 실행

# disable selinux
vi /etc/selinux/config
disabled

setenforce 0

# firewall
systemctl stop firewalld
systemctl disable firewalld

# yum update
yum update -y

# install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run
systemctl start docker
systemctl enable docker

curl -L --fail https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

# set hostname
hostnamectl set-hostname whisper

# git clone
mkdir -p /data/git
cd /data/git
git clone git@github.com:teamsmiley/my-whisper.git

GPU 설정

Install Nvidia kernel module

Prepare compilation environment

실행 중인 커널 버전에 대해 더 이상 kernel-devel and kernel-header를 사용할 수 없는 경우 최신 커널로 업데이트하고 재부팅해 보세요.

yum groupinstall -y "Development tools"
yum install -y kernel-devel-$(uname -r) kernel-devel-$(uname -r)

Install Nvidia driver

vi /etc/yum.repos.d/cuda.repo

[cuda-rhel7-x86_64]
name=cuda-rhel7-x86_64
baseurl=https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64
enabled=1
gpgcheck=0

yum install -y epel-release

yum install -y nvidia-driver-latest-dkms
# 에러가 나면 epel-release를 설치한다.

reboot

nvidia-smi  # check gpu on machine

Install Nvidia container runtime

엔비디아 컨테이너 런타임은 컨테이너 서비스를 위한 통합을 제공하고 GPU를 컨테이너에 동적으로 매핑합니다. 이 예제에서는 통합을 시연하기 위해 도커를 사용하고 있습니다.

현재는 도커만 지원을 한다.

vi /etc/yum.repos.d/libnvidia-container.repo

[libnvidia-container]
baseurl=https://nvidia.github.io/libnvidia-container/stable/centos7/$basearch
enabled=1
gpgcheck=0

yum install -y nvidia-container-toolkit

nvidia-ctk를 사용하여 런타임을 구성합니다. 이렇게 하면 기본적으로 daemon.json에 구성 섹션이 추가되어 컨테이너 생성 시 엔비디아 통합이 사용될 때 도커가 수행해야 할 작업을 알 수 있습니다.

nvidia-ctk runtime configure --runtime=docker

cat /etc/docker/daemon.json
{
  "runtimes": {
    "nvidia": {
      "args": [],
      "path": "nvidia-container-runtime"
    }
  }
}
systemctl restart docker

Testing

모든 것이 올바르게 작동한다면 컨테이너 내부에 호스트에서 실행되는 것과 동일한 nvidia-smi 출력이 표시되어야 합니다(프로세스 목록 제외).

docker run --rm --runtime=nvidia --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi
  • docker-compose

vi docker-compose.yml
version: '3.9'
services:
  whisper:
    build: .
    # gpu를 사용하기 위해서는 꼭 이 내용이 필요합니다.
    deploy:
      resources:
        reservations:
          devices:
            - driver: 'nvidia'
              capabilities: [gpu]
              count: 1
cd /data/git
git clone git@github.com:teamsmiley/my-whisper.git

cd my-whisper

docker-compose up --build

잘 실행됨을 알고 있습니다.

gpu 사용량

gpu가 사용됨을 확인하시려면 main.py에 다음 코드를 추가합니다.

import whisper
import torch
import time

if torch.cuda.is_available():
    device = torch.device("cuda")
    print("Using GPU:", torch.cuda.get_device_name(0))
else:
    device = torch.device("cpu")
    print("Using CPU")

cpu를 사용하는지 gpu를 사용하는지 확인할수 있습니다.

실제 gpu사용량이 보고 싶었습니다.

nvidia-smi

위 명령어를 실행해보면 gpu실 사용량이 보입니다. 한가지 주의하셔야할점은 현재 코드는 인터넷에서 모델을 다운받고 로드하고 하는부분이 있는데 이부분이 오래 걸립니다. 그래서 프로그램을 실행해도 한참을 0% 사용량을 보일것입니다. 실제로 연산하는 부분에서만 gpu가 올라가는걸 보실수 있을겁니다.

성능테스트

모델을 이것저것 바꿔가면서 정확성과 성능을 테스트해보시기 바랍니다. 저의 경우에는

3분짜리 mp3파일로 테스트해봣는데 다음과 같았습니다.

model
model size
transcribe

tiny

72M

5 sec

base

140M

6 sec

small

460M

7 sec

medium

1.4G

13 sec

large-v2

2.9G

17 sec

모델 다운로드시간은 뺀 결과입니다.

하시다보면 매번 모델 다운로드에 더 오래 걸리는걸 아실수 있습니다. 그래서 다음처럼 docker-compose.yml을 수정하시면 한번 다운받은 모델을 캐시하여 사용하실수 있습니다.

vi docker-compose.yaml
version: '3.9'
services:
  whisper:
    build: .
    # 이부분을 추가해주면 됩니다.
    volumes:
      - ./cache:/root/.cache/whisper:rw
    # for gpu
    deploy:
      resources:
        reservations:
          devices:
            - driver: 'nvidia'
              capabilities: [gpu]
              count: 1 # we need this

이제 프로젝트폴더에 cache폴더를 만들어주시면 모델들이 이 폴더에 저장이 되어 다음번에 실행할때 이 파일을 사용하는것을 알수 있습니다.

현재 릴리스된 Nvidia 드라이버는 dkms/rpm을 통해 배포되므로 사용자 지정 실행 스크립트를 통해 설치할 필요가 없습니다. dkms 덕분에 프로세스가 훨씬 쉬워졌으며 향후 커널 업데이트 시 모듈이 자동으로 다시 컴파일됩니다. (참고 )

도커 이외의 컨테이너 서비스의 경우 참고

https://github.com/openai/whisper#available-models-and-languages
https://docs.nvidia.com/datacenter/tesla/tesla-installation-notes/index.html
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#install-guide