コード例 #1
0
def test_get_all_sinks_and_sources(layers):
    forced_orders = get_forced_orders(layers)
    connections = get_connections(layers)
    layout = create_layout_stub(layers)
    all_sources = get_all_sources(forced_orders, connections, layout)

    assert all_sources == [
        'Input.outputs.default',
        'Input.output_deltas.default',
        'A.outputs.default',
        ('A.parameters.W', 'A.parameters.bias'),
        'A.output_deltas.default',
        ('A.gradients.W', 'A.gradients.bias'),
        'B.outputs.default',
        ('B.parameters.W', 'B.parameters.bias'),
        'B.output_deltas.default',
        ('B.gradients.W', 'B.gradients.bias'),
        'C.outputs.default',
        ('C.parameters.W', 'C.parameters.bias'),
        'C.output_deltas.default',
        ('C.gradients.W', 'C.gradients.bias'),
        'D.outputs.default',
        ('D.parameters.W', 'D.parameters.bias'),
        'D.output_deltas.default',
        ('D.gradients.W', 'D.gradients.bias')]
コード例 #2
0
def test_get_all_sinks_and_sources(layers):
    forced_orders = get_forced_orders(layers)
    connections = get_connections(layers)
    layout = create_layout_stub(layers)
    all_sources = get_all_sources(forced_orders, connections, layout)

    assert all_sources == [
        'Input.outputs.default',
        'Input.output_deltas.default',
        'A.outputs.default',
        ('A.parameters.W', 'A.parameters.bias'),
        'A.output_deltas.default',
        ('A.gradients.W', 'A.gradients.bias'),
        'B.outputs.default',
        ('B.parameters.W', 'B.parameters.bias'),
        'B.output_deltas.default',
        ('B.gradients.W', 'B.gradients.bias'),
        'C.outputs.default',
        ('C.parameters.W', 'C.parameters.bias'),
        'C.output_deltas.default',
        ('C.gradients.W', 'C.gradients.bias'),
        'D.outputs.default',
        ('D.parameters.W', 'D.parameters.bias'),
        'D.output_deltas.default',
        ('D.gradients.W', 'D.gradients.bias')]
コード例 #3
0
def test_create_layout_stub(layers):
    layout = create_layout_stub(layers)
    assert layout == {
        '@type': 'BufferView',
        'parameters': {
            '@type': 'array',
            '@index': 0
        },
        'gradients': {
            '@type': 'array',
            '@index': 1,
            '@is_backward_only': True
        },
        'Input': {
            '@type': 'BufferView',
            '@index': 2,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2)
                },
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2),
                    '@is_backward_only': True
                },
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6
            },
        },
        'A': {
            '@type': 'BufferView',
            '@index': 3,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2)
                }
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 3)
                }
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (3, 2)
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (3, )
                }
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2),
                    '@is_backward_only': True
                }
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 3),
                    '@is_backward_only': True
                }
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (3, 2),
                    '@is_backward_only': True
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (3, ),
                    '@is_backward_only': True
                }
            },
        },
        'B': {
            '@type': 'BufferView',
            '@index': 4,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2)
                }
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 5)
                }
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (5, 2)
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (5, )
                }
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 2),
                    '@is_backward_only': True
                }
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 5),
                    '@is_backward_only': True
                }
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (5, 2),
                    '@is_backward_only': True
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (5, ),
                    '@is_backward_only': True
                }
            },
        },
        'C': {
            '@type': 'BufferView',
            '@index': 5,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 8)
                }
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 7)
                }
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (7, 8)
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (7, )
                }
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 8),
                    '@is_backward_only': True
                }
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 7),
                    '@is_backward_only': True
                }
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (7, 8),
                    '@is_backward_only': True
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (7, ),
                    '@is_backward_only': True
                }
            },
        },
        'D': {
            '@type': 'BufferView',
            '@index': 6,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 12)
                }
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 11)
                }
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (11, 12)
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (11, )
                }
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 12),
                    '@is_backward_only': True
                }
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': ('T', 'B', 11),
                    '@is_backward_only': True
                }
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {
                    '@type': 'array',
                    '@index': 0,
                    '@shape': (11, 12),
                    '@is_backward_only': True
                },
                'bias': {
                    '@type': 'array',
                    '@index': 1,
                    '@shape': (11, ),
                    '@is_backward_only': True
                }
            },
        }
    }
