You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 12, 2020. It is now read-only.
I created this repository as a discussion hub for the ML ecosystem in Rust, "following" a talk I gave at the Rust meetup in London (slides).
I do believe that Rust has great potential in this area, but to fully realize this potential we need to provide building blocks: we need to tackle those shared challenges that, once removed, will enable more and more people to just come to Rust and build what they want to build.
The three building blocks I do see as fundamental for an ML ecosystem are:
n-dimensional arrays;
dataframes;
an ML model interface.
I have spent the last year, when it comes to open-source contributions, enhancing n-dimensional arrays: direct contributions to ndarray, statistical routines on top of it (ndarray-stats) and tutorials to help people to get into the Rust scientific ecosystem from Python, Julia or R. I do believe that ndarray is in more than a good shape when it comes to fulfil NumPy's role in the Rust ecosystem.
There is now movement as well when it comes to dataframes - a discussion is taking place at rust-dataframe/discussion#1 to explore use cases and potential designs. (The idea of opening this repository comes directly from this experiment of community-led design for dataframes).
Given that one of the two data structures that are usually consumed by ML models is ready (n-dimensional arrays) and the other one is baking (dataframes) I think it's time to start thinking about what to do with the ML-specific piece.
I don't want to steer the debate too much with the opening post (I'll chip in once the discussion starts), but the questions I'd like to see tackled are:
what use-cases could make Rust shine in the ML ecosystem?
what are the basic capabilities that have to be built to enable the usage of Rust for ML workloads?
how should we structure such a project? A core library with few traits and a set of separate crates tackling different aspects? A large battery-included scikit-learn equivalent?
I think the use case that coud make Rust shine, is deployment. Currently the de-facto "mainstream" stack is python based ( scikit-learn, np, pandas + your DL framework of choice, TensorFlow, Torch .. ). It shines for fast prototyping, because python, but it sucks for industrialization ( and deployment ), because ... python. I really think rust would do great. In that area, I kinda like TensorFlow serving, but it forces you to have a separate service ( that you call with their protobuf/RPC).
So :
nice conventions for training/inference
standard ways of serializing, loading models, and expose them to more "entreprisey" stacks, either with some kind of FFI ( for ex. jvm <-> jni ..) or RPC.
with all the goodies required for a industrial setups ( monitoring, robustness, ease of deployment ...).
Reacted by josh bowles, Luca Palmieri, Dhruv Dhamani, Todd Young, Clark Zinzow, Dave Challis, Thiago Machado, Markus Klein, skraman, ..o.n.o.. and 1 more
I'm currently building a large project with rust (i mention it here: https://users.rust-lang.org/t/interest-for-nlp-in-rust/15331/9), where I am doing the data engineering in rust (lots of string metrics). [tldr; I found lots of disparate projects with 50% of what I needed for string metrics but instead rolled my own, trying to incorporate previous work and give credit] I want to feed the feature vectors to Julia to experiment with what I want to use for classification and modelling, and then I'll want to be able to use rust for inference/classification etc.... I had to pause development for business reasons, but I'm starting again: one of my biggest issues was not ML related but finding a nice pattern for parallel file download (seems like it should be simple, but maybe I'm spoiled by go's simplicity lol).
From this real-world project point of view, as well from my time spent thinking in the abstract and surveying the ML ecosystem in rust (about a year), I would think that a focus on data engineering in general and serving models is the way to go (this also seems to be a widely shared sentiment). In a practical sense I would like to see rust jobs for data engineer and machine learning engineer... that is, the bookends of a typical data science project; serving the data and serving the model.
That is, targeting software developers, infrastructure, computational math, and data people. Trying to convince research scientists to use Rust would be wasted effort; for most of these people software is a secondary skill and so they need something easy to learn, dynamically typed, with a REPL... I've watched this play out in the Python/R/Matlab versus Julia world... and while IMO Julia has a lot to offer current python/r/matlab devs and is similar enough to those languages, trying to get that group of people to use Julia is not easy, i can't imagine what it'd be like proposing Rust.
Here are some challenges I see:
Dataframes: figuring out what to do with missing data is a challenge (i watched julia community struggle with that this last year).
LinearAlgebra: ndarray, nalgebra are both active projects... is there duplicated effort? (there are others as well).
Rust types more friendly for math: I've seen the power in Julia of being able to specify AbstractArray as a type, or have a Real as a type, that allows you to build generic functions that accept a vector of float32 or float64.
Swift: google and numerous well-known people (chris lattner[LLVM, Swift], jeremy howard[fast.ai]) have put their support behind swift for tensorflow. IMO swift has really long way to go. But for Rust, tackling areas where the swift-for-tf project are not focusing on is good.
Support for Julia: integration with Python is a necessity; but if there is a competitor for the research-scientist in the Python world it is Julia and I'd imagine keeping an eye on playing well with Julia could be a benefit. Competition here is hard to forecast and julia/rust are on really different ends of the spectrum; while julia pushes solving the "two language" problem i see no problem using rust and julia in project; I doubt competition is an issue, not like with Swift.
Reacted by Clark Zinzow, Jason Knight, rencire and Nestor Demeure
I do believe that ndarray is in more than a good shape when it comes to fulfil NumPy's role in the Rust ecosystem.
Really looking forward to digging into ndarray. Though I've had a slight delay, I'm writing up ndarray examples for the Grokking Deep Learning book where andrew trask introduces deep learning with only numpy. He's expressed interest and welcomed the examples... :)
Reacted by Todd Young, Luca Palmieri and Clark Zinzow
Tokenization fills the role of "turn the text into fixed vectors" that you'd feed into standard models. As an NLP practitioner and Rust user, tokenization is an incredibly important step in the pipeline, a big barrier to new people trying to apply NLP, and a place where lots of small bugs creep in due to non-standard implementations that take forever to find. Having a standard implementation for the simpler tokenization methods (like regex matching) would make NLP problems much more approachable in Rust.
Reacted by josh bowles, Dhruv Dhamani, Stefan Andresen, Clark Zinzow, Dave Challis, prestissimo and Alex Rozgo
One part of machine learning where Rust could shine right now is simulation for Reinforcement learning.
For instance if I training an agent to play blackjack, the biggest bottleneck here is the "playing" blackjack over and over by the agent to collect enough data for training.
Rayon and Actix could be used to create fast and performant game "environments" now, without need for an established ML ecosystem.
Reacted by Todd Young, Clark Zinzow, skraman, Jason Knight and Alex Rozgo
I agree with @DhruvDh, using Rust to simulate environments for RL agents would be great.
Having something akin to OpenAI's gym interface would be really nice. Many RL researchers are going to still want to use Python and all the associated deep learning libraries. So, I would love to see RL environments rendered in Rust that could be interfaced with both Python and Rust for agents.
Edit: I imagine that algorithms like Monte Carlo Tree Search would be really useful if they were written in Rust. I would not want to wait on Python to handle that bit.
if I training an agent to play blackjack, the biggest bottleneck here is the "playing" blackjack over and over by the agent to collect enough data for training.
Along these lines, I am working on a hobby project (link), which does this. It isn't quite ready for even an alpha release yet, but I am in the final stages of cleaning up the API with the intent to publish it.
I've been thinking of building a rust deep learning / GPU compute library on top of the TVM framework for a while now. I think it could address a lot of the things @flo-dhalluin is talking about. TVM's an amazing project that's currently flying a bit under the radar. It's an open source deep learning compiler - it compiles deep neural nets / large array operations to run on the GPU (or on OpenCL, or FPGA, or TPU, or WebGL...). You define an AST of computations via its API, and it spits out a small (<5mb) shared library containing just the operations you wanted, on whatever acceleration framework and target platform you want.
It currently has a working Rust runtime library, which lets you call a compiled model from Rust. It integrates with ndarray, and will let you e.g. take in an ndarray::Array, move it to a GPU, run whatever numerical operations you want on it, and get the result back as an ndarray::Array again.
That's pretty neat, and I don't think it would be too hard to build some really cool tools on top of it. My dream is something like:
lib.rs:
// a crate based on tvm// `cargo build` will (by default) download + checksum a prebuilt TVM library// that this links to, so that you don't have to wait for a whole compiler to compile.// The download will only be ~50mb -- way smaller and easier than lots of other deep// learning frameworks. It will also support running code on things besides cuda!// The output binary won't need to link the compiler (by default) and will therefore be// only a few megabytes.externcrate tvmrs;// a procedural macro that converts Rust code to Relay IR.// Relay IR is TVM's high-level IR for defining neural networks / computation chains,// sorta like a tensorflow Graph. It's also not too dissimilar to Rust.// The macro will compile the IR with TVM at build-time, and link the resulting artifacts// to this rust library.
tvmrs::accelerate! {// stateless operationfn relu_downsample(x:Tensor[c, n, h, w]) -> Tensor[c, n, h/2, w/2]{
relu(downsample(x))}// stateful operationstructBlock<oc> {
conv:Conv2d<3,3,oc>,
elu:Elu}implOpforBlock<oc> {fn run(self, input:Tensor[c, n, h, w]) -> Tensor[oc, n, h, w]{self.elu(self.conv(input))}}fn swap_channels(x:Tensor[2, n, h, w]) -> Tensor[2, n, h, w]{// a low-level tensor operation defined as a TVM Tensor expression.let out = compute!(x.shape, |cc, nn, hh, ww| x[(c + 1) % 2, nn, hh, ww)]);
out
}// a sequential network container.
sequential! Network{
#[opencl]Block<3,3,5>,// run on opencl
#[opencl] relu_downsample,
#[opencl]Conv2d::new(1,1,2),
#[rust] debug,// call a normal rust function
#[cpu] swap_channels // run this part on CPU to maximize throughput}// Compute a derivative of the network.// Relay IR is designed to be differentiable.
derivative! NetworkDerivative(Network);}// a normal rust functionfndebug(x:Tensor){
...}
All of this is of course pending mountains of bikeshedding, i have no idea what the final API will look like.
One of the nifty things here is that this isn't limited to deep learning models. TVM can handle pretty much any algorithm made of large array operations. So if you wanted to run your SVM on GPU, you can do that pretty easily!
Steps to take here:
Talk to the TVM people and see what they think of all this. We could do this work under their umbrella or in a fresh project.
Write Rust bindings to the TVM compiler (instead of just the runtime). TVM is written in C++ but is designed to be easy to bind, a lot of the work has already been done here.
Design an API like my sketch above that wraps the bindings in some way that makes them easy to use for training + deployment.
Build up cargo tooling to allow e.g. prebuilt binary downloads, TVM's auto-tuner support, etc.
Beef up TVM's autodifferentiation support. TVM can differentiate Relay IR, but a lot of derivatives aren't actually implemented yet. We could also roll our own autodifferentiation system and just use TVM for compilation; I'd prefer to avoid duplicating work tho.
Start writing non-deep-learning algorithms with this system as well, to kick the tires.
If people are interested in this implementation path we could throw a repo together and start work.
I mainly want this because I'm don't want to be stuck using Python and Cuda all the time for my deep learning research :)))
Reacted by Florent D'halluin, Clark Zinzow, Pratyush Mishra, rencire, Nestor Demeure, Miguel Iglesias and Song Feng (馮松)
Reacted by Dhruv Dhamani, Luca Palmieri, josh bowles, Clark Zinzow, Pratyush Mishra, Akira Makino, Andrew Tulloch, José Geraldo de Carvalho Pereira, kineticz, Miguel Iglesias and 1 more
Supports the most common deep neural network architectures.
Is GPU accelerated.
Doesn't use CUDA.
Supports every mainstream platform (Linux, MacOS, iOS, Android, Windows, WebAssembly) and hardware (AMD, NVIDIA, Intel GPUs) with a single codebase, and uses the same kernels for consistent results.
Is written in pure Rust so that it's trivial to cross-compile.
Has a simple to use Keras-like API.
Is small and simple enough that it can be reasonably understood and tested end-to-end. (Otherwise you risk situations like e.g. with TensorFlow where for two whole versions their dropout layer was completely broken.)
It's currently totally useless. Right now I'm in the process of adding a Vulkan backend (I have a few thousand lines of work-in-progress code on my disk which I've not pushed yet.); once I finish that in a few weeks I plan further build it up so that I can train CIFAR-10 up to at least ~90% accuracy, add some model import/export functionality (probably from/to the ONNX format) and only then it will be actually usable for something practical.
Some people would call this a waste of time and effort, and, well, I do agree that it would be probably more productive to not do this completely from scratch as I'm doing (e.g. by using TVM as kazimuth said), but I don't really care - I'm just trying to scratch my own itch.
Reacted by josh bowles, AlexNav73, Shock-1, Ahmed Masud and Jamal Simpson
@kazimuth while I love the snippets you've shown here, a lot of my love for Rust exists because of the all the compile time checks the compiler does, and the wonderfully easy to comprehend error messages. I feel that if one is using Rust just as a way to compose, and run functionality defined in other languages then there isn't much to gain here. Might as well just use Python.
And TVM looks more like a tool for deploying neural nets rather than training them; which is very useful but I would prefer to do both in Rust.
Something else that is also interesting is dual_num, which as I best understand it is some fancy math that might eventually let us to automatic differentiation.
@koute the long term road-map is amazing but I don't get why bother putting effort into the tensorflow backend. Admittedly I don't have enough know-how to imagine what a native backend would look like and the kind of work it would need.
@DhruvDh The TensorFlow backend will be most likely removed in the future. Currently it is there for a few reasons:
I wanted to quickly get something working to experiment with, and to be able to first work on the general interface of the library (e.g. defining the neural network graph, getting data in and out, etc.)
I can use it to write a comprehensive test suite and then cross-check that with my own backend. ML algorithms are very hard to write correctly, so I want the extra insurance not only that my algorithms match with what I have on paper, but also with another widely used framework. (Although from the amount of bugs I've encountered when dealing with TensorFlow it'd probably would have been better to pick a different framework...)
Some cool stuff coming to light. Is anyone familiar with work presented at c4ML? https://www.c4ml.org/
I don't think any of the presentations were using Rust... but certainly this is a space Rust could be competitive with. With that in mind, are any of the Rust compiler team interested in ML?
@quietlychris, I have a lot of same ideas as you and have really been looking to getting something regarding this. To me Edge ML and soft real-time control systems are something rust can excel in. I have actually been meaning to write a blog post about it, as imo this is the place where a killer rust framework can be created (like go has docker, ruby has rails etc.).
Rust also was one of my first languages, and honestly the ownership system according to me, mostly creates difficulty for programmers used to another language.
Its been said again and again by various people how rust married high level abstractions while allowing you to produce performant code by nudging you in the right direction.AI and ML fields that have been dominated by python doesn't really work when taken to embedded level. If someone needs to take their skills to embedded, the most likely will have to face c or c++.
On the other hand, if one looks over at the rust surveys, majority of users are coming from python and finding themselves comfortable. We can create an ecosystem that incentivizes them to try rust out and we can take significant market share here.
Not only this, ML algorithms that have to run locally on mobile phones is also an important market that checks the boxes of being resource constrained and something that will benefit highly from multithreaded execution (it's a trend among recent phone processors of increasing cores).
Also I am an ME undergraduate student with most of his work in control systems and has experience with the NN sort. Start something and I will surely help/join.
@quietlychris I definitely still plan on leading the working group but, I haven't heard anything from the Governance WG either. As I understood they would ping us on the ticket when they were ready to help guide the next official WG into this space. I know they had a a lot of things to figure out on the Governance side (as I check in on their channel from time to time) so I am unsure if this is still on their list just after they establish themselves or if it has accidentally fallen to the wayside.
As for your follow on points, I believe that is the direction I would like to do as well. Start with "nothing" and slowly start writing the Rust ML Book to do the classic first classifying MNIST problem. As we go along and find that libraries are out of date/missing/could be improved we do so, hopefully taking ownership or at minimum revitalize them as we go along.
@Shock-1 I also agree with edge since it's been blogged about a lot and as @quietlychris said) it's fairly easy to get Rust onto some micro-controllers, and even mobile devices. I am also REALLY excited about using Rust's error handling or utilizing the std::result::Result or std::option::Optionenums system to create transparent models that you can inspect at any stage to see/understand what the model is doing.
My plan forward from today is to ping Florian on the ticket about the creation of the working group, but I want to give that a week or so since I know Mozilla just had it's winter all-hands and it's best to let the dust settle before asking for new/more work ;). I hope to have something for this discussion group in about a week, no less than two. And, for what it is worth, I do not think the other proposed group (cryptography) has moved forward officially yet either.
@deg4uss3r That sounds like a plan to me. I don't see any particular rush in terms of getting the WG structure up and running right at this very moment, but touching base with the Governance group when things are little quieter does seem like a solid next step to me. As I mentioned, I'm still fairly new to ML, so am planning on personally laying out the MNIST classification problem in Python (and maybe MATLAB/Octave or Julia) to make sure I have a strong handle on what the somewhat canonical workflows and results look like with those tools.
Your comment about working on or building libraries along the way in the process is right along the lines of what I was thinking as well, and something I would definitely be on board with. I believe that while constant generics aren't going to be stable in the immediate future, they're fairly well into the RFC pipeline (rust-lang #44580), which I seem to understand could be helpful for writing numerical backends.
@Shock-1 It's wonderful to see other people interested in the same sort of thing, and coming from a similar background (my formal education was also in mechanical engineering, although my control systems courses mostly focused on classical theory like PID controllers and dynamical systems, not neural nets or other ML components). I honestly hadn't much considered edge deployments in terms of smartphones, but it makes a lot of sense in leveraging Rust's multithreading to pull performance out of some of those hexa- and octacore processors showing up. Your insights in new Rust users coming in from Python is valuable too--I hadn't seen that information before. As I mentioned a little earlier, I'm going to be spending some time brushing up on other language's frameworks, but will hopefully have something available for you to contribute to at some point moving forward.
Hello, it's been a while since I last checked up on the discussion here, but I'm glad it kept going and many people are interested in both hybrid and pure Rust DL.
I've written my thoughts about the current state of DL and what I think would be required for a pure Rust DL MVP. It maybe of interest to someone here.
@tiberiusferreira Thanks for posting that write-up! It was great to see a fairly comprehensive look at some of those topics. I think your insights into moving computations onto GPUs make a lot of sense in terms of the options that are available at the moment. I had looked into some of the Rust-native code (like the emu macro system written by calebwin), but the most of the ecosystem is still at an very early stage of development. In general, my particular preferences are not hugely partial to calling to system installations since I've had some bad experiences ending up with OS-level dependency hell, but for large backends like the ones I usually associate with ML, it might make more sense than pulling in fresh instances with Cargo.toml every time you wanted to start a new project. arrayfire-rust in particular caught my eye, since it looks like it's being maintained by the Arrayfire team themselves.
I'm just starting to work through Pytorch's system in Python, but once I get a little more comfortable with understanding that, I'm definitely going to be looking into replicating that with tch-rs to see how my own experience matches up with what you've described.
It was mentioned before by @davechallis but has any work been done on scaling and normalisation. I'm about to start implementing a new machine learning based crate and I find myself reaching for L1/L2 norm again and thinking there should be a crate with some fundamentals like that in
I work on data analysis. I am a fan of Rust and Julia. I recently wrote the hnsw_rs crate and considering writing a parallel stochastic gradient.
Just now my point of view is to write the base block using Rust and keep the upper part in Julia. Interfacing both languages is easy and keeping the interactive is really fine.
Surely some collaboration will occur.
Get BlueMail for Android
On Feb 5, 2020, 07:01, at 07:01, chris m ***@***.***> wrote:
@deg4uss3r Just joining the discussion at the moment, but I'm a little
curious about plans moving forward, since this issue has been fairly
quiet since this past year. I saw that the the machine learning WG
application got put off a little bit, since GameDev was given priority
in the queue (although got started and seems to be moving along as of
late last year), but wanted to see if there was a timeline for reaching
back out to the larger Rust organization regarding resubmitting or
getting new consideration of the existing application.
Also, to toss in my own two cents, since I haven't seen anyone else
with quite my direction of interest: as opposed to a data science or
NLP background, my primary interest in the application of ML to control
systems, particularly soft real-time control with respect to visual or
stereo imagery. Rust is great for a lot of this. It's extremely quick,
cross-compiling for embedded ARM boards is really easy, and the error
handling is typically fairly ergonomic for catching and dealing with
problems with `?` and or `Result` into `match` statements. I've done a
little work writing clustering algorithms for RGB images and for
cross-library compatibility between image formats to integrate with
OpenCV both for the `opencv-rust` binding and directly across the FFI
boundary, but am really interested in being able to deploy a control
system enabled by neural nets, deep learning, etc. natively from Rust.
I also want to point this out: while Rust has a reputation for being
difficult for new programmers, I consider it to be my first real
programming language, apart from writing some bash scripts. One of the
reasons I was able to do this is because the documentation surrounding
Rust in terms of both the language and standard library, as well as
most of the core crates through the ecosystem are superb, and the
tooling is both simple and powerful. As a result, I've been able to
pick up topics like image processing and file serialization much more
quickly than if I was trying to sort through either the C++11/14/17
standard library and be able to brute-force things that would have
taken much too long otherwise in a language like Python or MATLAB. From
first installing the language to flashing `#![no_std]`programs onto a
microcontroller, the structures in place for learning how to write code
that is safe, fast, and easy to understand in a number of domains have
made a world of difference.
In that thread, I think that potentially makes Rust a really good
choice for anyone interested in integrating some machine learning into
their systems, and would love to see an end result that enables a
similar story. My personal idea would be something similar to Embedded
Rust's "Discovery"
[__Book__](https://rust-embedded.github.io/discovery/index.html), with
starting from "hi there, please add these 1-2 dependencies to your
`Cargo.toml` file`, through building a classifer that does a decent job
at classifying the MNIST data set, or something else along those lines.
It also seems like having a Book like that would be really helpful for
giving both members of the Rust ML community and programmers at large a
jumping-off point at which they can start branching into other areas,
and in the immediate future, present a concrete objective around which
to organize and drive towards.
Obviously, much, much, easier said than done, but hey, that's what I'd
like to (help) build.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#1 (comment)
@jean-pierreBoth Nice! I'd love to see how you are using Julia + Rust... hope to look through HnswAnn.jl soon.
Any other examples or maybe a blog post?
@jean-pierreBoth have you seen the rust-cv org, they did a hnsw crate and might be working on other areas you're interested in https://github.com/rust-cv/hnsw could be worth collaborating. Many hands light work etc
@deg4uss3r I saw your post on the WG governance issue and @XAMPPRocky's response about emailing the core team, but was wondering if you've heard anything back through another channel that I might have missed. Obviously, there's a lot going at the moment, but in large part because of that, my own availability for working on projects like this has increased a bit for the foreseeable future. Of course, it's totally understandable that while that might be the case for some, other people in the chain might not be in the same position, so if this needs to take a backseat for the moment, not a problem.
@quietlychris I don't have a follow up on that response, but I wouldn't block your work on the core approval. There's no reason you can't organise and start having meetings and discussions. I'm not part of the approval process but I think it would probably go quicker if it could be shown a group was already regularly active and working. Since one of the concerns that is often brought up around creating new teams/groups is whether they will remain active after initial interest. So being able to show that a group is regularly productive, would largely address that.
@quietlychris Sorry for the delay but @XAMPPRocky is correct, have not heard anything. I'd say let's start hashing out what we want to group to look like, where to organize, how etc on another thread.
@XAMPPRocky@deg4uss3r Okay, that's good to know, and makes a lot of sense! I started a new issue with some of those points for discussion. I'm looking forward to hearing what people have to say. Thanks!
Just noticed that my ideas around building out a high level neural net framework similar to Keras were not at all original :)
@koute - how much progress have you made on your end with your high level interface?
@deg4uss3r and @quietlychris - My main area of interest/focus is in a pure Rust implementation (as opposed to bindings for Tensorflow et al.) given the guarantees on memory safety implicit in Rust as well as the ability to start using next-gen cross platform CPU/GPU interfaces directly (i.e Vulkan Compute and SPIR-V) without having to use intermediate languages based on C/C++ (like SYCL).
I'm aware that things are still getting organised but noticed that there is already a Deep Learning workstream defined. I've always viewed the neural net as the deep learning base structure so wondered if this would naturally fit into that workstream or if it should be captured as a separate (but dependent) one. What's your view?
Activity
Kibouo commentedon May 1, 2019
I want to note that, while it works great, https://github.com/twistedfall/opencv-rust is not particularly user-friendly or 'clean' in rust terms.
Maybe we could have a look at it?
flo-dhalluin commentedon May 1, 2019
I think the use case that coud make Rust shine, is deployment. Currently the de-facto "mainstream" stack is python based ( scikit-learn, np, pandas + your DL framework of choice, TensorFlow, Torch .. ). It shines for fast prototyping, because python, but it sucks for industrialization ( and deployment ), because ... python. I really think rust would do great. In that area, I kinda like TensorFlow serving, but it forces you to have a separate service ( that you call with their protobuf/RPC).
So :
jbowles commentedon May 1, 2019
I'm currently building a large project with rust (i mention it here: https://users.rust-lang.org/t/interest-for-nlp-in-rust/15331/9), where I am doing the data engineering in rust (lots of string metrics). [tldr; I found lots of disparate projects with 50% of what I needed for string metrics but instead rolled my own, trying to incorporate previous work and give credit] I want to feed the feature vectors to Julia to experiment with what I want to use for classification and modelling, and then I'll want to be able to use rust for inference/classification etc.... I had to pause development for business reasons, but I'm starting again: one of my biggest issues was not ML related but finding a nice pattern for parallel file download (seems like it should be simple, but maybe I'm spoiled by go's simplicity lol).
From this real-world project point of view, as well from my time spent thinking in the abstract and surveying the ML ecosystem in rust (about a year), I would think that a focus on data engineering in general and serving models is the way to go (this also seems to be a widely shared sentiment). In a practical sense I would like to see rust jobs for data engineer and machine learning engineer... that is, the bookends of a typical data science project; serving the data and serving the model.
That is, targeting software developers, infrastructure, computational math, and data people. Trying to convince research scientists to use Rust would be wasted effort; for most of these people software is a secondary skill and so they need something easy to learn, dynamically typed, with a REPL... I've watched this play out in the Python/R/Matlab versus Julia world... and while IMO Julia has a lot to offer current python/r/matlab devs and is similar enough to those languages, trying to get that group of people to use Julia is not easy, i can't imagine what it'd be like proposing Rust.
Here are some challenges I see:
jbowles commentedon May 1, 2019
Really looking forward to digging into ndarray. Though I've had a slight delay, I'm writing up ndarray examples for the Grokking Deep Learning book where andrew trask introduces deep learning with only numpy. He's expressed interest and welcomed the examples... :)
soaxelbrooke commentedon May 1, 2019
A standardized tokenization implementation!
Tokenization fills the role of "turn the text into fixed vectors" that you'd feed into standard models. As an NLP practitioner and Rust user, tokenization is an incredibly important step in the pipeline, a big barrier to new people trying to apply NLP, and a place where lots of small bugs creep in due to non-standard implementations that take forever to find. Having a standard implementation for the simpler tokenization methods (like regex matching) would make NLP problems much more approachable in Rust.
DhruvDh commentedon May 1, 2019
One part of machine learning where Rust could shine right now is simulation for Reinforcement learning.
For instance if I training an agent to play blackjack, the biggest bottleneck here is the "playing" blackjack over and over by the agent to collect enough data for training.
Rayon and Actix could be used to create fast and performant game "environments" now, without need for an established ML ecosystem.
yngtodd commentedon May 1, 2019
I agree with @DhruvDh, using Rust to simulate environments for RL agents would be great.
Having something akin to OpenAI's gym interface would be really nice. Many RL researchers are going to still want to use Python and all the associated deep learning libraries. So, I would love to see RL environments rendered in Rust that could be interfaced with both Python and Rust for agents.
Edit: I imagine that algorithms like Monte Carlo Tree Search would be really useful if they were written in Rust. I would not want to wait on Python to handle that bit.
masonk commentedon May 1, 2019
Along these lines, I am working on a hobby project (link), which does this. It isn't quite ready for even an alpha release yet, but I am in the final stages of cleaning up the API with the intent to publish it.
masonk commentedon May 1, 2019
Things Rust definitely needs:
const generics
16-bit floats
GATs (for efficient, non-copying iterators)
Things that we might want but I'm not sure:
Standard Inference + Train traits
Standard data frames trait
kazimuth commentedon May 1, 2019
I've been thinking of building a rust deep learning / GPU compute library on top of the TVM framework for a while now. I think it could address a lot of the things @flo-dhalluin is talking about. TVM's an amazing project that's currently flying a bit under the radar. It's an open source deep learning compiler - it compiles deep neural nets / large array operations to run on the GPU (or on OpenCL, or FPGA, or TPU, or WebGL...). You define an AST of computations via its API, and it spits out a small (<5mb) shared library containing just the operations you wanted, on whatever acceleration framework and target platform you want.
It currently has a working Rust runtime library, which lets you call a compiled model from Rust. It integrates with
ndarray, and will let you e.g. take in anndarray::Array, move it to a GPU, run whatever numerical operations you want on it, and get the result back as anndarray::Arrayagain.That's pretty neat, and I don't think it would be too hard to build some really cool tools on top of it. My dream is something like:
lib.rs:train.rs:run.rs:(Further reading: Introduction to Relay, TVM Tensor expressions)
All of this is of course pending mountains of bikeshedding, i have no idea what the final API will look like.
One of the nifty things here is that this isn't limited to deep learning models. TVM can handle pretty much any algorithm made of large array operations. So if you wanted to run your SVM on GPU, you can do that pretty easily!
Steps to take here:
If people are interested in this implementation path we could throw a repo together and start work.
I mainly want this because I'm don't want to be stuck using Python and Cuda all the time for my deep learning research :)))
koute commentedon May 1, 2019
A few months ago I have started a crate of my own for deep learning. My goal is to have a library which:
It's currently totally useless. Right now I'm in the process of adding a Vulkan backend (I have a few thousand lines of work-in-progress code on my disk which I've not pushed yet.); once I finish that in a few weeks I plan further build it up so that I can train CIFAR-10 up to at least ~90% accuracy, add some model import/export functionality (probably from/to the ONNX format) and only then it will be actually usable for something practical.
Some people would call this a waste of time and effort, and, well, I do agree that it would be probably more productive to not do this completely from scratch as I'm doing (e.g. by using TVM as kazimuth said), but I don't really care - I'm just trying to scratch my own itch.
DhruvDh commentedon May 1, 2019
@kazimuth while I love the snippets you've shown here, a lot of my love for Rust exists because of the all the compile time checks the compiler does, and the wonderfully easy to comprehend error messages. I feel that if one is using Rust just as a way to compose, and run functionality defined in other languages then there isn't much to gain here. Might as well just use Python.
And TVM looks more like a tool for deploying neural nets rather than training them; which is very useful but I would prefer to do both in Rust.
There's also tch-rs - bindings to PyTorch's libtorch.
Something else that is also interesting is dual_num, which as I best understand it is some fancy math that might eventually let us to automatic differentiation.
DhruvDh commentedon May 1, 2019
@koute the long term road-map is amazing but I don't get why bother putting effort into the tensorflow backend. Admittedly I don't have enough know-how to imagine what a native backend would look like and the kind of work it would need.
koute commentedon May 1, 2019
@DhruvDh The TensorFlow backend will be most likely removed in the future. Currently it is there for a few reasons:
jbowles commentedon May 1, 2019
Some cool stuff coming to light. Is anyone familiar with work presented at c4ML? https://www.c4ml.org/
I don't think any of the presentations were using Rust... but certainly this is a space Rust could be competitive with. With that in mind, are any of the Rust compiler team interested in ML?
Here are some references to work being done in Swift and Julia (Note, Rust, Swift, Julia were all top of the list for google's tensorflow project that eventually became swift-for-tf).
(e.g., automatic differentiation, differentiable programming... https://github.com/tensorflow/swift/blob/master/docs/AutomaticDifferentiation.md, https://juliacomputing.com/blog/2019/02/19/growing-a-compiler.html). Swift MLIR (https://drive.google.com/file/d/1hUeAJXcAXwz82RXA5VtO5ZoH8cVQhrOK/view) and Julia Zygote (https://www.julialang.org/blog/2018/12/ml-language-compiler).
I don't know of any projects in Rust along these lines ^^ ... of course, they are also all funded (google, and julia computing).
78 remaining items
Shock-1 commentedon Feb 5, 2020
@quietlychris, I have a lot of same ideas as you and have really been looking to getting something regarding this. To me Edge ML and soft real-time control systems are something rust can excel in. I have actually been meaning to write a blog post about it, as imo this is the place where a killer rust framework can be created (like go has docker, ruby has rails etc.).
Rust also was one of my first languages, and honestly the ownership system according to me, mostly creates difficulty for programmers used to another language.
Its been said again and again by various people how rust married high level abstractions while allowing you to produce performant code by nudging you in the right direction.AI and ML fields that have been dominated by python doesn't really work when taken to embedded level. If someone needs to take their skills to embedded, the most likely will have to face c or c++.
On the other hand, if one looks over at the rust surveys, majority of users are coming from python and finding themselves comfortable. We can create an ecosystem that incentivizes them to try rust out and we can take significant market share here.
Not only this, ML algorithms that have to run locally on mobile phones is also an important market that checks the boxes of being resource constrained and something that will benefit highly from multithreaded execution (it's a trend among recent phone processors of increasing cores).
Also I am an ME undergraduate student with most of his work in control systems and has experience with the NN sort. Start something and I will surely help/join.
deg4uss3r commentedon Feb 5, 2020
@quietlychris I definitely still plan on leading the working group but, I haven't heard anything from the Governance WG either. As I understood they would ping us on the ticket when they were ready to help guide the next official WG into this space. I know they had a a lot of things to figure out on the Governance side (as I check in on their channel from time to time) so I am unsure if this is still on their list just after they establish themselves or if it has accidentally fallen to the wayside.
As for your follow on points, I believe that is the direction I would like to do as well. Start with "nothing" and slowly start writing the Rust ML Book to do the classic first classifying MNIST problem. As we go along and find that libraries are out of date/missing/could be improved we do so, hopefully taking ownership or at minimum revitalize them as we go along.
@Shock-1 I also agree with edge since it's been blogged about a lot and as @quietlychris said) it's fairly easy to get Rust onto some micro-controllers, and even mobile devices. I am also REALLY excited about using Rust's error handling or utilizing the
std::result::Resultorstd::option::Optionenums system to create transparent models that you can inspect at any stage to see/understand what the model is doing.My plan forward from today is to ping Florian on the ticket about the creation of the working group, but I want to give that a week or so since I know Mozilla just had it's winter all-hands and it's best to let the dust settle before asking for new/more work ;). I hope to have something for this discussion group in about a week, no less than two. And, for what it is worth, I do not think the other proposed group (cryptography) has moved forward officially yet either.
quietlychris commentedon Feb 5, 2020
@deg4uss3r That sounds like a plan to me. I don't see any particular rush in terms of getting the WG structure up and running right at this very moment, but touching base with the Governance group when things are little quieter does seem like a solid next step to me. As I mentioned, I'm still fairly new to ML, so am planning on personally laying out the MNIST classification problem in Python (and maybe MATLAB/Octave or Julia) to make sure I have a strong handle on what the somewhat canonical workflows and results look like with those tools.
Your comment about working on or building libraries along the way in the process is right along the lines of what I was thinking as well, and something I would definitely be on board with. I believe that while constant generics aren't going to be stable in the immediate future, they're fairly well into the RFC pipeline (rust-lang #44580), which I seem to understand could be helpful for writing numerical backends.
@Shock-1 It's wonderful to see other people interested in the same sort of thing, and coming from a similar background (my formal education was also in mechanical engineering, although my control systems courses mostly focused on classical theory like PID controllers and dynamical systems, not neural nets or other ML components). I honestly hadn't much considered edge deployments in terms of smartphones, but it makes a lot of sense in leveraging Rust's multithreading to pull performance out of some of those hexa- and octacore processors showing up. Your insights in new Rust users coming in from Python is valuable too--I hadn't seen that information before. As I mentioned a little earlier, I'm going to be spending some time brushing up on other language's frameworks, but will hopefully have something available for you to contribute to at some point moving forward.
tiberiusferreira commentedon Feb 11, 2020
Hello, it's been a while since I last checked up on the discussion here, but I'm glad it kept going and many people are interested in both hybrid and pure Rust DL.
I've written my thoughts about the current state of DL and what I think would be required for a pure Rust DL MVP. It maybe of interest to someone here.
https://tiberiusferreira.github.io/blog/posts/current_deep_learning_ecosystem_from_a_rust_developer_perspective/
quietlychris commentedon Feb 13, 2020
@tiberiusferreira Thanks for posting that write-up! It was great to see a fairly comprehensive look at some of those topics. I think your insights into moving computations onto GPUs make a lot of sense in terms of the options that are available at the moment. I had looked into some of the Rust-native code (like the
emumacro system written by calebwin), but the most of the ecosystem is still at an very early stage of development. In general, my particular preferences are not hugely partial to calling to system installations since I've had some bad experiences ending up with OS-level dependency hell, but for large backends like the ones I usually associate with ML, it might make more sense than pulling in fresh instances withCargo.tomlevery time you wanted to start a new project.arrayfire-rustin particular caught my eye, since it looks like it's being maintained by the Arrayfire team themselves.I'm just starting to work through Pytorch's system in Python, but once I get a little more comfortable with understanding that, I'm definitely going to be looking into replicating that with
tch-rsto see how my own experience matches up with what you've described.aeroaks commentedon Feb 20, 2020
Hi All,
Maybe we should get yourselves noticed here -> https://discuss.ossdata.org/
xd009642 commentedon Feb 26, 2020
It was mentioned before by @davechallis but has any work been done on scaling and normalisation. I'm about to start implementing a new machine learning based crate and I find myself reaching for L1/L2 norm again and thinking there should be a crate with some fundamentals like that in
jean-pierreBoth commentedon Feb 27, 2020
jbowles commentedon Feb 27, 2020
@jean-pierreBoth Nice! I'd love to see how you are using Julia + Rust... hope to look through HnswAnn.jl soon.
Any other examples or maybe a blog post?
xd009642 commentedon Feb 27, 2020
@jean-pierreBoth have you seen the rust-cv org, they did a hnsw crate and might be working on other areas you're interested in https://github.com/rust-cv/hnsw could be worth collaborating. Many hands light work etc
quietlychris commentedon Mar 13, 2020
@deg4uss3r I saw your post on the WG governance issue and @XAMPPRocky's response about emailing the core team, but was wondering if you've heard anything back through another channel that I might have missed. Obviously, there's a lot going at the moment, but in large part because of that, my own availability for working on projects like this has increased a bit for the foreseeable future. Of course, it's totally understandable that while that might be the case for some, other people in the chain might not be in the same position, so if this needs to take a backseat for the moment, not a problem.
XAMPPRocky commentedon Mar 14, 2020
@quietlychris I don't have a follow up on that response, but I wouldn't block your work on the core approval. There's no reason you can't organise and start having meetings and discussions. I'm not part of the approval process but I think it would probably go quicker if it could be shown a group was already regularly active and working. Since one of the concerns that is often brought up around creating new teams/groups is whether they will remain active after initial interest. So being able to show that a group is regularly productive, would largely address that.
deg4uss3r commentedon Mar 14, 2020
@quietlychris Sorry for the delay but @XAMPPRocky is correct, have not heard anything. I'd say let's start hashing out what we want to group to look like, where to organize, how etc on another thread.
quietlychris commentedon Mar 15, 2020
@XAMPPRocky @deg4uss3r Okay, that's good to know, and makes a lot of sense! I started a new issue with some of those points for discussion. I'm looking forward to hearing what people have to say. Thanks!
xflowXen commentedon Apr 4, 2020
Just noticed that my ideas around building out a high level neural net framework similar to Keras were not at all original :)
@koute - how much progress have you made on your end with your high level interface?
@deg4uss3r and @quietlychris - My main area of interest/focus is in a pure Rust implementation (as opposed to bindings for Tensorflow et al.) given the guarantees on memory safety implicit in Rust as well as the ability to start using next-gen cross platform CPU/GPU interfaces directly (i.e Vulkan Compute and SPIR-V) without having to use intermediate languages based on C/C++ (like SYCL).
I'm aware that things are still getting organised but noticed that there is already a Deep Learning workstream defined. I've always viewed the neural net as the deep learning base structure so wondered if this would naturally fit into that workstream or if it should be captured as a separate (but dependent) one. What's your view?