Skip to content

Commit

Permalink
Merge branch 'main' into add-bark
Browse files Browse the repository at this point in the history
  • Loading branch information
ylacombe authored Jul 27, 2023
2 parents 29f31b8 + 38061a6 commit 377f505
Show file tree
Hide file tree
Showing 57 changed files with 2,853 additions and 1,011 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/build_main_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ jobs:
repository: 'huggingface/optimum-intel'
path: optimum-intel

- uses: actions/checkout@v2
with:
repository: 'huggingface/optimum-furiosa'
path: optimum-furiosa

- name: Set environment variables
run: |
cd optimum
Expand Down Expand Up @@ -76,18 +81,41 @@ jobs:
- name: Make Habana documentation
run: |
sudo docker system prune -a -f
cd optimum-habana
make doc BUILD_DIR=habana-doc-build VERSION=${{ env.VERSION }}
sudo mv habana-doc-build ../optimum
cd ..
- name: Make Intel documentation
run: |
sudo docker system prune -a -f
cd optimum-intel
make doc BUILD_DIR=intel-doc-build VERSION=${{ env.VERSION }}
sudo mv intel-doc-build ../optimum
cd ..
- name: Make Furiosa documentation
run: |
cd optimum-furiosa
pip install .
sudo apt update
sudo apt install -y ca-certificates apt-transport-https gnupg
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 5F03AFA423A751913F249259814F888B20B09A7E
sudo tee -a /etc/apt/auth.conf.d/furiosa.conf > /dev/null <<EOT
machine archive.furiosa.ai
login ${{ secrets.FURIOSA_ACCESS_KEY }}
password ${{ secrets.FURIOSA_SECRET_ACCESS_KEY }}
EOT
sudo chmod 400 /etc/apt/auth.conf.d/furiosa.conf
sudo tee -a /etc/apt/sources.list.d/furiosa.list <<EOT
deb [arch=amd64] https://archive.furiosa.ai/ubuntu jammy restricted
EOT
sudo apt update && sudo apt install -y furiosa-libnux
doc-builder build optimum.furiosa docs/source/ --build_dir furiosa-doc-build --version pr_$PR_NUMBER --version_tag_suffix "" --html --clean
mv furiosa-doc-build ../optimum
cd ..
- name: Make Optimum documentation
run: |
sudo docker system prune -a -f
Expand All @@ -101,7 +129,7 @@ jobs:
- name: Combine subpackage documentation
run: |
cd optimum
sudo python docs/combine_docs.py --subpackages graphcore habana intel neuron --version ${{ env.VERSION }}
sudo python docs/combine_docs.py --subpackages graphcore habana intel neuron furiosa --version ${{ env.VERSION }}
cd ..
- name: Push to repositories
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/build_pr_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
repository: 'huggingface/optimum-intel'
path: optimum-intel

- uses: actions/checkout@v2
with:
repository: 'huggingface/optimum-furiosa'
path: optimum-furiosa

- name: Setup environment
run: |
pip uninstall -y doc-builder
Expand All @@ -61,18 +66,41 @@ jobs:
- name: Make Habana documentation
run: |
sudo docker system prune -a -f
cd optimum-habana
make doc BUILD_DIR=habana-doc-build VERSION=pr_$PR_NUMBER
sudo mv habana-doc-build ../optimum
cd ..
- name: Make Intel documentation
run: |
sudo docker system prune -a -f
cd optimum-intel
make doc BUILD_DIR=intel-doc-build VERSION=pr_$PR_NUMBER
sudo mv intel-doc-build ../optimum
cd ..
- name: Make Furiosa documentation
run: |
cd optimum-furiosa
pip install .
sudo apt update
sudo apt install -y ca-certificates apt-transport-https gnupg
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 5F03AFA423A751913F249259814F888B20B09A7E
sudo tee -a /etc/apt/auth.conf.d/furiosa.conf > /dev/null <<EOT
machine archive.furiosa.ai
login ${{ secrets.FURIOSA_ACCESS_KEY }}
password ${{ secrets.FURIOSA_SECRET_ACCESS_KEY }}
EOT
sudo chmod 400 /etc/apt/auth.conf.d/furiosa.conf
sudo tee -a /etc/apt/sources.list.d/furiosa.list <<EOT
deb [arch=amd64] https://archive.furiosa.ai/ubuntu jammy restricted
EOT
sudo apt update && sudo apt install -y furiosa-libnux
doc-builder build optimum.furiosa docs/source/ --build_dir furiosa-doc-build --version pr_$PR_NUMBER --version_tag_suffix "" --html --clean
mv furiosa-doc-build ../optimum
cd ..
- name: Make Optimum documentation
run: |
sudo docker system prune -a -f
Expand All @@ -83,7 +111,7 @@ jobs:
- name: Combine subpackage documentation
run: |
cd optimum
sudo python docs/combine_docs.py --subpackages graphcore habana intel neuron --version pr_$PR_NUMBER
sudo python docs/combine_docs.py --subpackages graphcore habana intel neuron furiosa --version pr_$PR_NUMBER
sudo mv optimum-doc-build ../
cd ..
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_onnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install .[tests,onnxruntime] "tensorflow<2.12.0" tf2onnx
pip install .[tests,onnxruntime] tensorflow tf2onnx
- name: Test with unittest
working-directory: tests
run: |
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ If you'd like to use the accelerator-specific features of 🤗 Optimum, you can

