Exemple #1
0
def test_shape_of_variables_simple():
    x = theano.tensor.matrix('x')
    y = x + x
    fgraph = theano.FunctionGraph([x], [y])
    assert shape_of_variables(fgraph, {x: (5, 5)}) == {x: (5, 5), y: (5, 5)}

    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x.T)
    fgraph = theano.FunctionGraph([x], [y])
    shapes = shape_of_variables(fgraph, {x: (5, 1)})
    assert shapes[x] == (5, 1)
    assert shapes[y] == (5, 5)
def test_shape_of_variables_simple():
    x = theano.tensor.matrix('x')
    y = x+x
    fgraph = theano.FunctionGraph([x], [y])
    assert shape_of_variables(fgraph, {x: (5, 5)}) == {x: (5, 5), y: (5, 5)}

    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x.T)
    fgraph = theano.FunctionGraph([x], [y])
    shapes = shape_of_variables(fgraph, {x: (5, 1)})
    assert shapes[x] == (5, 1)
    assert shapes[y] == (5, 5)
Exemple #3
0
def test_shape_of_variables_simple():
    x = theano.tensor.matrix('x')
    y = x+x
    env = theano.Env([x], [y])
    assert shape_of_variables(env, {x: (5, 5)}) == {x: (5, 5), y: (5, 5)}

    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x.T)
    env = theano.Env([x], [y])
    shapes = shape_of_variables(env, {x: (5, 1)})
    assert shapes[x] == (5, 1)
    assert shapes[y] == (5, 5)
Exemple #4
0
def test_shape_of_variables_simple():
    x = theano.tensor.matrix('x')
    y = x + x
    env = theano.Env([x], [y])
    assert shape_of_variables(env, {x: (5, 5)}) == {x: (5, 5), y: (5, 5)}

    x = theano.tensor.matrix('x')
    y = theano.tensor.dot(x, x.T)
    env = theano.Env([x], [y])
    shapes = shape_of_variables(env, {x: (5, 1)})
    assert shapes[x] == (5, 1)
    assert shapes[y] == (5, 5)
Exemple #5
0
    def test_simple(self):
        x = theano.tensor.matrix("x")
        y = x + x
        fgraph = theano.FunctionGraph([x], [y], clone=False)
        shapes = shape_of_variables(fgraph, {x: (5, 5)})
        assert shapes == {x: (5, 5), y: (5, 5)}

        x = theano.tensor.matrix("x")
        y = theano.tensor.dot(x, x.T)
        fgraph = theano.FunctionGraph([x], [y], clone=False)
        shapes = shape_of_variables(fgraph, {x: (5, 1)})
        assert shapes[x] == (5, 1)
        assert shapes[y] == (5, 5)
Exemple #6
0
    def test_simple(self):
        x = theano.tensor.matrix("x")
        y = x + x
        fgraph = theano.FunctionGraph([x], [y], clone=False)
        shapes = shape_of_variables(fgraph, {x: (5, 5)})
        assert shapes == {x: (5, 5), y: (5, 5)}

        x = theano.tensor.matrix("x")
        y = theano.tensor.dot(x, x.T)
        fgraph = theano.FunctionGraph([x], [y], clone=False)
        shapes = shape_of_variables(fgraph, {x: (5, 1)})
        assert shapes[x] == (5, 1)
        assert shapes[y] == (5, 5)
def test_shape_of_variables_subtensor():
    x = theano.tensor.matrix('x')
    subx = x[1:]
    fgraph = theano.FunctionGraph([x], [subx])
    shapes = shape_of_variables(fgraph, {x: (10, 10)})
    assert shapes[subx] == (9, 10)
Exemple #8
0
 def test_subtensor(self):
     x = theano.tensor.matrix("x")
     subx = x[1:]
     fgraph = theano.FunctionGraph([x], [subx], clone=False)
     shapes = shape_of_variables(fgraph, {x: (10, 10)})
     assert shapes[subx] == (9, 10)
Exemple #9
0
def test_shape_of_variables_subtensor():
    x = theano.tensor.matrix('x')
    subx = x[1:]
    env = theano.Env([x], [subx])
    shapes = shape_of_variables(env, {x: (10, 10)})
    assert shapes[subx] == (9, 10)
Exemple #10
0
# give identifiers to all variables

fgraph = FunctionGraph(inputs, outputs)
theano.gof.utils.give_variables_names(fgraph.variables)
map(clean_variable, fgraph.variables)
fgraph2 = math_optimize(fgraph)
fgraph2_var_dict = {str(var): var for var in fgraph.variables}
input_shapes2 = {
    fgraph2_var_dict[str(var)]: input_shapes[var]
    for var in input_shapes
}

os.system('mkdir -p tmp')

all_shapes = shape_of_variables(fgraph, input_shapes)

