Skip to content

MichelRojo86WPP/copilot-config / skills/accelerated-computing-cudf

accelerated-computing-cudf

Verified

Official NVIDIA-authored guidance for NVIDIA cuDF GPU DataFrames, pandas acceleration, dask-cuDF, ETL, joins, groupby, CSV/Parquet I/O, nullable semantics, and multi-GPU DataFrame workloads.

FileKindSize
BENCHMARK.mdmarkdown4.2 KB
SKILL.mdskill md9.2 KB
evals/evals.jsonconfig15.8 KB
evals/files/cudf-apply-udf/code/generate_data.pyscript1.5 KB
evals/files/cudf-apply-udf/code/udf_pipeline.pyscript5.3 KB
evals/files/cudf-csv-etl/code/etl_pipeline.pyscript2.6 KB
evals/files/cudf-csv-etl/code/generate_data.pyscript1.2 KB
evals/files/cudf-groupby-agg/code/generate_data.pyscript1.4 KB
evals/files/cudf-groupby-agg/code/groupby_analysis.pyscript4.3 KB
evals/files/cudf-multi-join/code/generate_data.pyscript2.0 KB
evals/files/cudf-multi-join/code/multi_join.pyscript3.6 KB
evals/files/cudf-native-stream-handoff-boundary/NOTICE.mdmarkdown344 B
evals/files/cudf-native-stream-handoff-boundary/code/run_smoke.shscript464 B
evals/files/cudf-native-stream-handoff-boundary/code/threaded_handoff.cuother3.9 KB
evals/files/cudf-null-handling/code/generate_data.pyscript2.1 KB
evals/files/cudf-null-handling/code/null_pipeline.pyscript4.7 KB
evals/files/cudf-parquet-io/code/generate_data.pyscript2.0 KB
evals/files/cudf-parquet-io/code/parquet_pipeline.pyscript4.3 KB
evals/files/cudf-pivot-melt/code/generate_data.pyscript1.4 KB
evals/files/cudf-pivot-melt/code/reshape_analysis.pyscript4.6 KB
evals/files/cudf-string-ops/code/clean_contacts.pyscript3.4 KB
evals/files/cudf-string-ops/code/generate_data.pyscript2.7 KB
evals/files/cudf-timeseries-resample/code/generate_data.pyscript1.5 KB
evals/files/cudf-timeseries-resample/code/timeseries_analysis.pyscript4.1 KB
evals/files/cudf-window-functions/code/generate_data.pyscript1.4 KB
evals/files/cudf-window-functions/code/window_analysis.pyscript5.1 KB
evals/files/negative-deep-learning-training/code/train.pyscript1.4 KB
evals/files/source-cudf-null-fillna-semantics/NOTICE.mdmarkdown342 B
evals/files/source-cudf-null-fillna-semantics/code/null_cleanup.pyscript1.4 KB
references/api-patterns.mdmarkdown6.9 KB
references/cudf-pandas-accelerator.mdmarkdown3.6 KB
references/dask-cudf-patterns.mdmarkdown7.0 KB
skill-card.mdmarkdown4.0 KB
skill.oms.sigother12.2 KB

references/dask-cudf-patterns.md

View on GitHub
# dask-cuDF Patterns

## Preferred API: dask.dataframe Backend (release 24.06+)

The recommended way to use dask-cuDF is via the `dask.dataframe` backend config, **not** `import dask_cudf` directly. The backend API enables the query planning optimizer (predicate pushdown, projection pushdown) introduced in release 24.06+.

```python
import dask
dask.config.set({"dataframe.backend": "cudf"})

import dask.dataframe as dd

# Read — now GPU-backed with query planning
ddf = dd.read_parquet("data/*.parquet")
ddf = dd.read_csv("data/*.csv")

# All standard dask.dataframe operations work
result = ddf.groupby("key")["value"].sum()
```

**Explicit `dask_cudf` import is still valid** but bypasses query planning:
```python
import dask_cudf   # works, but no optimizer — use for legacy code only
ddf = dask_cudf.read_parquet("data/*.parquet")
```

## Cluster Setup

Always use `LocalCUDACluster`, even for a single GPU — it pins GPU affinity, enables the dashboard, and is required for proper spill configuration:

```python
from dask_cuda import LocalCUDACluster
from dask.distributed import Client
import dask
dask.config.set({"dataframe.backend": "cudf"})

# Standard setup — one worker per GPU
cluster = LocalCUDACluster(
    enable_cudf_spill=True,    # cuDF-native spill; preferred over device_memory_limit
    rmm_pool_size=0.8,         # leave headroom for non-RMM allocations
)
client = Client(cluster)

# With UCX automatic transport selection for communication-heavy workloads
cluster = LocalCUDACluster(
    enable_cudf_spill=True,
    rmm_pool_size=0.8,
    protocol="ucx",
)
```

## Partition Sizing

Partition size is the most impactful tuning parameter:

| Workload | Target Partition Size |
|---|---|
| General ETL | 1/32 – 1/8 of single GPU memory |
| Shuffle-intensive (groupby, join, sort) | 1/32 – 1/16 of GPU memory |

```python
# Check current partitions
print(f"Partitions: {ddf.npartitions}")

# Tune at read time (most efficient)
ddf = dd.read_parquet("data/", blocksize="256MB")  # adjust to hit target partition size

# Repartition after load if needed
ddf = ddf.repartition(npartitions=64)
```

