Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 52
Add sponsor project: Numba and llvmlite in the browser#362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
| import GetAQuotePage from '@site/src/components/fundable/GetAQuotePage'; | ||
| export default function FundablePage() { | ||
| const { siteConfig } = useDocusaurusContext(); | ||
| return ( | ||
| <GetAQuotePage/> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
| import LargeProjectCardPage from '@site/src/components/fundable/LargeProjectCardPage'; | ||
| export default function FundablePage() { | ||
| const { siteConfig } = useDocusaurusContext(); | ||
| return ( | ||
| <LargeProjectCardPage/> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| #### Overview | ||||||
| [Numba](https://numba.pydata.org/) is the standard | ||||||
| just-in-time (JIT) compiler for numerical Python, widely used | ||||||
| across the scientific stack to accelerate compute-heavy code. | ||||||
| [Pyodide](https://pyodide.org/) brings CPython to the browser | ||||||
| through WebAssembly and powers JupyterLite, while | ||||||
| [emscripten-forge](https://github.com/emscripten-forge) | ||||||
| provides a conda-based package distribution for the same | ||||||
| target. Today, Numba cannot run in either environment. | ||||||
| We propose to make Numba and its JIT backend, | ||||||
| [llvmlite](https://github.com/numba/llvmlite), | ||||||
| browser-compatible using WebAssembly, and thus enabling | ||||||
| Pyodide and emscripten-forge users to JIT-compile numerical | ||||||
| code just like they do on a native CPython interpreter. | ||||||
| #### Why Numba in the Browser Matters | ||||||
| In a native CPython environment, many paths exist to make | ||||||
| numerical Python fast: Numba's JIT compilation, | ||||||
| multiprocessing, native C extensions, or offloading to a GPU. | ||||||
| In the browser, multithreading/processing and GPU access are | ||||||
| mostly unavailable, and shipping pre-compiled native | ||||||
| extensions for everything is impractical. In addition, the | ||||||
Comment on lines
+24
to
+25
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't "shipping pre-compiled native extensions" exactly what we do in emscripten-forge? Why would it be more impractical for the browser than for native code? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key word is everything here. We can't ship compiled extensions for every loop and small code snippet. That is what is impractical on native and in the browser. Maybe it can be written better.
| ||||||
| overhead of the Python interpreter is larger in the browser | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced the overhead of the Python interpreter is larger in the browser, unless you can link to an independent study. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's generally cited in the pyodide community. The standard numbers are <2.5x native for compiled stuff (based on a 2019 paper), 2-5x for python (cited on pyodide issues in their roadmap and more based on their benchmarks). If you actually look at the pyodide benchmarks you could say 2 -10x though. I'll put a reference in. I don't think they have rigorously isolated the effect of the interpreter. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pyodide is not independent of course in that sense. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, perhaps link to a recent evaluation by PyOdide, then?
| ||||||
| and many existing libraries use Numba, sometimes as hard | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
| ||||||
| requirements. JIT compilation is therefore an interesting | ||||||
| route to improved performance in a fully client-side, | ||||||
| browser-based Python environment. | ||||||
| #### Current Progress | ||||||
| We have already patched llvmlite and demonstrated that it runs | ||||||
| in the browser including compilation and execution of the WASM | ||||||
| code it generates. A live demo is available at | ||||||
| https://notebook.link/@anutosh491/llvmlite. | ||||||
| We also have a working demo of Numba's `@jit` decorator | ||||||
| operating on scalar functions in the browser. However, several | ||||||
| issues have been identified that must be overcome to make | ||||||
| Numba work generally (e.g. with arrays). These likely include | ||||||
| WebAssembly's lack of writable-and-executable memory pages | ||||||
| (which rules out MCJIT), unsupported atomic instructions | ||||||
| without shared memory, variadic C calls that cannot be lowered | ||||||
| to WASM, and linkage incompatibilities in the LLVM WASM PIC | ||||||
| backend. But these seem surmountable based on our experience. | ||||||
Comment on lines
+42
to
+47
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove the details, some of which are probably wrong. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea could do. It would be nice to show that we have some idea about the non trivial parts though. | ||||||
| #### Why QuantStack | ||||||
| QuantStack is uniquely positioned to deliver this work. We | ||||||
| have shipped several JIT and WebAssembly projects in the | ||||||
| scientific Python ecosystem, including | ||||||
| [xeus-cpp](https://github.com/jupyter-xeus/xeus-cpp), a C++ | ||||||
| interpreter running in the browser via Clang and LLVM compiled | ||||||
| to WebAssembly. Our team also includes Numba core developers, | ||||||
| giving us a direct upstream relationship. | ||||||
Comment on lines
+56
to
+57
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not even sure I still have commit rights on Numba, and we have nobody else in the Numba team. So this sentence is a lie AFAICT. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, core developer is not correct? Or the upstream relationship?
| ||||||
| #### Proposed Work | ||||||
| The goal of this project is to: | ||||||
| - upstream llvmlite compatibility with browser environments, | ||||||
| based on our existing patches. | ||||||
| - build a proof of concept for general Numba use in the browser to | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say it's up to us to show a proof of concept before getting some funding. A sponsor will want dependable upstream changes for full-blown Numba functionality. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about this as well. But my understanding is that the proof of concept itself is a significant undertaking, and probably the main challenge right now. Under that hypothesis, funding already for the PoC would be necessary because otherwise we may not be able to stem it ourselves. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the effort to demonstrate JIT-acceleration of NumPy array code is that significant. @anutosh491 could perhaps give more insight. | ||||||
| - demonstrate, ideally all of Numba, or at least a large part of it, in the browser | ||||||
| - demonstrate the ability to run libraries that depend on it (such as pytensor/pymc) in the browser | ||||||
| - gather and understand the changes required | ||||||
| - upstream the required changes | ||||||
| Note that this is a proof of concept effort, we will advance | ||||||
| incrementally, deliver sub-parts, and adjust the plan based | ||||||
| on new learnings. | ||||||
| ##### Are you interested in this project? Either entirely or | ||||||
| partially, contact us for more information on how to help us | ||||||
| fund it. | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the MCJIT tidbit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes