피드로 돌아가기
Powerful ASR + diarization + speculative decoding with Hugging Face Inference Endpoints
Hugging Face BlogHugging Face Blog
Backend

Hugging Face Inference Endpoints에서 커스텀 핸들러를 통해 Whisper ASR, Pyannote 기반 화자 식별, 추론 가속화를 단일 API로 통합 제공

Powerful ASR + diarization + speculative decoding with Hugging Face Inference Endpoints

2024년 5월 1일12intermediate

Context

Whisper는 우수한 오픈소스 음성인식 모델이지만, Hugging Face Inference Endpoints에 배포할 때 화자 식별(diarization) 또는 추론 가속화(speculative decoding) 같은 추가 기능을 함께 제공하려면 여러 모델을 조합하면서도 단일 API 엔드포인트로 노출해야 하는 복잡성이 발생했다.

Technical Solution

  • Whisper ASR 파이프라인을 기본 구성 요소로 배포: transformers 라이브러리의 automatic-speech-recognition 파이프라인으로 음성 텍스트 변환 수행
  • Pyannote 모델 기반 화자 식별 추가: pyannote.audio.Pipeline을 ASR 출력 위에 추가하여 전사 텍스트를 화자별로 분할
  • Speculative decoding 구현: 더 작은 어시스턴트 모델이 생성 후보를 제시하고 큰 Whisper 모델이 검증하는 두 단계 구조 도입
  • PyTorch 2.2+ Flash Attention 2 활성화: 동적 프로그래밍 기반 어텐션(SDPA)으로 추론 속도 향상
  • 모듈화된 구조 설계: handler.py(초기화/추론), diarization_utils.py(화자 식별 전후처리), config.py(모델 설정)를 분리하여 선택적 사용 가능하게 구성
  • 환경 변수 기반 모델 선택: ModelSettings Pydantic 클래스로 asr_model, assistant_model, diarization_model을 런타임에 지정

Key Takeaway

Hugging Face Inference Endpoints의 커스텀 핸들러를 활용하면 여러 오픈소스 모델을 모듈화된 파이프라인으로 조합하여 단일 API로 제공할 수 있으며, 이를 통해 배포 복잡도를 감소시키면서도 다양한 구성 옵션(ASR 전용, ASR+화자 식별, ASR+추론 가속화)을 지원할 수 있다.


음성 처리 서비스를 구축하는 엔지니어는 Whisper에 Pyannote를 조합하고 `custom handler`에서 배치 크기 1 제약 하에 어시스턴트 모델(예: distilled Whisper)을 구성하면, 화자 식별과 추론 속도를 동시에 지원하는 엔드포인트를 Inference Endpoints 위에서 구현할 수 있다.

원문 읽기