Skip to content

Commit

Permalink
PyTorch attention cells, transformer, bert and conversion script (dml…
Browse files Browse the repository at this point in the history
…c#1532)

* torch attention cell

* torch layers

* torch bert

* torch bert conversion script

* update github actions

* Fix macos github action

* rename test files to fix ERROR collecting tests/torch/$name.py
  • Loading branch information
leezu authored Feb 26, 2021
1 parent 223f1f6 commit 8e41885
Show file tree
Hide file tree
Showing 20 changed files with 2,641 additions and 144 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,27 @@ jobs:
restore-keys: |
${{ runner.os }}-ccache
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64

# Install Linux specific dependencies
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
# TODO https://github.com/apache/incubator-mxnet/issues/18293
run: |
sudo apt-get install -y libopenblas-dev ninja-build libedit-dev libxml2-dev
python -m pip install "torch==1.7.1+cpu" -f https://download.pytorch.org/whl/torch_stable.html
# Install Mac specific dependencies
- name: Install Linux dependencies
if: matrix.os == 'macos-latest'
run: |
python -m pip install torch==1.7.1
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install Other Dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 3 additions & 1 deletion scripts/conversion_toolkits/convert_albert.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
set -ex

python3 -m pip install tensorflow==1.15 --upgrade --user
python3 -m pip install tensorflow_hub --upgrade --user
export TF_FORCE_GPU_ALLOW_GROWTH="true"
for model in base large xlarge xxlarge
do
hub_directory="google_albert_${model}_v2"
mkdir ${hub_directory}
mkdir -p ${hub_directory}
wget "https://tfhub.dev/google/albert_${model}/3?tf-hub-format=compressed" -O "${hub_directory}.tar.gz"
tar -xvf ${hub_directory}.tar.gz --directory ${hub_directory}
python3 convert_tf_hub_model.py --tf_hub_model_path ${hub_directory} --model_type albert --test
Expand Down
12 changes: 7 additions & 5 deletions scripts/conversion_toolkits/convert_bert.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
python3 -m pip install tensorflow==2.3.0 --upgrade --user
set -ex

python3 -m pip install 'tensorflow<3' --upgrade --user
python3 -m pip install tensorflow_hub --upgrade --user
export TF_FORCE_GPU_ALLOW_GROWTH="true"

Expand All @@ -8,7 +10,7 @@ do
for case in cased uncased
do
hub_directory="google_en_${case}_bert_${model}"
mkdir ${hub_directory}
mkdir -p ${hub_directory}
if [ ${model} == base ];then
url="https://tfhub.dev/google/bert_${case}_L-12_H-768_A-12/1?tf-hub-format=compressed"
else
Expand All @@ -24,7 +26,7 @@ done
# Conversion for Chinese Models
url="https://tfhub.dev/tensorflow/bert_zh_L-12_H-768_A-12/2?tf-hub-format=compressed"
hub_directory="google_zh_bert_base"
mkdir ${hub_directory}
mkdir -p ${hub_directory}
wget ${url} -O "${hub_directory}.tar.gz"
tar -xvf ${hub_directory}.tar.gz --directory ${hub_directory}
cp bert_base_config.json ${hub_directory}/assets/
Expand All @@ -33,7 +35,7 @@ python3 convert_tf_hub_model.py --tf_hub_model_path ${hub_directory} --model_typ
# Conversion for Multi-lingual Models
url="https://tfhub.dev/tensorflow/bert_multi_cased_L-12_H-768_A-12/2?tf-hub-format=compressed"
hub_directory="google_multi_cased_bert_base"
mkdir ${hub_directory}
mkdir -p ${hub_directory}
wget ${url} -O "${hub_directory}.tar.gz"
tar -xvf ${hub_directory}.tar.gz --directory ${hub_directory}
cp bert_base_config.json ${hub_directory}/assets/
Expand All @@ -43,7 +45,7 @@ python3 convert_tf_hub_model.py --tf_hub_model_path ${hub_directory} --model_typ
for case in cased uncased
do
hub_directory="google_en_${case}_bert_wwm_large"
mkdir ${hub_directory}
mkdir -p ${hub_directory}
url="https://tfhub.dev/tensorflow/bert_en_wwm_${case}_L-24_H-1024_A-16/2?tf-hub-format=compressed"
wget ${url} -O "${hub_directory}.tar.gz"
tar -xvf ${hub_directory}.tar.gz --directory ${hub_directory}
Expand Down
24 changes: 24 additions & 0 deletions scripts/conversion_toolkits/convert_bert_torch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set -ex

python3 -m pip install 'tensorflow<3' --upgrade --user
python3 -m pip install tensorflow_hub --upgrade --user
export TF_FORCE_GPU_ALLOW_GROWTH="true"

# Conversion for English Models
for model in base large
do
for case in cased uncased
do
hub_directory="google_en_${case}_bert_${model}"
mkdir -p ${hub_directory}
if [ ${model} == base ];then
url="https://tfhub.dev/google/bert_${case}_L-12_H-768_A-12/1?tf-hub-format=compressed"
else
url="https://tfhub.dev/google/bert_${case}_L-24_H-1024_A-16/1?tf-hub-format=compressed"
fi
wget ${url} -O "${hub_directory}.tar.gz"
tar -xvf ${hub_directory}.tar.gz --directory ${hub_directory}
cp bert_${model}_config.json ${hub_directory}/assets/
python3 convert_tf_hub_model.py --tf_hub_model_path ${hub_directory} --model_type bert --test --torch
done
done
Loading

0 comments on commit 8e41885

Please sign in to comment.