-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 18 commits
3d59000
9c0142e
1e4d7df
067cdd9
2d22174
59db2bb
10bc574
91301cf
dfcff7b
87de5fa
8863a94
a7979df
aef2f47
6e01ae8
97c1c82
fdc7741
2fb9b1d
298b09c
dec58de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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: | ||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind. Just check. I have renamed workflow_call. |
||
inputs: | ||
transformers_test: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this. Let's focus on a single test - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, drop |
||
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 |
There was a problem hiding this comment.
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.