cd /news/machine-learning/accelerate-your-ml-models-using-rapi… · home topics machine-learning article
[ARTICLE · art-106776] src=pub.towardsai.net ↗ pub= topic=machine-learning verified=true sentiment=↑ positive

Accelerate your ML models using RAPIDS AI

NVIDIA's open-source RAPIDS AI framework accelerates machine learning workflows by enabling GPU-based data processing, offering cuDF, a pandas-like library that performs operations on large datasets 100x-1000x faster than CPU-based pandas. The framework includes libraries for data analytics, preprocessing, graph algorithms, and ML, allowing users to speed up tasks such as loading, filtering, grouping, and aggregation on datasets with 10 million rows without changing traditional workflows.

read8 min views1 publishedAug 22, 2026

I’ve been heavily frustrated and agitated when I have to wait in those situations. Despite my impatience, I can’t explain my happiness when it’s trained properly and works well. I always wondered why it would take so much time to train these models. Only when I dive deeper into how the predictive models work, do I understand the reason and feel it was fair enough. However, a part of me still hated the slow processing and training.

There are several ways to optimise the models, both in terms of hardware and software. One such optimisation is to use GPUs for the data preprocessing and model training. With the sophistication of tools provided by NVIDIA, we always have the liberty to use GPUs for deep learning models. However, most machine learning models are trained on CPUs, which is the core reason for the slow training and inference. NVIDIA offers a framework to speed up data processing, ML, and visualization using GPUs, without changing the traditional workflow, and it’s amazing.

In this blog, we’ll look into the RAPIDS AI framework and how a data scientist or anybody who works with data can utilise it to optimise their workflows. We’ll also compare this with other optimisation techniques and figure out how to choose the right technique for specific situations. The right understanding of the features and capabilities of RAPIDS AI will help you optimise your process in the data science projects.

With the growth of AI and data generation, the demand for faster and efficient computations is also increasing at a higher speed.** RAPIDS AI is an open-source framework developed by NVIDIA that provides GPU support for data analytics, data preprocessing, graph algorithms, and ML workflows. It helps users build cloud-based machine learning experiments to build models faster, cheaper, and more easily. It has a GPU-optimized core data frame that helps to build databases and ML models, without changing the traditional workflows. It offers a collection of libraries for different tasks in the data engineering process. The most important libraries of RAPIDS AI are as follows:

I’ll walk you through a few of these libraries with examples and code snippets to use in your workflows. Before that, let me explain to you the actual need for such libraries.

Before we get started with the RAPIDS AI, it is essential to install the relevant libraries to access the functionality. You can run the following commands to install the required libraries and frameworks.

conda create -n rapids python=3.10 -yconda activate rapidsconda install -c rapidsai -c nvidia -c conda-forge \    cudf python=3.10 cudatoolkit=12.0 -y

Once you are done with the installation process, let's begin to explore the libraries offered by RAPIDS AI.

cuDF is a GPU-accelerated DataFrame library that gives massive speed-ups when working with large datasets. Pandas is great. But it struggles when you have tens of millions of rows, complex group-bys and joins, and repeated feature engineering for ML pipelines. cuDF is essentially the GPU equivalent of pandas in Python, designed to perform pandas-like operations on large datasets 100x-1000x faster by running them on NVIDIA GPUs instead of CPUs.

The cuDF offers an implementation that is very close to that of pandas. You can often take the existing pandas code and change just one line and get massive speedups.

Before we get to know how to use cuDF, let me show you an example of how cuDF works and how it performs in real-time. To showcase this, I have created a dataset with **10 million rows **and saved it as a parquet file. I tried to perform operations such as , filtering, grouping and aggregation using pandas and cuDF, which showcased massive differences.

