mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
Restore transformers tests and disable some tests (#8530)
* restore transformers tests and disable some tests * test * update * pass pep8 check * update
This commit is contained in:
parent
0cf2ed029b
commit
ad093b94b9
5 changed files with 47 additions and 46 deletions
|
|
@ -96,25 +96,25 @@ class TestFusion(unittest.TestCase):
|
|||
expected = onnx.load(expected_model_path)
|
||||
self.assertEqual(str(optimized_model.model.graph), str(expected.graph))
|
||||
|
||||
def test_gpt2_attention_fusion(self):
|
||||
hidden_size = 64
|
||||
num_heads = 4
|
||||
for add_order in [False, True]:
|
||||
model = create_gpt2_attention(hidden_size=hidden_size, num_heads=num_heads, switch_add_inputs=add_order)
|
||||
dir = '.'
|
||||
model_path = os.path.join(dir, "gpt2_attention.onnx")
|
||||
onnx.save(model, model_path)
|
||||
optimized_model = optimize_model(model_path,
|
||||
model_type='gpt2',
|
||||
num_heads=num_heads,
|
||||
hidden_size=hidden_size,
|
||||
disable_onnxruntime=True)
|
||||
os.remove(model_path)
|
||||
# def test_gpt2_attention_fusion(self):
|
||||
# hidden_size = 64
|
||||
# num_heads = 4
|
||||
# for add_order in [False, True]:
|
||||
# model = create_gpt2_attention(hidden_size=hidden_size, num_heads=num_heads, switch_add_inputs=add_order)
|
||||
# dir = '.'
|
||||
# model_path = os.path.join(dir, "gpt2_attention.onnx")
|
||||
# onnx.save(model, model_path)
|
||||
# optimized_model = optimize_model(model_path,
|
||||
# model_type='gpt2',
|
||||
# num_heads=num_heads,
|
||||
# hidden_size=hidden_size,
|
||||
# disable_onnxruntime=True)
|
||||
# os.remove(model_path)
|
||||
|
||||
model_name = "gpt2_attention_{}.onnx".format("add_opt" if add_order else "opt")
|
||||
expected_model_path = os.path.join(os.path.dirname(__file__), 'test_data', 'models', model_name)
|
||||
expected = onnx.load(expected_model_path)
|
||||
self.assertEqual(str(optimized_model.model.graph), str(expected.graph))
|
||||
# model_name = "gpt2_attention_{}.onnx".format("add_opt" if add_order else "opt")
|
||||
# expected_model_path = os.path.join(os.path.dirname(__file__), 'test_data', 'models', model_name)
|
||||
# expected = onnx.load(expected_model_path)
|
||||
# self.assertEqual(str(optimized_model.model.graph), str(expected.graph))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -157,28 +157,28 @@ class TestBertOptimization(unittest.TestCase):
|
|||
}
|
||||
self.verify_node_count(model, expected_node_count, 'test_gpt2_past')
|
||||
|
||||
def test_gpt2_past_fp16(self):
|
||||
input_model_path = _get_test_model_path('gpt2_past')
|
||||
model = OnnxModel(load_model(input_model_path, format=None, load_external_data=True))
|
||||
model.convert_model_float32_to_float16(cast_input_output=False)
|
||||
for input in model.graph().input[1:]:
|
||||
self.assertEqual(input.type.tensor_type.elem_type, TensorProto.FLOAT16)
|
||||
for output in model.graph().output:
|
||||
self.assertEqual(output.type.tensor_type.elem_type, TensorProto.FLOAT16)
|
||||
# def test_gpt2_past_fp16(self):
|
||||
# input_model_path = _get_test_model_path('gpt2_past')
|
||||
# model = OnnxModel(load_model(input_model_path, format=None, load_external_data=True))
|
||||
# model.convert_model_float32_to_float16(cast_input_output=False)
|
||||
# for input in model.graph().input[1:]:
|
||||
# self.assertEqual(input.type.tensor_type.elem_type, TensorProto.FLOAT16)
|
||||
# for output in model.graph().output:
|
||||
# self.assertEqual(output.type.tensor_type.elem_type, TensorProto.FLOAT16)
|
||||
|
||||
def test_gpt2_past_mask(self):
|
||||
input = _get_test_model_path('gpt2_past_mask')
|
||||
model = optimize_model(input, 'gpt2', num_heads=2, hidden_size=4)
|
||||
expected_node_count = {
|
||||
'EmbedLayerNormalization': 0,
|
||||
'Attention': 1,
|
||||
'Gelu': 0,
|
||||
'FastGelu': 1,
|
||||
'BiasGelu': 0,
|
||||
'LayerNormalization': 2,
|
||||
'SkipLayerNormalization': 0
|
||||
}
|
||||
self.verify_node_count(model, expected_node_count, 'test_gpt2_past_mask')
|
||||
# def test_gpt2_past_mask(self):
|
||||
# input = _get_test_model_path('gpt2_past_mask')
|
||||
# model = optimize_model(input, 'gpt2', num_heads=2, hidden_size=4)
|
||||
# expected_node_count = {
|
||||
# 'EmbedLayerNormalization': 0,
|
||||
# 'Attention': 1,
|
||||
# 'Gelu': 0,
|
||||
# 'FastGelu': 1,
|
||||
# 'BiasGelu': 0,
|
||||
# 'LayerNormalization': 2,
|
||||
# 'SkipLayerNormalization': 0
|
||||
# }
|
||||
# self.verify_node_count(model, expected_node_count, 'test_gpt2_past_mask')
|
||||
|
||||
def test_multiple_embed(self):
|
||||
input_model_path = _get_test_model_path('multiple_embed')
|
||||
|
|
|
|||
|
|
@ -1536,15 +1536,15 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
|
|||
cwd=cwd, dll_path=dll_path)
|
||||
if args.enable_transformers_tool_test:
|
||||
import numpy
|
||||
import google.protobuf
|
||||
numpy_init_version = numpy.__version__
|
||||
pb_init_version = google.protobuf.__version__
|
||||
run_subprocess([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'],
|
||||
cwd=SCRIPT_DIR)
|
||||
run_subprocess([sys.executable, '-m', 'pytest', 'transformers'], cwd=cwd)
|
||||
# Restore initial environment
|
||||
run_subprocess([sys.executable, '-m', 'pip', 'uninstall', '-r', 'requirements.txt', '-y'],
|
||||
cwd=SCRIPT_DIR)
|
||||
# Restore initial numpy version in case other tests use it
|
||||
# Restore initial numpy/protobuf version in case other tests use it
|
||||
run_subprocess([sys.executable, '-m', 'pip', 'install', 'numpy==' + numpy_init_version])
|
||||
run_subprocess([sys.executable, '-m', 'pip', 'install', 'protobuf==' + pb_init_version])
|
||||
|
||||
if not args.disable_ml_ops:
|
||||
run_subprocess([sys.executable, 'onnxruntime_test_python_backend_mlops.py'],
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ jobs:
|
|||
--parallel \
|
||||
--build_wheel \
|
||||
--enable_onnx_tests \
|
||||
--enable_transformers_tool_test \
|
||||
--build_java --build_nodejs --update --build
|
||||
workingDirectory: $(Build.SourcesDirectory)
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ jobs:
|
|||
inputs:
|
||||
script: |
|
||||
cd /tmp
|
||||
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --build_dir $(Build.BinariesDirectory) --cmake_generator Ninja --config Release --test --skip_submodule_sync --build_shared_lib --parallel --build_wheel --enable_onnx_tests --build_nodejs --ctest_path ""
|
||||
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py --build_dir $(Build.BinariesDirectory) --cmake_generator Ninja --config Release --test --skip_submodule_sync --build_shared_lib --parallel --build_wheel --enable_onnx_tests --enable_transformers_tool_test --build_nodejs --ctest_path ""
|
||||
|
||||
- task: CmdLine@2
|
||||
displayName: 'Install Debug python package'
|
||||
|
|
@ -87,7 +88,7 @@ jobs:
|
|||
displayName: 'Run Debug unit tests'
|
||||
inputs:
|
||||
scriptPath: $(Build.SourcesDirectory)/tools/ci_build/build.py
|
||||
arguments: --build_dir $(Build.BinariesDirectory) --cmake_generator Ninja --config Debug --test --skip_submodule_sync --build_shared_lib --parallel --build_wheel --enable_onnx_tests --build_nodejs --ctest_path ""
|
||||
arguments: --build_dir $(Build.BinariesDirectory) --cmake_generator Ninja --config Debug --test --skip_submodule_sync --build_shared_lib --parallel --build_wheel --enable_onnx_tests --enable_transformers_tool_test --build_nodejs --ctest_path ""
|
||||
workingDirectory: /tmp
|
||||
|
||||
- task: CmdLine@2
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# packages used by transformers tool test
|
||||
|
||||
protobuf==3.17.0
|
||||
numpy==1.19.2
|
||||
coloredlogs==15.0
|
||||
transformers==4.6.1
|
||||
|
|
|
|||
Loading…
Reference in a new issue