Skip to content

Commit

Permalink
Merge branch 'master' into support-clip-vision-model
Browse files Browse the repository at this point in the history
  • Loading branch information
fxmarty committed Jun 28, 2024
2 parents a042ec4 + d0a84a9 commit 6260ad5
Show file tree
Hide file tree
Showing 23 changed files with 579 additions and 321 deletions.
56 changes: 23 additions & 33 deletions .github/workflows/check_code_quality.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
name: check_code_quality
name: Code Quality

on:
push:
branches: [ main ]
paths:
- "optimum/**.py"
- "tests/**.py"
- "examples/**.py"
branches: [main]

pull_request:
branches: [ main ]
paths:
- "optimum/**.py"
- "tests/**.py"
- "examples/**.py"
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -29,25 +21,23 @@ jobs:

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Create and start a virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: |
source venv/bin/activate
pip install --upgrade pip
pip install .[quality]
- name: Check style with black
run: |
source venv/bin/activate
black --check .
- name: Check style with ruff
run: |
source venv/bin/activate
ruff .
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install --upgrade pip
pip install .[quality]
- name: Check style with black
run: |
black --check .
- name: Check style with ruff
run: |
ruff .
59 changes: 38 additions & 21 deletions .github/workflows/test_gptq.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
name: GPTQ Quantization / Test GPU
name: GPTQ / Python - Test

