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传自己的参数。

相关推荐
2401_8769075210 分钟前
Python机器学习实践指南
开发语言·python·机器学习
张张123y38 分钟前
RAG从0到1学习:技术架构、项目实践与面试指南
人工智能·python·学习·面试·架构·langchain·transformer
Shi_haoliu1 小时前
openClaw源码部署-linux
前端·python·ai·openclaw
gf13211111 小时前
python_查询并删除飞书多维表格中的记录
java·python·飞书
带娃的IT创业者1 小时前
WeClaw 离线消息队列实战:异步任务队列如何保证在服务器宕机时不丢失任何一条 AI 回复?
运维·服务器·人工智能·python·websocket·fastapi·实时通信
坐吃山猪3 小时前
Python进度条
linux·服务器·python
l1t4 小时前
四种python工具包用SQL查询csv和parquet文件的方法比较
大数据·python·sql
清水白石0084 小时前
Python 并发三剑客:多线程、多进程与协程的实战抉择
java·服务器·python