import numpy as npimport pandas as pdimport cudfimport time# -------------------------------------------------# 1. Generate dataset (10 M rows)# -------------------------------------------------N = 10_000_000np.random.seed(42)print(f"Generating {N:,} rows...")review_options = ["Great product!", "Fast shipping", "Poor quality", "As expected",                  "Love it!", "Too expensive", "Would buy again", None]reviews = np.random.choice(review_options, size=N)reviews = np.where(pd.isna(reviews), "", reviews)          # None → empty stringdata = {    "user_id":     np.random.randint(1, 500_000, N),    "product_id":  np.random.randint(1, 50_000, N),    "category":    np.random.choice(["Electronics","Clothing","Home","Books","Toys"], N),    "price":       np.random.exponential(50, N).round(2),    "quantity":    np.random.randint(1, 20, N),    "is_returned": np.random.choice([False, True], N, p=[0.93, 0.07]),    "country":     np.random.choice(["US","UK","DE","JP","CA","AU"], N),    "timestamp":   pd.date_range("2024-01-01", periods=N, freq="1min"),    "rating":      np.random.choice([1,2,3,4,5], N, p=[0.05,0.1,0.15,0.3,0.4]),    "review_text": reviews,}df_pd = pd.DataFrame(data).sample(frac=1, random_state=42).reset_index(drop=True)df_pd.to_parquet("sales_10M.parquet")print("Dataset saved")# -------------------------------------------------# 2. Load with pandas and cuDF# -------------------------------------------------df_pandas = pd.read_parquet("sales_10M.parquet")df_cudf = cudf.read_parquet("sales_10M.parquet")# Convert ALL object columns to cuDF string dtypefor col in df_cudf.select_dtypes(include=['object']).columns:    df_cudf[col] = df_cudf[col].astype("string")print("dtypes in cuDF:")print(df_cudf.dtypes)# -------------------------------------------------# 3. Analysis functions (separate for pandas & cuDF)# -------------------------------------------------def run_analysis_pandas(df, name):    print(f"\n=== {name} ===")    start = time.time()        result = (df        .query("price > 10 and not is_returned")        .assign(revenue = lambda x: x.price * x.quantity)        .groupby(["country", "category"], as_index=False)        .agg(            revenue     = ("revenue", "sum"),            avg_rating  = ("rating",  "mean"),            users       = ("user_id", "nunique"),            great_count = ("review_text", lambda x: x.str.contains("Great", case=False).sum())        )        .sort_values("revenue", ascending=False)    )        elapsed = time.time() - start    print(f"{name} took {elapsed:.3f} seconds")    print(result.head(5))    return elapseddef run_analysis_cudf(df, name):    print(f"\n=== {name} ===")    start = time.time()        # Filter and calculate revenue    filtered = df.query("price > 10 and not is_returned").copy()    filtered["revenue"] = filtered["price"] * filtered["quantity"]        # Pre-compute the "Great" flag before groupby    # cuDF requires regex=False when using case=False    filtered["has_great"] = filtered["review_text"].str.contains("Great", case=False, regex=False)        # Now groupby with only built-in aggregations    result = (filtered        .groupby(["country", "category"], as_index=False)        .agg(            revenue     = ("revenue", "sum"),            avg_rating  = ("rating",  "mean"),            users       = ("user_id", "nunique"),            great_count = ("has_great", "sum")  # sum of boolean = count of True        )        .sort_values("revenue", ascending=False)    )        elapsed = time.time() - start    print(f"{name} took {elapsed:.3f} seconds")    print(result.head(5))    return elapsed# -------------------------------------------------# 4. Run!# -------------------------------------------------t_pd = run_analysis_pandas(df_pandas, "pandas")t_cd = run_analysis_cudf(df_cudf,   "cuDF")print(f"\n{'='*60}")print(f"cuDF was {t_pd/t_cd:.1f}× faster!")print(f"{'='*60}")

The output showcased that pandas took 8.909 seconds and cuDF took 0.860 seconds, which is 10.4x faster.

Generating 10,000,000 rows...Dataset saveddtypes in cuDF:user_id                 int64product_id              int64category               objectprice                 float64quantity                int64is_returned              boolcountry                objecttimestamp      datetime64[ns]rating                  int64review_text            objectdtype: object=== pandas ===pandas took 8.909 seconds   country  category       revenue  avg_rating   users  great_count28      US      Home  1.534648e+08    3.899226  199265        3172816      JP  Clothing  1.529607e+08    3.895079  199083        3133124      UK      Toys  1.528698e+08    3.898011  199599        3156323      UK      Home  1.527598e+08    3.901141  199196        3183419      JP      Toys  1.527436e+08    3.899543  198891        31676=== cuDF ===cuDF took 0.860 seconds   country  category       revenue  avg_rating   users  great_count28      US      Home  1.534648e+08    3.899226  199265        3172816      JP  Clothing  1.529607e+08    3.895079  199083        3133124      UK      Toys  1.528698e+08    3.898011  199599        3156323      UK      Home  1.527598e+08    3.901141  199196        3183419      JP      Toys  1.527436e+08    3.899543  198891        31676============================================================cuDF was 10.4× faster!============================================================

