Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 6 min read How-to mediumAdept

Getting Started with Hugging Face Transformers for IPUs with Optimum

Optimum Graphcore lets Hugging Face Transformers models be fine-tuned on Graphcore IPUs with minimal code changes, starting with an IPU-optimized BERT. The walkthrough covers enabling the Poplar SDK and PopART on an IPU-POD16 in Graphcloud, installing PopTorch and optimum[graphcore], and running the run_qa.py example to fine-tune bert-base-uncased on SQuAD v1.1 via the IPUTrainer class with an ipu_config.json. Three epochs ran in about 368 seconds at roughly 721 samples/s, reaching 80.66 exact match and 88.28 F1.

Assumes: PyTorch basicsHugging Face TransformersBERT fine-tuning

Related posts

  • Deep Dive: Vision Transformers On Hugging Face Optimum Graphcore

    Hugging Face mediumAdept

    A step-by-step walkthrough of fine-tuning a pre-trained ViT model (google/vit-base-patch16-224-in21k) for multi-label disease classification on the NIH ChestX-ray14 dataset using Hugging Face Optimum Graphcore on IPUs. It covers converting text labels to N-hot arrays, building a dataset via a metadata.jsonl file and Arrow format, matching the checkpoint's preprocessing (224x224, grayscale to RGB, 0.5 mean/std normalization), and configuring IPUConfig, IPUTrainingArguments and IPUTrainer. A custom AUC_ROC metric is used for evaluation. Training runs 3 epochs with a 25% warm-up followed by cosine decay, and loss settles around 0.1. Suggested next steps for better accuracy are longer training, optimizer and learning-rate schedule changes, and loss scaling.

  • Hugging Face ❤️ TorchTPU: TPUs, Natively

    Hugging Face mediumAdept

    TorchTPU is a native PyTorch backend that makes TPU an ordinary device, replacing the lazy-tensor torch_xla path and making Optimum TPU unnecessary for running Hugging Face models. Transformers loads models with device_map="tpu", and Diffusers pipelines run with pipe.to("tpu"), optionally with torch.compile and tensor parallelism across chips. Pallas kernels from the Kernels Hub, such as a Tokamax ragged-dot MoE kernel, speed up batch-64 decoding by 21.5× on Qwen3-30B-A3B and 12.8× on Gemma 4 26B-A4B. Of the Transformers tests that run on TPU, 96.5% pass, and 34 TorchTPU issues have been reported so far, 19 of them fixed.

  • Getting Started with Transformers on Habana Gaudi

    Hugging Face mediumAdept

    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.

  • Training a language model with 🤗 Transformers using TensorFlow and TPUs

    Hugging Face mediumAdept

    Training a RoBERTa-base masked language model from scratch on WikiText with TensorFlow on TPUs, end to end: training a Unigram tokenizer with 🤗 tokenizers, tokenizing and chunking text into fixed 128-token sequences, sharding into TFRecords stored in Google Cloud Storage, and training under TPUStrategy with XLA-compatible Transformers models. Key details include initializing the model and optimizer inside the strategy scope, using a TF-native DataCollatorForLanguageModeling (return_tensors="tf"), and streaming data from GCS because TPU node host memory is small. The takeaway is that existing TF/Keras Transformers pipelines need little change to scale on TPU pods, offering an alternative to scarce GPUs.

  • Accelerated Inference with Optimum and Transformers Pipelines

    Hugging Face mediumAdept

    Optimum 1.2 adds inference support via ONNX Runtime with ORTModelForXxx classes that drop into Hugging Face Transformers pipelines in place of AutoModelForXxx. An end-to-end tutorial converts deepset/roberta-base-squad2 to ONNX, applies graph optimization (operator fusion, constant folding) with ORTOptimizer, then dynamic int8 quantization with ORTQuantizer targeting AVX512-VNNI on an m5.xlarge. Quantization shrinks the model from 473MB to 292MB while keeping 99.61% of original accuracy on SQuAD v2 (F1 81.83 vs 82.15), and latency is then benchmarked at sequence length 128.

The quest for software engineering knowledge.

Look:
Layout: