Demo entry 6782418

defvariable_on_cpu(name,shape):# Create variables on CPUwithtf.device("/cpu:0"):var=tf.get_variable(name,shape)returnvartower_grads=[]foriinxrange(num_gpus):withtf.device('/gpu:%d'%i):# compute loss and gradients on each GPUlayer1_w=variable_on_cpu("layer1_weight",[feature_dim,layer1_dim])layer1_o=tf.matmul(features,layer1_w)...loss=tf.cross_entropy(layerN_o,labels)grads=SGDoptimizer.compute_gradients(loss)tower_grads.append(grads)withtf.device('/cpu:0'):# avarage and apply gradient on CPUgrads=average_gradients(tower_grads)train_op=opt.apply_gradients(grads,global_step=global_step)forstepinxrange(FLAGS.max_steps):_,loss_value=sess.run([train_op,loss])