Giter Site home page Giter Site logo

visionscaper / stateful_multi_gpu Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 1.0 6 KB

Experimental utility to build stateful RNN models for multi GPU training.

License: MIT License

Python 100.00%
keras keras-tensorflow rnn lstm gru multi-gpu keras-models

stateful_multi_gpu's Introduction

stateful_multi_gpu

Experimental utility in development to build stateful RNN models for multi GPU training.

How to use stateful_multi_gpu()

See example.py for a toy example of how the utility function can be used.

To make stateful models in Keras you need to provide the batch size you are using.
stateful_multi_gpu() ensures that the right batch size is used throughout the model.

To use this utility function you need to create a inputs_generator method that can make inputs for your model, for any batch size, and a model_generator method that can make your model for any batch size.

For instance, as follows:

def inputs_generator(batch_size):
    rnn_input = Input(
        name="rnn-input-%d" % batch_size,
        batch_shape=(batch_size, seq_len, num_symbols))

    return rnn_input
def model_generator(batch_size):
    inputs = inputs_generator(batch_size)

    layer_output = RNNLayer(
        state_size,
        stateful=stateful_model,
        return_sequences=True)(inputs)
    outputs = TimeDistributed(Dense(num_classes))(layer_output)

    return Model(inputs=inputs, outputs=outputs)

stateful_multi_gpu uses these generator methods to create model inputs that expect batch size batch_size and model replica's (one per GPU) that expect batch size batch_size // num_gpus. E.g.:

parallel_model = stateful_multi_gpu(inputs_generator, model_generator, training_batch_size, num_gpus)

It is important that batch_size is wholly dividable by num_gpus.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.