cuDF stores the data in the GPU memory and is optimised to parse the large files in parallel.

2. Data Inspection

Most of the methods used in cuDF are similar to the ones used in pandas.

3. Data Selection, Indexing, and Operations

The data selection, indexing, and other operations can be done using cuDF, similar to the pandas library. Some of the examples are attached below.

The cuDF DataFrames can then be converted into a pandas DataFrame, which will bring the data to the CPU. This has to be done with utmost care, considering the size of the dataset.

pdf = cdf.to_pandas()

It is advised to avoid transferring large DataFrames repeatedly, as the copying operation is very expensive.

4. Scaling with dask-cudf

If one GPU is not enough, use **dask-cudf **to partition the data across a cluster or a bunch of GPUs.

import dask_cudf ddf = dask_cudf.read_csv('bigdata-*.csv')agg = ddf.groupby('col').sum().compute()

Modin is another option to optimise pandas. Though cuDF and modin are used for a similar purpose, they differ in how they function.

The cuML library provides GPU-accelerated versions of scikit-learn algorithms. It keeps the same APIs (fit(), predict(), transform()), the same algorithm names, and often the same hyperparameters. The only difference is that the execution happens on thousands of GPU cores.

GPUs excel at parallel numeric computations, so cuML takes common ML tasks and runs them on the GPU.

#scikit-learnfrom sklearn.cluster import KMeans# cuMLfrom cuml.cluster import KMeans

All the other functions and operations remain almost the same in both scikit-learn and cuML. The supported algorithms in cuML are listed below.

Let me demonstrate an example using Logistic regression.

cuGraph is the GPU-accelerated graph analytics library in the RAPIDS ecosystem. Most of the graph algorithms, such as PageRank, BFS, SSSP, and Community Detection, are expensive. They have to traverse millions or billions of edges, and performing them on a CPU takes a long time to compute. cuGraph solves this by using CUDA and storing the graph data in GPU memory. It helps to perform parallel graph computation, which results in 10x — 500x speedups compared to NetworkX for large graphs.

cuGraph integrates with cuDF and cuML for GPU-based DataFrames and Machine Learning. Let’s try to use it on a small dataset for demonstration.

Before usage, we must install the packages. To install, use the following command.

pip install cugraph-cu12 --extra-index-url=https://pypi.nvidia.com

Once installed, we can access the algorithms through the built-in APIs.

import cudfimport cugraph# Sample edge listedges = cudf.DataFrame({    "src": [0, 1, 2, 3, 4],    "dst": [1, 2, 0, 4, 3]})# Create a GraphG = cugraph.Graph()G.from_cudf_edgelist(edges, source="src", destination="dst")# Run PageRankpagerank_scores = cugraph.pagerank(G)print(pagerank_scores)
vertex  pagerank0       0       0.21       1       0.22       2       0.23       3       0.24       4       0.2

If you’ve made it this far, you’ve seen how RAPIDS can transform your data workflows. But among the advantages offered by RAPIDS, the exciting thing is that it’s literally the same implementation. Just a few changes in the code. All the functions, APIs, and parameters remain almost the same.

If you are someone who works with tabular data, graphs, or machine learning at any non-trivial scale, then favor yourself by choosing RAPIDS AI. Together, these tools form one of the fastest end-to-end data science pipelines available today. Accelerate your processes and build more systems.

Do follow me for more such insightful blogs and experiences. I’d love to hear about your experiences in designing and building ML systems in the comments below!

Raj 🧑🏼💻

Accelerate your ML models using RAPIDS AI was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #machine-learning 4 stories · sorted by recency
── more on @nvidia 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/accelerate-your-ml-m…] indexed:0 read:8min 2026-08-22 ·