Getting Started with Transformers on Habana Gaudi
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.
Related posts
- Pre-Train BERT with Hugging Face Transformers and Habana Gaudi
Hugging Face mediumAdeptBERT-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. The workflow merges BookCorpus and Wikipedia, trains a 32k-vocab tokenizer, and packs the text into 512-token chunks on a CPU instance. Training then runs data-parallel across 8 HPUs by swapping Trainer for GaudiTrainer, launched remotely with EC2 Remote Runner. 100k steps at global batch 256 took about 12.5 hours, which projects a full 1M-step pre-training to roughly $1,650. That is about 25% cheaper than a DeepSpeed V100 baseline estimated at around $2,075.
- Accelerating Hugging Face Transformers with AWS Inferentia2
Hugging Face easyNoviceHugging 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. On average Inferentia2 delivered 4.5x lower latency than the A10G and 4x lower than Inferentia1, with BERT-base about 6x faster up to sequence length 256 and ViT-base about 2x faster than the GPU. The GPU runs were unoptimized fp32. Models compile for Inferentia2 through Optimum Neuron and the AWS Neuron SDK, and instances start at $0.76/hour.
- Why we’re switching to Hugging Face Inference Endpoints, and maybe you should too
Hugging Face mediumAdeptA 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. In ab benchmarks with a RoBERTa text classifier, a 4-vCPU endpoint answered in 80±30 ms versus ~200 ms on their ECS container, and an 8-vCPU endpoint in 43 ms. Cost runs 24–50% higher than Fargate (about $60/month more for a large instance), which they judge worth it without a dedicated MLOps team, though not at hundreds of services. The main gap they note is the lack of a Terraform provider; they deploy with their own hugie CLI.
- Fast Inference on Large Language Models: BLOOMZ on Habana Gaudi2 Accelerator
Hugging Face mediumAdeptBLOOMZ (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. In batch-1 greedy generation of 100 tokens, Gaudi2 is 1.42x faster than an 8x A100 80GB setup on the 176B model (3.1 s vs 4.4 s) and 2.89x faster on BLOOMZ-7B. Unlike A100, Gaudi2 benefits from model parallelism on the 7B model. First-gen Gaudi (AWS DL1, about $13/hr) offers better price-performance than A100 for the 7B checkpoint, and the post includes commands to reproduce the benchmark or run generation over any Hugging Face dataset.
- 1 Billion Classifications
Hugging Face mediumAdeptProcessing 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. The method serves models with Infinity on Hugging Face Inference Endpoints and load-tests them with k6's shared-iterations executor. It sweeps batch size and virtual users using an exponential-then-binary search with a 2% improvement threshold, then scales cost horizontally by adding replicas. The best configurations were batch 64 / 448 VUs for classification, 32 / 256 for embedding and 4 / 4 for vision. The cheap T4 lost to the L4, partly because Flash Attention 2 requires newer GPUs.