Giter Site home page Giter Site logo

xinyuye-intel / optimum-habana Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huggingface/optimum-habana

0.0 0.0 0.0 4.13 MB

Easy and lightning fast training of ๐Ÿค— Transformers on Habana Gaudi processor (HPU)

License: Apache License 2.0

Shell 0.04% Python 99.31% Makefile 0.16% Jupyter Notebook 0.49%

optimum-habana's Introduction

Optimum Habana

๐Ÿค— Optimum Habana is the interface between the ๐Ÿค— Transformers and Diffusers libraries and Habana's Gaudi processor (HPU). It provides a set of tools enabling easy model loading, training and inference on single- and multi-HPU settings for different downstream tasks. The list of officially validated models and tasks is available here. Users can try other models and tasks with only few changes.

What is a Habana Processing Unit (HPU)?

HPUs offer fast model training and inference as well as a great price-performance ratio. Check out this blog post about BERT pre-training and this article benchmarking Habana Gaudi2 versus Nvidia A100 GPUs for concrete examples. If you are not familiar with HPUs and would like to know more about them, we recommend you take a look at our conceptual guide.

Install the library and get example scripts

Option 1: Use the latest stable release

To install the latest stable release of this package

pip install --upgrade-strategy eager optimum[habana]

The --upgrade-strategy eager option is needed to ensure optimum-habana is upgraded to the latest stable release.

To use the example associated with the latest stable release, run:

git clone https://github.com/huggingface/optimum-habana
cd optimum-habana && git checkout v1.11.1

with v1.11.1 the version number of this release.

Option 2: Use the latest main branch under development

Optimum Habana is a fast-moving project, and you may want to install it from source and get the latest scripts :

pip install git+https://github.com/huggingface/optimum-habana.git
git clone https://github.com/huggingface/optimum-habana

Install dependencies

To use DeepSpeed on HPUs, you also need to run the following command:

pip install git+https://github.com/HabanaAI/[email protected]

To install the requirements for every example:

cd <example-folder>
pip install -r requirements.txt

How to use it?

Quick Start

๐Ÿค— Optimum Habana was designed with one goal in mind: to make training and inference straightforward for any ๐Ÿค— Transformers and ๐Ÿค— Diffusers user while leveraging the complete power of Gaudi processors.

Transformers Interface

There are two main classes one needs to know:

  • GaudiTrainer: the trainer class that takes care of compiling and distributing the model to run on HPUs, and performing training and evaluation.
  • GaudiConfig: the class that enables to configure Habana Mixed Precision and to decide whether optimized operators and optimizers should be used or not.

The GaudiTrainer is very similar to the ๐Ÿค— Transformers Trainer, and adapting a script using the Trainer to make it work with Gaudi will mostly consist in simply swapping the Trainer class for the GaudiTrainer one. That's how most of the example scripts were adapted from their original counterparts.

Here is an example:

- from transformers import Trainer, TrainingArguments
+ from optimum.habana import GaudiConfig, GaudiTrainer, GaudiTrainingArguments