on:
workflow_dispatch:
schedule:
- cron: 0 1 */3 * * # at 1am every 3 days
push:
branches: [main]
paths:
- tests/gptq/**
- optimum/gptq/**
- .github/workflows/test_gptq.yml
pull_request:
types: [opened, synchronize, reopened, labeled]
# uncomment to enable on PR merge on main branch:
#push:
# branches:
# - main
branches: [main]
paths:
- tests/gptq/**
- optimum/gptq/**
- .github/workflows/test_gptq.yml
schedule:
# every day at midnight
- cron: "0 0 * * *"

jobs:
do-the-job:
if: ${{ (github.event_name == 'workflow_dispatch') || (github.event_name == 'schedule') || contains( github.event.pull_request.labels.*.name, 'gpu-test') }}
name: Start self-hosted EC2 runner
test_gptq:
runs-on: [single-gpu, nvidia-gpu, t4, ci]
env:
AWS_REGION: us-east-1

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build image
run: |
docker build -f tests/gptq/Dockerfile_quantization_gpu -t gptq-gpu .
- name: Test with unittest within docker container
run: |
docker run --rm --gpus all -v $(pwd)/hf_cache:/root/.cache/huggingface --workdir=/workspace/optimum/tests gptq-gpu:latest
- name: Checkout code
uses: actions/checkout@v4

- name: Run tests
uses: addnab/docker-run-action@v3
with:
image: pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime
# latest auto-gptq was built with pytorch 2.2 and cuda 12.1
options: |
--rm
--gpus all
--shm-size 16G
--env RUN_SLOW=1
--env HF_HOME=/mnt/cache/
--volume /mnt/cache/:/mnt/cache/
--volume ${{ github.workspace }}:/workspace
--workdir /workspace
run: |
pip install auto-gptq
pip install -e .[tests]
pytest tests/gptq -s -vvvv --durations=0
42 changes: 23 additions & 19 deletions .github/workflows/test_offline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Offline usage / Python - Test

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -15,29 +15,33 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: [3.8, 3.9]
os: [ubuntu-20.04]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters,onnxruntime]
- name: Test with unittest
run: |
HF_HOME=/tmp/ huggingface-cli download hf-internal-testing/tiny-random-gpt2
- name: Checkout code
uses: actions/checkout@v4

HF_HOME=/tmp/ HF_HUB_OFFLINE=1 optimum-cli export onnx --model hf-internal-testing/tiny-random-gpt2 gpt2_onnx --task text-generation
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

huggingface-cli download hf-internal-testing/tiny-random-gpt2
- name: Install dependencies for pytorch export
run: |
pip install .[tests,exporters,onnxruntime]
HF_HUB_OFFLINE=1 optimum-cli export onnx --model hf-internal-testing/tiny-random-gpt2 gpt2_onnx --task text-generation
- name: Test with pytest
run: |
HF_HOME=/tmp/ huggingface-cli download hf-internal-testing/tiny-random-gpt2
pytest tests/onnxruntime/test_modeling.py -k "test_load_model_from_hub and not from_hub_onnx" -s -vvvvv
HF_HOME=/tmp/ HF_HUB_OFFLINE=1 optimum-cli export onnx --model hf-internal-testing/tiny-random-gpt2 gpt2_onnx --task text-generation
HF_HUB_OFFLINE=1 pytest tests/onnxruntime/test_modeling.py -k "test_load_model_from_hub and not from_hub_onnx" -s -vvvvv
huggingface-cli download hf-internal-testing/tiny-random-gpt2
HF_HUB_OFFLINE=1 optimum-cli export onnx --model hf-internal-testing/tiny-random-gpt2 gpt2_onnx --task text-generation
pytest tests/onnxruntime/test_modeling.py -k "test_load_model_from_hub and not from_hub_onnx" -s -vvvvv
HF_HUB_OFFLINE=1 pytest tests/onnxruntime/test_modeling.py -k "test_load_model_from_hub and not from_hub_onnx" -s -vvvvv
18 changes: 12 additions & 6 deletions docs/source/_redirects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ habana/tutorials/pretraining: habana/usage_guides/pretraining

# Optimum Intel
intel_index: intel/index
intel_quickstart: intel/optimization_inc
intel_configuration: intel/reference_inc
intel_optimization: intel/optimization_inc
intel_quantization: intel/optimization_inc
intel_pruning: intel/optimization_inc
intel_trainer: intel/reference_inc
intel_quickstart: intel/index
intel_configuration: intel/neural_compressor/reference
intel_optimization: intel/neural_compressor/optimization
intel_quantization: intel/neural_compressor/optimization
intel_pruning: intel/neural_compressor/optimization
intel_trainer: intel/neural_compressor/reference
intel/inference: intel/openvino/inference
intel/optimization_ov: intel/openvino/optimization
intel/reference_ov: intel/openvino/reference
intel/optimization_inc: intel/neural_compressor/optimization
intel/distributed_training: intel/neural_compressor/distributed_training
intel/reference_inc: intel/neural_compressor/reference

# Optimum Neuron
docs/optimum-neuron/index: /docs/optimum-neuron/index
Expand Down
30 changes: 26 additions & 4 deletions optimum/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import json
import os
import re
import warnings
from typing import Any, Dict, List, Tuple, Union

from huggingface_hub import HfFolder
from packaging import version
from transformers import PretrainedConfig
from transformers import __version__ as transformers_version_str
Expand Down Expand Up @@ -93,7 +93,19 @@ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub:
repo_id = self._create_repo(repo_id, **kwargs)

use_auth_token = kwargs.get("use_auth_token", None)
token = HfFolder.get_token() if use_auth_token is True else use_auth_token
token = kwargs.get("token", None)

if use_auth_token is not None:
warnings.warn(
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
FutureWarning,
)
if token is not None:
raise ValueError(
"You cannot use both `use_auth_token` and `token` arguments at the same time."
)
kwargs["token"] = use_auth_token
token = use_auth_token

files_timestamps = self._get_files_timestamps(save_directory)

Expand Down Expand Up @@ -197,6 +209,7 @@ def _get_config_dict(
resume_download = kwargs.pop("resume_download", False)
proxies = kwargs.pop("proxies", None)
use_auth_token = kwargs.pop("use_auth_token", None)
token = kwargs.pop("token", None)
local_files_only = kwargs.pop("local_files_only", False)
revision = kwargs.pop("revision", None)
trust_remote_code = kwargs.pop("trust_remote_code", None)
Expand All @@ -205,6 +218,15 @@ def _get_config_dict(
from_auto_class = kwargs.pop("_from_auto", False)
commit_hash = kwargs.pop("_commit_hash", None)

if use_auth_token is not None:
warnings.warn(
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
FutureWarning,
)
if token is not None:
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
token = use_auth_token

if trust_remote_code is True:
logger.warning(
"The argument `trust_remote_code` is to be used with Auto classes. It has no effect here and is"
Expand Down Expand Up @@ -255,7 +277,7 @@ def _get_config_dict(
proxies=proxies,
resume_download=resume_download,
local_files_only=local_files_only,
use_auth_token=use_auth_token,
token=token,
user_agent=user_agent,
)
else:
Expand All @@ -268,7 +290,7 @@ def _get_config_dict(
proxies=proxies,
resume_download=resume_download,
local_files_only=local_files_only,
use_auth_token=use_auth_token,
token=token,
user_agent=user_agent,
revision=revision,
subfolder=subfolder,
Expand Down
21 changes: 17 additions & 4 deletions optimum/exporters/onnx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Entry point to the optimum.exporters.onnx command line."""

import argparse
import warnings
from pathlib import Path

from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
Expand Down Expand Up @@ -66,6 +67,7 @@ def main_export(
force_download: bool = False,
local_files_only: bool = False,
use_auth_token: Optional[Union[bool, str]] = None,
token: Optional[Union[bool, str]] = None,
for_ort: bool = False,
do_validation: bool = True,
model_kwargs: Optional[Dict[str, Any]] = None,
Expand Down Expand Up @@ -135,9 +137,11 @@ def main_export(
cached versions if they exist.
local_files_only (`Optional[bool]`, defaults to `False`):
Whether or not to only look at local files (i.e., do not try to download the model).
use_auth_token (`Optional[str]`, defaults to `None`):
use_auth_token (`Optional[Union[bool,str]]`, defaults to `None`):
Deprecated. Please use the `token` argument instead.
token (`Optional[Union[bool,str]]`, defaults to `None`):
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
when running `transformers-cli login` (stored in `~/.huggingface`).
when running `huggingface-cli login` (stored in `huggingface_hub.constants.HF_TOKEN_PATH`).
model_kwargs (`Optional[Dict[str, Any]]`, defaults to `None`):
Experimental usage: keyword arguments to pass to the model during
the export. This argument should be used along the `custom_onnx_configs` argument
Expand Down Expand Up @@ -174,6 +178,15 @@ def main_export(
```
"""

if use_auth_token is not None:
warnings.warn(
"The `use_auth_token` argument is deprecated and will be removed soon. Please use the `token` argument instead.",
FutureWarning,
)
if token is not None:
raise ValueError("You cannot use both `use_auth_token` and `token` arguments at the same time.")
token = use_auth_token

if fp16:
if dtype is not None:
raise ValueError(
Expand Down Expand Up @@ -250,7 +263,7 @@ def main_export(
subfolder=subfolder,
revision=revision,
cache_dir=cache_dir,
use_auth_token=use_auth_token,
token=token,
local_files_only=local_files_only,
force_download=force_download,
trust_remote_code=trust_remote_code,
Expand Down Expand Up @@ -283,7 +296,7 @@ def main_export(
subfolder=subfolder,
revision=revision,
cache_dir=cache_dir,
use_auth_token=use_auth_token,
token=token,
local_files_only=local_files_only,
force_download=force_download,
trust_remote_code=trust_remote_code,
Expand Down
Loading

0 comments on commit 6260ad5

Please sign in to comment.