---
title: "Getting Started with Transformers on Habana Gaudi"
description: "Fine-tuning BERT for text classification on Habana Gaudi accelerators takes a few steps on AWS: launch an EC2 DL1 instance (8 Gaudi processors) from the Habana Deep Learning AMI, raise EBS storage to 50GB, and pull the Habana PyTorch container."
url: "https://swe.quest/articles/getting-started-with-transformers-on-habana-gaudi-edc0b7eeb1b053a5"
canonical: "https://huggingface.co/blog/getting-started-habana"
source: "Hugging Face"
published: "2022-04-26"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["model-training","hardware","cloud"]
---

# Getting Started with Transformers on Habana Gaudi

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-04-26, 4 min read, How-to. Original: [https://huggingface.co/blog/getting-started-habana](https://huggingface.co/blog/getting-started-habana)

## Summary

Fine-tuning BERT for text classification on Habana Gaudi accelerators takes a few steps on AWS: launch an EC2 DL1 instance (8 Gaudi processors) from the Habana Deep Learning AMI, raise EBS storage to 50GB, and pull the Habana PyTorch container. From there, Optimum Habana's run\_glue.py example fine-tunes bert-large-uncased-whole-word-masking on GLUE MRPC using a Gaudi config pulled from the Hugging Face Hub. The 3-epoch job finished in about 2 minutes 12 seconds with an eval F1 of about 0.90, and a Spot Instance cut the hourly price from $13.11 to $3.93, roughly 70% off.

Written by swe.quest, not by the author.

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

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)

## Prerequisites

- AWS EC2 basics ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))
- Docker ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- Hugging Face Transformers

## Keywords

Habana Gaudi, Optimum Habana, Amazon EC2 DL1, BERT, SynapseAI, Hugging Face Transformers, GLUE MRPC

## Related posts

- [Pre-Train BERT with Hugging Face Transformers and Habana Gaudi](https://swe.quest/articles/pre-train-bert-with-hugging-face-transformers-and-habana-gaudi-81eabeeaee082cc4.md): Hugging Face · 2022-08-22 · Medium · 10 min read · Model training, LLMs, Hardware, Cost optimization, Python
  BERT-base can be pre-trained from scratch with masked-language modeling on an AWS DL1 instance (Habana Gaudi), using Hugging Face Transformers, Datasets and Optimum Habana.
- [Accelerating Hugging Face Transformers with AWS Inferentia2](https://swe.quest/articles/accelerating-hugging-face-transformers-with-aws-inferentia2-732d2daf15bc9874.md): Hugging Face · 2023-04-17 · Easy · 5 min read · Inference & serving, Hardware, Performance engineering, Cloud platforms
  Hugging Face benchmarked popular Transformer models on AWS Inferentia2 (inf2.xlarge) against Inferentia1 (inf1.2xlarge) and an NVIDIA A10G GPU (g5.2xlarge), running 144 p95-latency experiments at batch size 1 across six architectures and sequence lengths from 8 to 512.
- [Why we’re switching to Hugging Face Inference Endpoints, and maybe you should too](https://swe.quest/articles/why-we-re-switching-to-hugging-face-inference-endpoints-and-maybe-you-should-too-bfdcddeceab350fa.md): Hugging Face · 2023-02-15 · Medium · 6 min read · Inference & serving, ML platforms, Cost optimization, Cloud platforms
  A team moved CPU-based transformer inference off a self-built FastAPI + Docker + AWS ECS/Fargate stack onto Hugging Face Inference Endpoints, collapsing deployment to train, push to Hub, deploy.
- [Fast Inference on Large Language Models: BLOOMZ on Habana Gaudi2 Accelerator](https://swe.quest/articles/fast-inference-on-large-language-models-bloomz-on-habana-gaudi2-accelerator-b18b18c9b1b881f4.md): Hugging Face · 2023-03-28 · Medium · 8 min read · Inference & serving, LLMs, Hardware, Performance engineering
  BLOOMZ (176B parameters, 352 GB in 16-bit) runs inference on a single 8-HPU Habana Gaudi2 server using Optimum Habana with Habana's DeepSpeed-inference fork, HPU graphs and a KV cache.
- [1 Billion Classifications](https://swe.quest/articles/1-billion-classifications-90168b62de6ffa1b.md): Hugging Face · 2025-02-13 · Medium · 17 min read · Inference & serving, Cost optimization, Performance engineering, Machine learning
  Processing 1B classifications or embeddings on a single-GPU baseline costs about $254 for DistilBERT sentiment classification and $409 for ModernBERT-based gte embeddings on an NVIDIA L4 ($0.8/hr), but roughly $44,500 for ColQwen2 vision embeddings.

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)