- training_args = TrainingArguments(
+ training_args = GaudiTrainingArguments(
  # training arguments...
+ use_habana=True,
+ use_lazy_mode=True,  # whether to use lazy or eager mode
+ gaudi_config_name=path_to_gaudi_config,
)

# A lot of code here

# Initialize our Trainer
- trainer = Trainer(
+ trainer = GaudiTrainer(
    model=model,
    args=training_args,  # Original training arguments.
    train_dataset=train_dataset if training_args.do_train else None,
    eval_dataset=eval_dataset if training_args.do_eval else None,
    compute_metrics=compute_metrics,
    tokenizer=tokenizer,
    data_collator=data_collator,
)

where gaudi_config_name is the name of a model from the Hub (Gaudi configurations are stored in model repositories) or a path to a local Gaudi configuration file (you can see here how to write your own).

Diffusers Interface

You can generate images from prompts using Stable Diffusion on Gaudi using the GaudiStableDiffusionPipeline class and the [GaudiDDIMScheduler] which have been both optimized for HPUs. Here is how to use them and the differences with the ๐Ÿค— Diffusers library:

- from diffusers import DDIMScheduler, StableDiffusionPipeline
+ from optimum.habana.diffusers import GaudiDDIMScheduler, GaudiStableDiffusionPipeline


model_name = "runwayml/stable-diffusion-v1-5"

- scheduler = DDIMScheduler.from_pretrained(model_name, subfolder="scheduler")
+ scheduler = GaudiDDIMScheduler.from_pretrained(model_name, subfolder="scheduler")

- pipeline = StableDiffusionPipeline.from_pretrained(
+ pipeline = GaudiStableDiffusionPipeline.from_pretrained(
    model_name,
    scheduler=scheduler,
+   use_habana=True,
+   use_hpu_graphs=True,
+   gaudi_config="Habana/stable-diffusion",
)

outputs = generator(
    ["An image of a squirrel in Picasso style"],
    num_images_per_prompt=16,
+   batch_size=4,
)

Documentation

Check out the documentation of Optimum Habana for more advanced usage.

Validated Models

The following model architectures, tasks and device distributions have been validated for ๐Ÿค— Optimum Habana:

In the tables below, โœ”๏ธ means single-card, multi-card and DeepSpeed have all been validated.

  • Transformers:
Architecture Training Inference Tasks
BERT โœ”๏ธ โœ”๏ธ
  • text classification
  • question answering
  • language modeling
  • RoBERTa โœ”๏ธ โœ”๏ธ
  • question answering
  • language modeling
  • ALBERT โœ”๏ธ โœ”๏ธ
  • question answering
  • language modeling
  • DistilBERT โœ”๏ธ โœ”๏ธ
  • question answering
  • language modeling
  • GPT2 โœ”๏ธ โœ”๏ธ
  • language modeling
  • text generation
  • BLOOM(Z)
  • DeepSpeed
  • text generation
  • StarCoder
  • Single card
  • text generation
  • GPT-J
  • DeepSpeed
  • Single card
  • DeepSpeed
  • language modeling
  • text generation
  • GPT-NeoX
  • DeepSpeed
  • DeepSpeed
  • language modeling
  • text generation
  • OPT
  • DeepSpeed
  • text generation
  • Llama 2 / CodeLlama / Llama 3 โœ”๏ธ โœ”๏ธ
  • language modeling
  • text generation
  • question answering
  • StableLM
  • Single card
  • text generation
  • Falcon
  • LoRA
  • โœ”๏ธ
  • language modeling
  • text generation
  • CodeGen
  • Single card
  • text generation
  • MPT
  • Single card
  • text generation
  • Mistral
  • Single card
  • text generation
  • Phi โœ”๏ธ
  • Single card
  • language modeling
  • text generation
  • Mixtral
  • Single card
  • text generation
  • Persimmon
  • Single card
  • text generation
  • Qwen2
  • Single card
  • Single card
  • language modeling
  • text generation
  • Gemma โœ”๏ธ
  • Single card
  • language modeling
  • text generation
  • T5 / Flan T5 โœ”๏ธ โœ”๏ธ
  • summarization
  • translation
  • question answering
  • BART
  • Single card
  • summarization
  • translation
  • question answering
  • ViT โœ”๏ธ โœ”๏ธ
  • image classification
  • Swin โœ”๏ธ โœ”๏ธ
  • image classification
  • Wav2Vec2 โœ”๏ธ โœ”๏ธ
  • audio classification
  • speech recognition
  • Whisper โœ”๏ธ โœ”๏ธ
  • speech recognition
  • SpeechT5
  • Single card
  • text to speech
  • CLIP โœ”๏ธ โœ”๏ธ
  • contrastive image-text training
  • BridgeTower โœ”๏ธ โœ”๏ธ
  • contrastive image-text training
  • ESMFold
  • Single card
  • protein folding
  • Blip
  • Single card
  • visual question answering
  • image to text
  • OWLViT
  • Single card
  • zero shot object detection
    • Diffusers:
    Architecture Training Inference Tasks
    Stable Diffusion
  • textual inversion
  • ControlNet
  • Single card
  • text-to-image generation
  • Stable Diffusion XL
  • fine-tuning
  • Single card
  • text-to-image generation
  • LDM3D
  • Single card
  • text-to-image generation
    • TRL:
    Architecture Training Inference Tasks
    Llama 2 โœ”๏ธ
  • DPO Pipeline
  • Llama 2 โœ”๏ธ
  • PPO Pipeline
  • Stable Diffusion โœ”๏ธ
  • DDPO Pipeline
  • Other models and tasks supported by the ๐Ÿค— Transformers and ๐Ÿค— Diffusers library may also work. You can refer to this section for using them with ๐Ÿค— Optimum Habana. Besides, this page explains how to modify any example from the ๐Ÿค— Transformers library to make it work with ๐Ÿค— Optimum Habana.

    If you find any issues while using those, please open an issue or a pull request.

    Gaudi Setup

    Please refer to Habana Gaudi's official installation guide.

    Tests should be run in a Docker container based on Habana Docker images.

    The current version has been validated for SynapseAI 1.15.

    Development

    Check the contributor guide for instructions.

    optimum-habana's People

    Contributors

    ankurneog avatar baihuijin avatar bgoldberg-habana avatar bhargaveede avatar fxmarty avatar hlahkar avatar hsubramony avatar huijuanzh avatar jiminha avatar jychen21 avatar kalyanjk avatar lewtun avatar libinta avatar lkk12014402 avatar mandy-li avatar mohitintel avatar polisettyvarma avatar regisss avatar schoi-habana avatar skaulintel avatar skavulya avatar ssarkar2 avatar sywangyi avatar tjs-intel avatar vidyasiv avatar vivekgoe avatar xinyuye-intel avatar xt574chen avatar yeonsily avatar zhaifeiyue avatar

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.