# Path: minos/model/parameters.py
# def is_custom_activation(name):
#     return name in custom_activations
# 
# def get_custom_activation(name):
#     return custom_activations.get(name, None)
# 
# def is_custom_layer(name):
#     return name in custom_layers
# 
# def get_custom_layer(name):
#     return custom_layers.get(name, None)
# 
# Path: minos/tf_utils.py
# def get_logical_device(physical_device):
#     if is_gpu_device(physical_device):
#         return '/gpu:0'
#     return physical_device
# 
# def cpu_device():
#     return '/cpu:0'


from copy import deepcopy
from keras.engine.topology import Input, Merge, merge
from keras.engine.training import Model
from keras.layers.core import Dense, Lambda
from keras.regularizers import L1L2Regularizer
from minos.model.parameters import is_custom_activation, get_custom_activation,\
    is_custom_layer, get_custom_layer
from minos.tf_utils import get_logical_device, cpu_device
import logging
import traceback
import keras
    import tensorflow as tf
    import tensorflow as tf
class MultiGpuModel(Model):

    def __init__(self, model, model_input, model_output):
        super().__init__(input=model_input, output=model_output)
        self.model = model

    def save(self, filepath, overwrite=True):
        self.model.save(filepath=filepath, overwrite=overwrite)


def _build_multi_gpu_model(blueprint, devices):
    model = _build_single_device_model(blueprint, cpu_device())

    def get_input(data, idx, parts):
        shape = tf.shape(data)
        size = tf.concat([shape[:1] // parts, shape[1:]], 0)
        stride = tf.concat([shape[:1] // parts, shape[1:] * 0], 0)
        start = stride * idx
        return tf.slice(data, start, size)

    outputs = []
    for i, device in enumerate(devices):
        with tf.device(device):
            x = model.inputs[0]
            input_shape = tuple(x.get_shape().as_list())[1:]
            model_input = Lambda(
                get_input,
                output_shape=input_shape,
                arguments={'idx': i, 'parts': len(devices)})(x)
            outputs.append(model(model_input))

# Path: minos/model/parameters.py
# def is_custom_activation(name):
#     return name in custom_activations
# 
# def get_custom_activation(name):
#     return custom_activations.get(name, None)
# 
# def is_custom_layer(name):
#     return name in custom_layers
# 
# def get_custom_layer(name):
#     return custom_layers.get(name, None)
# 
# Path: minos/tf_utils.py
# def get_logical_device(physical_device):
#     if is_gpu_device(physical_device):
#         return '/gpu:0'
#     return physical_device
# 
# def cpu_device():
#     return '/cpu:0'


# Path: minos/model/build.py
from copy import deepcopy
from keras.engine.topology import Input, Merge, merge
from keras.engine.training import Model
from keras.layers.core import Dense, Lambda
from keras.regularizers import L1L2Regularizer
from minos.model.parameters import is_custom_activation, get_custom_activation,\
    is_custom_layer, get_custom_layer
from minos.tf_utils import get_logical_device, cpu_device
import logging
import traceback
import keras
    import tensorflow as tf
    import tensorflow as tf

class MultiGpuModel(Model):

    def __init__(self, model, model_input, model_output):
        super().__init__(input=model_input, output=model_output)
        self.model = model

    def save(self, filepath, overwrite=True):
        self.model.save(filepath=filepath, overwrite=overwrite)


def _build_multi_gpu_model(blueprint, devices):
    model = _build_single_device_model(blueprint, cpu_device())

    def get_input(data, idx, parts):
        shape = tf.shape(data)
        size = tf.concat([shape[:1] // parts, shape[1:]], 0)
        stride = tf.concat([shape[:1] // parts, shape[1:] * 0], 0)
        start = stride * idx
        return tf.slice(data, start, size)

    outputs = []
    for i, device in enumerate(devices):
        with tf.device(device):
            x = model.inputs[0]
            input_shape = tuple(x.get_shape().as_list())[1:]
            model_input = Lambda(
                get_input,
                output_shape=input_shape,
                arguments={'idx': i, 'parts': len(devices)})(x)
            outputs.append(model(model_input))

    with tf.device(cpu_device()):