---
title: "Optimizing Bark using 🤗 Transformers"
description: "Bark, Suno's four-stage transformer text-to-speech model, can be made much cheaper to run in 🤗 Transformers with three one-line optimizations: Better Transformer (Flash Attention kernel fusion), fp16 half-precision, and CPU offload of idle sub-models via Accelerate."
url: "https://swe.quest/articles/optimizing-bark-using-transformers-8cf8d4b8561c07e2"
canonical: "https://huggingface.co/blog/optimizing-bark"
source: "Hugging Face"
published: "2023-08-09"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["inference","speech-audio","performance","python"]
---

# Optimizing Bark using 🤗 Transformers

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-08-09, 11 min read, How-to. Original: [https://huggingface.co/blog/optimizing-bark](https://huggingface.co/blog/optimizing-bark)

## Summary

Bark, Suno's four-stage transformer text-to-speech model, can be made much cheaper to run in 🤗 Transformers with three one-line optimizations: Better Transformer (Flash Attention kernel fusion), fp16 half-precision, and CPU offload of idle sub-models via Accelerate. On a 100-iteration benchmark of bark-large on a TITAN RTX, combining all three cut latency 23% and memory 80% (5 GB to about 1 GB) at batch size 1. At batch size 8, fp16 roughly halves latency and nearly doubles throughput. Better Transformer is effectively free, while offload trades about 10% speed for large memory savings.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Speech & audio](https://swe.quest/tags/speech-audio.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- Hugging Face Transformers
- GPU inference ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

Bark, Hugging Face Transformers, Optimum, Accelerate, BetterTransformer, Flash Attention, EnCodec

## Related posts

- [How Together AI built the world’s fastest speech-to-text stack](https://swe.quest/articles/how-together-ai-built-the-world-s-fastest-speech-to-text-stack-b5ccd6ddea6a414d.md): Together AI · 2026-05-29 · Hard · 7 min read · Inference & serving, Speech & audio, Performance engineering, Python, Linux
  Speech-to-text serving is a full-path systems problem, because ASR models are small while audio inputs are large and need heavy CPU preprocessing.
- [Blazingly fast whisper transcriptions with Inference Endpoints](https://swe.quest/articles/blazingly-fast-whisper-transcriptions-with-inference-endpoints-d93b7d262c3a1210.md): Hugging Face · 2025-05-13 · Easy · 6 min read · Inference & serving, Speech & audio, Performance engineering
  Hugging Face Inference Endpoints now offers a Whisper deployment built on vLLM that delivers up to roughly 8x higher real-time factor (RTFx) than the Transformers implementation, with comparable word error rate.
- [Transcribe speech 100x faster and 100x cheaper with open models](https://swe.quest/articles/transcribe-speech-100x-faster-and-100x-cheaper-with-open-models-c3de3ba8f557cf48.md): Modal · 2025-07-23 · Medium · 11 min read · Speech & audio, Inference & serving, Cost optimization, Performance engineering, Serverless
  Open-weights ASR models such as NVIDIA's parakeet-tdt-0.6b-v2 and canary-1b-flash, deployed as a batch transcription service on Modal GPUs, transcribed about a week of ESB benchmark audio in roughly a minute for about $1.
- [Accelerated Inference with Optimum and Transformers Pipelines](https://swe.quest/articles/accelerated-inference-with-optimum-and-transformers-pipelines-9ff6245f88a35ca0.md): Hugging Face · 2022-05-10 · Medium · 12 min read · Inference & serving, Python, Performance engineering, Machine learning
  Optimum 1.2 adds inference support via ONNX Runtime with ORTModelForXxx classes that drop into Hugging Face Transformers pipelines in place of AutoModelForXxx.
- [Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2](https://swe.quest/articles/accelerating-pytorch-transformers-with-intel-sapphire-rapids-part-2-c41ef6f6c233e349.md): Hugging Face · 2023-02-06 · Medium · 6 min read · Inference & serving, Hardware, Performance engineering, Python
  Intel Sapphire Rapids CPUs with AMX instructions, combined with Hugging Face Optimum Intel running in bfloat16 with JIT compilation, cut p99 inference latency for DistilBERT, BERT and RoBERTa text classification by roughly 3x compared with vanilla Transformers on Ice Lake.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
