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

相关推荐
qq_4138474011 分钟前
Redis怎样设计企业级备份策略_结合全量RDB与增量AOF实现多级数据保护
jvm·数据库·python
zhengyquan15 分钟前
特斯拉无方向盘Cybercab落地,自动驾驶商业化再提速!
人工智能·机器学习·自动驾驶
qq_3729069318 分钟前
如何通过点击事件动态展开和收起 HTML 元素
jvm·数据库·python
qq_3721542331 分钟前
Golang Gin怎么做JWT登录认证_Golang Gin JWT教程【实用】
jvm·数据库·python
2401_8716965232 分钟前
C#怎么实现文件上传下载 C#如何用WebAPI实现大文件断点续传功能【网络】
jvm·数据库·python
m0_3776182334 分钟前
如何在 pytest 中通过组合多个 fixture 实现参数化测试
jvm·数据库·python
Full Stack Developme36 分钟前
Hutool StrUtil 教程
开发语言·网络·python
小糖学代码37 分钟前
LLM系列:2.pytorch入门:2.PyTorch张量运算
pytorch·python·aigc·numpy
lkforce37 分钟前
MiniMind学习笔记(零)--基础概念
人工智能·算法·机器学习·token·分词器·minimind·词汇表
给自己做减法38 分钟前
RAG调参实践一
python·ai编程·rag