question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Feature: Multithreaded Training

See original GitHub issue

A GIF or MEME to give some spice of the internet

(I’m opening a new issue for this to start a conversation before submitting a pull request, so please let me know what you think.)

This adds new functionality to trainAsyc(), so that NodeJS users can utilize multiple gpus and cpus to train a single NeuralNetwork. This should significantly speed up training if you have a large neural net and/or a large training data set.

Is this a feature that we would want to merge into develop? [y/n]

Code

This branch, based on master, has a working example: massaroni/feature-parallel-training-m This other branch is mergeable into develop, but develop is too unstable at this point to demo the multithreaded training. massaroni/feature-parallel-training

See the example in parallel-trainer-example.js. It basically just shows that the algorithm does converge. See the main functionality in parallel-trainer.js

Documentation

trainAsync() in parallel mode, can train a single net on multiple threads. This should speed up training for large nets, large training sets, or both.

Train a NeuralNetwork on 3 cpu threads.

  const net = new brain.NeuralNetwork();
  net
    .trainAsync(data, {
      parallel: {
        threads: 3,
        partitionSize: 1500, // optional. send a partition of 1500 items from the training set to each thread.  Raise this number to get some overlap in the training data partitions.
        epochs: 20000, // optional. limit each thread to 20,000 training runs
      },
      // ... and the usual training options
    })
    .then(res => {
      // do something with my trained network
    })
    .catch(handleError);

Train a NeuralNetwork on 6 cpu threads and 2 GPU threads.

  const net = new brain.NeuralNetwork();
  net
    .trainAsync(data, {
      parallel: {
        threads: {
          NeuralNetwork: 6,
          NeuralNetworkGPU: 2
        }
      },
      // ... and the usual training options
    })
    .then(res => {
      // do something with my trained network
    })
    .catch(handleError);

Train a single NeuralNetwork on 6 cpu threads and 2 GPU threads, and send 10x more training data to the GPUs because they can run through it faster.

  const net = new brain.NeuralNetwork();
  net
    .trainAsync(data, {
      parallel: {
        threads: {
          NeuralNetwork: {
            threads: 6,
            trainingDataSize: 2200
          },
          NeuralNetworkGPU: {
            threads: 2,
            trainingDataSize: 22000
          }
        }
      },
      // ... and the usual training options
    })
    .then(res => {
      // do something with my trained network
    })
    .catch(handleError);

Roadmap

  • support all other neural net types
  • web workers, for multithreaded training in the browser
  • distributed training (multiple machines) (async SGD w/stale gradient handling?)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:25
  • Comments:24 (14 by maintainers)

github_iconTop GitHub Comments

7reactions
blackforest-tcommented, Oct 2, 2020

I would like to donate something if I could use four cores at the same time instead of one, in my case! Is this also intended for LSTM (not LSTMTimeStep)?

i’ll like to know about it too

4reactions
Rocketblaster247commented, Jul 15, 2019

Anything to make training faster!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Speeding up Model Training with Multithreading
Today, I'm going to talk about multithreading. Specifically, how to concurrently run (1) ... Assume we have 2 functions: Data loading and Model...
Read more >
Top Multithreading Courses Online - Updated [December 2022]
Concurrency, Multithreading and Parallel Computing in Java ... Get your team access to Udemy's top 19,000+ courses ... Java 8 New Features In...
Read more >
10 Best Java Multithreading and Concurrency Courses
Top 10 Online Courses to learn Multithreading and Concurrency in Java [2022] ... multi-threaded application before then you know that creating new threads ......
Read more >
Multithreading in Java - Everything You MUST Know
We can create Threads by either implementing Runnable interface or by extending Thread Class. Thread t = new Thread(new Runnable() ...
Read more >
Python Multithreading and Multiprocessing Tutorial - Toptal
Threading is a feature usually provided by the operating system. ... In this Python multithreading example, we will write a new module to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found