Beispiel #1
0
 def __init__(self, backend, backend_options):
     try:
         load_backend(backend)
     except LoadingError as e:
         pytest.skip(f"Can't load {backend}: {e.__cause__}")
     self.pip = standard_pipeline.configure({
         'compile.backend':
         backend,
         'compile.backend_options':
         backend_options
     }).make()
Beispiel #2
0
 def __init__(self, backend, backend_options):
     try:
         self.backend = load_backend(backend, backend_options)
     except LoadingError as e:
         pytest.skip(f"Can't load {backend}: {e.__cause__}")
     self.pip = standard_pipeline.configure({
         'resources.backend.name':
         backend,
         'resources.backend.options':
         backend_options
     }).make()
Beispiel #3
0
from myia.utils import Profile  # , no_prof

from ..common import MA, f32, to_abstract_test
from ..test_grad import grad_pipeline, grad_wrap

torch = pytest.importorskip("torch")
nn = torch.nn
F = torch.nn.functional

activate_frontend('pytorch')

fwd_compile_pipeline = standard_pipeline

# Uncomment this line to print values at specific precision
# torch.set_printoptions(precision=8)
""" # This is for if/when tested with backends besides nnvm later
def get_backend_options(args, backend):
    device_type = args.dev

    backend_options_dict = {
        'pytorch': {'device': device_type},
        'nnvm': {'target': device_type, 'device_id': 0},
        'relay': {'target': device_type, 'device_id': 0}
    }

    backend_options = backend_options_dict[backend]

    return backend_options

# TODO: add relay support
# TODO: maybe fixture for return_backend=True and return_backend=False
Beispiel #4
0
from copy import copy
from pytest import mark

from myia.pipeline import standard_pipeline

debug_lin_pipeline = standard_pipeline.configure(
    {'compile.linear_impl': 'debug'})


def parse_compare(*tests):
    def decorate(fn):
        def test(args):
            if not isinstance(args, tuple):
                args = (args, )
            py_result = fn(*map(copy, args))
            argspec = tuple({'value': a} for a in args)
            res = debug_lin_pipeline.run(input=fn, argspec=argspec)
            myia_fn = res['output']
            myia_result = myia_fn(*map(copy, args))
            assert py_result == myia_result

        m = mark.parametrize('args', list(tests))(test)
        m.__orig__ = fn
        return m

    return decorate


@parse_compare((1, ))
def test_debug_add(a):
    return a + 2
Beispiel #5
0
"""Edge cases that may pop up but it's not clear where else to test them."""

from dataclasses import dataclass

import numpy as np
import pytest

from myia import myia
from myia.compile.backends import get_backend_names
from myia.lib import core
from myia.operations import array_map
from myia.pipeline import standard_pipeline
from myia.testing.multitest import eqtest

pipeline2 = standard_pipeline.configure(preresolve=True)


@pytest.fixture(
    params=[pytest.param(backend) for backend in get_backend_names()]
)
def _backend_fixture(request):
    return request.param


def test_static_inline_array_map(_backend_fixture):
    backend = _backend_fixture

    @core(static_inline=True)
    def inl(x, y):
        return x + y
Beispiel #6
0
from myia.operations import (
    array_getitem,
    array_setitem,
    bool_and,
    partial,
    primitives as P,
    scalar_add,
    tagged,
)
from myia.pipeline import standard_pipeline

from .common import MA, MB, Point
from .multitest import mt, run, run_no_relay, run_relay_debug

run_no_opt = run.configure(
    pipeline=standard_pipeline.configure({"opt.phases.main": []}))


@run(2, 3)
def test_simple(x, y):
    return x + y


@run(42)
def test_constant(x):
    return x == 42


@mt(run(False, True), run(True, True), run(True, False), run(False, False))
def test_bool_and(x, y):
    return bool_and(x, y)