Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2993b50
Add `.gitignore`
smokestacklightnin Aug 16, 2024
7d9afd8
Add github test workflow
smokestacklightnin Oct 23, 2024
2543b3e
Add push trigger
smokestacklightnin Oct 23, 2024
a2e3e79
Add expected failures and skips
smokestacklightnin Oct 23, 2024
ec31f6f
Also test on python version 3.11
smokestacklightnin Oct 23, 2024
2b39506
Remove python version 3.11 due to dependency error
smokestacklightnin Oct 23, 2024
93d3b12
Add note on how to run tests
smokestacklightnin Oct 24, 2024
bce2804
Merge remote-tracking branch 'upstream/master' into ci/testing/add-wo…
smokestacklightnin May 3, 2025
2c72e78
Merge branch 'master' into ci/testing/add-workflow-with-unittest
peytondmurray Jul 3, 2025
609976a
Add `tf-keras` as a dependency
smokestacklightnin Jul 4, 2025
3849ac9
Add expect failure for several tests and test classes all suffering f…
smokestacklightnin Jul 4, 2025
a9e43e6
Remove import to nonexistant modules
smokestacklightnin Jul 5, 2025
a3812b9
Install `libprotobuf-c-dev` for unit tests in CI
smokestacklightnin Jul 11, 2025
47de67f
Merge remote-tracking branch 'upstream/master' into ci/testing/add-wo…
smokestacklightnin Jul 15, 2025
da31bf3
Temporarily remove `expectedFailure`s
smokestacklightnin Jul 15, 2025
c0a6305
Fix `EvalConfig` imports
smokestacklightnin Jul 15, 2025
261a29f
Add more `expectedFailure`s
smokestacklightnin Jul 15, 2025
8363c74
Remove `unexpectedFailure` from unexpected success
smokestacklightnin Jul 15, 2025
127493b
Add Python 3.11 to CI tests
smokestacklightnin Jul 15, 2025
00f0f29
Remove `libprotobuf-c-dev`
smokestacklightnin Jul 15, 2025
f00949b
Remove unnecessary import
smokestacklightnin Jul 15, 2025
231c157
Add `expectedFailure`
smokestacklightnin Jul 15, 2025
1597b19
Use `skip` instead of `expectedFailure`
smokestacklightnin Jul 15, 2025
1023622
Fix code comment
smokestacklightnin Jul 15, 2025
7ba7ea8
Run for all users
smokestacklightnin Jul 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Github action definitions for unit-tests with PRs.

name: tfma-unit-tests
on:
push:
pull_request:
branches: [ master ]
paths-ignore:
- '**.md'
- 'docs/**'
workflow_dispatch:

jobs:
unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.py

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y protobuf-compiler
pip install .

