Latest / Talk Python To Me / #60: Scaling Python to 1000's of cores with Ufora
Transcript
- 0:00You've heard me talk previously about scaling Python and Python performance on the show,
- 0:03but on this episode, I'm bringing you a very interesting project pushing the upper bound
- 0:07Python performance for a certain class of applications. You'll meet Braxton McKee from
- 0:12Euphoria. They are developing an entirely new Python runtime that is focused on horizontally
- 0:17scaling Python applications across thousands of CPU cores and even across GPUs. They describe it
- 0:24as compiled automatically parallel Python for data science. Let's dig into it on Talk Python To Me,
- 0:30episode 60, recorded May 2nd, 2016.
- 0:33Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 1:02ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
- 1:07where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm
- 1:12and follow the show on Twitter via at Talk Python. This episode is brought to you by SnapCI and
- 1:19OpBeat. Thank them for supporting the show on Twitter via snap underscore CI and OpBeat.
- 1:24Braxton, welcome to the show.
- 1:27Oh, thanks, Michael. I'm excited to be here.
- 1:28Yeah, we're going to take Python to a whole other level of scalability here with sort of
- 1:33computational Python, which is where Python has actually struggled the most in parallelism. So
- 1:38I'm really excited to talk about that.
- 1:39Well, it's a complicated topic. It's something I spent a lot of years on and it's actually really
- 1:46fun. So we'll have a lot of good stuff to talk about.
- 1:48Yeah, I don't know how many people have heard of your project, but I'm really excited to share
- 1:52with them because it sounds super promising. But before we get into all of this, let's start at the
- 1:57your story. How did you get into Python and programming?
- 1:59Well, I've been programming for pretty much my entire life. I think I started when I was eight
- 2:04years old and I'm like 36 now. So it's kind of the way I think. I studied math in school, but
- 2:12writing code has always been the way I think about approaching problems. So like when I was doing math
- 2:17assignments, if I wanted to understand what was going on, I'd usually go write some kind of program to
- 2:22try to understand what was happening, do the numeric integral by hand or whatever. And then when I
- 2:27left college, I went and I started working in the hedge fund industry, which was a great experience
- 2:33as a young person. I got to log code. I had to solve some really interesting problems. And it was really
- 2:40there that my sort of desire to work on tools came around because I was just consistently frustrated with
- 2:47how much effort it took me to actually implement these solutions. I would talk with my colleagues about
- 2:53some computation that we wanted to do and we could describe in principle what it was in five minutes.
- 2:58And then they would ask me, all right, how long is this going to take? And I said, all right, come back to me in three months.
- 3:03Because, you know, getting things to actually scale up is really challenging.
- 3:09I started writing Python code actually after I left the hedge fund industry, which was in 2008. So, you know, Python really got big in, you know, 05, 06, 07. And it got into my attention.
- 3:21And then when I was doing, I was actually doing some speech recognition work. And I spent a lot of time doing the same thing that, you know, most people who are frustrated with Python's performance end up doing, which is you, you try and figure out the little bit of it that's slow and stick that in C++.
- 3:37And then write, write wrappers for that, and then try and do all the rest of your work in Python.
- 3:42And a lot of the things that I've been interested in recently, and I think a lot of the pretty awesome projects that are out there for speeding Python up, are essentially trying to address that same problem.
- 3:53Saying, how can we get more and more of what you're doing to live in Python, because you pick Python for a reason, and be able to just use the tool the way you want and not have to pay a performance penalty?
- 4:01Yeah, you know, I've noticed in the industry, there seems to be more and more attention given to the speed of Python.
- 4:08I know the NumPy guys have been around for a while, the PyPy guys have been around for a while, really working on this issue.
- 4:15But it seems like more and more people are trying different angles of approach.
- 4:19So in Python 3.6, they have some really interesting stuff to speed up method invocation in Python, which is one of the slower bits.
- 4:26There's the PyJohn stuff coming from Microsoft.
- 4:30There's a lot of really interesting work.
- 4:32And so yours kind of lands in that space as well, right?
- 4:36Yeah, absolutely.
- 4:37And I think that what's going on is, you know, Python is a really lovely language to program as an implementer.
- 4:43It's got a lot of weird corner cases, and it's a very hard thing for computers to reason about.
- 4:49And, you know, the core of what makes it possible for systems to speed up code is their ability to reason about the code that you've written.
- 4:58So if you look at, like, a C++ compiler, it does all of these fancy tricks inside to transform your code into something that's faster.
- 5:05And it does that because it can make really strong assumptions about what you're doing that it can apply to the machine language that it's generating.
- 5:13And that's really hard to do in Python because Python gives you so much flexibility.
- 5:18And so I think that the reason you're seeing so many different approaches is because there's a million different ways to look at the problem and say, okay, we can look at what people have written and start to identify particular things that we want to speed up or make, I think this is the more common case, start to put some constraints around what we're going to tell people is going to be fast.
- 5:36And as soon as you put constraints, now you give these optimizers something to work with.
- 5:41And I bet you if you looked in the internals of all of these different things, each one of them would have a different way of looking at Python and picking a subset of it saying, this is the stuff that we're going to make fast.
- 5:51Like NumPy, if you look at it originally, the whole point of NumPy, why it's fast is because you can really, if you look at its roots, really just stick floats and ints in there.
- 6:00It's not trying to be fast for arbitrary Python.
- 6:02It's trying to make Python fast for matrix algebra, linear algebra kind of stuff.
- 6:10And adding that constraint is what allows it to be fast.
- 6:14Yeah, that's interesting.
- 6:14I think a lot of those things I mentioned do add constraints.
- 6:18PyPy sort of gave up the C module integration in order to get its speed.
- 6:23Whereas the PyJon stuff from Microsoft, they're trying to make sure they're 100% compatible, but that puts a different kinds of pressure and makes it harder on them.
- 6:32The NumPy stuff, like you said, is focused basically on matrix algebra and matrix multiplication and stuff.
- 6:38Yeah, absolutely.
- 6:39And I think that guys like the PyPy guys have a big amount of respect for what they're doing because they're trying to solve a really, really brutal problem.
- 6:48Which is, let's make anything written in Python orders of magnitude faster.
- 6:52For most of my work, I've focused on a slightly restricted problem, which is to say, let's try and make Python programs that are written in this sort of purely functional style faster.
- 7:06Our original goal was not just to get a compiler to be faster, but also to get code to be able to scale, right?
- 7:14To be able to write idiomatic simple Python and get something that can use thousands of cores effectively without the programmer having to really think about how that's happening.
- 7:24One of the crucial ways that you can do that is you say, okay, I'm going to make it so that if you make a list of integers, you can't change it again.
- 7:31That seems like a pretty trivial change, but it's the underpinning for an enormous amount of different optimizations that we can do inside the program.
- 7:38And if you look at systems like Hadoop and Spark, they have as a core tenant this idea that the datasets themselves are immutable and you make transformations on those datasets.
- 7:49And that immutability is sort of the key to them being able to do things in a distributed context.
- 7:55We said we can take that same idea and apply it not just at the outermost level of the operations we're allowing, but we can let that filter all the way through the program.
- 8:06And you can take that same constraint and apply it not just to make things distributed, but also to make the compiled machine code faster.
- 8:14Because if I make a list of integers, I can now assume that it's going to be a list of integers forever because you can't change it.
- 8:20That makes me able to generate much faster machine code if I'm from the compiler because I can start to make really strong assumptions about what's going on inside of it.
- 8:28Okay, that's awesome.
- 8:29And you said a few things that I'm sure have piqued people's interest.
- 8:32Python, thousands of cores, and machine instructions and compiled code.
- 8:36So maybe we can take a step back just for a minute and tell us about your project, Euphora, and what you guys are up to there.
- 8:41And then we can dig into the details.
- 8:43Yeah, absolutely.
- 8:44So Euphora is a platform for executing Python code at massive scale.
- 8:51And the basic idea is that you should be able to write simple idiomatic Python that expresses what you want and get the same performance that you get,
- 9:00not just if you had rewritten the code in C, but if you had rewritten the code in C and used threads and message passing to generate a parallel implementation.
- 9:13You should be able to do this directly from the Python source code without making any modifications to it and having the compiler really see everything going on inside of your code and use that to generate a fast form.
- 9:24So we've been working on this for about five years.
- 9:28We have a totally separate runtime and compiler framework that we've developed to do this.
- 9:34And we actually think of the languages almost like front end.
- 9:36So we built a VM.
- 9:37And I mean VM in the sense of like the Java virtual machine or Microsoft CLR.
- 9:42It sort of has enough structure for it to be able to reason about programs in this context and make them fast.
- 9:50And then what we've basically built is a cross compiler from Python down into that virtual machine.
- 9:57And we're planning on doing other languages at some point in the future.
- 10:01But there's so much goodness in Python that we really wanted to start there because that was what our roots were.
- 10:08The project is 100% open source.
- 10:11So you can just go get it on GitHub.
- 10:13And the Python front end for this thing has really only been around for about nine months.
- 10:19So it's still a work in progress.
- 10:20But it's evolving pretty rapidly.
- 10:22And, you know, we've been able to get cases where you can take relatively naive looking Python programs, dump this into this thing,
- 10:29and get them to work actually pretty efficiently on thousands of cores.
- 10:34Our biggest installations have gone up to six or 7,000 cores running on Amazon Web Services.
- 10:39And actually being able to use those things efficiently without really having to think about it is pretty fun.
- 10:44Yeah, that's really amazing.
- 10:45Distributed sort of grid computing type frameworks are not totally new.
- 10:50But I think two of the things that are super interesting about what you've told me,
- 10:55maybe the first and most interesting thing is that you don't have to write special distributed code, right?
- 11:03You just write regular code and the system reasons about how to parallelize it.
- 11:07Is that correct?
- 11:07Right, absolutely.
- 11:09And that comes, as I mentioned, from this idea that we put some constraints on the language.
- 11:15So the idea is it's immutable Python.
- 11:17So you make a list and you don't modify the list.
- 11:20You make a new list by writing a list comprehension that scans over the old one and makes a transformation of it.
- 11:26Because of that constraint, the system can now see, okay, like you're doing all of these operations on these data structures.
- 11:33And I can see you're doing this function now, but you're going to call this other function next.
- 11:39And it can reason about the flow of data inside of that and say, okay, you know, these things are independent of each other.
- 11:46I can schedule them separately if I want to.
- 11:48That freedom then gives the runtime the ability to say, okay, now it's trying to solve this problem of what's the most efficient way to lay things out.
- 11:57But the end result is that if you say, okay, here's a list comprehension or I've got a divide and conquer algorithm where I take something, I scan over it, I do some computation, cut it in half, and then recurse.
- 12:10It can see that that's what you're doing and parallelize that.
- 12:14And it turns out that if you look at regular people's code, there's all kinds of opportunities to parallelize it that they probably weren't thinking about.
- 12:21They wouldn't only have thought about it if they really hit a performance bottleneck, but it's in there.
- 12:26Like, if you're computing the covariance of two time series, you end up having three different dot products that you need to do, and they can all be done independently of each other.
- 12:36And, you know, if you write it out the naive way, the Py4 compiler can actually see that parallelism.
- 12:42And if those tasks are big enough, it will split them into three and actually do those on separate threads for you, and you don't have to actually explicitly say that.
- 12:51And, you know, in my thinking, there's been a continual movement in computing to raise the level of abstraction at which we work.
- 12:59So, like, we used to write an assembler, I guess, 40 years ago, right around when I was being born.
- 13:05And then they came up with C and Fortran, and these really made it possible to write more complicated programs because more and more of the details were abstracted away.
- 13:13And if you look at Python, Python is like the natural extension of that idea on single-threaded computing as far as it can go.
- 13:20You can be so concise and clear in Python because so many low-level details have been extracted away from you.
- 13:26But we're still not there on parallel computing.
- 13:29Like, people still spend a huge amount of time writing custom code to do parallel compute.
- 13:34I think the reason that technologies like Hadoop and Spark have been so successful is that within certain problem domains, they can make a lot of that complexity go away.
- 13:43And I wanted to take it a step further and say, let's not just do it for specific patterns of computing, MapReduce jobs or whatever.
- 13:51But, like, let's do this for all of your code, everything that you write.
- 13:54There should be enough structure in it for us to see and make it fast.
- 13:57That's great.
- 13:57Maybe you could just tell folks who are not familiar with Spark and Hadoop how they work and then, you know, like, what you mean by taking a little farther to general code with yours because I'm sure a lot of people know about Hadoop, but not everyone.
- 14:09Sure. So, Hadoop began out of Yahoo as the technology they developed to index the web.
- 14:17And, you know, the core component of it is you take your data set and you split it across a bunch of machines.
- 14:24And you're given two basic primitives.
- 14:28You've given math and reduce.
- 14:30And the basic idea is that if you think hard enough, you can fit any big parallel compute job into that pattern.
- 14:37Mappers basically allow you to take every element in your data set and run a little function on it to get a new element.
- 14:43And reduce allows you to take collections of elements and jam them together.
- 14:48And for a lot of big data parallel applications, this turns out to be a very natural way to express things.
- 14:55And the reason these technologies have been successful is because if you can figure out how to fit what you're doing into MapReduce, it's actually a very easy way to program.
- 15:05And the infrastructure, the Hadoop ecosystem, can give you all these benefits.
- 15:09So, Hadoop is very fault tolerant.
- 15:12You can turn the power off on any one of the machines or a rack of machines running Hadoop.
- 15:17And because of the programming model, the central scheduler that's making decisions about what to do can react to that and still ensure that your calculation completes because it can schedule the map and reduce jobs that were running on that machine on another machine.
- 15:32As an example.
- 15:33So, if you work within this framework, you suddenly make a bunch of problems that are sort of endemic to parallel computing go away.
- 15:42But the problem is that map and reduce and the other primitives that the community has since added to those systems are still relatively clumsy ways of describing computations.
- 15:54There's a bunch of things that fit really naturally into them.
- 15:56So, page rank and a lot of the things that people do with web scale data fit very naturally.
- 16:02But scientific computing, numerical computing, things where the calculations don't just fall naturally into this very embarrassingly parallel structure don't fit that well.
- 16:13And it can take some real thinking to jury rig your application into that model.
- 16:19So, when I talk about wanting to be able to do this from the arbitrary code, what I really mean is that you should be able to write code the way you're thinking about solving your problem.
- 16:27And the infrastructure should be able to generate that parallel implementation from your code as opposed to you saying, look, here's the place in my code where there's a million little tasks, each one of which can be done in parallel.
- 16:39Go do them in parallel, which is what you're essentially doing when you break things down to fit them into the MapReduce model, which I think pretty much what 90% of people doing large-scale computing right now are doing, at least the ones that I'm talking to.
- 16:52Yeah, you really have to change the way you approach the problem to fit it into MapReduce, right?
- 16:57Yeah, and a lot of people are not comfortable with that.
- 17:01Like, my best, my favorite example of that is, is like nested parallelism.
- 17:05So, like, imagine you have a data set that has some tree structure to it.
- 17:11So, you say, well, I've got a bunch of companies, and then for each company I have a bunch of transactions.
- 17:16And now you've kind of got two layers to your hierarchy.
- 17:20And if you say, I want to do something in parallel first over the companies, but then within each company in parallel again over all of the transactions, that's like a very unnatural thing to say in MapReduce because which thing are you mapping over?
- 17:32Are you mapping over the companies?
- 17:34Are you mapping over the records?
- 17:35You need to kind of jury-rig it in order to make it work.
- 17:38But if I told you to do that in Python, you would just have two loops.
- 17:41It would be totally obvious to you how to do it.
- 17:43And the only reason you would ever go to the MapReduce land is because you really needed that performance.
- 17:49And at the end of the day, this gets back to this original frustration I had, like, I think it was almost 10 years ago when I left the hedge fund industry thinking about this stuff.
- 17:56Like, thinking to myself, why is it so hard for the system to see that I have two loops and that there's parallelism in both of them and just make it parallel?
- 18:06Why am I having to, like, rejigger everything in order to fit the model that's been given to me?
- 18:11And that turns out to be an easy thing to say and a hard thing to implement.
- 18:14That's what we've been doing.
- 18:16Yeah, that's really amazing.
- 18:17So maybe it's worth digging into that a little bit.
- 18:19You said in the beginning you thought that you would have to use a different language other than Python, right?
- 18:25Yeah, and this has been a really interesting evolution for us.
- 18:29So that mutability idea, the idea that, like, if I make a data structure, I can't change it, is at the heart of pretty much any system that's scaled.
- 18:39And the reason is because it gets rid of all of these concurrency issues.
- 18:44It's like if the data element changes on one machine and you allow that, then if you have a distributed system, you have to make sure that that right operation propagates to everybody else who needs it.
- 18:54And that can create real serious problems.
- 18:57And if you don't handle it correctly, you end up with programs that are unstable or give you the wrong answer or really slow because there's a huge amount of locking.
- 19:05But if you look at Python, Python as a language is a very immutable thing.
- 19:10When you make a class, you start with an empty class and you start by pushing methods into it, right?
- 19:17And the way people build up lists of operations is they make lists that are empty and they keep appending things to them.
- 19:22So when I was first coming to this problem, thinking to myself, okay, I want everything that's good in Python, namely this ability to just pass functions around and not think about typing.
- 19:32You know, all of the good things about Python's object model.
- 19:35But I don't want that mutability.
- 19:37I, my first thought was, okay, this is going to be completely impossible to do with vanilla Python.
- 19:43I also thought to myself, well, actually there's a bunch of features in other languages that are purely functional.
- 19:49Things like, like OCaml that are really nice features that Python doesn't have.
- 19:53And we might actually need those things when we take away the immutability.
- 19:57Yeah, that's interesting because, you know, Python is super mutable.
- 20:01It's not just the data itself is mutable, but the structures that make up the execution of your program, like the classes and functions themselves are mutable, right?
- 20:11So this is a really hard problem to solve with Python.
- 20:13If you actually look at good Python programs, like they go through two phases.
- 20:17They go through one phase where they set everything up and then they go through another phase where you don't change things.
- 20:22Like the worst bugs I've ever seen in live Python programs are the ones where people are changing the methods on classes, like as they're running their program.
- 20:31And so now, you know, you've got some class and it's got some function on it and the meaning of that function changes as the program is running.
- 20:39You know, it's impossible for a human being to reason about those programs.
- 20:43So like large scale stuff, people don't do that.
- 20:45People actually tend, the bigger their program gets, the more closely it adheres to the actual, to the immutable style, because that actually makes it possible for human beings to reason about the code.
- 20:56And let me move it this way.
- 20:58If a human being can't reason about your program, the chances that a computer can reason about it are pretty low, at least right now, maybe in two or three more years.
- 21:05That won't be true.
- 21:06But they haven't figured that one out yet.
- 21:07That's right.
- 21:08That's right.
- 21:09Continuous delivery isn't just a buzzword.
- 21:25It's a shift in productivity that will help your whole team become more efficient.
- 21:29With SnapCI's continuous delivery tool, you can test, debug, and deploy your code quickly and reliably.
- 21:35Get your product in the hands of your users faster and deploy from just about anywhere at any time.
- 21:41And did you know that ThoughtWorks literally wrote the book on continuous integration and continuous delivery?
- 21:47Connect Snap to your GitHub repo and they'll build and run your first pipeline automagically.
- 21:51Thanks SnapCI for sponsoring this episode by trying them for free at snap.ci slash talkpython.
- 21:58So yeah, that immutability key, it felt, my initial reaction was it was going to be impossible and we needed new language constructs.
- 22:13But after we built the language out, I realized, wow, this is basically Python.
- 22:17Like there's no, it didn't actually change that much.
- 22:20And what we ended up with is, is basically our language is now like bit code.
- 22:26Like actually mapping Python down into our language, which is called Fora.
- 22:31And saying Fora is now bit code for all of this other stuff.
- 22:35It's like, it's like a language for describing scalable parallel scripting.
- 22:40That frees it from needing to be a language that you would program in every day because we have that.
- 22:46We have Python.
- 22:47And so it was actually a fairly nice transition for us.
- 22:50The reason I chose to do this, it came out of a conversation I had with someone who's done a lot of modified Python.
- 22:57So my original, if you talked to me five years ago, I would have said, look, no one wants a language that has weird, messed up semantics.
- 23:04They want Python to be Python and it's going to give them something different.
- 23:08It should be its own very pure thing.
- 23:10But I talked to this guy named Mike Dubno.
- 23:12He was the CTO of Goldman Sachs for many years.
- 23:15He's the godfather of new language stuff on Wall Street.
- 23:19The team that worked for him at Goldman in the 80s, they've all gone to all the other financial institutions in New York and all re-implemented really interesting large-scale computation systems.
- 23:29Usually they have a language component to them.
- 23:31Yeah, there's a lot of interesting language work happening on Wall Street.
- 23:34A friend of mine just got hired at a startup to build a new language to express ideas just slightly differently.
- 23:41You know, it's so, yeah, that's cool.
- 23:43Yeah, no.
- 23:43And I bet you if you trace it back, it traces back to Mike Dubno at some level.
- 23:47He was the one that convinced me that actually Python with slightly modified semantics is actually something people are totally comfortable with.
- 23:57And his evidence was that, you know, he built a system at Bank of America that's got hundreds of millions of lines of Python code.
- 24:03And it's a big graph calculation thing.
- 24:06Like you make one node that represents the price of oil and another node that's some trade that some trader needs to have repriced.
- 24:13And you describe these things in Python.
- 24:15And they're updated.
- 24:16They can run on different machines from each other, but they kind of look like they're on one machine.
- 24:20And there are some rules about how that needs to work.
- 24:24It's not vanilla Python.
- 24:26And his point was that Python programmers are totally happy having some constraints around their work as long as it's mostly Python.
- 24:34And his evidence was there's a hundred million lines of code written against this thing.
- 24:38And I thought that was pretty good evidence.
- 24:39And that convinced me that...
- 24:40That's good evidence, yeah.
- 24:41Right.
- 24:41That I could make a go of this idea of restricted, you know, of immutable Python, that that was something that people could work in.
- 24:49Yeah.
- 24:50And you were able to basically take those ideas and then map them to your custom runtime, right?
- 24:54Yeah.
- 24:55Yeah.
- 24:55And it actually didn't even take that long.
- 24:57Like, there's been a...
- 24:58Most of the work has been around libraries and tooling.
- 25:01But we had the core mapping from, like, the Python object model and runtime down into...
- 25:08Down into Fora done in just a few weeks.
- 25:11Mostly because the object models are really not that different.
- 25:14Most of the pain is around all of the little idiosyncrasies of Python.
- 25:18Like, if you divide two integers in Python 2, you get an int.
- 25:22But if you divide them in Python 3, you get a float.
- 25:25Like, these little details, making sure that all that stuff works perfectly tends to be a lot of work.
- 25:29But that's not the meat of the intellectual problem, right?
- 25:33That's the details of getting a working system that can run existing Python code and get the same answer as what you get in a regular Python interpreter.
- 25:40That totally makes sense.
- 25:41So there's a bunch of questions I have.
- 25:43The first one is, you know, what kind of problems are you guys solving?
- 25:48And what kind of problems do you see other people solving with this system?
- 25:51Like, where are you focused on applying it?
- 25:54Sure. So for the most part, we're interested in data science and machine learning.
- 25:59So because of the immutable nature of this version of Python, it's really not a good fit for systems programming tasks.
- 26:06Like, I wouldn't write a real-time transaction processing thing in it because it's designed to take really big data sets, do really big computations on them efficiently.
- 26:15You could think of it almost like we optimized for throughput of calculations, not for latency.
- 26:21Like, anything you stick into this thing is going to take at least a half second.
- 26:23But the goal of it is to be able to use 10,000 cores to take something that might take five hours down to five seconds or something like that.
- 26:31Right.
- 26:31We're obviously good at solving all of the standard data parallel things.
- 26:35So, like, what you're saying is I've got a bunch of data on Amazon S3, and I want to pull it into memory and parse it and, you know, slice it the way you would in Pandas.
- 26:45All that kind of stuff works pretty well.
- 26:47And, you know, the goal of the platform is to actually make it so you can write regular idiomatic Pandas code and just have that scale.
- 26:55We haven't done all of the functions, but we're working towards that.
- 26:58I think the place where you really see differentiation is when you have a more complicated algorithm where you've got, as I said before, some kind of structure that doesn't fit nicely into MapReduce.
- 27:09Like, I'll give you an example of one project that we did.
- 27:12One of our customers does Bayesian modeling of retail transactions.
- 27:16So they have all of these transactions from different human beings at different vendors, and they build these models to try and predict whether they're going to be, you know, good customers for these vendors in the future.
- 27:28And they're trying to ask questions like, well, you know, what does it mean about you for your purchases at Home Depot?
- 27:35So the fact that I can tell that you go to Dunkin' Donuts every single day in the morning for coffee.
- 27:39So they're interested in relationships across vendors.
- 27:41And so you end up with this structure of observations where you can group the data by person or you can group the data by vendor.
- 27:51And you have variables that have to do with, like, how much people care about that particular vendor because, you know, the way people interact with Amazon.com is very different than the way they interact with Lowe's.
- 28:01And then you also have this information about the individual person.
- 28:06And so this ends up wanting to suck about 100 gigabytes of data, keep it in memory, and then pass over that data in different orders depending on whether you're trying to update the variables about the individuals or whether you're updating the variables about the vendors.
- 28:23It turns out that it's very easy to describe this in Python.
- 28:26You just have two different loops, one in one direction, one in the other.
- 28:30And you kind of alternate back and forth between them as you're updating the model.
- 28:35This would have been very hard to express as pure map produced, but it's just, you know, it's the whole project is like a couple hundred lines of Python code, which is pretty nice.
- 28:43And this is all distributed and whatnot, right, across the different cores and machines?
- 28:48Exactly.
- 28:49The reason it's only a couple hundred lines of code is because all of the painful stuff, which is making it fast, getting the numeric likelihood calculation to be fast, doing the gradient descent minimization, like, all of that is handled by the infrastructure as opposed to being explicitly
- 29:04described by the user.
- 29:05So the workflow is literally you run a command line thing that boots machines in AWS.
- 29:12We're a big fan of using spot instances in Amazon's infrastructure.
- 29:16If you're not familiar with that, it allows you to basically bid for the market against the market price for compute.
- 29:23If the market price goes above your level, then you don't get the machine, but if it goes below, then you do.
- 29:28And it is usually around 10% of the regular cost of buying a machine, which means that I can get something like a thousand cores for something like 10 bucks, which is a pretty insane price for that level of hardware.
- 29:42That's great.
- 29:43And spot instances are really good for when you want to spin up some stuff, do some work for 30 minutes and throw them away.
- 29:48It's less good for like running them indefinitely as a web server, right?
- 29:52Yeah, exactly.
- 29:53Although there are people who are figuring out that if you spread your spot instance request over enough different zones in Amazon, that the chances that the price spikes in more than two or three of those zones is relatively low.
- 30:07So like I know there are people running real time ad bidding networks entirely on spot and the pricing is so cheap that that's feasible, but it takes a lot of careful design to make it work.
- 30:18But for the kind of analytics workloads we're talking about, it's pretty perfect because usually as a programmer, what you're hoping to do is, you know, tune your algorithm, get it so that you like it on a small scale, and then fire it off and just have as many machines as is required to get the calculation done, you know, in an amount of time that allows you to like look at the answer and solve whatever business objective you have.
- 30:41And so spot is perfect for that because you can literally just say, all right, how many machines do I need to get this done in a half an hour?
- 30:47You know, you look at the workload, you look at the throughput, you divide, and it will just happen.
- 30:52And then you're not committed to holding onto that hardware for any longer than you need it.
- 30:55And at least in our case, because the backend infrastructure is fault tolerant, if the market price happens to change and you lose the machines, you can just go and raise your bid price or wait for the price to drop again and continue where you left off.
- 31:11You don't really lose anything from having the volatility of the pricing shutting your machines down.
- 31:16Yeah, that's really interesting from a distributed computing perspective.
- 31:19It sounds to me with the restriction on sort of read-only type of operations that not every package out there is going to be suitable.
- 31:28So can I go to your system and say pip install something and start working that way?
- 31:34And are there packages that will run or does it have to kind of all be from scratch?
- 31:38It's certainly the case that if you do it from scratch, you can control everything and that you have the highest likelihood that it works.
- 31:45We adopted this hybrid approach where we said we're going to have two kinds of code.
- 31:50There's going to be code that we understand how to translate, and then there's going to be code where we know there's no hope of translating it, mostly because it's written in C.
- 31:59Like if you look at the core of NumPy and Pandas, they're all written in C.
- 32:02There's nothing to even analyze there.
- 32:04So you don't need to do anything to make them fast, but you would need to do something in order to make them parallel.
- 32:09So what we have is a library translation approach.
- 32:13So we've rewritten the core of NumPy and Pandas in pure Python.
- 32:19And then whenever we see that you're using the libraries, we replace your calls to the C versions of those libraries with calls to the pure Python versions.
- 32:29And that allows our infrastructure to see the library and make it scale out.
- 32:35The downside is that we obviously have to translate any libraries that are written in C that way back into Python.
- 32:42It's not as much work as you'd think because part of the reason those libraries are so complicated is, in fact, because they're written in C.
- 32:48Like NumPy has to have separate implementations of every routine for both floats and doubles and ints and everything else.
- 32:55But if you just write it as Python, it's obviously a lot simpler.
- 32:58And the compiler is responsible for generating all of those specializations.
- 33:03As a user, this means that, you know, you're better off if your algorithm either uses really vanilla stuff that we've already translated, or if you're willing to write the algorithm in regular Python yourself.
- 33:17So most of the work where we've had really good success scaling this up is cases where people wrote their own algorithm anyways, because it didn't work with something off the shelf.
- 33:27But our vision over time is that we could get most of the major algorithms like scikit-learn-stop, pandas, NumPy, all of the core stuff that people use, translated back into pure Python in a way that works with the compiler.
- 33:39And it's pretty easy to do these translations.
- 33:43So, you know, one of the things I'd say to the community is if you're using the system and you run into a function that's not there, you know, go and do the translation.
- 33:51In most cases, it's pretty easy, and you can contribute it back, and it's a nice way of extending the system.
- 33:58We're working on that kind of thing all the time, and we just tend to do the functions as we run into them, as we need them for our other work.
- 34:05This episode is brought to you by OpBeat.
- 34:20OpBeat is application monitoring for developers.
- 34:23It's performance monitoring, error logging, release tracking, and workflow in one simple product.
- 34:27OpBeat is integrated with your code base and makes monitoring and debugging of your production apps much faster and your code better.
- 34:35OpBeat is free for an unlimited number of users.
- 34:37And starting today, December 1st, OpBeat is announcing that their Flask support is graduating from beta to a full commercial product.
- 34:45Visit opbeat.com slash Flask to get started today.
- 34:56We also have plans that should be released later this summer of letting you run stuff out of process in regular Python so that if you don't want to translate it and you're willing to say, look, here's some crazy model that somebody wrote.
- 35:11It's in C. I'm never going to translate it.
- 35:13I don't want to run this model in parallel.
- 35:15I want to run thousands of copies of it.
- 35:17The distinction is I don't need this model itself to scale.
- 35:20I just need to have lots and lots of different versions of it running on different machines.
- 35:24In that case, we'll be able to let you run that out of process basically using the same kind of thing that you would do if you were solving this problem by hand, which is multiprocessing.
- 35:36And this is basically the same approach as what PyPy has taken, which is to say you then chunk the problem up into smaller chunks yourself.
- 35:44We'll ship each slice of the problem to a different Python interpreter on a different machine, and then it'll just run in vanilla Python the way it runs.
- 35:52The upside of that approach is that it makes it possible to access all of this content that may never fit nicely into one of these models.
- 36:00The downside of that approach is that you end up with all of the headaches that are usually associated with things like PySpark, which is like if that process runs out of memory and crashes, you don't have any idea what happened.
- 36:13PySpark can't know.
- 36:14You know, we won't really be able to know why that happened.
- 36:16And then the responsibility is now back on the user of the system to figure out, well, why did it run out of memory?
- 36:23What do I need to do to get it to fit?
- 36:24Which is all stuff that we can make go away when we can actually see the source code in itself and translate it.
- 36:30So I think it's kind of a necessary step to getting everything working for a lot of use cases.
- 36:35Yeah, absolutely.
- 36:36Because you don't want to try to translate the long tail of all these libraries and stuff.
- 36:41So talk to me about how you share memory.
- 36:43So, for example, if I've got a list in memory and it's, as far as my program is concerned, has like a billion objects in it, what does that look like to the system, really?
- 36:54Sure.
- 36:55This is a super interesting question.
- 36:57So the idea is we put it in chunks, each chunk being a reasonably small amount of memory, like 50 or 100 megabytes.
- 37:04And then the idea is that these chunks are scattered throughout memory.
- 37:08So, like, imagine that you had a billion strings and each string is like, on average, a kilobyte.
- 37:13So you've got a terabyte of stuff in that list.
- 37:18But, like, the strings are different lengths, right?
- 37:20So, you know, you might have some chunks might have 50,000 records and some other chunks might have 5,000 records and some other might have 500,000 records, depending on how you and how your data actually looks.
- 37:32So the system chunks it up.
- 37:34And then what it does is, as your program is running, it thinks about this sort of at the page level.
- 37:40It says, okay, I can see your program is running.
- 37:42And depending on what it's doing, it needs different blocks of that data to be located together on the same machine.
- 37:49So if you do a really simple thing, like, imagine you say, okay, let's make a list comprehension.
- 37:53I'll scan over my list of strings and take the length of each one.
- 37:57Well, that's a really simple operation.
- 37:59You know, I don't need anything more than each individual string at once to do that.
- 38:04So it doesn't have to move any data around.
- 38:06It just literally goes to every chunk and says, okay, take that chunk and apply the length function to it, and now you get back a bunch of integers.
- 38:12But you could do something more complicated.
- 38:14You could say, all right, imagine that these strings are log messages and, you know, the first tenth of them are from one machine and the second tenth are from another machine.
- 38:25You might say, okay, I'm actually going to go figure out the indices of the different machines,
- 38:28and I want to do something where I'm scanning through them and looking at them at different timestamps across all the different machines.
- 38:35So now you actually have a more complicated relationship.
- 38:39You need different chunks.
- 38:40You might need the first hundred thousand strings and string 500 million to 503 million.
- 38:47You might need those two blocks together because you're actually doing something with the two of them.
- 38:50One partition might be really evenly distributed across the machine.
- 38:55Then you ask the question the right way, and it just parallels it perfectly.
- 38:57But you might cross-cut it really badly, right?
- 38:59There's two problems here, right?
- 39:01One of them is, did you write something where I can get enough data in memory to solve your problem without having to load a lot of stuff?
- 39:09And then the other problem is, like, which things need to be together.
- 39:12So, like, what I was just describing is a case where if you just naively put the chunks on different machines,
- 39:18it's very easy to ask a query where the chunks are in the wrong place.
- 39:22And our system can handle that, right?
- 39:24So it'll see, like, oh, you're accessing these two chunks together because you're using both of them.
- 39:30That problem it solves well because you can actually see that co-location and break your problem down.
- 39:36It's basically active working sets of pages.
- 39:39And so it'll just shuffle everything around in memory to meet the requirements of your problem.
- 39:43There's a second issue, which is, like, imagine you said, look, I've got a terabyte of strings.
- 39:47I'm going to start indexing randomly into the set of terabytes of strings,
- 39:52and you're just not going to be able to predict anything about what I'm going to do.
- 39:56I'm just going to grab them randomly in sequence.
- 39:58You know, there's kind of no way to make that fast.
- 40:01What you'll end up doing is repeatedly waiting on the network while the system goes and fetches, you know,
- 40:07string 1 million and then string 99 million and then, you know, whatever.
- 40:10It's going around and grabbing.
- 40:11And this is just because you've written an algorithm that doesn't have any cache locality to it whatsoever.
- 40:17And so there isn't really a good solution around that other than trying to minimize the amount of network latency.
- 40:24But the way I try and articulate it to people is to say, try and think about it so that your program in your mind,
- 40:30you could break it down into sets of Python function calls that use, you know, a couple of gigs of data at a time.
- 40:37And it will figure out how to get those gigs of data to the right place.
- 40:41You know, it'll see what that structure is by basically through actually running your program and seeing where you have cache misses.
- 40:48Yeah, that's pretty interesting because one of the things you can do to make your code much more high performance,
- 40:54especially around parallelism, but even in general, is to think about caching cache misses on the CPU cache, right?
- 41:02Like locality of data, things like that.
- 41:05And that's, you know, running on my own machine.
- 41:08But it's interesting that that also applies on the distributed sense for you guys.
- 41:12Yeah, well, in many senses, it's exactly the same problem.
- 41:15It's just that it's a much, much, much worse problem.
- 41:18Like when you cache miss on L1 cache in your CPU, you're doing something and the data is not present.
- 41:25Like it's like 100 CPU cycles to go and fetch that data from long-term memory, which is like much slower than what your CPU is used to.
- 41:34But that's still incredibly, incredibly fast.
- 41:36Like if you have a job running on one computer on a network and it says, hey, I need this 50 meg of data on another machine.
- 41:43Like go get that for me.
- 41:45Like if you have 10 gig Ethernet, that means you can move like a gigabyte around per second on that network between two machines.
- 41:52That's like a 20th of a second that you're going to have to wait to get that 50 meg.
- 41:55You know, four orders of magnitude, five, I don't even know.
- 41:59It's some stupidly larger number of time to wait for that data to be present.
- 42:03So it's the same basic problem.
- 42:05It's just that you're way more sensitive to the cache locality issue when you're operating in a distributed context.
- 42:11And it's one of the reasons why the MapReduce Spark model has been so successful is like you're giving the framework a very clear idea of what the cache locality is going to be.
- 42:23When you say take this function and run it on every element of this data set, what you're implicitly telling it is like copy the data for this function to every single machine before you do the job.
- 42:33And now you'll never be waiting for any data.
- 42:36And like we're saying, look, you can take that even a step further.
- 42:39You can infer which data actually needs to go there for arbitrarily complicated patterns and make sure that you're not waiting on cache misses.
- 42:49But it's all boiling down to like trying to fit the program into a model where threads are not waiting on data, where you're getting the most out of the CPUs as you possibly can.
- 43:00Okay.
- 43:00Yeah, that makes a lot of sense.
- 43:01So let me ask you a little bit about your business model.
- 43:05Euphoria is open source.
- 43:08You can go to GitHub.com slash Euphoria and check it out, right?
- 43:12But obviously you guys are doing this as a job.
- 43:15So what's the story there?
- 43:16Sure.
- 43:17So we're basically a data science and engineering consultancy at this point.
- 43:23We deploy Euphoria as part of our work for our clients.
- 43:29We open sourced it because we wanted technology to get to as many people's hands as possible.
- 43:36You know, I didn't leave the hedge fund industry in order to purely just make a pile of money, right?
- 43:41I wanted to build stuff that people could use that would enable the world to do interesting things.
- 43:47So we put it out there and we're hoping that we're hoping other people will pick it up.
- 43:51But our business model mostly revolves around us actually doing data science and engineering work for our clients.
- 43:59And so in some cases, the Euphoria platform is really only 25% or 30% of the solution because you have algorithmic work that needs to be done regardless of what platform you're doing it in.
- 44:10And then you have data integration work that needs to be done, you know, making all these various databases talk to each other.
- 44:17And so the infrastructure ends up being sort of a part of it.
- 44:21I think over time we're anticipating building out additional products and services on top of the Euphoria platform and selling as standalone applications.
- 44:32But infrastructure like this really wants to be open source.
- 44:35Like it's very hard to charge for it successfully because you're asking people to take infrastructure and then build a lot of things on top of it.
- 44:44And nobody likes to do that if they don't actually control the infrastructure.
- 44:47And it's also one of the things that really benefits from community involvement.
- 44:53Again, like this idea of the library work.
- 44:56We as a small company are not going to be able to port every library.
- 45:00But if I put this infrastructure out there and it's useful for people, then each marginal developer can look at it and say, hey, there's some piece of content in NumPy or some crazy scikit-learn algorithm that I'm missing.
- 45:11It's not that much work for me to go port that one thing and contribute it back.
- 45:15And that spirit of like everybody working together is the kind of thing that makes these big platform systems actually run, which is, I think, again, why you've seen so much access in open source for this kind of platform infrastructure.
- 45:29That sounds really nice.
- 45:30I think the one thing I could see that you guys could make sort of directly charge for is if you actually managed the servers and you kind of sold it as computation as a service or something like this.
- 45:42I thought about that, but it's a little like there was a company called PyCloud that raised a bunch of venture funding.
- 45:50Yeah, I met some of those guys.
- 45:51Yeah, and their stuff was super awesome.
- 45:53And I think they ultimately shut that down because they didn't feel like they could generate the kind of return that they wanted.
- 46:00And, you know, the Databricks guys are doing Spark host as a service.
- 46:05But then Google came out with Spark host as a service and Google's cost to be able to provide that infrastructure is super low.
- 46:13So, you know, I looked at it and it's a nice idea.
- 46:16But I think that you just you run into this problem where if you're successful, Amazon or Google will just run the same thing and their cost advantage will eat your lunch.
- 46:25You know, I think in enterprise land, there's a lot more value to solving the LDAP problem, which is, you know, most of the people listening to this podcast are probably big users of open source software.
- 46:36And a lot of them, you know, will pick this kind of technology up to use personally.
- 46:40When you bring this kind of technology into the enterprise, you need all these additional support services that regular people don't need.
- 46:47It needs to integrate with some crazy Microsoft legacy product from 10 years ago.
- 46:52It needs to be able to talk to all kinds of funny databases that that startups don't have, as an example.
- 46:57I think that a lot of the monetization and open source happens around that kind of that kind of problems.
- 47:03Yeah, I think you're right.
- 47:04Enterprise definitely has a lot of its own special challenges, let's say.
- 47:08And that's great.
- 47:09Right.
- 47:09And those challenges, they don't affect adoption.
- 47:11They affect how big organizations like charade and lock this kind of technology down.
- 47:18And so it makes sense to basically build products and services around that and to try and make the core infrastructure as widely used as possible in the community so that it's as good as it can be.
- 47:30Yeah.
- 47:30Okay, great.
- 47:31So you said you have some interesting things going on and sort of what's coming as well.
- 47:35And one of them is you had recently added iPython notebook integration, right?
- 47:40Yeah, so this is something that had been on our to-do list for a while.
- 47:44It doesn't turn out that it's actually that much work.
- 47:46You just need to make sure that you understand where to get the source code.
- 47:50Because instead of living on disk, like most Python modules, it's in memory in these specialized Python notebook cells.
- 47:58We also did some work around getting feedback from the cluster.
- 48:01So you can fire something off now and it will tell you while the thing is running, you're using 500 cores.
- 48:07You can see that number go up and down as it paralyzes your computation because you can write something that is naturally single-threaded.
- 48:15And then you'll get feedback saying, hey, like this thing that you wrote, it's really only using one core because you've got some loop that can't be parallelized, something like that.
- 48:22And this is, I think, a place we're planning on doing more, giving more feedback, more introspection, like some profiling tools and stuff like that.
- 48:30So that as you're running your calculation, you can see, okay, it's really spending a lot of time inside of these functions.
- 48:35This place is like thrashing because it's using too much data or whatever.
- 48:40So I think there's a lot that we can do there to sort of help give more feedback to people about what's going on in their calculations.
- 48:47This is a common problem in any distributed programming context, which is like when you're working on a regular Python interpreter, you can just put print statements and everything is good.
- 48:55But when you're working on across hundreds of machines, even if you could get all the print statements, you'd be drowning in print statements.
- 49:03You wouldn't be able to get anything productive out of it.
- 49:05And it can be really hard for people to understand, like, you know, okay, in a distributed context, why is this slow or fast?
- 49:12So I think there's a lot to do to give people more clarity.
- 49:16I think the other things that we're working on right now that I think are super interesting is we just finished doing something where we're actually making an estimate of how long your computation is going to run for.
- 49:30So what we do is as we're running your computation, we're constantly breaking it up into little pieces.
- 49:35And we actually look at what functions you're calling and what values are on the stack.
- 49:39So, you know, I can notice that if you, you know, if you call F with the number 10, it takes one second.
- 49:44If you call it with the number 1,000, it takes 100 seconds.
- 49:48I can build a little model for all your function calls about how long they take.
- 49:51And this means that on subsequent runs, I can actually make a projection for how long the different pieces of the computation are going to take.
- 49:58And this is useful in two ways.
- 50:01This is useful for the scheduler because now I can say, okay, well, this super long computation, I'd better schedule that first because that will improve the overall runtime of the computation, gives it a sense of how to spread the calculations across the system better.
- 50:15But it's also useful in that I think over the long run, we'll actually be able to give you accurate estimates of how long your calculation is going to take from the beginning and actually make recommendations to you about how much hardware you should use, which would move us towards a more automated way of using the cloud.
- 50:32Where instead of booting machines and thinking of them as your cluster, you just literally fire the thing off and think purely in terms of cost.
- 50:39That's great.
- 50:40So you have like some machine that would just be sort of in charge of orchestrating this and you say, go run this job.
- 50:46And it would go, all right, that's 100 reserve or 100 spot instances at this price of this many cores and go.
- 50:52Something like that?
- 50:53Yeah, exactly.
- 50:54Like it could actually, it could come back to you and say, I think this is going to take, you know, 100,000 compute seconds, you know, and that it's parallelizable up to 1,000 cores.
- 51:05So this is how much it's going to cost.
- 51:07And you could think of it totally that way and then really completely abstract away the actual machines.
- 51:13But you can't really do until you have a good estimate because the problem with computer programs is like you can keep adding zeros and quickly get to runtimes that are astronomical.
- 51:23So you don't want to do that naively because then you'll end up with some system that just says, hey, like I'm just going to run on a million cores and send you an astronomical Amazon bill, which you really don't want.
- 51:33So actually getting a good estimate is pretty important if you're going to make that feature work.
- 51:39But like that model also has incredibly useful features because it's essentially a profile of your code.
- 51:44It can tell you, hey, by the way, the reason why your program is taking so long is that like when you're calling this function, it's taking 3,000 compute seconds.
- 51:51And then that tells you, oh, I should go look there and maybe see why it is that it's so slow.
- 51:55Yeah.
- 51:56Yeah.
- 51:56That's really cool.
- 51:57And so far what we've been talking about is running this on CPUs, on dedicated VMs in the cloud.
- 52:04But if you're going to do computational stuff like pure mathy type stuff, some of the fastest hardware you can get a hold of are actually graphics units, GPUs, right?
- 52:14Yeah, absolutely.
- 52:15I think that that's the thing that's driving the current AI renaissance right now is the fact that like these graphics processors aren't just good for playing video games.
- 52:26They're good for doing general math.
- 52:27And in many cases, they're several hundred times more math operations than your regular CPU can do.
- 52:33The biggest issue with them is that they're really, really challenging to program.
- 52:38Unlike your CPU, where each of the cores on your machine can do a completely different thing at once, and you can just program as if they're totally independent of each other.
- 52:47The threads on a GPU all have to do exactly the same thing simultaneously.
- 52:51They can kind of try and hide that from you a little bit.
- 52:54But as soon as you do something that the GPU doesn't like, it suddenly gets hundreds of times slower and there's no benefit to using it.
- 53:00It's really hard to write code.
- 53:01It's efficient on a GPU.
- 53:05And one of the things that we're spending a lot of time on, Euphoria, is figuring out how to get the Python code to run natively on GPU and to solve some of these programming problems.
- 53:15And so the idea is, in the same way that we're able to make fast programs scaling out on the cluster by actually running them and learning from the way they're behaving, like which functions are slow and how they're accessing data, we can apply those same techniques to solve some of the problems that people have with GPUs.
- 53:33So as an example, we can identify places where threads are in fact all doing something together in lockstep and say, hey, we've noticed that this is a good piece of code to run on a GPU and schedule that automatically.
- 53:45And then there are more aggressive program transformations you can do where you can detect that if you've modified the program slightly, you would end up with something that actually would run efficiently on GPU.
- 53:59I was reading some blog post by a guy at NVIDIA where he pointed out that if you move an array from local memory to shared memory in a GPU, suddenly it speeds up 25 times, which is like an enormous performance difference, right?
- 54:14And I didn't even remember exactly when I was reading it, like what's the difference between local and shared memory?
- 54:19And my point is that this is the kind of thing that like an optimizer that actually had a statistical model of your program would be perfectly capable of doing in an automated way, which would free you from the burden of trying to figure that out.
- 54:32And in some cases might do optimizations that no programmer had ever thought of because it's such a hard thing to optimize and they didn't realize, wow, if I move this one little thing over, it's going to be faster.
- 54:41So we're just getting started with this, but I think there's an enormous amount that we can do and you should expect to see more commits related to that coming out over the summer.
- 54:50Yeah, I think that's really amazing.
- 54:52And just for those of you guys who don't know out there, you can go to Amazon, AWS EC2 and say, I would like to get a GPU cluster with NVIDIA or ATI Radeon or whatever type of graphics cards, right?
- 55:04Yeah.
- 55:05So what's even better is you can do this with Spot.
- 55:09So you can go and get machines that have four Teslas on them and you can pay like 25 cents an hour for that.
- 55:17And so you can put a hundred machines with four Teslas on them for 25 bucks, which is just an incredible, that's like just a stupid amount of computing hardware.
- 55:27The GPU instance prices on Amazon fluctuate a little bit more wildly because I think there are some researchers doing a whole lot of deep learning research on there.
- 55:36So it's actually kind of funny.
- 55:38Sometimes the smaller GPU instances actually cost a lot more than the larger ones because there's pressure for those on pricing.
- 55:45But it is an amazing ecosystem.
- 55:47And a lot of our work is focused on this idea that like not only is it easy to boot those machines, but it should be easy to use 100 GPUs without having to think about it, right?
- 55:56There's actually some great software out there right now for using a single GPU effectively.
- 56:02But what happens when you now say, okay, well, I have data on one GPU and it wants to talk to data on a completely different GPU on a completely different machine, right?
- 56:10That's the thing that I'm trying to make totally transparent.
- 56:12That's a really awesome problem.
- 56:13And so obviously the GPUs are fast and this would make it possibly, maybe possible for you to get an answer to your question sooner.
- 56:21But would it actually make it cheaper as well to answer your question in general?
- 56:25No question that there are a whole host of problems that if you move them from CPU to GPU, your total cost of computation goes down by a couple orders of magnitude.
- 56:36So actually as an example, this maximum likelihood calculation I was doing on the retail stuff for one of our customers, one of the reasons we're pushing into the GPU space is that we currently use about 40 Amazon machines,
- 56:50the really big instances to get their calculation done about an hour, but they have to do this fairly frequently to update the model when new data comes in.
- 56:58And, you know, I mean, that costs them 10 bucks every time they run it.
- 57:01And if they, you know, do that every day, four times a day for a long enough time, that starts to become real money again.
- 57:06You know, we've estimated that it would be about 5% of the cost if we can get that same calculation to run as efficiently as we think it could using GPU.
- 57:17Now the problem with that is like, as soon as you do that, it's not clear that people will take the cost savings and not just reinvest it into a solving a bigger problem.
- 57:25But like, look, that's great for them if they want to do it.
- 57:27Yeah, that's interesting.
- 57:29So 20 times cheaper when you say 5%.
- 57:31Yeah, something like that.
- 57:32Yeah, that's awesome.
- 57:33I mean, it's extremely dependent on the problem.
- 57:35Sometimes it's only like two times faster.
- 57:38Sometimes it's slower.
- 57:39And sometimes it's like, look, for the neural network stuff that people are doing, it's at least 100 times faster slash cheaper.
- 57:45I mean, the neural network people all think in terms of electricity costs, right?
- 57:50They literally say how many like training cycles they can do per kilowatt hour.
- 57:53Wow.
- 57:54Okay, that's really amazing.
- 57:57So is there a way with your system to sort of extrapolate and estimate how much something would cost?
- 58:04Is there a way to say, I have these three problems?
- 58:07If I were to give it this much data, how much would each one of these cost?
- 58:10Because I can only afford to answer one.
- 58:12Well, so that's one of the things that we're hoping to answer with some of this extrapolatory runtime stuff, this ability to predict what runtime is actually going to be and how much compute power you need.
- 58:25So the idea would be that you would run all three problems at several smaller scales.
- 58:30The system could see how the runtime of all the little functions was changing as you're changing the problem size.
- 58:37And then it would be able to extrapolate from there.
- 58:40At the end of the day, though, it all depends on how accurate you want your estimate to be.
- 58:46If you really want a perfect estimate, you should actually do that experiment yourself and make a decision.
- 58:51And like, honestly, the way I usually do this problem is doing that process by hand.
- 58:56I'll run it with some smaller input and I'll just keep adding zeros until it becomes appreciably slow.
- 59:01And then I'll try and understand why it's changing.
- 59:03But yeah, in principle, that's totally the direction that we're moving in where you can literally just get a price estimate for each of the three things.
- 59:12And there might be, you know, plus minus two times or whatever, depending on how accurate the estimates are.
- 59:18Yeah.
- 59:19Okay.
- 59:19That sounds great.
- 59:20So I guess the last thing we have time to cover is how do you get started?
- 59:24Like, I know it's on GitHub, but there's a lot of moving pieces with distributed computing.
- 59:29And so can you just walk me through going from nothing until I have an answer, maybe, what that looks like?
- 59:35Yeah, absolutely.
- 59:36So we publish Docker images with the software backend every time we do a release.
- 59:42So if you want to run this on your local machine, you pip install the front end, which is called Pyfora.
- 59:49And that's just vanilla Python code that, like, has the thing that takes your Python code and sends it to the server.
- 59:56And then you need to get some nodes that can actually run work.
- 1:00:00And you've got two options.
- 1:00:01One of them is to run it just on your local machine.
- 1:00:03And doing this gets you the benefit of using the cores on your local machine.
- 1:00:07So it's not trivial.
- 1:00:08So to do that, you just do Docker run the euphora slash service colon latest.
- 1:00:15That, you know, pulls the latest version of the euphora service and runs it.
- 1:00:18And then if you want to run this on Amazon, which is the way I do everything, we have a little command line utility called Pyfora AWS.
- 1:00:24And that thing can just boot instances.
- 1:00:28You have to have your AWS credentials exposed in the environment the same way you would if you were using Voto to interact with AWS.
- 1:00:35But if you do that, it knows how to start machines and stop them.
- 1:00:39And it will make sure everything is configured on there correctly.
- 1:00:41You do need to make some decisions about the security model.
- 1:00:45Personally, I prefer to boot machines and then use SSH tunneling.
- 1:00:49So then I'm connecting to a server that looks like it's on local host and SSH is taking care of all of the security.
- 1:00:56But there are other ways to do it that are documented in Pyfora AWS.
- 1:00:59But the basic idea is you use AWS or you use Docker locally to get something going, you know, one of these machines.
- 1:01:06And that gives you an IP address that you can talk to.
- 1:01:09In your Python program, you connect to that IP address.
- 1:01:12You get a little connection object.
- 1:01:14And then any code that you want to execute in Euphoria, you just put inside of a with block that references that connection.
- 1:01:21So you say with my connection colon.
- 1:01:24And then anything inside of there when the Python, when your Python interpreter gets to it, instead of executing it, it will take that code and all the resulting objects, ship them over to the server.
- 1:01:34The server will execute them and then it will ship it back.
- 1:01:38You know, I'm going to be now that we have Python notebook integration, I'm going to be publishing a bunch of example, Python notebooks.
- 1:01:45So you should be able to go to our website and just pull down a few examples of those things operating.
- 1:01:49But, you know, the basic point is that if you if you are a user of Amazon already, you can get up and running with the amount of time it takes to boot an AWS instance.
- 1:02:00And how long it takes you to pip install Pyfora.
- 1:02:03Wow, that sounds really cool.
- 1:02:05Nice work on that.
- 1:02:06And props for using the context manager, the width block.
- 1:02:10It turns out it's a really it's a really nice way of doing it there.
- 1:02:13You have to you have to do some clever trickery under the hood to make that work, especially when it comes time to propagate exceptions.
- 1:02:22Because if you produce an exception on the server, you've got to take that state move back over and then kind of rebuild the appropriate stack trace objects on the, you know, on the client, which is a kind of an interesting thing to do.
- 1:02:35But the end result is a is a really nice integration.
- 1:02:37And it gives you this nice ability to pick and choose where you want to do the Pyfora, you know, to use the technology.
- 1:02:45So it means that if there are parts of your code that are really never going to be paralyzed and you don't want to move them or if you're touching things on your file or you're reading things off of the Internet or whatever, that stuff can all happen on your local box.
- 1:02:57It's just a heavy compute stuff can happen remotely.
- 1:03:00It also gives you a nice way of deciding, like, which objects are going to live remotely and which objects are going to live locally.
- 1:03:06So you can do a calculation that ends up producing this, you know, like think about the example we were talking about earlier.
- 1:03:12We have a list of a billion strings like in the width block.
- 1:03:15That list of a billion strings, you can do whatever you want in your local Python interpreter.
- 1:03:20You'll end up with like a reference to that list.
- 1:03:22It's like a proxy object.
- 1:03:24You can't do anything with it locally because you obviously can't bring a terabyte of strings back into your local Python process without crashing it or waiting for hours and hours.
- 1:03:33But you can then pass that back into a subsequent width block and do something there.
- 1:03:37Cut it down to something smaller if you want to pull back a slice of it or whatever.
- 1:03:42And so it makes a really nice workflow for kind of describing which things are going to be in your local process and which things are going to be remote.
- 1:03:47That sounds awesome.
- 1:03:48This is really cool.
- 1:03:50If you've got big data processing, it sounds like people should check it out.
- 1:03:53So I think we're going to have to leave it there.
- 1:03:55We're just about out of time.
- 1:03:56Let me ask you just a couple questions to wrap things up.
- 1:04:00I always ask my guests what their favorite PyPI package is.
- 1:04:05There's 75,000, 80,000 of them out there, and we all get experience with different ones that we'd want to tell people about.
- 1:04:10What's yours?
- 1:04:11Well, I hate to not be super interesting on this, but I have to say I love Pandas.
- 1:04:16I think Wes did a great job.
- 1:04:18I would argue that the resurgence of Python in the financial services community is basically due to the existence of Pandas pulling people out of the R mindset and into Python.
- 1:04:29So if you're not familiar with it, check it out.
- 1:04:31Probably everybody listening to this knows about it.
- 1:04:33Yeah, Pandas is very cool.
- 1:04:34And how about an editor?
- 1:04:36What do you open up if you're going to write some code?
- 1:04:37I am a strict adherent to Sublime.
- 1:04:40I even paid for it, although I didn't have the energy to actually paste the key so that it still keeps asking me for the key.
- 1:04:47But I did pay for it.
- 1:04:48I think he did a great job with that editor.
- 1:04:50Yeah, Sublime is great.
- 1:04:51All right, so final call to action.
- 1:04:54What should people do to get started with you for it?
- 1:04:56So go and check us out on GitHub.
- 1:04:59Try running some code.
- 1:05:01We've tried to make it as easy as possible to get started.
- 1:05:04As I said before, we're going to be posting a bunch of my Python notebooks with examples.
- 1:05:07And then, you know, please give us feedback.
- 1:05:11Tell us what libraries you want ported, what problems you're running into using it.
- 1:05:17And, you know, like, honestly, if you run into some NumPy function that we didn't get to yet, take a crack at implementing it yourself.
- 1:05:23It's a pretty straightforward model.
- 1:05:25And send us a pull request.
- 1:05:26We'd love to include it.
- 1:05:27All right.
- 1:05:28Excellent.
- 1:05:29I think this is a great project you're on, and I'm happy to share with everyone.
- 1:05:32So thanks for being on the show, Braxton.
- 1:05:34Thank you so much for having me.
- 1:05:35It's a pleasure to talk about this stuff, as always.
- 1:05:37This has been another episode of Talk Python To Me.
- 1:05:41Today's guest was Braxton McKee, and this episode has been sponsored by SnapCI and OpBeat.
- 1:05:46Thank you guys for supporting the show.
- 1:05:48SnapCI is modern, continuous integration and delivery.
- 1:05:51Build, test, and deploy your code directly from GitHub, all in your browser with debugging, Docker, and parallels included.
- 1:05:57Try them for free at snap.ci slash talkpython.
- 1:06:00OpBeat is mission control for your Python web applications.
- 1:06:05Keep an eye on errors, performance, profiling, and more in your Django, Flask, and Pyramid web apps.
- 1:06:09Tell them thanks for supporting the show on Twitter, where they're at, OpBeat.
- 1:06:13Are you or a colleague trying to learn Python?
- 1:06:15Have you tried books and videos that left you bored by just covering topics point by point?
- 1:06:20Well, check out my online course, Python Jumpstart by Building 10 Apps, at talkpython.fm/course,
- 1:06:26to experience a more engaging way to learn Python.
- 1:06:28You can find the links from this show at talkpython.fm/episodes slash show slash 60.
- 1:06:35Be sure to subscribe to the show.
- 1:06:37Open your favorite podcatcher and search for Python.
- 1:06:39We should be right at the top.
- 1:06:40You can also find the iTunes feed at /itunes, Google Play feed at /play,
- 1:06:45and direct RSS feed at /rss on talkpython.fm.
- 1:06:49Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:06:54You can hear the entire song at talkpython.fm/music.
- 1:06:58This is your host, Michael Kennedy.
- 1:07:00Thanks so much for listening.
- 1:07:01I really appreciate it.
- 1:07:02Smix, let's get out of here.
- 1:07:12Mike Beckton, who rocked his best.
- 1:07:14I'm first developers.
- 1:07:16I'm first developers.
- 1:07:18I'm first developers.
- 1:07:19I'm first developers.
- 1:07:22I'm first developers.
- 1:07:25.
- 1:07:26Don't forget.