EvoScientist 0.0.1.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EvoScientist/EvoScientist.py +157 -0
- EvoScientist/__init__.py +24 -0
- EvoScientist/__main__.py +4 -0
- EvoScientist/backends.py +392 -0
- EvoScientist/cli.py +1553 -0
- EvoScientist/middleware.py +35 -0
- EvoScientist/prompts.py +277 -0
- EvoScientist/skills/accelerate/SKILL.md +332 -0
- EvoScientist/skills/accelerate/references/custom-plugins.md +453 -0
- EvoScientist/skills/accelerate/references/megatron-integration.md +489 -0
- EvoScientist/skills/accelerate/references/performance.md +525 -0
- EvoScientist/skills/bitsandbytes/SKILL.md +411 -0
- EvoScientist/skills/bitsandbytes/references/memory-optimization.md +521 -0
- EvoScientist/skills/bitsandbytes/references/qlora-training.md +521 -0
- EvoScientist/skills/bitsandbytes/references/quantization-formats.md +447 -0
- EvoScientist/skills/find-skills/SKILL.md +133 -0
- EvoScientist/skills/find-skills/scripts/install_skill.py +211 -0
- EvoScientist/skills/flash-attention/SKILL.md +367 -0
- EvoScientist/skills/flash-attention/references/benchmarks.md +215 -0
- EvoScientist/skills/flash-attention/references/transformers-integration.md +293 -0
- EvoScientist/skills/llama-cpp/SKILL.md +258 -0
- EvoScientist/skills/llama-cpp/references/optimization.md +89 -0
- EvoScientist/skills/llama-cpp/references/quantization.md +213 -0
- EvoScientist/skills/llama-cpp/references/server.md +125 -0
- EvoScientist/skills/lm-evaluation-harness/SKILL.md +490 -0
- EvoScientist/skills/lm-evaluation-harness/references/api-evaluation.md +490 -0
- EvoScientist/skills/lm-evaluation-harness/references/benchmark-guide.md +488 -0
- EvoScientist/skills/lm-evaluation-harness/references/custom-tasks.md +602 -0
- EvoScientist/skills/lm-evaluation-harness/references/distributed-eval.md +519 -0
- EvoScientist/skills/ml-paper-writing/SKILL.md +937 -0
- EvoScientist/skills/ml-paper-writing/references/checklists.md +361 -0
- EvoScientist/skills/ml-paper-writing/references/citation-workflow.md +562 -0
- EvoScientist/skills/ml-paper-writing/references/reviewer-guidelines.md +367 -0
- EvoScientist/skills/ml-paper-writing/references/sources.md +159 -0
- EvoScientist/skills/ml-paper-writing/references/writing-guide.md +476 -0
- EvoScientist/skills/ml-paper-writing/templates/README.md +251 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/README.md +534 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/aaai2026-unified-supp.tex +144 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/aaai2026-unified-template.tex +952 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/aaai2026.bib +111 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/aaai2026.bst +1493 -0
- EvoScientist/skills/ml-paper-writing/templates/aaai2026/aaai2026.sty +315 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/README.md +50 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/acl.sty +312 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/acl_latex.tex +377 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/acl_lualatex.tex +101 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/acl_natbib.bst +1940 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/anthology.bib.txt +26 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/custom.bib +70 -0
- EvoScientist/skills/ml-paper-writing/templates/acl/formatting.md +326 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/README.md +3 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/colm2025_conference.bib +11 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/colm2025_conference.bst +1440 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/colm2025_conference.pdf +0 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/colm2025_conference.sty +218 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/colm2025_conference.tex +305 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/fancyhdr.sty +485 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/math_commands.tex +508 -0
- EvoScientist/skills/ml-paper-writing/templates/colm2025/natbib.sty +1246 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/fancyhdr.sty +485 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/iclr2026_conference.bib +24 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/iclr2026_conference.bst +1440 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/iclr2026_conference.pdf +0 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/iclr2026_conference.sty +246 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/iclr2026_conference.tex +414 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/math_commands.tex +508 -0
- EvoScientist/skills/ml-paper-writing/templates/iclr2026/natbib.sty +1246 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/algorithm.sty +79 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/algorithmic.sty +201 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/example_paper.bib +75 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/example_paper.pdf +0 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/example_paper.tex +662 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/fancyhdr.sty +864 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/icml2026.bst +1443 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/icml2026.sty +767 -0
- EvoScientist/skills/ml-paper-writing/templates/icml2026/icml_numpapers.pdf +0 -0
- EvoScientist/skills/ml-paper-writing/templates/neurips2025/Makefile +36 -0
- EvoScientist/skills/ml-paper-writing/templates/neurips2025/extra_pkgs.tex +53 -0
- EvoScientist/skills/ml-paper-writing/templates/neurips2025/main.tex +38 -0
- EvoScientist/skills/ml-paper-writing/templates/neurips2025/neurips.sty +382 -0
- EvoScientist/skills/peft/SKILL.md +431 -0
- EvoScientist/skills/peft/references/advanced-usage.md +514 -0
- EvoScientist/skills/peft/references/troubleshooting.md +480 -0
- EvoScientist/skills/ray-data/SKILL.md +326 -0
- EvoScientist/skills/ray-data/references/integration.md +82 -0
- EvoScientist/skills/ray-data/references/transformations.md +83 -0
- EvoScientist/skills/skill-creator/LICENSE.txt +202 -0
- EvoScientist/skills/skill-creator/SKILL.md +356 -0
- EvoScientist/skills/skill-creator/references/output-patterns.md +82 -0
- EvoScientist/skills/skill-creator/references/workflows.md +28 -0
- EvoScientist/skills/skill-creator/scripts/init_skill.py +303 -0
- EvoScientist/skills/skill-creator/scripts/package_skill.py +110 -0
- EvoScientist/skills/skill-creator/scripts/quick_validate.py +95 -0
- EvoScientist/stream/__init__.py +53 -0
- EvoScientist/stream/emitter.py +94 -0
- EvoScientist/stream/formatter.py +168 -0
- EvoScientist/stream/tracker.py +115 -0
- EvoScientist/stream/utils.py +255 -0
- EvoScientist/subagent.yaml +147 -0
- EvoScientist/tools.py +135 -0
- EvoScientist/utils.py +207 -0
- evoscientist-0.0.1.dev2.dist-info/METADATA +227 -0
- evoscientist-0.0.1.dev2.dist-info/RECORD +107 -0
- evoscientist-0.0.1.dev2.dist-info/WHEEL +5 -0
- evoscientist-0.0.1.dev2.dist-info/entry_points.txt +5 -0
- evoscientist-0.0.1.dev2.dist-info/licenses/LICENSE +21 -0
- evoscientist-0.0.1.dev2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ray-data
|
|
3
|
+
description: Scalable data processing for ML workloads. Streaming execution across CPU/GPU, supports Parquet/CSV/JSON/images. Integrates with Ray Train, PyTorch, TensorFlow. Scales from single machine to 100s of nodes. Use for batch inference, data preprocessing, multi-modal data loading, or distributed ETL pipelines.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Orchestra Research
|
|
6
|
+
license: MIT
|
|
7
|
+
tags: [Data Processing, Ray Data, Distributed Computing, ML Pipelines, Batch Inference, ETL, Scalable, Ray, PyTorch, TensorFlow]
|
|
8
|
+
dependencies: ["ray[data]", pyarrow, pandas]
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Ray Data - Scalable ML Data Processing
|
|
12
|
+
|
|
13
|
+
Distributed data processing library for ML and AI workloads.
|
|
14
|
+
|
|
15
|
+
## When to use Ray Data
|
|
16
|
+
|
|
17
|
+
**Use Ray Data when:**
|
|
18
|
+
- Processing large datasets (>100GB) for ML training
|
|
19
|
+
- Need distributed data preprocessing across cluster
|
|
20
|
+
- Building batch inference pipelines
|
|
21
|
+
- Loading multi-modal data (images, audio, video)
|
|
22
|
+
- Scaling data processing from laptop to cluster
|
|
23
|
+
|
|
24
|
+
**Key features**:
|
|
25
|
+
- **Streaming execution**: Process data larger than memory
|
|
26
|
+
- **GPU support**: Accelerate transforms with GPUs
|
|
27
|
+
- **Framework integration**: PyTorch, TensorFlow, HuggingFace
|
|
28
|
+
- **Multi-modal**: Images, Parquet, CSV, JSON, audio, video
|
|
29
|
+
|
|
30
|
+
**Use alternatives instead**:
|
|
31
|
+
- **Pandas**: Small data (<1GB) on single machine
|
|
32
|
+
- **Dask**: Tabular data, SQL-like operations
|
|
33
|
+
- **Spark**: Enterprise ETL, SQL queries
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
### Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install -U 'ray[data]'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Load and transform data
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import ray
|
|
47
|
+
|
|
48
|
+
# Read Parquet files
|
|
49
|
+
ds = ray.data.read_parquet("s3://bucket/data/*.parquet")
|
|
50
|
+
|
|
51
|
+
# Transform data (lazy execution)
|
|
52
|
+
ds = ds.map_batches(lambda batch: {"processed": batch["text"].str.lower()})
|
|
53
|
+
|
|
54
|
+
# Consume data
|
|
55
|
+
for batch in ds.iter_batches(batch_size=100):
|
|
56
|
+
print(batch)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Integration with Ray Train
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import ray
|
|
63
|
+
from ray.train import ScalingConfig
|
|
64
|
+
from ray.train.torch import TorchTrainer
|
|
65
|
+
|
|
66
|
+
# Create dataset
|
|
67
|
+
train_ds = ray.data.read_parquet("s3://bucket/train/*.parquet")
|
|
68
|
+
|
|
69
|
+
def train_func(config):
|
|
70
|
+
# Access dataset in training
|
|
71
|
+
train_ds = ray.train.get_dataset_shard("train")
|
|
72
|
+
|
|
73
|
+
for epoch in range(10):
|
|
74
|
+
for batch in train_ds.iter_batches(batch_size=32):
|
|
75
|
+
# Train on batch
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
# Train with Ray
|
|
79
|
+
trainer = TorchTrainer(
|
|
80
|
+
train_func,
|
|
81
|
+
datasets={"train": train_ds},
|
|
82
|
+
scaling_config=ScalingConfig(num_workers=4, use_gpu=True)
|
|
83
|
+
)
|
|
84
|
+
trainer.fit()
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Reading data
|
|
88
|
+
|
|
89
|
+
### From cloud storage
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import ray
|
|
93
|
+
|
|
94
|
+
# Parquet (recommended for ML)
|
|
95
|
+
ds = ray.data.read_parquet("s3://bucket/data/*.parquet")
|
|
96
|
+
|
|
97
|
+
# CSV
|
|
98
|
+
ds = ray.data.read_csv("s3://bucket/data/*.csv")
|
|
99
|
+
|
|
100
|
+
# JSON
|
|
101
|
+
ds = ray.data.read_json("gs://bucket/data/*.json")
|
|
102
|
+
|
|
103
|
+
# Images
|
|
104
|
+
ds = ray.data.read_images("s3://bucket/images/")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### From Python objects
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
# From list
|
|
111
|
+
ds = ray.data.from_items([{"id": i, "value": i * 2} for i in range(1000)])
|
|
112
|
+
|
|
113
|
+
# From range
|
|
114
|
+
ds = ray.data.range(1000000) # Synthetic data
|
|
115
|
+
|
|
116
|
+
# From pandas
|
|
117
|
+
import pandas as pd
|
|
118
|
+
df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]})
|
|
119
|
+
ds = ray.data.from_pandas(df)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Transformations
|
|
123
|
+
|
|
124
|
+
### Map batches (vectorized)
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Batch transformation (fast)
|
|
128
|
+
def process_batch(batch):
|
|
129
|
+
batch["doubled"] = batch["value"] * 2
|
|
130
|
+
return batch
|
|
131
|
+
|
|
132
|
+
ds = ds.map_batches(process_batch, batch_size=1000)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Row transformations
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Row-by-row (slower)
|
|
139
|
+
def process_row(row):
|
|
140
|
+
row["squared"] = row["value"] ** 2
|
|
141
|
+
return row
|
|
142
|
+
|
|
143
|
+
ds = ds.map(process_row)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Filter
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
# Filter rows
|
|
150
|
+
ds = ds.filter(lambda row: row["value"] > 100)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Group by and aggregate
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
# Group by column
|
|
157
|
+
ds = ds.groupby("category").count()
|
|
158
|
+
|
|
159
|
+
# Custom aggregation
|
|
160
|
+
ds = ds.groupby("category").map_groups(lambda group: {"sum": group["value"].sum()})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## GPU-accelerated transforms
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
# Use GPU for preprocessing
|
|
167
|
+
def preprocess_images_gpu(batch):
|
|
168
|
+
import torch
|
|
169
|
+
images = torch.tensor(batch["image"]).cuda()
|
|
170
|
+
# GPU preprocessing
|
|
171
|
+
processed = images * 255
|
|
172
|
+
return {"processed": processed.cpu().numpy()}
|
|
173
|
+
|
|
174
|
+
ds = ds.map_batches(
|
|
175
|
+
preprocess_images_gpu,
|
|
176
|
+
batch_size=64,
|
|
177
|
+
num_gpus=1 # Request GPU
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Writing data
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
# Write to Parquet
|
|
185
|
+
ds.write_parquet("s3://bucket/output/")
|
|
186
|
+
|
|
187
|
+
# Write to CSV
|
|
188
|
+
ds.write_csv("output/")
|
|
189
|
+
|
|
190
|
+
# Write to JSON
|
|
191
|
+
ds.write_json("output/")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Performance optimization
|
|
195
|
+
|
|
196
|
+
### Repartition
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
# Control parallelism
|
|
200
|
+
ds = ds.repartition(100) # 100 blocks for 100-core cluster
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Batch size tuning
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Larger batches = faster vectorized ops
|
|
207
|
+
ds.map_batches(process_fn, batch_size=10000) # vs batch_size=100
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Streaming execution
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
# Process data larger than memory
|
|
214
|
+
ds = ray.data.read_parquet("s3://huge-dataset/")
|
|
215
|
+
for batch in ds.iter_batches(batch_size=1000):
|
|
216
|
+
process(batch) # Streamed, not loaded to memory
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Common patterns
|
|
220
|
+
|
|
221
|
+
### Batch inference
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
import ray
|
|
225
|
+
|
|
226
|
+
# Load model
|
|
227
|
+
def load_model():
|
|
228
|
+
# Load once per worker
|
|
229
|
+
return MyModel()
|
|
230
|
+
|
|
231
|
+
# Inference function
|
|
232
|
+
class BatchInference:
|
|
233
|
+
def __init__(self):
|
|
234
|
+
self.model = load_model()
|
|
235
|
+
|
|
236
|
+
def __call__(self, batch):
|
|
237
|
+
predictions = self.model(batch["input"])
|
|
238
|
+
return {"prediction": predictions}
|
|
239
|
+
|
|
240
|
+
# Run distributed inference
|
|
241
|
+
ds = ray.data.read_parquet("s3://data/")
|
|
242
|
+
predictions = ds.map_batches(BatchInference, batch_size=32, num_gpus=1)
|
|
243
|
+
predictions.write_parquet("s3://output/")
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Data preprocessing pipeline
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
# Multi-step pipeline
|
|
250
|
+
ds = (
|
|
251
|
+
ray.data.read_parquet("s3://raw/")
|
|
252
|
+
.map_batches(clean_data)
|
|
253
|
+
.map_batches(tokenize)
|
|
254
|
+
.map_batches(augment)
|
|
255
|
+
.write_parquet("s3://processed/")
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Integration with ML frameworks
|
|
260
|
+
|
|
261
|
+
### PyTorch
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
# Convert to PyTorch
|
|
265
|
+
torch_ds = ds.to_torch(label_column="label", batch_size=32)
|
|
266
|
+
|
|
267
|
+
for batch in torch_ds:
|
|
268
|
+
# batch is dict with tensors
|
|
269
|
+
inputs, labels = batch["features"], batch["label"]
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### TensorFlow
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
# Convert to TensorFlow
|
|
276
|
+
tf_ds = ds.to_tf(feature_columns=["image"], label_column="label", batch_size=32)
|
|
277
|
+
|
|
278
|
+
for features, labels in tf_ds:
|
|
279
|
+
# Train model
|
|
280
|
+
pass
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Supported data formats
|
|
284
|
+
|
|
285
|
+
| Format | Read | Write | Use Case |
|
|
286
|
+
|--------|------|-------|----------|
|
|
287
|
+
| Parquet | ✅ | ✅ | ML data (recommended) |
|
|
288
|
+
| CSV | ✅ | ✅ | Tabular data |
|
|
289
|
+
| JSON | ✅ | ✅ | Semi-structured |
|
|
290
|
+
| Images | ✅ | ❌ | Computer vision |
|
|
291
|
+
| NumPy | ✅ | ✅ | Arrays |
|
|
292
|
+
| Pandas | ✅ | ❌ | DataFrames |
|
|
293
|
+
|
|
294
|
+
## Performance benchmarks
|
|
295
|
+
|
|
296
|
+
**Scaling** (processing 100GB data):
|
|
297
|
+
- 1 node (16 cores): ~30 minutes
|
|
298
|
+
- 4 nodes (64 cores): ~8 minutes
|
|
299
|
+
- 16 nodes (256 cores): ~2 minutes
|
|
300
|
+
|
|
301
|
+
**GPU acceleration** (image preprocessing):
|
|
302
|
+
- CPU only: 1,000 images/sec
|
|
303
|
+
- 1 GPU: 5,000 images/sec
|
|
304
|
+
- 4 GPUs: 18,000 images/sec
|
|
305
|
+
|
|
306
|
+
## Use cases
|
|
307
|
+
|
|
308
|
+
**Production deployments**:
|
|
309
|
+
- **Pinterest**: Last-mile data processing for model training
|
|
310
|
+
- **ByteDance**: Scaling offline inference with multi-modal LLMs
|
|
311
|
+
- **Spotify**: ML platform for batch inference
|
|
312
|
+
|
|
313
|
+
## References
|
|
314
|
+
|
|
315
|
+
- **[Transformations Guide](references/transformations.md)** - Map, filter, groupby operations
|
|
316
|
+
- **[Integration Guide](references/integration.md)** - Ray Train, PyTorch, TensorFlow
|
|
317
|
+
|
|
318
|
+
## Resources
|
|
319
|
+
|
|
320
|
+
- **Docs**: https://docs.ray.io/en/latest/data/data.html
|
|
321
|
+
- **GitHub**: https://github.com/ray-project/ray ⭐ 36,000+
|
|
322
|
+
- **Version**: Ray 2.40.0+
|
|
323
|
+
- **Examples**: https://docs.ray.io/en/latest/data/examples/overview.html
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Ray Data Integration Guide
|
|
2
|
+
|
|
3
|
+
Integration with Ray Train and ML frameworks.
|
|
4
|
+
|
|
5
|
+
## Ray Train integration
|
|
6
|
+
|
|
7
|
+
### Basic training with datasets
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import ray
|
|
11
|
+
from ray.train import ScalingConfig
|
|
12
|
+
from ray.train.torch import TorchTrainer
|
|
13
|
+
|
|
14
|
+
# Create datasets
|
|
15
|
+
train_ds = ray.data.read_parquet("s3://data/train/")
|
|
16
|
+
val_ds = ray.data.read_parquet("s3://data/val/")
|
|
17
|
+
|
|
18
|
+
def train_func(config):
|
|
19
|
+
# Get dataset shards
|
|
20
|
+
train_ds = ray.train.get_dataset_shard("train")
|
|
21
|
+
val_ds = ray.train.get_dataset_shard("val")
|
|
22
|
+
|
|
23
|
+
for epoch in range(config["epochs"]):
|
|
24
|
+
# Iterate over batches
|
|
25
|
+
for batch in train_ds.iter_batches(batch_size=32):
|
|
26
|
+
# Train on batch
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
# Launch training
|
|
30
|
+
trainer = TorchTrainer(
|
|
31
|
+
train_func,
|
|
32
|
+
train_loop_config={"epochs": 10},
|
|
33
|
+
datasets={"train": train_ds, "val": val_ds},
|
|
34
|
+
scaling_config=ScalingConfig(num_workers=4, use_gpu=True)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
result = trainer.fit()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## PyTorch integration
|
|
41
|
+
|
|
42
|
+
### Convert to PyTorch Dataset
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
# Option 1: to_torch (recommended)
|
|
46
|
+
torch_ds = ds.to_torch(
|
|
47
|
+
label_column="label",
|
|
48
|
+
batch_size=32,
|
|
49
|
+
drop_last=True
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
for batch in torch_ds:
|
|
53
|
+
inputs = batch["features"]
|
|
54
|
+
labels = batch["label"]
|
|
55
|
+
# Train model
|
|
56
|
+
|
|
57
|
+
# Option 2: iter_torch_batches
|
|
58
|
+
for batch in ds.iter_torch_batches(batch_size=32):
|
|
59
|
+
# batch is dict of tensors
|
|
60
|
+
pass
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## TensorFlow integration
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
tf_ds = ds.to_tf(
|
|
67
|
+
feature_columns=["image", "text"],
|
|
68
|
+
label_column="label",
|
|
69
|
+
batch_size=32
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
for features, labels in tf_ds:
|
|
73
|
+
# Train TensorFlow model
|
|
74
|
+
pass
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Best practices
|
|
78
|
+
|
|
79
|
+
1. **Shard datasets in Ray Train** - Automatic with `get_dataset_shard()`
|
|
80
|
+
2. **Use streaming** - Don't load entire dataset to memory
|
|
81
|
+
3. **Preprocess in Ray Data** - Distribute preprocessing across cluster
|
|
82
|
+
4. **Cache preprocessed data** - Write to Parquet, read in training
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Ray Data Transformations
|
|
2
|
+
|
|
3
|
+
Complete guide to data transformations in Ray Data.
|
|
4
|
+
|
|
5
|
+
## Core operations
|
|
6
|
+
|
|
7
|
+
### Map batches (vectorized)
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
# Recommended for performance
|
|
11
|
+
def process_batch(batch):
|
|
12
|
+
# batch is dict of numpy arrays or pandas Series
|
|
13
|
+
batch["doubled"] = batch["value"] * 2
|
|
14
|
+
return batch
|
|
15
|
+
|
|
16
|
+
ds = ds.map_batches(process_batch, batch_size=1000)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Performance**: 10-100× faster than row-by-row
|
|
20
|
+
|
|
21
|
+
### Map (row-by-row)
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
# Use only when vectorization not possible
|
|
25
|
+
def process_row(row):
|
|
26
|
+
row["squared"] = row["value"] ** 2
|
|
27
|
+
return row
|
|
28
|
+
|
|
29
|
+
ds = ds.map(process_row)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Filter
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# Remove rows
|
|
36
|
+
ds = ds.filter(lambda row: row["score"] > 0.5)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Flat map
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
# One row → multiple rows
|
|
43
|
+
def expand_row(row):
|
|
44
|
+
return [{"value": row["value"] + i} for i in range(3)]
|
|
45
|
+
|
|
46
|
+
ds = ds.flat_map(expand_row)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## GPU-accelerated transforms
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
def gpu_transform(batch):
|
|
53
|
+
import torch
|
|
54
|
+
data = torch.tensor(batch["data"]).cuda()
|
|
55
|
+
# GPU processing
|
|
56
|
+
result = data * 2
|
|
57
|
+
return {"processed": result.cpu().numpy()}
|
|
58
|
+
|
|
59
|
+
ds = ds.map_batches(gpu_transform, num_gpus=1, batch_size=64)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Groupby operations
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
# Group by column
|
|
66
|
+
grouped = ds.groupby("category")
|
|
67
|
+
|
|
68
|
+
# Aggregate
|
|
69
|
+
result = grouped.count()
|
|
70
|
+
|
|
71
|
+
# Custom aggregation
|
|
72
|
+
result = grouped.map_groups(lambda group: {
|
|
73
|
+
"sum": group["value"].sum(),
|
|
74
|
+
"mean": group["value"].mean()
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Best practices
|
|
79
|
+
|
|
80
|
+
1. **Use map_batches over map** - 10-100× faster
|
|
81
|
+
2. **Tune batch_size** - Larger = faster (balance with memory)
|
|
82
|
+
3. **Use GPUs for heavy compute** - Image/audio preprocessing
|
|
83
|
+
4. **Stream large datasets** - Use iter_batches for >memory data
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|