Skip to content

Commit aabe730

Browse files
authored
[Integration-Testing] Fix for post-merge tests (#887)
1 parent 7615e30 commit aabe730

17 files changed

+65
-50
lines changed

.github/workflows/Integrations-post-merge-check.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Integrations Testing
1+
name: Integrations Testing Post-Merge
22
on:
33
push:
44
branches:
@@ -33,6 +33,10 @@ jobs:
3333
repository: "neuralmagic/sparsezoo"
3434
path: "sparsezoo"
3535
ref: ${{needs.test-setup.outputs.branch}}
36+
- name: Set up Python 3.8
37+
uses: actions/setup-python@v3
38+
with:
39+
python-version: 3.8
3640
- name: "⚙️ Install sparsezoo dependencies"
3741
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
3842
- name: "Clean sparsezoo directory"
@@ -46,4 +50,4 @@ jobs:
4650
- name: "Install yolov5 integration"
4751
run: sparseml.yolov5.train --help
4852
- name: "🔬 Running integrations tests (cadence: commit}})"
49-
run: make testinteg TARGETS=transformers,yolov5,image_classification
53+
run: make testinteg TARGETS=yolov5,transformers,image_classification

.github/workflows/integrations-check.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ jobs:
5454
repository: "neuralmagic/sparsezoo"
5555
path: "sparsezoo"
5656
ref: ${{needs.test-setup.outputs.branch}}
57-
- name: Set up Python 3.8}}
57+
- name: Set up Python 3.8
5858
uses: actions/setup-python@v3
5959
with:
6060
python-version: 3.8
6161
- name: "⚙️ Install sparsezoo dependencies"
62-
run: |
63-
python --version
64-
pip3 install -U pip && pip3 install setuptools sparsezoo/
62+
run: pip3 install -U pip && pip3 install setuptools sparsezoo/
6563
- name: "Clean sparsezoo directory"
6664
run: rm -r sparsezoo/
6765
- name: "Upgrade protobuf version"

tests/integrations/base_tester.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from pydantic import BaseModel
3939

4040
from tests.integrations.config import Config
41-
from tests.integrations.helpers import get_configs_with_cadence
4241

4342

4443
__all__ = [
@@ -258,7 +257,9 @@ class BaseIntegrationTester:
258257
stage is `train`, `export`, or `deploy` and name is a unique name to describe the
259258
test. This naming convention is used and enforced within the decorator
260259
`@skip_inactive_stage`
261-
"""
260+
261+
Adding the fixture below to each test class will parameterize the test over
262+
the set of test configs that match the cadence setting.
262263
263264
@pytest.fixture(
264265
params=get_configs_with_cadence(
@@ -267,6 +268,8 @@ class BaseIntegrationTester:
267268
),
268269
scope="class",
269270
)
271+
"""
272+
270273
def integration_manager(request):
271274
"""
272275
Fixture with a lifecycle of:

tests/integrations/config.py

+14
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
from pathlib import Path
1517
from typing import Dict, List, Optional
1618

1719
from pydantic import BaseModel
1820

1921

22+
# path to sparseml root directory
23+
ROOT = Path(Path(__file__).resolve().parents[2])
24+
2025
__all__ = ["Config"]
2126

2227

@@ -49,6 +54,15 @@ def __init__(
4954
self.test_args = config.pop("test_args", {})
5055
# whether to replace '_' with '-' for run keywords
5156
self.dashed_keywords = False
57+
58+
# Construct explicit path from relative path, using sparseml base directory
59+
# as root
60+
recipe = getattr(self.run_args, "recipe", None)
61+
if recipe and not recipe.startswith("zoo:"):
62+
self.run_args.recipe = str(
63+
Path(os.path.join(ROOT, self.run_args.recipe)).resolve()
64+
)
65+
5266
self._validate_config()
5367

5468
def create_command_script(self):

tests/integrations/helpers.py

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def get_configs_with_cadence(cadence: str, dir_path: str = "."):
5454
if line.split(":")[1].strip().strip('"').lower() == cadence:
5555
matching_files.append(file)
5656
break
57+
58+
print(f"\nFor {cadence} found matching files: {matching_files}")
59+
5760
return matching_files
5861

5962

tests/integrations/image_classification/args.py

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def __post_init__(self):
145145

146146

147147
class ImageClassificationExportArgs(_ImageClassificationBaseArgs):
148+
model_tag: Optional[str] = Field(
149+
Default=None, description="required - tag for model under save_dir"
150+
)
148151
onnx_opset: int = Field(
149152
default=11, description="The onnx opset to use for exporting the model"
150153
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cadence: "commit"
2+
abridged: True
3+
train:
4+
command_args:
5+
dataset: imagenette
6+
dataset_path: imagenette
7+
recipe_path: tests/integrations/image_classification/configs/commit/recipe_short_prune_quant.md
8+
arch_key: mobilenet
9+
train_batch_size: 4
10+
test_batch_size: 4
11+
model_tag: mobilenet-imagenette-pruned
12+
save_dir: image_classification-end_to_end-test
13+
export:
14+
command_args:
15+
num_classes: 10
16+
deploy:
17+
command_args: null

tests/integrations/image_classification/configs/commit/test_ended_to_end_pruned_quantized_resnet50_imagenette.yaml

-24
This file was deleted.

tests/integrations/image_classification/test_image_classification.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def capture_pre_run_state(self):
8484
export_args.save_dir = self.save_dir.name
8585
else:
8686
export_args.checkpoint_path = self.expected_checkpoint_path
87-
export_args.save_dir = train_args.save_dir
87+
export_args.save_dir = train_args.save_dir + "_exported"
88+
export_args.model_tag = train_args.model_tag
89+
export_args.arch_key = train_args.arch_key
8890

8991
if "deploy" in self.configs:
9092
deploy_args = self.configs["deploy"].run_args
@@ -96,8 +98,8 @@ def capture_pre_run_state(self):
9698

9799
def add_abridged_configs(self):
98100
if "train" in self.command_types:
99-
self.configs["train"].max_train_steps = 10
100-
self.configs["train"].max_eval_steps = 10
101+
self.configs["train"].run_args.max_train_steps = 2
102+
self.configs["train"].run_args.max_eval_steps = 2
101103

102104
def teardown(self):
103105
"""
@@ -181,7 +183,7 @@ def test_train_metrics(self, integration_manager):
181183
def test_export_onnx_graph(self, integration_manager):
182184
export_args = integration_manager.configs["export"]
183185
expected_onnx_path = os.path.join(
184-
integration_manager.save_dir.name,
186+
export_args.run_args.save_dir,
185187
export_args.run_args.model_tag,
186188
"model.onnx",
187189
)
@@ -201,7 +203,7 @@ def test_export_target_model(self, integration_manager):
201203
zoo_model = Zoo.load_model_from_stub(target_model_path)
202204
target_model_path = zoo_model.onnx_file.downloaded_path()
203205
export_model_path = os.path.join(
204-
integration_manager.save_dir.name,
206+
export_args.run_args.save_dir,
205207
export_args.run_args.model_tag,
206208
"model.onnx",
207209
)

tests/integrations/transformers/configs/commit/test_end_to_end_quantized_question_answering.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ train:
1212
per_device_train_batch_size: 16
1313
max_seq_length: 384
1414
doc_stride: 128
15+
per_device_train_batch_size: 4
16+
per_device_eval_batch_size: 4
1517
export:
1618
command_args:
1719
task: qa

tests/integrations/transformers/configs/pre-commit/test_cli_question_answering.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cadence: "pre-commit"
2-
abridged: True
32
train:
43
task: Question-Answering
54
command_args:

tests/integrations/transformers/configs/pre-commit/test_cli_text_classification.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cadence: "pre-commit"
2-
abridged: True
32
train:
43
task: Text-Classification
54
command_args:

tests/integrations/transformers/test_transformers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def save_stage_information(self, command_type):
119119

120120
def add_abridged_configs(self):
121121
if "train" in self.command_types:
122-
self.configs["train"].max_train_samples = 10
123-
self.configs["train"].max_eval_samples = 10
122+
self.configs["train"].run_args.max_train_samples = 2
123+
self.configs["train"].run_args.max_eval_samples = 2
124124

125125
def get_root_commands(self, raw_configs):
126126
self.task = (

tests/integrations/yolov5/args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Yolov5TrainArgs(BaseModel):
9191
cost_lr: bool = Field(default=False, description="cosine LR scheduler")
9292
label_smoothing: float = Field(default=0.0, description="Label smoothing epsilon")
9393
patience: int = Field(
94-
default=100, description="EarlyStopping patience (epochs without improvement)"
94+
default=0, description="EarlyStopping patience (epochs without improvement)"
9595
)
9696
freeze: str = Field(
9797
default="0", description="Freeze layers: backbone=10, first3=0 1 2"

tests/integrations/yolov5/configs/commit/test_ended_to_end_pruned_quantized.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ train:
44
command_args:
55
weights: "zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none"
66
recipe: "tests/integrations/yolov5/configs/commit/recipe_short_prune_quant.md"
7-
test_args:
8-
target_name: "map0.5"
9-
target_mean: 52.5
10-
target_std: 3
7+
batch_size: 4
118
export:
129
command_args:
1310
dynamic: True

tests/integrations/yolov5/configs/pre-commit/test_cli.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cadence: "pre-commit"
2-
abridged: True
32
train:
43
command_args:
54
weights: "zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none"

tests/integrations/yolov5/test_yolov5.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ def capture_pre_run_state(self):
100100

101101
def add_abridged_configs(self):
102102
if "train" in self.command_types:
103-
self.configs["train"].max_train_steps = 10
104-
self.configs["train"].max_eval_steps = 10
105-
self.configs["train"].data = "coco128.yaml"
103+
self.configs["train"].run_args.max_train_steps = 2
104+
self.configs["train"].run_args.max_eval_steps = 2
106105

107106
def teardown(self):
108107
if "train" in self.command_types:

0 commit comments

Comments
 (0)