or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-distributed.mddata-processing.mddistributed-training.mdhyperparameter-tuning.mdindex.mdmodel-serving.mdreinforcement-learning.mdutilities-advanced.md

index.mddocs/

0

# Ray

1

2

Ray is a unified framework for scaling AI and Python applications. Ray consists of a core distributed runtime and a set of AI libraries for simplifying ML compute. It enables parallel and distributed execution of Python code with minimal changes, providing libraries for data processing, training, hyperparameter tuning, reinforcement learning, and model serving.

3

4

## Package Information

5

6

- **Package Name**: ray

7

- **Language**: Python

8

- **Installation**: `pip install ray`

9

- **Documentation**: https://docs.ray.io/

10

11

## Core Imports

12

13

```python

14

import ray

15

```

16

17

For specific libraries:

18

19

```python

20

import ray.data

21

import ray.train

22

import ray.tune

23

import ray.serve

24

```

25

26

## Basic Usage

27

28

```python

29

import ray

30

31

# Initialize Ray

32

ray.init()

33

34

# Define a remote function

35

@ray.remote

36

def compute_something(x):

37

return x * x

38

39

# Execute remotely and get object reference

40

future = compute_something.remote(4)

41

42

# Get the result

43

result = ray.get(future)

44

print(result) # 16

45

46

# Define a remote class (Actor)

47

@ray.remote

48

class Counter:

49

def __init__(self):

50

self.count = 0

51

52

def increment(self):

53

self.count += 1

54

return self.count

55

56

# Create and use an actor

57

counter = Counter.remote()

58

result = ray.get(counter.increment.remote())

59

print(result) # 1

60

61

# Shutdown Ray

62

ray.shutdown()

63

```

64

65

## Architecture

66

67

Ray's architecture consists of:

68

69

- **Core Runtime**: Distributed task execution engine with actors, tasks, and object store

70

- **Ray Data**: Distributed data processing for ML workloads

71

- **Ray Train**: Distributed training with multi-framework support (PyTorch, TensorFlow, XGBoost)

72

- **Ray Tune**: Hyperparameter tuning and experiment management

73

- **Ray Serve**: Scalable model serving and application deployment

74

- **Ray RLlib**: Reinforcement learning library

75

- **Ray AIR**: Unified ML workflows combining data, train, tune, and serve

76

77

## Capabilities

78

79

### Core Distributed Computing

80

81

Core Ray functionality for distributed task execution, actor management, and object storage. Includes initialization, remote execution, data management, and cluster utilities.

82

83

```python { .api }

84

def init(address=None, **kwargs): ...

85

def get(object_refs, timeout=None): ...

86

def put(value, **kwargs): ...

87

def remote(num_cpus=None, num_gpus=None, **kwargs): ...

88

def wait(object_refs, num_returns=1, timeout=None): ...

89

def shutdown(): ...

90

def show_in_dashboard(message: str, key: str = "", dtype: str = "text"): ...

91

def cpp_function(function_name: str): ...

92

def java_function(class_name: str, function_name: str): ...

93

def java_actor_class(class_name: str): ...

94

```

95

96

[Core Distributed Computing](./core-distributed.md)

97

98

### Data Processing

99

100

Distributed data processing capabilities for ML workloads. Provides datasets, transformations, and integrations with ML frameworks and storage systems.

101

102

```python { .api }

103

class Dataset:

104

def map(self, fn, **kwargs): ...

105

def filter(self, fn, **kwargs): ...

106

def groupby(self, key): ...

107

def to_torch(self, **kwargs): ...

108

109

def read_parquet(paths, **kwargs): ...

110

def read_csv(paths, **kwargs): ...

111

def read_json(paths, **kwargs): ...

112

def read_bigquery(query, **kwargs): ...

113

def read_delta(table_uri, **kwargs): ...

114

def read_mongo(uri, database, collection, **kwargs): ...

115

def read_tfrecords(paths, **kwargs): ...

116

```

117

118

[Data Processing](./data-processing.md)

119

120

### Distributed Training

121

122

Distributed training for machine learning with support for PyTorch, TensorFlow, XGBoost, and other frameworks. Includes fault-tolerant training and automatic scaling.

123

124

```python { .api }

125

class Trainer:

126

def fit(self, dataset=None): ...

127

def predict(self, dataset): ...

128

129

class TorchTrainer(Trainer): ...

130

class TensorflowTrainer(Trainer): ...

131

class XGBoostTrainer(Trainer): ...

132

```

133

134

[Distributed Training](./distributed-training.md)

135

136

### Hyperparameter Tuning

137

138

Comprehensive hyperparameter optimization with multiple search algorithms, schedulers, and experiment management. Supports all major ML frameworks.

139

140

```python { .api }

141

class Tuner:

142

def fit(self): ...

143

def get_results(self): ...

144

145

def tune_config(metric, mode, **kwargs): ...

146

class GridSearch: ...

147

class RandomSearch: ...

148

class HyperOptSearch: ...

149

```

150

151

[Hyperparameter Tuning](./hyperparameter-tuning.md)

152

153

### Model Serving

154

155

Scalable model serving and application deployment with automatic scaling, batching, and multi-model support.

156

157

```python { .api }

158

@serve.deployment

159

class ModelDeployment: ...

160

161

def start(detached=False, http_options=None): ...

162

def run(target, **kwargs): ...

163

def shutdown(): ...

164

```

165

166

[Model Serving](./model-serving.md)

167

168

### Reinforcement Learning

169

170

Reinforcement learning algorithms and environments with support for distributed training and various RL frameworks.

171

172

```python { .api }

173

class Policy:

174

def compute_actions(self, obs_batch): ...

175

def learn_on_batch(self, samples): ...

176

177

class Algorithm:

178

def train(self): ...

179

def evaluate(self): ...

180

```

181

182

[Reinforcement Learning](./reinforcement-learning.md)

183

184

### Utilities and Advanced Features

185

186

Utility functions, placement groups, debugging tools, actor pools, and advanced distributed computing features.

187

188

```python { .api }

189

class PlacementGroup:

190

def ready(self): ...

191

192

def placement_group(bundles, strategy="PACK"): ...

193

def get_placement_group(name): ...

194

class ActorPool: ...

195

def init_collective_group(world_size, rank, backend="nccl"): ...

196

def allreduce(tensor, group_name="default", op="SUM"): ...

197

def broadcast(tensor, src_rank, group_name="default"): ...

198

```

199

200

[Utilities and Advanced Features](./utilities-advanced.md)

201

202

## Types

203

204

```python { .api }

205

# Core ID Types

206

class ObjectRef: ...

207

class ObjectRefGenerator: ...

208

class DynamicObjectRefGenerator: ...

209

class ActorID: ...

210

class TaskID: ...

211

class JobID: ...

212

class NodeID: ...

213

class PlacementGroupID: ...

214

class ClusterID: ...

215

216

# Runtime Types

217

class LoggingConfig:

218

def __init__(self, encoding="TEXT", log_level="INFO"): ...

219

220

# Language Support

221

class Language:

222

PYTHON = "PYTHON"

223

JAVA = "JAVA"

224

CPP = "CPP"

225

```