[HN Gopher] Brain.js: GPU Accelerated Neural Networks in JavaScript
___________________________________________________________________
Brain.js: GPU Accelerated Neural Networks in JavaScript
Author : andsoitis
Score : 167 points
Date : 2022-07-07 15:22 UTC (7 hours ago)
(HTM) web link (brain.js.org)
(TXT) w3m dump (brain.js.org)
| danielEM wrote:
| Long time ago wanted to so something good and took a part in W3C
| webmachinelearning standardization group. Inspired by simplicity
| of brain.js wanted browser API to offer something similar to it -
| simple and easy to learn and easy to understand, also wanted a
| training API to be available. It is possible to keep simplicity
| of brain.js and flexibility of any other op set. And my oh my -
| did hit the wall HARD! Paid seats in W3C rules. They do what they
| want there. Your voice there matters only if it aligns well with
| their voice. Browsers API is now their own domain and whenever
| there is a conflict of interest their choice is obvious.
| dennisy wrote:
| That group has been around for so long, seems mostly Intel
| folks.
|
| I just don't get why the progress is so slow!
|
| I was trying to follow along, and joined calls, but the group
| moves like a glacier.
| davidatbu wrote:
| There's also tract, from Sonos[0]. 100% Rust[1]. I'm currently
| using it to do speech recognition with a variant of the Conformer
| architecture (exported to ONNX).
|
| The final goal is to do it in WASM client-side.
|
| [0] https://github.com/sonos/tract
|
| [1] To be clear, I'm not saying that writing in Rust is some
| inherent advantage for an NN inference engine. But I personally
| gravitate to using libraries written in languages I know/want to
| learn, and Rust might be that for some people.
| brrrrrm wrote:
| For inference, models should be compiled down directly to WASM
| or WebGPU or whatever, right? The driving language really
| shouldn't matter at the end of the day.
|
| Unless you've got massive compute bound transformers or old-
| school full convolutions, if you're interpreting a list of
| operations you're going to lose perf.
| leeoniya wrote:
| also https://github.com/photopea/UNN.js
| misterdata wrote:
| See also https://github.com/webonnx/wonnx, which runs ONNX models
| through WebGPU. It is written in Rust and can be used natively on
| Windows, macOS and Linux (through wgpu which uses either DX12,
| Vulkan or Metal) or on the web (it has a JS API that uses WASM
| under the hood, which calls into the browser's WebGPU API). There
| is a Python module as well.
| davidatbu wrote:
| I've ran across this before, but haven't figured out if a GPU
| is _required_ to use it. That would be a deal-breaker for any
| consumer facing web app right?
| misterdata wrote:
| It will work with software implementations (e.g.
| llvmpipe/lavapipe is used in CI). That will be slower though.
| However you'd be surprised at how many devices have a usable
| GPU. Not all have NVIDIA RTX'es of course, but a simple iGPU
| will do. I tested it on a fairly low specced Dell office PC
| with an Intel Iris iGPU and that works just fine. Also most
| mobile devices will have a GPU these days.
| nightski wrote:
| I'm curious if there are many scenarios where a CPU fallback,
| especially javascript based, would have acceptable
| performance when a GPU is not present. Is that even really a
| solution?
| neodypsis wrote:
| There's also TensorFlow.js: https://www.tensorflow.org/js
| ch_sm wrote:
| also ONNX.js, which is great for interop:
| https://github.com/microsoft/onnxjs
| ge96 wrote:
| I used their facial landmark model, took some messing around
| (import/dep issues) but worked in my react project.
|
| My use case was just automatic picture taking when a face was
| detected in a video stream.
| jppope wrote:
| brain.js is significantly simpler to deploy basic projects than
| TensorFlow.js
| yeldarb wrote:
| For object detection, we made a way to do it from scratch in
| a couple of hours (for free if your project is open
| source[1]): https://docs.roboflow.com/inference/web-browser
|
| [1] https://blog.roboflow.com/computer-vision-datasets-and-
| apis/
| neodypsis wrote:
| I was checking it out, but it seems limited in terms of the
| type of models you can implement. You don't have CNNs for
| example.
| pluc wrote:
| https://dannjs.org/
| neodypsis wrote:
| Does it support GPU?
| cubano wrote:
| So being semi-retired (unable to find work due to 10yr+ past
| background issues) and living in Vegas, I've really given serious
| thought to building some sort of NN to help with gambling in
| general and specifically the picking of horses (or perhaps even
| baseball outcomes).
|
| I can't help but think that buried in all the race data their are
| correlations that are impossible to figure with standard
| statistical methods but can be sussed out using NNs. Of course I
| am vaguely aware that many people are already using NNs to
| predict race outcomes, but I am purposely trying to keep that
| info at arms length as I don't really want to be negatively
| influenced existing attitudes.
|
| However, if someone does happen to know of a good NN/horseracing
| blog that has a positive outlook and is making money, I would be
| interested in such a site.
|
| Anyway, this type of easy-to-use NN could be exactly what I'm
| looking for with getting started on this project, and once again,
| I would be interested in hearing about the pros and cons of using
| such a lightweight easy-to-use NN for my explorations.
| FrenchDevRemote wrote:
| what do you think the bookmakers are using to set the odds?
|
| If you don't have a PHD level and a large amount of money to
| start with, don't even try to think about it.
|
| I've spent a few months tinkering with this kind of stuff, with
| a huuuge dataset, my simulations never went past the annual
| return of an average ETF, and by eliminating 99/99.5% of bets
| possible, so you'd only have a few bets that are worth it per
| month, a bad streak would ruin your return for the year, and
| you'd have to have access to a lot of bookmakers to get the
| best odds.
|
| It's just not worth it IMO.
| vosper wrote:
| If you can consistently make money the bookies / betting
| platforms will just ban you.
| jdmoreira wrote:
| There is a good book that I recommend
|
| Precision Statistical and Mathematical Methods in Horse Racing
|
| the book will set you in the right path at least and I learnt
| some good mental models from it
| jdmoreira wrote:
| I just want to clarify I never gambled in my life. But I did
| have similar thoughts to yours and the book scratched that
| itch for me.
| jsiaajdsdaa wrote:
| Tangentially, I'm just curious, is it something that appears in
| your criminal background check that causes you to not receive
| offers? Or is it a lack of interviews due to gaps on a resume?
|
| I am a firm believer that if someone demonstrates they have
| motivation and skill in a writing sample, they deserve an
| interview. If that person then passes a technical interview,
| they deserve a job. And if that person is friendly and does not
| commit any crimes while working, they deserve to keep that job.
| [deleted]
| TekMol wrote:
| unable to find work due to 10yr+ past background issues
|
| The broken url in your profile might also be a factor.
| ww520 wrote:
| There might not be enough data to train a NN, and it's probably
| prone to overfitting the model. It's a similar problem to using
| NN to predict the stock market. You might have better luck with
| shallow learning statistical techniques that require less data
| to train a model.
| mhh__ wrote:
| Those standard statical methods probably don't have the gift of
| thousands of parameters.
| carnitine wrote:
| Well no, but what's your point?
| mhh__ wrote:
| It's a pretty strange comparison if you think about it
| computationally.
|
| I'm very much on the deep learning train but comparisons
| with traditional statistics are rather somewhat tortured.
| m00dy wrote:
| I think a js framework doesn't make sense because all people I
| know dealing with dnns using python as base language. I'm also
| working on something very similar and I think my stack is a lot
| better because I used pyodide + webassembly + webgpu . So far, I
| managed to implement a very small grad based dnn framework with
| couple of ops. (like matmul, etc.)
|
| One of the limitations is that webassembly vm has 4gb address
| space. This could be a problem during loading/unloading from/to
| gpu.
| revskill wrote:
| Because many devs just don't want to use a language like
| Python.
| paradite wrote:
| The point is to train and run DNN in browsers and mobile
| phones.
| darepublic wrote:
| The mobile site needs some work. Why is the hero present on every
| page, not just the lander? On mobile firefox the flex box in the
| hero is not wrapping like it should. In terms of marketing and
| communication, you need to specify up front what lib is being
| used for the gpu accelerated parts. Can I do everything with this
| as I could with, say, pytorch, except in js?
| m00dy wrote:
| No, you can't
| fbanon654 wrote:
| not yet (and not with this framework) but soon with pytorch
| itself
|
| https://dev-discuss.pytorch.org/t/proposal-torch-js-a-
| javasc...
| pixelbyindex wrote:
| > It's pretty much a certainty that a web standard for
| eager-mode machine learning will spring up when WebGPU
| comes online
|
| I can agree on this point. The fusion of the browser and
| the GPU will likely open up some new pathways to ML
| concepts that were previously impeded.
|
| At the same time, is there a possibility that websites
| begin implementing heavy GPU operations at scale, in the
| same way that SPA webapps are heavy on memory today?
| jppope wrote:
| I ABSOLUTELY loved this project and used it for all of my "quick
| and dirty" ML stuff where I was fooling around... the only
| problem, which I don't think has been fixed is that it still
| requires *Python 2.7*.
|
| End of life for Python 2.7 was 2020!
| vorticalbox wrote:
| Yeah this is a big issue that is super annoying to fix on
| latest Ubuntu.
|
| That said if you can get it working the api is very simple but
| you can do a lot of things with it.
|
| I created a LSTM network to predict your next move in rocker,
| paper, scissors in very little code.
| nmstoker wrote:
| As others say, it's headless-gl, and that in turn seems to be
| due to node-gyp.
|
| However the good news seems this is probably more a case of
| documentation inertia than actual requirements: it looks like
| you actually can install a version of node-gyp that works with
| Python 3.x and then in turn should be able to get headless-gl
| working too, which then let's brain.js work with a non -EOL
| version of Python
| Aspos wrote:
| What do you mean? Brain.js is JavaScript ML engine.
| synchronizing wrote:
| Check out the README: https://github.com/BrainJS/brain.js
| YetAnotherNick wrote:
| It's just a requirement. Python 2 is available on all the
| systems I know. What difficulty are you facing in
| installing it?
| Aspos wrote:
| Oh, you don't need to use python if you don't want to.
| Brain.js happily runs in a broswer.
| dhritzkiv wrote:
| Thanks for pointing this out. I've submitted a PR to resolve
| this: https://github.com/gpujs/gpu.js/issues/757
|
| That being said, if you're not building from source (you're
| running an LTS version of node on a supported platform), you
| don't need to worry about python or many of the build deps.
| pmelendez wrote:
| It sounds like the problem is with its dependency with
| headless-gl, but still you have a point
___________________________________________________________________
(page generated 2022-07-07 23:00 UTC)