- name: Run unit tests
shell: bash
run: |
python -m unittest discover -p "*_test.py"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we don't use pytest here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to do with pickling errors in pytest that aren't present in unit test

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ cd dist
pip3 install tensorflow_model_analysis-<version>-py3-none-any.whl
```

### Running tests

To run tests, run

```
python -m unittest discover -p *_test.py
```

from the root project directory.

### Jupyter Lab

As of writing, because of https://github.com/pypa/pip/issues/9187, `pip install`
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def select_constraint(default, nightly=None, git_master=None):
nightly='>=1.18.0.dev',
git_master='@git+https://github.com/tensorflow/tfx-bsl@master',
),
'tf-keras',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@embr tests fail without this, but I was wondering if this should be a dependency for the whole package, or only a test dependency.

CC: @peytondmurray

],
'extras_require': {
'all': [*_make_extra_packages_tfjs(), *_make_docs_packages()],
Expand Down
10 changes: 10 additions & 0 deletions tensorflow_model_analysis/api/model_eval_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import os
import tempfile
import unittest

from absl.testing import absltest
from absl.testing import parameterized
Expand Down Expand Up @@ -1122,6 +1123,9 @@ def testRunModelAnalysisWithQueryBasedMetrics(self):
for k in expected_metrics[group]:
self.assertIn(k, got_metrics[group])

# PR 189: Remove the `skip` mark if the test passes for all supported versions
# of python
@unittest.skip('Fails for some versions of Python, including 3.9')
def testRunModelAnalysisWithUncertainty(self):
examples = [
self._makeExample(age=3.0, language='english', label=1.0),
Expand Down Expand Up @@ -1391,6 +1395,8 @@ def testRunModelAnalysisWithSchema(self):
self.assertEqual(1.0, got_buckets[1]['lowerThresholdInclusive'])
self.assertEqual(2.0, got_buckets[-2]['upperThresholdExclusive'])

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testLoadValidationResult(self):
result = validation_result_pb2.ValidationResult(validation_ok=True)
path = os.path.join(absltest.get_default_test_tmpdir(), 'results.tfrecord')
Expand All @@ -1399,6 +1405,8 @@ def testLoadValidationResult(self):
loaded_result = model_eval_lib.load_validation_result(path)
self.assertTrue(loaded_result.validation_ok)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testLoadValidationResultDir(self):
result = validation_result_pb2.ValidationResult(validation_ok=True)
path = os.path.join(
Expand All @@ -1409,6 +1417,8 @@ def testLoadValidationResultDir(self):
loaded_result = model_eval_lib.load_validation_result(os.path.dirname(path))
self.assertTrue(loaded_result.validation_ok)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testLoadValidationResultEmptyFile(self):
path = os.path.join(
absltest.get_default_test_tmpdir(), constants.VALIDATIONS_KEY
Expand Down
2 changes: 0 additions & 2 deletions tensorflow_model_analysis/export_only/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ def eval_input_receiver_fn():
tfma_export.export.export_eval_saved_model(...)
"""

from tensorflow_model_analysis.eval_saved_model import export
from tensorflow_model_analysis.eval_saved_model import exporter
12 changes: 12 additions & 0 deletions tensorflow_model_analysis/extractors/inference_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from tensorflow_serving.apis import logging_pb2
from tensorflow_serving.apis import prediction_log_pb2

import unittest


class TfxBslPredictionsExtractorTest(testutil.TensorflowModelAnalysisTest):

Expand Down Expand Up @@ -70,6 +72,8 @@ def _create_tfxio_and_feature_extractor(
)
return tfx_io, feature_extractor

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testIsValidConfigForBulkInferencePass(self):
saved_model_proto = text_format.Parse(
"""
Expand Down Expand Up @@ -129,6 +133,8 @@ def testIsValidConfigForBulkInferencePass(self):
)
)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testIsValidConfigForBulkInferencePassDefaultSignatureLookUp(self):
saved_model_proto = text_format.Parse(
"""
Expand Down Expand Up @@ -184,6 +190,8 @@ def testIsValidConfigForBulkInferencePassDefaultSignatureLookUp(self):
)
)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testIsValidConfigForBulkInferenceFailNoSignatureFound(self):
saved_model_proto = text_format.Parse(
"""
Expand Down Expand Up @@ -239,6 +247,8 @@ def testIsValidConfigForBulkInferenceFailNoSignatureFound(self):
)
)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testIsValidConfigForBulkInferenceFailKerasModel(self):
saved_model_proto = text_format.Parse(
"""
Expand Down Expand Up @@ -296,6 +306,8 @@ def testIsValidConfigForBulkInferenceFailKerasModel(self):
)
)

# PR 189: Remove the `expectedFailure` mark if the test passes
@unittest.expectedFailure
def testIsValidConfigForBulkInferenceFailWrongInputType(self):
saved_model_proto = text_format.Parse(
"""
Expand Down
3 changes: 2 additions & 1 deletion tensorflow_model_analysis/metrics/bleu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np
import tensorflow as tf
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis import constants
from tensorflow_model_analysis.evaluators import metrics_plots_and_validations_evaluator
from tensorflow_model_analysis.metrics import bleu
Expand Down Expand Up @@ -573,7 +574,7 @@ def test_bleu_end_2_end(self):
}
}
""",
tfma.EvalConfig(),
config_pb2.EvalConfig(),
)

example1 = {
Expand Down
3 changes: 2 additions & 1 deletion tensorflow_model_analysis/metrics/example_count_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np
import tensorflow as tf
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis.metrics import example_count
from tensorflow_model_analysis.metrics import metric_types
from tensorflow_model_analysis.metrics import metric_util
Expand Down Expand Up @@ -109,7 +110,7 @@ def testExampleCountsWithoutLabelPredictions(self):
}
}
""",
tfma.EvalConfig(),
config_pb2.EvalConfig(),
)
name_list = ['example_count']
expected_results = [0.6]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from apache_beam.testing import util
import numpy as np
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis.metrics import metric_types
from google.protobuf import text_format


class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):

@parameterized.named_parameters(('_max_recall',
Expand All @@ -41,7 +41,7 @@ class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"maxrecall"'
}
}
""", tfma.EvalConfig()), ['maxrecall'], [2 / 3]),
""", config_pb2.EvalConfig()), ['maxrecall'], [2 / 3]),
('_precision_at_recall',
text_format.Parse(
"""
Expand All @@ -59,7 +59,7 @@ class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"precisionatrecall"'
}
}
""", tfma.EvalConfig()), ['precisionatrecall'], [3 / 5]),
""", config_pb2.EvalConfig()), ['precisionatrecall'], [3 / 5]),
('_recall',
text_format.Parse(
"""
Expand All @@ -77,7 +77,7 @@ class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"recall"'
}
}
""", tfma.EvalConfig()), ['recall'], [2 / 3]), ('_precision',
""", config_pb2.EvalConfig()), ['recall'], [2 / 3]), ('_precision',
text_format.Parse(
"""
model_specs {
Expand All @@ -94,7 +94,7 @@ class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"precision"'
}
}
""", tfma.EvalConfig()), ['precision'], [0.5]), ('_threshold_at_recall',
""", config_pb2.EvalConfig()), ['precision'], [0.5]), ('_threshold_at_recall',
text_format.Parse(
"""
model_specs {
Expand All @@ -111,7 +111,7 @@ class ObjectDetectionConfusionMatrixMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"thresholdatrecall"'
}
}
""", tfma.EvalConfig()), ['thresholdatrecall'], [0.3]))
""", config_pb2.EvalConfig()), ['thresholdatrecall'], [0.3]))
def testObjectDetectionMetrics(self, eval_config, name_list,
expected_results):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from apache_beam.testing import util
import numpy as np
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis.metrics import metric_types
from tensorflow_model_analysis.utils import test_util

Expand Down Expand Up @@ -45,7 +46,7 @@ def testConfusionMatrixPlot(self):
'"max_num_detections":100, "name":"iou0.5"'
}
}
""", tfma.EvalConfig())
""", config_pb2.EvalConfig())
extracts = [
# The match at iou_threshold = 0.5 is
# gt_matches: [[0]] dt_matches: [[0, -1]]
Expand Down
21 changes: 11 additions & 10 deletions tensorflow_model_analysis/metrics/object_detection_metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from apache_beam.testing import util
import numpy as np
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis.metrics import metric_types
from google.protobuf import text_format

Expand Down Expand Up @@ -59,7 +60,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"iou0.5"'
}
}
""", tfma.EvalConfig()), ['iou0.5'], [0.916]),
""", config_pb2.EvalConfig()), ['iou0.5'], [0.916]),
('_average_precision_iou0.75',
text_format.Parse(
"""
Expand All @@ -77,7 +78,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"iou0.75"'
}
}
""", tfma.EvalConfig()), ['iou0.75'], [0.416]),
""", config_pb2.EvalConfig()), ['iou0.75'], [0.416]),
('_average_precision_ave',
text_format.Parse(
"""
Expand All @@ -95,7 +96,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"iouave"'
}
}
""", tfma.EvalConfig()), ['iouave'], [0.666]), ('_average_recall_mdet1',
""", config_pb2.EvalConfig()), ['iouave'], [0.666]), ('_average_recall_mdet1',
text_format.Parse(
"""
model_specs {
Expand All @@ -112,7 +113,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"name":"mdet1"'
}
}
""", tfma.EvalConfig()), ['mdet1'], [0.375]), ('_average_recall_mdet10',
""", config_pb2.EvalConfig()), ['mdet1'], [0.375]), ('_average_recall_mdet10',
text_format.Parse(
"""
model_specs {
Expand All @@ -129,7 +130,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"name":"mdet10"'
}
}
""", tfma.EvalConfig()), ['mdet10'], [0.533]),
""", config_pb2.EvalConfig()), ['mdet10'], [0.533]),
('_average_recall_mdet100',
text_format.Parse(
"""
Expand All @@ -147,7 +148,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"name":"mdet100"'
}
}
""", tfma.EvalConfig()), ['mdet100'], [0.533]),
""", config_pb2.EvalConfig()), ['mdet100'], [0.533]),
('_average_recall_arsmall',
text_format.Parse(
"""
Expand All @@ -165,7 +166,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"arsmall"'
}
}
""", tfma.EvalConfig()), ['arsmall'], [0.500]),
""", config_pb2.EvalConfig()), ['arsmall'], [0.500]),
('_average_recall_armedium',
text_format.Parse(
"""
Expand All @@ -183,7 +184,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"armedium"'
}
}
""", tfma.EvalConfig()), ['armedium'], [0.300]),
""", config_pb2.EvalConfig()), ['armedium'], [0.300]),
('_average_recall_arlarge',
text_format.Parse(
"""
Expand All @@ -201,7 +202,7 @@ class ObjectDetectionMetricsTest(parameterized.TestCase):
'"max_num_detections":100, "name":"arlarge"'
}
}
""", tfma.EvalConfig()), ['arlarge'], [0.700]))
""", config_pb2.EvalConfig()), ['arlarge'], [0.700]))
def testMetricValuesWithLargerData(self, eval_config, name_list,
expected_results):

Expand Down Expand Up @@ -283,7 +284,7 @@ def check_result(got):
'"predictions_to_stack":["bbox", "class_id", "scores"]'
}
}
""", tfma.EvalConfig()), ['iou0.5'], [0.916]))
""", config_pb2.EvalConfig()), ['iou0.5'], [0.916]))
def testMetricValuesWithSplittedData(self, eval_config, name_list,
expected_results):

Expand Down
3 changes: 2 additions & 1 deletion tensorflow_model_analysis/metrics/rouge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import numpy as np
import tensorflow as tf
import tensorflow_model_analysis as tfma
from tensorflow_model_analysis.proto import config_pb2
from tensorflow_model_analysis import constants
from tensorflow_model_analysis.evaluators import metrics_plots_and_validations_evaluator
from tensorflow_model_analysis.metrics import metric_types
Expand Down Expand Up @@ -659,7 +660,7 @@ def testRougeEnd2End(self):
}
}
""",
tfma.EvalConfig(),
config_pb2.EvalConfig(),
)
rouge_types = ['rouge1', 'rouge2', 'rougeL', 'rougeLsum']
example_weights = [0.5, 0.7]
Expand Down
Loading
Loading