## Reading Data

### Local Parquet (Recommended)

```python
import dask.dataframe as dd

# Project only needed columns — pushed down to storage
ddf = dd.read_parquet("data/*.parquet", columns=["col1", "col2", "key"])

# aggregate_files=True merges small files into larger partitions
ddf = dd.read_parquet("data/", aggregate_files=True, blocksize="512MB")
```

### Remote Storage (S3, GCS)

```python
# Use blocksize=None to avoid slow metadata collection on remote stores
ddf = dd.read_parquet(
    "s3://bucket/prefix/",
    blocksize=None,
    filesystem="arrow",    # pyarrow filesystem for S3/GCS
    columns=["col1", "col2"],
)
```

## Aggregation Patterns

### Low-cardinality groupby

```python
# split_out=1 avoids unnecessary shuffle for few output groups
result = ddf.groupby("status_code")["amount"].sum(split_out=1)
```

### High-cardinality groupby (default)

```python
result = ddf.groupby("customer_id").agg({"amount": "sum", "count": "count"})
```

## Join / Merge Patterns

```python
# Standard join (both datasets distributed)
merged = large_ddf.merge(other_large_ddf, on="id", how="left")

# Small table join: broadcast=True avoids shuffling the large table
merged = large_ddf.merge(
    small_lookup_df,    # cuDF DataFrame or small dask-cuDF
    on="id",
    how="left",
    broadcast=True,     # sends small_lookup to all workers; no shuffle
)
```

## Sort vs. Shuffle

```python
# sort_values is expensive — triggers full shuffle + materialization
# AVOID unless you actually need a globally ordered output:
sorted_ddf = ddf.sort_values("timestamp")   # use sparingly

# If you need rows grouped by key (not sorted), use shuffle instead:
from dask_cudf import shuffle
shuffled = shuffle(ddf, on="customer_id")   # redistributes by key, much cheaper
```

## Building Distributed Collections

```python
# Preferred: from_map enables column projection pushdown
from dask.dataframe import from_map
import cudf

def load_partition(path, columns=None):
    return cudf.read_parquet(path, columns=columns)

files = ["data/part_0000.parquet", "data/part_0001.parquet"]
ddf = from_map(
    load_partition,
    files,
    meta=cudf.read_parquet(files[0], nrows=0),   # avoids eager first-partition read
)

# from_delayed works but loses projection pushdown
from dask import delayed
parts = [delayed(cudf.read_parquet)(f) for f in files]
ddf = dask_cudf.from_delayed(parts)   # fallback if from_map doesn't apply
```

## Eager Execution Traps

These calls trigger immediate computation — avoid mid-pipeline:

| Call | Why it's expensive |
|---|---|
| `.compute()` on large collection | Pulls all data to one GPU |
| `.persist()` without `client.wait()` | Silent if client not set up |
| `len(ddf)` | Full scan |
| `ddf.head()` / `ddf.tail()` | Materializes first/last partition |
| `ddf.sort_values(...)` | Full shuffle |
| `ddf.set_index(col)` | Full shuffle + sort |

**Persist pattern** (when you query the same data multiple times):
```python
ddf = ddf.persist()
client.wait(ddf)           # block until all partitions are in GPU memory
result1 = ddf[ddf["a"] > 0].compute()
result2 = ddf[ddf["b"] > 0].compute()  # fast — data already in memory
```

**Never call `.compute()` on a collection larger than single-GPU memory** — it will OOM. Instead write to Parquet and read back in pieces.

## Writing Results

```python
# Parquet (recommended — partitioned output)
ddf.to_parquet("output/", write_index=False)

# To single cuDF DataFrame — only when result fits in GPU memory
result_cudf = ddf.compute()

# To pandas — only at the very end for CPU or non-GPU handoff
result_pd = ddf.to_pandas()
```

## OOM Diagnosis

```python
# Step 1: Check worker memory pressure from dashboard
print(client.dashboard_link)   # open in browser → Workers tab

# Step 2: Increase partition count to reduce per-partition memory
ddf = ddf.repartition(npartitions=ddf.npartitions * 2)

# Step 3: If not already enabled, add cuDF-native spilling
# (restart cluster with enable_cudf_spill=True, rmm_pool_size=0.9)

# Step 4: Move filter/project before expensive operations
ddf = ddf[["needed_col1", "needed_col2", "key"]]  # project first
ddf = ddf[ddf["amount"] > 0]                      # filter early
result = ddf.groupby("key")["needed_col1"].sum().compute()
```

## Anti-Patterns

For new dask-cuDF code, use the backend setup shown in the Preferred API
section above. The examples here focus on execution and materialization
mistakes after the backend has been selected.

```python
# AVOID: calling .compute() mid-pipeline
intermediate = ddf.groupby("a")["b"].sum().compute()   # breaks lazy graph
result = intermediate.groupby("c")["b"].mean()         # now CPU pandas!

# CORRECT: chain lazily, compute once
result = (
    ddf.groupby("a")["b"].sum()
       .reset_index()
       .groupby("c")["b"].mean()
       .compute()
)

# AVOID: collecting huge dataset to display
print(ddf.compute())   # OOM risk

# CORRECT: sample or head
print(ddf.head(10))    # shows first 10 rows only
```
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall