Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HPUs (Intel® Gaudi®) support #2450

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b7069e5
Add initial imports and usage of `wrap_in_hpu_graph`
PiotrBLL Oct 31, 2024
8c3680c
Add requires_hpu marker in tests
PiotrBLL Oct 31, 2024
c7fe328
Add testing hpu file
PiotrBLL Oct 31, 2024
2365157
Update requirements
PiotrBLL Oct 31, 2024
9269b2a
Add HPU support in transcribe and timing + tests
PiotrBLL Oct 31, 2024
52062dd
Add hpu_utils
PiotrBLL Oct 31, 2024
bee2865
Fix importing habana-frameworks library conditionally
PiotrBLL Nov 5, 2024
c479ff3
Add hpu transcribe test
PiotrBLL Nov 5, 2024
6e66088
Add Dockerfile_hpu + README.md section of hpu usage
PiotrBLL Nov 5, 2024
1be8041
Add hpu usage info in jupyter notebook files
PiotrBLL Nov 5, 2024
a49838c
Add Pytorch Docker images info in README.md
PiotrBLL Nov 6, 2024
3825dd0
Rename and Fix Dockerfile.hpu, add .dockerignore, update in README.md
PiotrBLL Nov 7, 2024
9e39365
Add optimum[habana]==1.13.1 in Dockerfile.hpu
PiotrBLL Nov 7, 2024
82a5380
Fix Dockerfile.hpu `ffmpeg` package install, update README.md whisper…
PiotrBLL Nov 8, 2024
2d5a552
Fix hpu device_name typo
PiotrBLL Nov 8, 2024
50adb76
Fix warnings
PiotrBLL Nov 9, 2024
f6ccd01
Wrap model to HPU + update Dockerfile packages
PiotrBLL Nov 11, 2024
32ec355
Upgrade the Dockerfile.hpu ubuntu image
PiotrBLL Nov 11, 2024
e1d4b7b
Add checking sparse tensors in Whisper model
PiotrBLL Nov 11, 2024
d36696f
Add util checking hpu tensor
PiotrBLL Nov 11, 2024
b0cf21b
Add HPU checking in decoding and transcribe handle
PiotrBLL Nov 11, 2024
e1545f4
Fix: compute_device name in Whisper model
PiotrBLL Nov 11, 2024
adaec5a
Add requirements_hpu.txt
PiotrBLL Nov 12, 2024
866fece
Delete redundant linux packages in Dockerfile.hpu + update README.md
PiotrBLL Nov 12, 2024
3e826a2
Delete timestamps test
PiotrBLL Nov 12, 2024
6770610
Update Dockerfile.hpu and README.md files:
PiotrBLL Nov 12, 2024
8c4e659
Add word_timestamps fix in model.transcribe
PiotrBLL Nov 19, 2024
1a42019
Merge pull request #2 from BlueLabelLabs/feat/Add-HPU-support
PiotrBLL Nov 20, 2024
cd48514
Merge branch 'openai:main' into main
PiotrBLL Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.graph_dumps
34 changes: 34 additions & 0 deletions Dockerfile.hpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use the official Gaudi Docker image with PyTorch
FROM vault.habana.ai/gaudi-docker/1.18.0/ubuntu22.04/habanalabs/pytorch-installer-2.4.0:latest

# Set environment variables for Habana
ENV HABANA_VISIBLE_DEVICES=all
ENV OMPI_MCA_btl_vader_single_copy_mechanism=none
ENV PT_HPU_LAZY_ACC_PAR_MODE=0
ENV PT_HPU_ENABLE_LAZY_COLLECTIVES=1

# Set timezone to UTC and install essential packages
ENV DEBIAN_FRONTEND="noninteractive" TZ=Etc/UTC
RUN apt-get update && apt-get install -y \
tzdata \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Download and install the static build of ffmpeg
RUN mkdir -p /usr/local/bin/ffmpeg && \
cd /usr/local/bin/ffmpeg && \
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
tar -xf ffmpeg-release-amd64-static.tar.xz && \
cp -a ffmpeg-*-static/ffmpeg /usr/bin/ffmpeg && \
cp -a ffmpeg-*-static/ffprobe /usr/bin/ffprobe && \
rm -rf /usr/local/bin/ffmpeg

COPY . /workspace/whisper
WORKDIR /workspace/whisper

# Copy HPU requirements
COPY requirements_hpu.txt /workspace/requirements_hpu.txt

# Install Python packages
RUN pip install --upgrade pip \
&& pip install -r requirements_hpu.txt
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Adding `--task translate` will translate the speech into English:

whisper japanese.wav --language Japanese --task translate

The following command will transcribe speech in audio files, using the Intel® Gaudi® HPU (`--device hpu` option):

whisper audio.flac audio.mp3 audio.wav --model turbo --device hpu

Run the following to view all available options:

whisper --help
Expand Down Expand Up @@ -140,6 +144,61 @@ result = whisper.decode(model, mel, options)
print(result.text)
```

## Intel® Gaudi® hpu usage

### Build the Docker Image

```bash
docker build -t whisper_hpu:latest -f Dockerfile.hpu .
```

In the `Dockerfile.hpu`, we use the `vault.habana.ai/gaudi-docker/1.18.0/ubuntu22.04/habanalabs/pytorch-installer-2.3.1:latest` base image, make sure to replace it with the appropriate version for your environment if needed.
See the [PyTorch Docker Images for the Intel® Gaudi® Accelerator](https://developer.habana.ai/catalog/pytorch-container/) for more information.

### Run the Container

```bash
docker run -it --runtime=habana whisper_hpu:latest
```

Using a mapping volume (`-v`) is optional, but it allows you to access the Whisper repository from within the container.
You can make this by adding `-v /path/to/your/whisper:/workspace/whisper` to the `docker run` command.
If you decide to use the mapping make sure to replace `/path/to/your/whisper` with the path to the Whisper repository on your local machine.

### Command-line usage with Intel® Gaudi® hpu

To run the `transcribe` process with Intel® Gaudi® HPU, you can use the `--device hpu` option:

```bash
python3 -m whisper.transcribe audio_file.wav --model turbo --device hpu
```

* Note: Change `audio_file.wav` to the path of the audio file you want to transcribe. (Example file: https://www.kaggle.com/datasets/pavanelisetty/sample-audio-files-for-speech-recognition?resource=download)

To run the `transcribe` tests with Intel® Gaudi® HPU, make sure to install the `pytest` package:

```bash
pip install pytest
```

and run the following command:

```bash
PYTHONPATH=. pytest -s tests/test_transcribe.py::test_transcribe_hpu
```

### Python usage with Intel® Gaudi® hpu

To use Intel® Gaudi® hpu within Python, you can specify the device when loading the model:

```python
import whisper

model = whisper.load_model("turbo", device="hpu")
result = model.transcribe("audio.mp3")
print(result["text"])
```

## More examples

Please use the [🙌 Show and tell](https://github.com/openai/whisper/discussions/categories/show-and-tell) category in Discussions for sharing more example usages of Whisper and third-party extensions such as web demos, integrations with other tools, ports for different platforms, etc.
Expand Down
36 changes: 29 additions & 7 deletions notebooks/LibriSpeech.ipynb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading