Loading...
Loading...
Compare original and translation side by side
cudf.pandascudf.pandascudf.pandas.to_pandas().values.numpy()enable_cudf_spill=Truereferences/dask-cudf-patterns.mdcudf.pandas.to_pandas().values.numpy()enable_cudf_spill=Truereferences/dask-cudf-patterns.md%load_ext cudf.pandas
import pandas as pd # now GPU-backed; falls back silently for unsupported opspython -m cudf.pandas my_script.pyimport cudf.pandas
cudf.pandas.install() # must come BEFORE pandas import, before Pool creation
from multiprocessing import Poolreferences/cudf-pandas-accelerator.md%load_ext cudf.pandas
import pandas as pd # 现在由GPU支持;遇到不支持的操作会自动回退到CPUpython -m cudf.pandas my_script.pyimport cudf.pandas
cudf.pandas.install() # 必须在导入pandas和创建Pool之前执行
from multiprocessing import Poolreferences/cudf-pandas-accelerator.mdimport cudfimport cudfreferences/api-patterns.md
**Keep data on GPU end-to-end.** Only call `.to_pandas()` at the very end for display or CPU or non-GPU handoff.
Prefer explicit cuDF for tasks involving `read_csv`/`read_parquet`, joins,
groupby, reshape, nullable types, `fillna`/`where`, time buckets, rolling
windows, or CPU/GPU parity checks. Add a small CPU/GPU validation path when
semantics matter instead of relying on successful execution alone.
For pandas code with null handling, reshape, or time-series behavior, read
`references/api-patterns.md` for the relevant semantic checklist before
rewriting. A `cudf.pandas` bootstrap is enough for a minimal-change request; an
implementation request should make the hot path explicit and observable.
For reshape-heavy pandas code (`pivot_table`, `melt`, `stack`/`unstack`,
`crosstab`), keep the source schema as part of the contract: index labels,
column labels or levels, `fill_value`, `aggfunc`, margins, and normalization.
Use explicit cuDF where the equivalent is supported; use `cudf.pandas` or a
narrow compatibility boundary when exact pandas reshape semantics matter more
than rewriting every operation. Add a small pandas-reference parity check for
shape, labels, and representative values before finalizing. See
`references/api-patterns.md`.
**全程保持数据在GPU上**。仅在最后展示数据、传输到CPU或交给非GPU系统时调用`.to_pandas()`。
对于涉及`read_csv`/`read_parquet`、连接操作、分组操作、数据重塑、可空类型、`fillna`/`where`、时间桶、滚动窗口或CPU/GPU语义一致性检查的任务,优先使用显式cuDF API。当语义重要时,添加一个小型CPU/GPU验证路径,而不是仅依赖执行成功。
对于包含空值处理、数据重塑或时间序列行为的pandas代码,在重写前请阅读`references/api-patterns.md`中的相关语义检查清单。对于最小改动需求,使用`cudf.pandas`即可;对于实现需求,应使热点路径显式化且可观测。
对于以数据重塑为主的pandas代码(`pivot_table`、`melt`、`stack`/`unstack`、`crosstab`),将源schema作为契约的一部分:索引标签、列标签或层级、`fill_value`、`aggfunc`、margins和归一化方式。在支持等效操作的场景下使用显式cuDF API;当精确的pandas重塑语义比重写每个操作更重要时,使用`cudf.pandas`或设置狭窄的兼容性边界。在最终确定前,添加一个小型pandas参考的一致性检查,比较数据形状、标签和代表性数值。详情请参考`references/api-patterns.md`。references/dask-cudf-patterns.mdfrom dask_cuda import LocalCUDACluster
from dask.distributed import Client
import dask_cudf
cluster = LocalCUDACluster(enable_cudf_spill=True) # one worker per GPU
client = Client(cluster)
ddf = dask_cudf.read_parquet("s3://bucket/data/*.parquet")
result = ddf.groupby("key").agg({"value": "sum"}).compute()references/dask-cudf-patterns.mdfrom dask_cuda import LocalCUDACluster
from dask.distributed import Client
import dask_cudf
cluster = LocalCUDACluster(enable_cudf_spill=True) # 每个GPU对应一个工作进程
client = Client(cluster)
ddf = dask_cudf.read_parquet("s3://bucket/data/*.parquet")
result = ddf.groupby("key").agg({"value": "sum"}).compute()import cudf
cudf.set_option("spill", True) # spill to host RAM when GPU is fullimport rmm
rmm.set_current_device_resource(rmm.mr.CudaAsyncMemoryResource())import cudf
cudf.set_option("spill", True) # 当GPU内存不足时,将数据溢出到主机内存import rmm
rmm.set_current_device_resource(rmm.mr.CudaAsyncMemoryResource())
| GPU Free vs Dataset | Strategy |
|---|---|
| Free > 2× dataset | Single GPU cuDF |
| Free 1–2× dataset | cuDF + `cudf.set_option("spill", True)` |
| Dataset > GPU mem | dask-cuDF |
| Dataset > node mem | dask-cuDF + multi-node (see accelerated-computing-mpf) |
| GPU可用内存 vs 数据集大小 | 策略 |
|---|---|
| 可用内存 > 2×数据集大小 | 单GPU cuDF |
| 可用内存 1–2×数据集大小 | cuDF + `cudf.set_option("spill", True)` |
| 数据集大小 > GPU内存 | dask-cuDF |
| 数据集大小 > 节点内存 | dask-cuDF + 多节点(参考accelerated-computing-mpf) |%%cudf.pandas.profilereferences/api-patterns.mdcudf.set_option("spill", True)accelerated-computing-rmmreferences/api-patterns.md.to_pandas().from_pandas()<NA>NaNreferences/api-patterns.mdstable=Truefloat64float32%%cudf.pandas.profilereferences/api-patterns.mdcudf.set_option("spill", True)accelerated-computing-rmmreferences/api-patterns.md.to_pandas().from_pandas()<NA>NaNreferences/api-patterns.mdstable=Truefloat64float32fillnawheremaskreferences/api-patterns.mdwheremaskfillnato_pandas(nullable=True)fillnawheremaskreferences/api-patterns.mdwheremaskfillnato_pandas(nullable=True)references/cudf-pandas-accelerator.mdreferences/api-patterns.mdreferences/dask-cudf-patterns.mdreferences/cudf-pandas-accelerator.mdreferences/api-patterns.mdreferences/dask-cudf-patterns.md