Giter Club home page Giter Club logo

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.

stateful_multi_gpu's People

Contributors

visionscaper avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stateful_multi_gpu's Issues

evaluate_on_batch fails

Hi, have you tried model.evaluate_on_batch? I keep getting this error:

InvalidArgumentError (see above for traceback): You must feed a value for 
placeholder tensor 'single_input' with dtype int32 and shape [<sub_batch_size>,?]

where single_input is the input created with batch_size = sub_batch_size.

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.