swi-ml
- 2 minsTable of Contents:
- What is swi-ml?
- But what is a switchable backend?
- How do I use it?
- What dependencies do I need to install?
- Roadmap/Code/Documentation
- Cherry Points
Small Disclaimer: This library is NOT an alternative to amazing libraries like scikit-learn and cuML. Their interfaces are complete on their own!
What is swi-ml?
swi-ml is a small lightweight Python library, which implements a subset of classical machine learning algorithms, with a twist - it has a switchable backend!
from swi_ml import set_backend
# numpy backend (CPU)
set_backend("numpy")
# cupy backend (GPU)
set_backend("cupy")
But what is a switchable backend?
NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It is the backbone for many such libraries, like scikit-learn.
But, most of its code is in serial order.
numpy
is primarily designed to be as fast as possible on a single core, and to be as parallelizable as possible if you need to do so.
Moreover, vanilla NumPy cannot accelerate computing on a GPU.
CuPy comes to rescue!
CuPy is an open-source array library accelerated with NVIDIA CUDA, which speeds up some operations more than 100X.
“CuPy’s interface is highly compatible with NumPy; in most cases it can be used as a drop-in replacement.” - So why not use this and create a small library which implements a domain-problem (machine learning in this case) and benefit from both libraries at a single interface?
This is what swi-ml does.
It was built in a duration of a month, where I mostly learnt:
- Test-Driven development
- Object-Oriented code structure
- building a pip installable library
- implementing correct Logging (bybye
print()
statement!) - and most importantly - implementing a
singleton
Backend (with correct raises and runtime imports)
How do I use it?
swi-ml
is published to PyPI at this URL: https://pypi.org/project/swi-ml/
So installing it is as simple as:
pip install swi-ml
Or, via GitHub:
pip install git+https://github.com/aitikgupta/swi-ml
What dependencies do I need to install?
Except NumPy, there’s no hard-dependency!
Although, to use the GPU-accelerated backend, a working installation of CuPy (install guide) is required.
Other than this, some plot functions might require a working installation of matplotlib, but it will be a runtime-dependency soon (see Roadmap).
(Recommended) Checkout the README.md on GitHub for a detailed guide.
Roadmap/Code/Documentation
Code is open sourced at GitHub, one can find many, many comments within the library.
Cherry Points
There was a time in developing cycles, when I decided to change the name of the library - cherry points if one can figure out the previous name! (HINT: It is close to an amazing library by RapidsAI, and has a commit dedicated to it)