Code Monkey home page Code Monkey logo

ddl-tensorflow's Introduction

IBM DDL-Tensorflow

Using DDL for distributed processing on GPU

Two examples:

  • Simple MNIST Classifier using shallow neural network - ddl.py
  • MNIST recognition using CNN - deep_mnist.py

Loading DDL library

ddl = tf.load_op_library('/opt/DL/ddl-tensorflow/lib/ddl_MDR.so')

Initializing DDL with number of proccess and working directives with the CPU

with tf.Session(config=config) as sess:
  with tf.device('/cpu:0'):
    rank, size, gpuid = sess.run(ddl.init(4, mode = '-mode r:4 -dump_iter 100'))

Using the gpu, start the graph definition inside this scope

with tf.device('/gpu:%d' %gpuid):

Loading the Matrix Variables into the GPU's memory with ddl.bcast

W = tf.Variable(ddl.bcast(tf.zeros([784, 10])))
b = tf.Variable(ddl.bcast(tf.zeros([10])))

After computing the gradients with Tensorflow's optmizer executing an all_reduce operation for the average and applying the result to the network

opt = tf.train.GradientDescentOptimizer(0.5)

grads_and_vars = opt.compute_gradients(cross_entropy)
grads, vars = zip(*grads_and_vars)
grads_and_vars_ddl = zip(ddl.all_reduce_n(grads, op='avg'), vars)

objective = opt.apply_gradients(grads_and_vars_ddl)

Training the data in mini-batches dividing it in each GPU

with tf.Session(config=config) as sess:
  sess.run(tf.global_variables_initializer())
    for i in range(1000):
      batch_x, batch_y = mnist.train.next_batch(batch_size*size)
      batch_x = np.split(batch_x,size)[rank]
      batch_y = np.split(batch_y,size)[rank]
      
      sess.run(objective, feed_dict={x: batch_x, y_: batch_y})

ddl-tensorflow's People

Contributors

otazz avatar

Watchers

 avatar

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.