| Accelerator | Installation |
|:-----------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------|
| [ONNX Runtime](https://onnxruntime.ai/docs/) | `python -m pip install optimum[onnxruntime]` |
| [Intel Neural Compressor](https://www.intel.com/content/www/us/en/developer/tools/oneapi/neural-compressor.html) | `python -m pip install optimum[neural-compressor]`|
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `python -m pip install optimum[openvino,nncf]` |
| [Habana Gaudi Processor (HPU)](https://habana.ai/training/) | `python -m pip install optimum[habana]` |
| [ONNX Runtime](https://onnxruntime.ai/docs/) | `pip install --upgrade-strategy eager optimum[onnxruntime]` |
| [Intel Neural Compressor](https://www.intel.com/content/www/us/en/developer/tools/oneapi/neural-compressor.html) | `pip install --upgrade-strategy eager optimum[neural-compressor]`|
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `pip install --upgrade-strategy eager optimum[openvino,nncf]` |
| [Habana Gaudi Processor (HPU)](https://habana.ai/training/) | `pip install --upgrade-strategy eager optimum[habana]` |
| [FuriosaAI](https://www.furiosa.ai/) | `pip install --upgrade-strategy eager optimum[furiosa]` |

The `--upgrade-strategy eager` option is needed to ensure the different packages are upgraded to the latest possible version.

To install from source:

```bash
python -m pip install git+https://github.com/huggingface/optimum.git
```

For the accelerator-specific features, append `#egg=optimum[accelerator_type]` to the above command:
For the accelerator-specific features, append `optimum[accelerator_type]` to the above command:

```bash
python -m pip install git+https://github.com/huggingface/optimum.git#egg=optimum[onnxruntime]
python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
```

## Accelerated Inference
Expand Down Expand Up @@ -59,7 +62,7 @@ The [export](https://huggingface.co/docs/optimum/exporters/overview) and optimiz

### OpenVINO

This requires to install the OpenVINO extra by doing `pip install optimum[openvino,nncf]`
This requires to install the OpenVINO extra by doing `pip install --upgrade-strategy eager optimum[openvino,nncf]`

To load a model and run inference with OpenVINO Runtime, you can just replace your `AutoModelForXxx` class with the corresponding `OVModelForXxx` class. To load a PyTorch checkpoint and convert it to the OpenVINO format on-the-fly, you can set `export=True` when loading your model.

Expand All @@ -82,7 +85,7 @@ You can find more examples in the [documentation](https://huggingface.co/docs/op

### Neural Compressor

This requires to install the Neural Compressor extra by doing `pip install optimum[neural-compressor]`
This requires to install the Neural Compressor extra by doing `pip install --upgrade-strategy eager optimum[neural-compressor]`

Dynamic quantization can be applied on your model:

Expand Down Expand Up @@ -167,7 +170,7 @@ We support many providers:

### Habana

This requires to install the Habana extra by doing `pip install optimum[habana]`
This requires to install the Habana extra by doing `pip install --upgrade-strategy eager optimum[habana]`

```diff
- from transformers import Trainer, TrainingArguments
Expand Down
5 changes: 2 additions & 3 deletions docs/combine_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def rename_subpackage_toc(subpackage: str, toc: Dict):
# if "local" is not in file, it means we have a subsection, hence the recursive call
rename_subpackage_toc(subpackage, [file])

# Just keep the name of the partner
toc[0]["title"] = toc[0]["title"].split("Optimum ")[-1]


def rename_copy_subpackage_html_paths(subpackage: str, subpackage_path: Path, optimum_path: Path, version: str):
"""
Expand Down Expand Up @@ -138,6 +135,8 @@ def main():
subpackage_toc = yaml.safe_load(f)
# Extend table of contents sections with the subpackage name as the parent folder
rename_subpackage_toc(subpackage, subpackage_toc)
# Just keep the name of the partner in the TOC title
subpackage_toc[0]["title"] = subpackage_toc[0]["title"].split("Optimum ")[-1]
if subpackage != "graphcore":
# Update optimum table of contents
base_toc.insert(1, subpackage_toc[0])
Expand Down
1 change: 1 addition & 0 deletions docs/source/bettertransformer/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The list of supported model below:
- [BART](https://arxiv.org/abs/1910.13461)
- [BERT](https://arxiv.org/abs/1810.04805)
- [BERT-generation](https://arxiv.org/abs/1907.12461)
- [BLIP-2](https://arxiv.org/abs/2301.12597)
- [CamemBERT](https://arxiv.org/abs/1911.03894)
- [CLIP](https://arxiv.org/abs/2103.00020)
- [CodeGen](https://arxiv.org/abs/2203.13474)
Expand Down
8 changes: 4 additions & 4 deletions docs/source/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ As such, Optimum enables developers to efficiently use any of these platforms wi
><div class="w-full text-center bg-gradient-to-br from-orange-400 to-orange-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">AWS Trainium/Inferentia</div>
<p class="text-gray-700">Accelerate your training and inference workflows with <a href="https://aws.amazon.com/machine-learning/trainium/">AWS Trainium</a> and <a href="https://aws.amazon.com/machine-learning/inferentia/">AWS Inferentia</a></p>
</a>
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./furiosa/index"
><div class="w-full text-center bg-gradient-to-br from-green-400 to-green-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">FuriosaAI</div>
<p class="text-gray-700">Fast and efficient inference on <a href="https://www.furiosa.ai/">FuriosaAI WARBOY</a></p>
</a>
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./onnxruntime/overview"
><div class="w-full text-center bg-gradient-to-br from-pink-400 to-pink-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">ONNX Runtime</div>
<p class="text-gray-700">Apply quantization and graph optimization to accelerate Transformers models training and inference with <a href="https://onnxruntime.ai/">ONNX Runtime</a></p>
</a>
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./exporters/overview"
><div class="w-full text-center bg-gradient-to-br from-green-400 to-green-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Exporters</div>
<p class="text-gray-700">Export your PyTorch or TensorFlow model to different formats such as ONNX and TFLite</p>
</a>
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./bettertransformer/overview"
><div class="w-full text-center bg-gradient-to-br from-yellow-400 to-yellow-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">BetterTransformer</div>
<p class="text-gray-700">A one-liner integration to use <a href="https://pytorch.org/blog/a-better-transformer-for-fast-transformer-encoder-inference/">PyTorch's BetterTransformer</a> with Transformers models</p>
Expand Down
15 changes: 8 additions & 7 deletions docs/source/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ If you'd like to use the accelerator-specific features of 🤗 Optimum, you can

| Accelerator | Installation |
|:-----------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------|
| [ONNX runtime](https://onnxruntime.ai/docs/) | `python -m pip install optimum[onnxruntime]` |
| [Intel Neural Compressor (INC)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/neural-compressor.html) | `python -m pip install optimum[neural-compressor]`|
| [Intel OpenVINO](https://docs.openvino.ai/latest/index.html) | `python -m pip install optimum[openvino,nncf]` |
| [Graphcore IPU](https://www.graphcore.ai/products/ipu) | `python -m pip install optimum[graphcore]` |
| [Habana Gaudi Processor (HPU)](https://habana.ai/training/) | `python -m pip install optimum[habana]` |
| [ONNX runtime](https://onnxruntime.ai/docs/) | `pip install --upgrade-strategy eager install optimum[onnxruntime]`|
| [Intel Neural Compressor (INC)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/neural-compressor.html) | `pip install --upgrade-strategy eager optimum[neural-compressor]` |
| [Intel OpenVINO](https://docs.openvino.ai/latest/index.html) | `pip install --upgrade-strategy eager optimum[openvino,nncf]` |
| [Habana Gaudi Processor (HPU)](https://habana.ai/training/) | `pip install --upgrade-strategy eager optimum[habana]` |
| [FuriosaAI](https://www.furiosa.ai/) | `pip install --upgrade-strategy eager optimum[furiosa]` |

The `--upgrade-strategy eager` option is needed to ensure the different packages are upgraded to the latest possible version.

If you'd like to play with the examples or need the bleeding edge of the code and can't wait for a new release, you can install the base library from source as follows:

```bash
python -m pip install git+https://github.com/huggingface/optimum.git
```

For the accelerator-specific features, you can install them by appending `#egg=optimum[accelerator_type]` to the `pip` command, e.g.
For the accelerator-specific features, you can install them by appending `optimum[accelerator_type]` to the `pip` command, e.g.

```bash
python -m pip install git+https://github.com/huggingface/optimum.git#egg=optimum[onnxruntime]
python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
```
9 changes: 9 additions & 0 deletions docs/source/onnxruntime/package_reference/modeling_ort.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,12 @@ The following ORT classes are available for the following custom tasks.
#### ORTStableDiffusionInpaintPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionInpaintPipeline


#### ORTStableDiffusionXLPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionXLPipeline

#### ORTStableDiffusionXLImg2ImgPipeline

[[autodoc]] onnxruntime.ORTStableDiffusionXLImg2ImgPipeline
51 changes: 48 additions & 3 deletions docs/source/onnxruntime/usage_guides/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ It is also possible, just as with regular [`~transformers.PreTrainedModel`]s, to
... )
```

## Export and inference of sequence-to-sequence models
## Sequence-to-sequence models

Sequence-to-sequence (Seq2Seq) models can also be used when running inference with ONNX Runtime. When Seq2Seq models
are exported to the ONNX format, they are decomposed into three parts that are later combined during inference:
Expand Down Expand Up @@ -92,7 +92,7 @@ Here is an example of how you can load a T5 model to the ONNX format and run inf
>>> # [{'translation_text': "Il n'est jamais sorti sans un livre sous son bras, et il est souvent revenu avec deux."}]
```

## Export and inference of Stable Diffusion models
## Stable Diffusion

Stable Diffusion models can also be used when running inference with ONNX Runtime. When Stable Diffusion models
are exported to the ONNX format, they are split into four components that are later combined during inference:
Expand All @@ -104,7 +104,7 @@ are exported to the ONNX format, they are split into four components that are la
Make sure you have 🤗 Diffusers installed.

To install `diffusers`:
```
```bash
pip install diffusers
```

Expand Down Expand Up @@ -183,3 +183,48 @@ mask_image = download_image(mask_url).resize((512, 512))
prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
```


## Stable Diffusion XL

Before using `ORTStableDiffusionXLPipeline` make sure to have `diffusers` and `invisible_watermark` installed. You can install the libraries as follows:

```bash
pip install diffusers
pip install invisible-watermark>=2.0
```

### Text-to-Image

Here is an example of how you can load a PyTorch SD XL model, convert it to ONNX on-the-fly and run inference using ONNX Runtime:

```python
from optimum.onnxruntime import ORTStableDiffusionXLPipeline

model_id = "stabilityai/stable-diffusion-xl-base-0.9"
pipeline = ORTStableDiffusionXLPipeline.from_pretrained(model_id, export=True)
prompt = "sailing ship in storm by Leonardo da Vinci"
image = pipeline(prompt).images[0]

# Don't forget to save the ONNX model
save_directory = "a_local_path"
pipeline.save_pretrained(save_directory)

```

### Image-to-Image

The image can be refined by making use of a model like [stabilityai/stable-diffusion-xl-refiner-0.9](https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-0.9). In this case, you only have to output the latents from the base model.


```python
from optimum.onnxruntime import ORTStableDiffusionXLImg2ImgPipeline

use_refiner = True
model_id = "stabilityai/stable-diffusion-xl-refiner-0.9"
refiner = ORTStableDiffusionXLImg2ImgPipeline.from_pretrained(model_id, export=True)

image = pipeline(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
image = refiner(prompt=prompt, image=image[None, :]).images[0]
image.save("sailing_ship.png")
```
Loading

0 comments on commit 377f505

Please sign in to comment.