-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[formrecognizer] Adding custom forms perf test #16969
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
Merged
catalinaperalta
merged 9 commits into
Azure:master
from
catalinaperalta:feature/formPerfStressTest
Mar 3, 2021
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
61ccd54
Adding custom forms perf test
catalinaperalta cfb857e
improve test to use labeled model
catalinaperalta 6f72175
add README
catalinaperalta 37c3696
update test name
catalinaperalta 6dbeb5e
use async training client
catalinaperalta f17e866
rename file
catalinaperalta 6615a36
fix test check
catalinaperalta 6c31092
update readme cmd instructions
catalinaperalta 05a2484
update
catalinaperalta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
sdk/formrecognizer/azure-ai-formrecognizer/tests/perfstress_tests/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Form Recognizer Performance Tests | ||
|
|
||
| In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the `dev_requirements` install. | ||
| Start by creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7. | ||
|
|
||
| ### Setup for test resources | ||
|
|
||
| The following environment variable will need to be set for the tests to access the live resources: | ||
|
|
||
| ``` | ||
| FORMRECOGNIZER_TEST_ENDPOINT=<form recognizer service endpoint> | ||
| FORMRECOGNIZER_TEST_API_KEY=<form recognizer API Key> | ||
| FORMRECOGNIZER_TRAINING_DATA_CONTAINER_SAS_URL=<SAS url for container with training data> | ||
| ``` | ||
|
|
||
| ### Setup for perf test runs | ||
|
|
||
| ```cmd | ||
| (env) ~/azure-ai-formrecognizer> pip install -r dev_requirements.txt | ||
| (env) ~/azure-ai-formrecognizer> pip install -e . | ||
| ``` | ||
|
|
||
| ## Test commands | ||
|
|
||
| When `azure-devtools` is installed, you will have access to the `perfstress` command line tool, which will scan the current module for runable perf tests. Only a specific test can be run at a time (i.e. there is no "run all" feature). | ||
|
|
||
| ```cmd | ||
| (env) ~/azure-ai-formrecognizer> cd tests | ||
| (env) ~/azure-ai-formrecognizer/tests> perfstress | ||
| ``` | ||
| Using the `perfstress` command alone will list the available perf tests found. | ||
|
|
||
| ### Common perf command line options | ||
| These options are available for all perf tests: | ||
| - `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10. | ||
| - `--iterations=1` Number of test iterations to run. Default is 1. | ||
| - `--parallel=1` Number of tests to run in parallel. Default is 1. | ||
| - `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. | ||
| - `--sync` Whether to run the tests in sync or async. Default is False (async). This flag must be used for Storage legacy tests, which do not support async. | ||
| - `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted). | ||
|
|
||
| ## Example command | ||
| ```cmd | ||
| (env) ~/azure-ai-formrecognizer/tests/perfstress_tests> perfstress RecognizeCustomForms | ||
| ``` |
Empty file.
75 changes: 75 additions & 0 deletions
75
sdk/formrecognizer/azure-ai-formrecognizer/tests/perfstress_tests/perf_custom_forms.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # coding=utf-8 | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
|
|
||
| import os | ||
| import pytest | ||
| import functools | ||
| from io import BytesIO | ||
| from datetime import date, time | ||
| from azure_devtools.perfstress_tests import PerfStressTest | ||
| from azure.core.credentials import AzureKeyCredential | ||
| from azure.ai.formrecognizer import FormRecognizerClient, FormContentType | ||
| from azure.ai.formrecognizer.aio import FormRecognizerClient as AsyncFormRecognizerClient, FormTrainingClient as AsyncFormTrainingClient | ||
|
|
||
| class RecognizeCustomForms(PerfStressTest): | ||
|
|
||
| def __init__(self, arguments): | ||
| super().__init__(arguments) | ||
|
|
||
| with open(os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "./../sample_forms/forms/Form_1.jpg")), "rb") as fd: | ||
| self.custom_form_jpg = fd.read() | ||
|
|
||
| # read test related env vars | ||
| self.formrecognizer_storage_container_sas_url = os.environ["FORMRECOGNIZER_TRAINING_DATA_CONTAINER_SAS_URL"] | ||
| formrecognizer_test_endpoint = os.environ["FORMRECOGNIZER_TEST_ENDPOINT"] | ||
| form_recognizer_account_key = os.environ["FORMRECOGNIZER_TEST_API_KEY"] | ||
|
|
||
| # assign the clients that will be used in the perf tests | ||
| self.service_client = FormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
| self.async_service_client = AsyncFormRecognizerClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
|
|
||
| # training client will be used for model training in set up | ||
| self.async_training_client = AsyncFormTrainingClient(formrecognizer_test_endpoint, AzureKeyCredential(form_recognizer_account_key)) | ||
|
|
||
| async def global_setup(self): | ||
| """The global setup is run only once.""" | ||
| poller = await self.async_training_client.begin_training( | ||
| self.formrecognizer_storage_container_sas_url, | ||
| use_training_labels=True, | ||
| model_name="labeled") | ||
| model = await poller.result() | ||
| self.model_id = model.model_id | ||
|
|
||
| async def global_cleanup(self): | ||
| """The global cleanup is run only once.""" | ||
| await self.async_training_client.delete_model(self.model_id) | ||
|
|
||
| async def close(self): | ||
| """This is run after cleanup.""" | ||
| await self.async_service_client.close() | ||
| self.service_client.close() | ||
| await self.async_training_client.close() | ||
| await super().close() | ||
|
|
||
| def run_sync(self): | ||
| """The synchronous perf test.""" | ||
| poller = self.service_client.begin_recognize_custom_forms( | ||
| self.model_id, | ||
| self.custom_form_jpg, | ||
| content_type=FormContentType.IMAGE_JPEG) | ||
| result = poller.result() | ||
| if result is not None: | ||
| pass | ||
|
|
||
| async def run_async(self): | ||
| """The asynchronous perf test.""" | ||
| poller = await self.async_service_client.begin_recognize_custom_forms( | ||
| self.model_id, | ||
| self.custom_form_jpg, | ||
| content_type=FormContentType.IMAGE_JPEG) | ||
| result = await poller.result() | ||
| if result is not None: | ||
| pass | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.