コード例 #4
0
def test_create_layout_stub(layers):
    layout = create_layout_stub(layers)
    assert layout == {
        '@type': 'BufferView',
        'parameters': {
            '@type': 'array',
            '@index': 0
        },
        'gradients': {
            '@type': 'array',
            '@index': 1,
            '@is_backward_only': True
        },
        'Input': {
            '@type': 'BufferView',
            '@index': 2,
            'inputs': {'@type': 'BufferView', '@index': 0},
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2)},
            },
            'parameters': {'@type': 'BufferView', '@index': 2},
            'internals': {'@type': 'BufferView', '@index': 3},
            'input_deltas': {'@type': 'BufferView', '@index': 4},
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2),
                            '@is_backward_only': True},
            },
            'gradients': {'@type': 'BufferView', '@index': 6},
        },
        'A': {
            '@type': 'BufferView',
            '@index': 3,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2)}
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 3)}
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {'@type': 'array', '@index': 0, '@shape': (3, 2)},
                'bias': {'@type': 'array', '@index': 1, '@shape': (3,)}
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2),
                            '@is_backward_only': True}
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 3),
                            '@is_backward_only': True}
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {'@type': 'array', '@index': 0, '@shape': (3, 2),
                      '@is_backward_only': True},
                'bias': {'@type': 'array', '@index': 1, '@shape': (3,),
                         '@is_backward_only': True}
            },
        },
        'B': {
            '@type': 'BufferView',
            '@index': 4,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2)}
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 5)}
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {'@type': 'array', '@index': 0, '@shape': (5, 2)},
                'bias': {'@type': 'array', '@index': 1, '@shape': (5,)}
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 2),
                            '@is_backward_only': True}
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 5),
                            '@is_backward_only': True}
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {'@type': 'array', '@index': 0, '@shape': (5, 2),
                      '@is_backward_only': True},
                'bias': {'@type': 'array', '@index': 1, '@shape': (5,),
                         '@is_backward_only': True}
            },
        },
        'C': {
            '@type': 'BufferView',
            '@index': 5,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 8)}
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 7)}
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {'@type': 'array', '@index': 0, '@shape': (7, 8)},
                'bias': {'@type': 'array', '@index': 1, '@shape': (7,)}
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3,
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 8),
                            '@is_backward_only': True}
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 7),
                            '@is_backward_only': True}
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {'@type': 'array', '@index': 0, '@shape': (7, 8),
                      '@is_backward_only': True},
                'bias': {'@type': 'array', '@index': 1, '@shape': (7,),
                         '@is_backward_only': True}
            },
        },
        'D': {
            '@type': 'BufferView',
            '@index': 6,
            'inputs': {
                '@type': 'BufferView',
                '@index': 0,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 12)}
            },
            'outputs': {
                '@type': 'BufferView',
                '@index': 1,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 11)}
            },
            'parameters': {
                '@type': 'BufferView',
                '@index': 2,
                'W': {'@type': 'array', '@index': 0, '@shape': (11, 12)},
                'bias': {'@type': 'array', '@index': 1, '@shape': (11,)}
            },
            'internals': {
                '@type': 'BufferView',
                '@index': 3
            },
            'input_deltas': {
                '@type': 'BufferView',
                '@index': 4,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 12),
                            '@is_backward_only': True}
            },
            'output_deltas': {
                '@type': 'BufferView',
                '@index': 5,
                'default': {'@type': 'array', '@index': 0,
                            '@shape': ('T', 'B', 11),
                            '@is_backward_only': True}
            },
            'gradients': {
                '@type': 'BufferView',
                '@index': 6,
                'W': {'@type': 'array', '@index': 0, '@shape': (11, 12),
                      '@is_backward_only': True},
                'bias': {'@type': 'array', '@index': 1, '@shape': (11,),
                         '@is_backward_only': True}
            },
        }}