Skip to content

Instantly share code, notes, and snippets.

@aniketbiprojit
Last active November 15, 2020 15:33
Show Gist options
  • Save aniketbiprojit/b9a3dfd356e5e54b715be33eaed89b09 to your computer and use it in GitHub Desktop.
Save aniketbiprojit/b9a3dfd356e5e54b715be33eaed89b09 to your computer and use it in GitHub Desktop.
Training Loop
const cluster = require('cluster')
const os = require('os')
const numCPUs = os.cpus().length
const tf = require('@tensorflow/tfjs-node')
if (cluster.isMaster) {
console.log(X[0])
console.log(y[0], y[1])
console.log('X:', X.length)
console.log('y:', y.length)
console.log(`Master ${process.pid} is running`)
for (let i = 0; i < numCPUs; i++) {
cluster.fork()
}
} else {
const batch_size = 1024
let index = cluster.worker.id
const start = (index - 1) * batch_size
const end = index * batch_size
const X_tensor = tf.tensor2d(X.slice(start, end), [batch_size, 784])
const y_tensor = tf.tensor2d(y.slice(start, end), [batch_size, 10])
console.log(`Worker ${process.pid} started:`)
const run = require('./model')
run(X_tensor, y_tensor, index)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment