예제 #1
0
def skip_if_pylint_unavailable():
    return pytest.mark.skipif(
        not _is_importable("pylint"),
        reason="pylint is required to run tests in this module")
예제 #2
0
        mlflow.pytorch.log_model(model, artifact_path="model")
        model_uri = mlflow.get_artifact_uri("model")

    resp = pyfunc_serve_and_score_model(
        model_uri,
        data[0],
        pyfunc_scoring_server.CONTENT_TYPE_JSON_SPLIT_ORIENTED,
        extra_args=EXTRA_PYFUNC_SERVING_TEST_ARGS,
    )
    scores = pd.DataFrame(json.loads(resp.content))
    np.testing.assert_array_almost_equal(scores.values[:, 0],
                                         _predict(model=model, data=data))


@pytest.mark.large
@pytest.mark.skipif(not _is_importable("transformers"),
                    reason="This test requires transformers")
def test_pyfunc_serve_and_score_transformers():
    from transformers import BertModel, BertConfig  # pylint: disable=import-error

    class MyBertModel(BertModel):
        def forward(self, *args, **kwargs):  # pylint: disable=arguments-differ
            return super().forward(*args, **kwargs).last_hidden_state

    model = MyBertModel(
        BertConfig(
            vocab_size=16,
            hidden_size=2,
            num_hidden_layers=2,
            num_attention_heads=2,
            intermediate_size=2,
예제 #3
0
    with mlflow.start_run():
        mlflow.pytorch.log_model(model, artifact_path="model")
        model_uri = mlflow.get_artifact_uri("model")

    resp = pyfunc_serve_and_score_model(
        model_uri,
        data[0],
        pyfunc_scoring_server.CONTENT_TYPE_JSON_SPLIT_ORIENTED,
        extra_args=EXTRA_PYFUNC_SERVING_TEST_ARGS,
    )
    scores = pd.DataFrame(json.loads(resp.content))
    np.testing.assert_array_almost_equal(scores.values[:, 0], _predict(model=model, data=data))


@pytest.mark.large
@pytest.mark.skipif(not _is_importable("transformers"), reason="This test requires transformers")
def test_pyfunc_serve_and_score_transformers():
    from transformers import BertModel, BertConfig  # pylint: disable=import-error

    class MyBertModel(BertModel):
        def forward(self, *args, **kwargs):  # pylint: disable=arguments-differ
            return super().forward(*args, **kwargs).last_hidden_state

    model = MyBertModel(
        BertConfig(
            vocab_size=16,
            hidden_size=2,
            num_hidden_layers=2,
            num_attention_heads=2,
            intermediate_size=2,
        )
예제 #4
0
    """Ensures that keras models without save_format can still be loaded."""
    mlflow.keras.save_model(tf_keras_model, model_path, save_format="h5")
    model_conf_path = os.path.join(model_path, "MLmodel")
    model_conf = Model.load(model_conf_path)
    flavor_conf = model_conf.flavors.get(mlflow.keras.FLAVOR_NAME)
    assert flavor_conf is not None
    del flavor_conf["save_format"]
    model_conf.save(model_conf_path)

    model_loaded = mlflow.keras.load_model(model_path)
    assert tf_keras_model.to_json() == model_loaded.to_json()


@pytest.mark.large
@pytest.mark.skipif(
    not _is_importable("transformers"),
    reason=
    "This test requires transformers, which is incompatible with Keras < 2.3.0",
)
def test_pyfunc_serve_and_score_transformers():
    from transformers import BertConfig, TFBertModel  # pylint: disable=import-error

    bert = TFBertModel(
        BertConfig(
            vocab_size=16,
            hidden_size=2,
            num_hidden_layers=2,
            num_attention_heads=2,
            intermediate_size=2,
        ))
    dummy_inputs = bert.dummy_inputs["input_ids"].numpy()
예제 #5
0
import pytest

from tests.helper_functions import _is_importable

pytestmark = pytest.mark.skipif(
    not _is_importable("pylint"),
    reason="pylint is required to run tests in this module")


@pytest.fixture(scope="module")
def test_case():
    # Ref: https://pylint.pycqa.org/en/latest/how_tos/custom_checkers.html#testing-a-checker
    import pylint.testutils
    from pylint_plugins import PytestRaisesWithoutMatch

    class TestPytestRaisesWithoutMatch(pylint.testutils.CheckerTestCase):
        CHECKER_CLASS = PytestRaisesWithoutMatch

    test_case = TestPytestRaisesWithoutMatch()
    test_case.setup_method()
    return test_case


def create_message(msg_id, node):
    import pylint.testutils

    return pylint.testutils.Message(msg_id=msg_id, node=node)


def extract_node(code):
    import astroid