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

[Test] Add transformers test #1175

Merged
merged 19 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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
7 changes: 7 additions & 0 deletions .github/scripts/spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import torch

DEVICE_NAME = 'xpu'

MANUAL_SEED_FN = torch.xpu.manual_seed
EMPTY_CACHE_FN = torch.xpu.empty_cache
DEVICE_COUNT_FN = torch.xpu.device_count
174 changes: 174 additions & 0 deletions .github/workflows/_linux_transformers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Linux Transformers Test

on:
pull_request:
branches:
- main
paths:
- '.github/scripts/spec.py'
- '.github/workflows/_linux_transformers.yml'
workflow_call:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add on: pull_request. We need verify workflow before merging.

inputs:
pytorch:
required: false
type: string
default: 'nightly'
description: Pytorch branch/commit
python:
required: false
type: string
default: '3.10'
description: Python version
runner:
required: true
type: string
default: 'linux.idc.xpu'
description: Runner label
driver:
required: false
type: string
default: 'lts'
description: Driver lts/rolling
nightly_whl:
required: false
type: string
default: ''
description: Pytorch nightly wheel version
transformers:
required: false
type: string
default: 'v4.47.0'
description: Transformers version
workflow_dispatch:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work. You will need to duplicate all inputs from workflow_call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. Just check. I have renamed workflow_call.

inputs:
transformers_test:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this. Let's focus on a single test - backbone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, drop transformers_test. We will most likely rework how to setup test scope.

required: true
type: string
default: ''
description: Test scope. `test_py,benchmark,generation,models,pipelines,trainer,utils,backbone,trainer_not_ray` Delimiter is comma

permissions: read-all

jobs:
Torch-XPU-Transformers-Tests:
runs-on: ${{ inputs.runner != '' && inputs.runner || 'linux.idc.xpu' }}
env:
NEOReadDebugKeys: ${{ inputs.driver == 'rolling' && '1' || '0' }}
DisableScratchPages: ${{ inputs.driver == 'rolling' && '1' || '0' }}
python: ${{ inputs.python != '' && inputs.python || '3.10' }}
pytorch: ${{ inputs.pytorch != '' && inputs.pytorch || 'nightly' }}
TRANSFORMERS_TEST_DEVICE_SPEC: 'spec.py'
steps:
- name: Checkout torch-xpu-ops
uses: actions/checkout@v4
with:
path: torch-xpu-ops
- name: Checkout Transformers
uses: actions/checkout@v4
with:
repository: huggingface/transformers
ref: ${{ inputs.transformers != '' && inputs.transformers || 'v4.47.0' }}
path: transformers
- name: Prepare OS environment
run: |
sudo apt-get update
sudo apt-get install -y \
espeak-ng \
git-lfs \
pkg-config \
libavcodec-dev \
libavdevice-dev \
libavfilter-dev \
libavformat-dev \
libavutil-dev \
libswresample-dev \
libswscale-dev
git lfs install
- name: Prepare Conda ENV
run: |
which conda && conda clean -ay
conda remove --all -y -n huggingface_transformers_test || rm -rf $(dirname ${CONDA_EXE})/../envs/huggingface_transformers_test
conda create -y -n huggingface_transformers_test python=${{ env.python }}
source activate huggingface_transformers_test
- name: Prepare Stock XPU Pytorch
run: |
pwd
source activate huggingface_transformers_test
if [ -z "${{ inputs.nightly_whl }}" ]; then
pip install torch torchvision torchaudio --pre --index-url https://download.pytorch.org/whl/nightly/xpu
else
pip install torch==$(echo ${{ inputs.nightly_whl }}) torchvision torchaudio --pre --index-url https://download.pytorch.org/whl/nightly/xpu
fi
- name: Prepare Transformers
run: |
pwd
source activate huggingface_transformers_test
cd transformers
pip install -e .
pip install -e ".[dev-torch,testing,video]"
rm -rf tests_log && mkdir -p tests_log
rm -rf reports
cp ${{ github.workspace }}/torch-xpu-ops/.github/scripts/spec.py ./
- name: Report installed versions
id: installed
run: |
source activate huggingface_transformers_test
echo "TORCH_BRANCH_ID=$(python -c 'import torch; print(torch.__version__)')" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
echo "TORCH_COMMIT_ID=$(python -c 'import torch; print(torch.version.git_version)')" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
echo "pip installed packages:"
pip list | tee ${{ github.workspace }}/transformers/tests_log/pip_list.txt
echo "GPU render nodes:"
cat /sys/class/drm/render*/device/device | tee ${{ github.workspace }}/transformers/tests_log/device_IDs.txt
- name: Sanitry check installed packages
run: |
source activate huggingface_transformers_test
# These checks are to exit earlier if for any reason Transformers
# reinstalled torch packages back to CUDA versions (not expected).
pip show torch | grep Version | grep xpu
pip show torchaudio | grep Version | grep xpu
pip show torchvision | grep Version | grep xpu
- name: Run XPU backbone
run: |
source activate huggingface_transformers_test
cd transformers
python3 -m pytest -rsf --make-reports=tests_benchmark -k backbone tests
# On-demand launch
- name: OnDemand Test (${transformers_test})
if: github.event_name == 'workflow_dispatch'
run: |
source activate huggingface_transformers_test
cd transformers

# check param
function contains() {
contains_status="echo 'Start $2 ...'"
{
[[ $1 =~ (^|,)$2($|,) ]]
} || {
echo "[Warning] $2 is not suppotted type! Skipped!"
contains_status="continue"
}
}
set -xe
for transformers_test in $(echo ${{ inputs.transformers_test }} |sed 's/,/ /g')
do
contains "test_py,benchmark,generation,models,pipelines,trainer,utils,backbone,trainer_not_ray" $transformers_test
$contains_status
if [ "${transformers_test}" == "test_py" ];then
python3 -m pytest -rsf --make-reports=tests_py tests/*.py
elif [ "${transformers_test}" == "trainer_not_ray" ];then
python3 -m pytest -rsf --make-reports=tests_trainer_not_ray -k "not ray" tests/trainer
elif [ "${transformers_test}" == "backbone" ];then
python3 -m pytest -rsf --make-reports=tests_backbone -k backbone tests
else
python3 -m pytest -rsf --make-reports=tests_${transformers_test} tests/${transformers_test}
fi
done
- name: Upload Test log
if: ${{ ! cancelled() }}
uses: actions/upload-artifact@v4
with:
name: Torch-XPU-Transformers-Log-${{ github.event.pull_request.number || github.sha }}
path: |
${{ github.workspace }}/transformers/reports
${{ github.workspace }}/transformers/tests_log
2 changes: 1 addition & 1 deletion .github/workflows/nightly_ondemand_whl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ concurrency:

jobs:
Linux-Nightly-Ondemand-UT-WHL-Tests:
if: github.event_name == 'schedule' || ${{ inputs.ut_suite }}
if: github.event_name == 'schedule' || ${{ inputs.ut }}
uses: ./.github/workflows/_linux_ut.yml
with:
ut: ${{ github.event_name == 'schedule' && 'op_regression,op_regression_dev1,op_extended,op_ut,torch_xpu' || inputs.ut }}
Expand Down
Loading