# Compute Cost
compute_times = comptime_dict(fgraph, input_shapes, 10, machines,
                              machine_groups)
save_dict('tmp/compute_times.dat', compute_times)
# compute_times = load_dict('tmp/compute_times.dat')
compute_cost = make_runtime_function(compute_times)

# Communication Cost
comm_dict = commtime_dict(network, [10, 100, 1000, 2000] * 5)

save_dict('tmp/comm_times.dat', comm_dict)
# comm_dict = load_dict('tmp/comm_times.dat')
comm_cost = make_commtime_function(comm_dict, all_shapes)
Exemple #11
0
def test_shape_of_variables_subtensor():
    x = theano.tensor.matrix('x')
    subx = x[1:]
    env = theano.Env([x], [subx])
    shapes = shape_of_variables(env, {x: (10, 10)})
    assert shapes[subx] == (9, 10)
Exemple #12
0
 def test_subtensor(self):
     x = theano.tensor.matrix('x')
     subx = x[1:]
     fgraph = theano.FunctionGraph([x], [subx], clone=False)
     shapes = shape_of_variables(fgraph, {x: (10, 10)})
     assert shapes[subx] == (9, 10)
Exemple #13
0
from nfs_triple import machine_groups, network, machines
from kalman import inputs, outputs, input_shapes

# give identifiers to all variables

fgraph = FunctionGraph(inputs, outputs)
theano.gof.utils.give_variables_names(fgraph.variables)
map(clean_variable, fgraph.variables)
fgraph2 = math_optimize(fgraph)
fgraph2_var_dict = {str(var): var for var in fgraph.variables}
input_shapes2 = {fgraph2_var_dict[str(var)]: input_shapes[var] for var in input_shapes}

os.system("mkdir -p tmp")


all_shapes = shape_of_variables(fgraph, input_shapes)

# Compute Cost
compute_times = comptime_dict(fgraph, input_shapes, 10, machines, machine_groups)
save_dict("tmp/compute_times.dat", compute_times)
# compute_times = load_dict('tmp/compute_times.dat')
compute_cost = make_runtime_function(compute_times)

# Communication Cost
comm_dict = commtime_dict(network, [10, 100, 1000, 2000] * 5)

save_dict("tmp/comm_times.dat", comm_dict)
# comm_dict = load_dict('tmp/comm_times.dat')
comm_cost = make_commtime_function(comm_dict, all_shapes)

Exemple #14
0
import theano
from ape.timings.communication.master import make_commtime_function, commtime_dict
from theano.tensor.utils import shape_of_variables

x = theano.tensor.matrix('x')
y = theano.tensor.matrix('y')
dotxx = theano.tensor.dot(x, x)
z = dotxx + y[:, 0].sum() - x * y

env = theano.FunctionGraph([x, y], [z])

dot = env.toposort()[2]
known_shapes = shape_of_variables(env, {x: (100, 100), y: (100, 100)})


def test_make_commtime_function():
    data = {
        ('a', 'b'): {
            'intercept': 1,
            'slope': 1
        },
        ('b', 'a'): {
            'intercept': 0,
            'slope': 10
        }
    }

    commtime = make_commtime_function(data, known_shapes)

    assert commtime(dotxx, 'a', 'b') == 4 * 100 * 100 * 1 + 1
    assert commtime(dotxx, 'b', 'a') == 4 * 100 * 100 * 10 + 0
Exemple #15
0
 def test_err(self):
     x = theano.tensor.matrix("x")
     subx = x[1:]
     fgraph = theano.FunctionGraph([x], [subx])
     with pytest.raises(ValueError):
         shape_of_variables(fgraph, {x: (10, 10)})
Exemple #16
0
import theano
from ape.timings.communication.master import make_commtime_function, commtime_dict
from theano.tensor.utils import shape_of_variables

x = theano.tensor.matrix("x")
y = theano.tensor.matrix("y")
dotxx = theano.tensor.dot(x, x)
z = dotxx + y[:, 0].sum() - x * y

env = theano.FunctionGraph([x, y], [z])

dot = env.toposort()[2]
known_shapes = shape_of_variables(env, {x: (100, 100), y: (100, 100)})


def test_make_commtime_function():
    data = {("a", "b"): {"intercept": 1, "slope": 1}, ("b", "a"): {"intercept": 0, "slope": 10}}

    commtime = make_commtime_function(data, known_shapes)

    assert commtime(dotxx, "a", "b") == 4 * 100 * 100 * 1 + 1
    assert commtime(dotxx, "b", "a") == 4 * 100 * 100 * 10 + 0


def test_make_commtime_function_non_clique_network():
    data = {
        ("a", "b"): {"intercept": 1, "slope": 1},
        ("b", "a"): {"intercept": 0, "slope": 10},
        ("b", "c"): {"intercept": 0, "slope": 10},
    }