CuML + Cudf (RAPIDS) 加速python数据分析脚本

如果有人在用Nvidia RAPIDS加速pandas和sklearn等库,请看我这个小示例,可以节省你大量时间。

1. 创建环境

请使用uv,而非conda/mamba。

shell 复制代码
# install uv if not yet

curl -LsSf https://astral.sh/uv/install.sh | sh

uv init data_gpu

cd data_gpu

uv venv --python 3.12

source .venv/bin/activate

# 大的要来了

# 使用阿里云开源镜像

uv pip install \

  -i http://mirrors.aliyun.com/pypi/simple/ \

  --extra-index-url=https://pypi.nvidia.com \

  "cudf-cu12==25.4.*" "cuml-cu12==25.4.*" \

  "polars[pandas,numpy,pyarrow,style,plot,excel,gpu]" \

  polars-u64-idx scikit-learn scipy statsmodels tqdm ipykernel jupyter --prerelease=allow --index-strategy unsafe-best-match

2. 在脚本中启用

python 复制代码
import cudf.pandas
cudf.pandas.install()
from cuml.accel.core import install as cuml_install
cuml_install(disable_uvm=False)
import pandas as pd
import polars as pl
import numpy as np
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

现在,pandas, sklearn, polars都有GPU加持。但是并非所有函数都受支持。具体情况自己去看官方文档。

另外,不要使用 python -m cuml.accel my_script.py,这样你就无法向my_script.py传自己的参数。

相关推荐
_橙时_2 分钟前
【EM算法例子】
机器学习·em算法
就叫你天选之人啦5 分钟前
安装torch+vllm+flash_attn的prompt
人工智能·pytorch·python
wuyk55538 分钟前
21.计数排序:不用比较的“空间换时间”排序算法
python·算法·排序算法
智码看视界39 分钟前
第4篇:循环神经网络及其变体 LSTM/GRU 实战
python·自然语言处理·gru·lstm·循环神经网络·情感分析·梯度消失
Web3&Basketball40 分钟前
Agent外传审计实战:3类失准事故拦截脚本
python·大模型·agent·性能调优·推理优化
船厂电气自动化ai大模型1 小时前
AI大模型与数学|第81天 课程:正交向量、正交基、格拉姆‑施密特(Gram‑Schmidt)正交化
开发语言·数据结构·人工智能·线性代数·机器学习
何以解忧,唯有..1 小时前
Milvus 向量数据库的 DDL、DML、DQL 操作详解
python
罗狮粉 991 小时前
AI-Gateway — 面向 AI Agent 的本地 Runtime Gateway
人工智能·python·inscode·ai编程
FL16238631291 小时前
电力场景变电站设备识别关键部件识别分割数据集labelme格式1660张15类别
人工智能·机器学习
蓝胖的四次元口袋1 小时前
Python数据结构知识梳理
python