-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M1 Mac, nodejs GPU train time way longer than CPU #818
Comments
XOR uses approximately 3 neurons. It will always be faster on CPU. For GPU to break even you need something like 512x512 neurons. This is a limitation of hardware and not a bug. However the browser issue you raised may be legitimate. Did you load GPU.js prior to brain.js in a browser? |
I tried both ways, initially just loading brain.js from the CDN: then adding a script tag before first to load from https://unpkg.com/gpu.js@latest/dist/gpu-browser.min.js results in: Same results in both Chrome and Firefox. gpu.js as loaded off the CDN looks like an ES module (loading it Just out of curiosity, is the minimum time to run on the GPU a result of uploading batches of data, or modifying kernels with each epoch or both? |
The data is first uploaded (and a tiny compiled kernel for uploading training data) and then the kernels are compiled in the first iteration of learning. After that everything exists and is ran from the GPU. |
Ahha, I didn't realize the hidden layers were where the advantage was. The trade-off point seems to be around [128,128]. With 512 rows of training data, benchmark on the M1 is about 11 seconds for both CPU and GPU at that size. Beyond that GPU takes off =) |
Closing this issue because of having a sufficient explanation. |
What is wrong?
Running the basic XOR example, 10k interations. With brain.NeuralNetwork(), 46 milliseconds. With brain.NeuralNetworkGPU(), 14.6 seconds.
Where does it happen?
brain.js@2.0.0-beta.15. Node 18.3.0 running on the command line, Python 3.9.13 (don't think this matters?), M1 Macbook Pro (Max, 32 GPU cores).
How do we replicate the issue?
1 - Run the first XOR example in the Readme.md, (speed shown was attained using default config options, not passing a config to NeuralNetwork()).
Expected behavior (i.e. solution)
The GPU version... shouldn't be ...slower?
Version information
Nodejs:
Node 18.3.0
Browser:
N/A
Brain.js:
brain.js@2.0.0-beta.15
How important is this (1-5)?
5 if it's a bug, 0 if it's a mistake on my end.
Other Comments
This is my first time trying brain.js so it's quite possible I've just got something misconfigured. Love the project and the ease of use! The fact that on CPU that training took 46ms is hard to believe.
As a side note, I was unable to get the browser version to work at all from the CDN, it kept throwing
js_gpu is undefined
or something along those lines, then when I side-loaded gpu.js I gotjs_gpu.GPU is not a constructor
. I'd rather use it in Node anyway...The text was updated successfully, but these errors were encountered: