global_chunk_id
int64
0
478
text
stringlengths
288
999
200
@ray.remote def echo(a: int, b: int, c: int): """This function prints its input values to stdout.""" print(a, b, c) # Passing the literal values (1, 2, 3) to `echo`. echo.remote(1, 2, 3) # -> prints "1 2 3" # Put the values (1, 2, 3) into Ray's object store. a, b, c = ray.put(1), ray.put(2), ray.put(3) # Pa...
201
Passing an object as a nested argument: When an object is passed within a nested object, for example, within a Python list, Ray will not de-reference it. This means that the task will need to call ray.get() on the reference to fetch the concrete value. However, if the task never calls ray.get(), then the object value n...
202
# Put the values (1, 2, 3) into Ray's object store. a, b, c = ray.put(1), ray.put(2), ray.put(3) # Passing an object as a nested argument to `echo_and_get`. Ray does not # de-reference nested args, so `echo_and_get` sees the references. echo_and_get.remote([a, b, c]) # -> prints args: [ObjectRef(...), ObjectRef(...), ...
203
# Examples of passing objects to actor method calls. actor_handle.method.remote(obj) # by-value actor_handle.method.remote([obj]) # by-reference Closure Capture of Objects# You can also pass objects to tasks via closure-capture. This can be convenient when you have a large object that you want to share verbatim b...
204
@ray.remote def print_via_capture(): """This function prints the values of (a, b, c) to stdout.""" print(ray.get([a, b, c])) # Passing object references via closure-capture. Inside the `print_via_capture` # function, the global object refs (a, b, c) can be retrieved and printed. print_via_capture.remote() # -...
205
Serialization# Since Ray processes do not share memory space, data transferred between workers and nodes will need to serialized and deserialized. Ray uses the Plasma object store to efficiently transfer objects across different processes and different nodes. Numpy arrays in the object store are shared between workers ...
206
Plasma Object Store# Plasma is an in-memory object store. It has been originally developed as part of Apache Arrow. Prior to Ray’s version 1.0.0 release, Ray forked Arrow’s Plasma code into Ray’s code base in order to disentangle and continue development with respect to Ray’s architecture and performance needs. Plasma ...
207
Serializing ObjectRefs# Explicitly serializing ObjectRefs using ray.cloudpickle should be used as a last resort. Passing ObjectRefs through Ray task arguments and return values is the recommended approach. Ray ObjectRefs can be serialized using ray.cloudpickle. The ObjectRef can then be deserialized and accessed with r...
208
Warning ray._private.internal_api.free(obj_ref) is a private API and may be changed in future Ray versions. This code example demonstrates how to serialize an ObjectRef, store it in external storage, deserialize and use it, and lastly free its object. import ray from ray import cloudpickle FILE = "external_store.pick...
209
# The deserialized ObjectRef works as expected. assert ray.get(new_obj_ref) == my_dict # Explicitly free the object. ray._private.internal_api.free(new_obj_ref) Numpy Arrays# Ray optimizes for numpy arrays by using Pickle protocol 5 with out-of-band data. The numpy array is stored as a read-only object, and all Ra...
210
Fixing “assignment destination is read-only”# Because Ray puts numpy arrays in the object store, when deserialized as arguments in remote functions they will become read-only. For example, the following code snippet will crash: import ray import numpy as np @ray.remote def f(arr): # arr = arr.copy() # Adding a c...
211
Serialization notes# Ray is currently using Pickle protocol version 5. The default pickle protocol used by most python distributions is protocol 3. Protocol 4 & 5 are more efficient than protocol 3 for larger objects. For non-native objects, Ray will always keep a single copy even it is referred multiple times in an o...
212
Customized Serialization# Sometimes you may want to customize your serialization process because the default serializer used by Ray (pickle5 + cloudpickle) does not work for you (fail to serialize some objects, too slow for certain objects, etc.). There are at least 3 ways to define your custom serialization process: ...
213
original = DBConnection("/tmp/db") print(original.conn) copied = ray.get(ray.put(original)) print(copied.conn) <sqlite3.Connection object at ...> <sqlite3.Connection object at ...> If you want to customize the serialization of a type of objects, but you cannot access or modify the corresponding class, you can...
214
# Register serializer and deserializer for class A: ray.util.register_serializer( A, serializer=custom_serializer, deserializer=custom_deserializer) ray.get(ray.put(A(1))) # success! # You can deregister the serializer at any time. ray.util.deregister_serializer(A) try: ray.get(ray.put(A(1))) # fail! except Type...
215
We also provide you an example, if you want to customize the serialization of a specific object: import threading class A: def __init__(self, x): self.x = x self.lock = threading.Lock() # could not serialize! try: ray.get(ray.put(A(1))) # fail! except TypeError: pass class SerializationHe...
216
Troubleshooting# Use ray.util.inspect_serializability to identify tricky pickling issues. This function can be used to trace a potential non-serializable object within any Python object – whether it be a function, class, or object instance. Below, we demonstrate this behavior on a function with a non-serializable objec...
217
lock = threading.Lock() def test(): print(lock) inspect_serializability(test, name="test") The resulting output is: ============================================================= Checking Serializability of <function test at 0x7ff130697e50> ============================================================= !!...
218
FailTuple(lock [obj=<unlocked _thread.lock object at 0x7ff1306a9f30>, parent=<function test at 0x7ff130697e50>]) was found to be non-serializable. There may be multiple other undetected variables that were non-serializable. Consider either removing the instantiation/imports of these variables or moving the instant...
219
For even more detailed information, set environmental variable RAY_PICKLE_VERBOSE_DEBUG='2' before importing Ray. This enables serialization with python-based backend instead of C-Pickle, so you can debug into python code at the middle of serialization. However, this would make serialization much slower. Known Issues...
220
Object Spilling# Ray spills objects to a directory in the local filesystem once the object store is full. By default, Ray spills objects to the temporary directory (for example, /tmp/ray/session_2025-03-28_00-05-20_204810_2814690). Spilling to a custom directory# You can specify a custom directory for spilling objects...
221
CLI ray start --object-spilling-directory=/path/to/spill/dir For advanced usage and customizations, reach out to the Ray team. Stats# When spilling is happening, the following INFO level messages are printed to the Raylet logs-for example, /tmp/ray/session_latest/logs/raylet.out: local_object_manager.cc:166: Spil...
222
Scheduling# For each task or actor, Ray will choose a node to run it and the scheduling decision is based on the following factors. Resources# Each task or actor has the specified resource requirements. Given that, a node can be in one of the following states: Feasible: the node has the required resources to run the ...
223
Infeasible: the node doesn’t have the required resources. For example a CPU-only node is infeasible for a GPU task. Resource requirements are hard requirements meaning that only feasible nodes are eligible to run the task or actor. If there are feasible nodes, Ray will either choose an available node or wait until a u...
224
“DEFAULT”# "DEFAULT" is the default strategy used by Ray. Ray schedules tasks or actors onto a group of the top k nodes. Specifically, the nodes are sorted to first favor those that already have tasks or actors scheduled (for locality), then to favor those that have low resource utilization (for load balancing). Within...
225
otherwise it is the resource utilization itself (score 1 means the node is fully utilized). Ray selects the best node for scheduling by randomly picking from the top k nodes with the lowest scores. The value of k is the max of (number of nodes in the cluster * RAY_scheduler_top_k_fraction environment variable) and RAY_...
226
@ray.remote(num_cpus=1) class Actor: pass # If unspecified, "DEFAULT" scheduling strategy is used. func.remote() actor = Actor.remote() # Explicitly set scheduling strategy to "DEFAULT". func.options(scheduling_strategy="DEFAULT").remote() actor = Actor.options(scheduling_strategy="DEFAULT").remote() # Zero-CPU ...
227
NodeAffinitySchedulingStrategy# NodeAffinitySchedulingStrategy is a low-level strategy that allows a task or actor to be scheduled onto a particular node specified by its node id. The soft flag specifies whether the task or actor is allowed to run somewhere else if the specified node doesn’t exist (e.g. if the node die...
228
It’s a low-level strategy which prevents optimizations by a smart scheduler. It cannot fully utilize an autoscaling cluster since node ids must be known when the tasks or actors are created. It can be difficult to make the best static placement decision especially in a multi-tenant cluster: for example, an application ...
229
Locality-Aware Scheduling# By default, Ray prefers available nodes that have large task arguments local to avoid transferring data over the network. If there are multiple large task arguments, the node with most object bytes local is preferred. This takes precedence over the "DEFAULT" scheduling strategy, which means R...
230
@ray.remote def small_object_func(): # Small object is returned inline directly to the caller, # instead of storing in the distributed memory. return [1] @ray.remote def consume_func(data): return len(data) large_object = large_object_func.remote() small_object = small_object_func.remote() # Ray wi...
231
Environment Dependencies# Your Ray application may have dependencies that exist outside of your Ray script. For example: Your Ray script may import/depend on some Python packages. Your Ray script may be looking for some specific environment variables to be available. Your Ray script may import some files outside of th...
232
One frequent problem when running on a cluster is that Ray expects these “dependencies” to exist on each Ray node. If these are not present, you may run into issues such as ModuleNotFoundError, FileNotFoundError and so on. To address this problem, you can (1) prepare your dependencies on the cluster in advance (e.g. us...
233
Concepts# Ray Application. A program including a Ray script that calls ray.init() and uses Ray tasks or actors. Dependencies, or Environment. Anything outside of the Ray script that your application needs to run, including files, packages, and environment variables. Files. Code files, data files or other files that ...
234
Preparing an environment using the Ray Cluster launcher# The first way to set up dependencies is to prepare a single environment across the cluster before starting the Ray runtime. You can build all your files and dependencies into a container image and specify this in your your Cluster YAML Configuration. You can als...
235
The second way to set up dependencies is to install them dynamically while Ray is running. A runtime environment describes the dependencies your Ray application needs to run, including files, packages, environment variables, and more. It is installed dynamically on the cluster at runtime and cached for future use (see ...
236
runtime_env = {"pip": ["emoji"]} ray.init(runtime_env=runtime_env) @ray.remote def f(): import emoji return emoji.emojize('Python is :thumbs_up:') print(ray.get(f.remote())) Python is 👍 A runtime environment can be described by a Python dict: runtime_env = { "pip": ["emoji"], "env_vars": {"TF_WARNIN...
237
For more examples, jump to the API Reference. There are two primary scopes for which you can specify a runtime environment: Per-Job, and Per-Task/Actor, within a job. Specifying a Runtime Environment Per-Job# You can specify a runtime environment for your whole job, whether running a script directly on the cluster, ...
238
client = JobSubmissionClient("http://<head-node-ip>:8265") job_id = client.submit_job( entrypoint="python my_ray_script.py", runtime_env=runtime_env, ) # Option 3: Using Ray Jobs API (CLI). (Note: can use --runtime-env to pass a YAML file instead of an inline JSON string.) $ ray job submit --address="http://<...
239
Warning Specifying the runtime_env argument in the submit_job or ray job submit call ensures the runtime environment is installed on the cluster before the entrypoint script is run. If runtime_env is specified from ray.init(runtime_env=...), the runtime env is only applied to all children Tasks and Actors, not the entr...
240
The default is option 1. To change the behavior to option 2, add "eager_install": False to the config of runtime_env. Specifying a Runtime Environment Per-Task or Per-Actor# You can specify different runtime environments per-actor or per-task using .options() or the @ray.remote decorator: # Invoke a remote task that...
241
# Specify a runtime environment in the actor definition. Future instantiations # via `MyClass.remote()` will use this runtime environment unless overridden by # using `.options()` as above. @ray.remote(runtime_env=runtime_env) class MyClass: pass This allows you to have actors and tasks running in their own envi...
242
Common Workflows# This section describes some common use cases for runtime environments. These use cases are not mutually exclusive; all of the options described below can be combined in a single runtime environment. Using Local Files# Your Ray application might depend on source files or data files. For a development ...
243
# Specify a runtime environment for the entire Ray job ray.init(runtime_env={"working_dir": "/tmp/runtime_env_working_dir"}) # Create a Ray task, which inherits the above runtime env. @ray.remote def f(): # The function will have its working directory changed to its node's # local copy of /tmp/runtime_env_work...
244
The specified local directory will automatically be pushed to the cluster nodes when ray.init() is called. You can also specify files via a remote cloud storage URI; see Remote URIs for details. If you specify a working_dir, Ray always prepares it first, and it’s present in the creation of other runtime environments in...
245
Using conda or pip packages# Your Ray application might depend on Python packages (for example, pendulum or requests) via import statements. Ray ordinarily expects all imported packages to be preinstalled on every node of the cluster; in particular, these packages are not automatically shipped from your local machine t...
246
@ray.remote def reqs(): return requests.get("https://www.ray.io/").status_code print(ray.get(reqs.remote())) 200 You may also specify your pip dependencies either via a Python list or a local requirements.txt file. Consider specifying a requirements.txt file when your pip install command requires options such ...
247
Warning Since the packages in the runtime_env are installed at runtime, be cautious when specifying conda or pip packages whose installations involve building from source, as this can be slow. Note When using the "pip" field, the specified packages will be installed “on top of” the base environment using virtualenv, ...
248
Note conda environments must have the same Python version as the Ray cluster. Do not list ray in the conda dependencies, as it will be automatically installed. Using uv for package management# The recommended approach for package management with uv in runtime environments is through uv run. This method offers sever...
249
We plan to make it the default after collecting more feedback, and adapting the behavior if necessary. Create a file pyproject.toml in your working directory like the following: [project] name = "test" version = "0.1" dependencies = [ "emoji", "ray", ] And then a test.py like the following: import emoji impor...
250
@ray.remote def f(): return emoji.emojize('Python is :thumbs_up:') # Execute 1000 copies of f across a cluster. print(ray.get([f.remote() for _ in range(1000)])) and run the driver script with uv run test.py. This runs 1000 copies of the f function across a number of Python worker processes in a Ray cluster. The...
251
This command makes sure both the driver and workers of the job run in the uv environment as specified by your pyproject.toml. Using uv with Ray Serve: With appropriate pyproject.toml and app.py files, you can run a Ray Serve application with uv run serve run app:main. Best Practices and Tips: Use uv lock to generate a...
252
Advanced use cases: Under the hood, the uv run support is implemented using a low level runtime environment plugin called py_executable. It allows you to specify the Python executable (including arguments) that Ray workers will be started in. In the case of uv, the py_executable is set to uv run with the same parameter...
253
Applications with heterogeneous dependencies: Ray supports using a different runtime environment for different tasks or actors. This is useful for deploying different inference engines, models, or microservices in different Ray Serve deployments and also for heterogeneous data pipelines in Ray Data. To implement this, ...
254
Library Development# Suppose you are developing a library my_module on Ray. A typical iteration cycle will involve Making some changes to the source code of my_module Running a Ray script to test the changes, perhaps on a distributed cluster. To ensure your local changes show up across all Ray workers and can be impo...
255
ray.get(test_my_module.remote()) API Reference# The runtime_env is a Python dictionary or a Python class ray.runtime_env.RuntimeEnv including one or more of the following fields: working_dir (str): Specifies the working directory for the Ray workers. This must either be (1) an local existing directory with total ...
256
Examples "."  # cwd "/src/my_project" "/src/my_project.zip" "s3://path/to/my_dir.zip" Note: Setting a local directory per-task or per-actor is currently unsupported; it can only be set per-job (i.e., in ray.init()). Note: If the local directory contains a .gitignore file, the files and paths specified there are not...
257
Examples of entries in the list: "." "/local_dependency/my_dir_module" "/local_dependency/my_file_module.py" "s3://bucket/my_module.zip" my_module # Assumes my_module has already been imported, e.g. via 'import my_module' my_module.whl "s3://bucket/my_module.whl" The modules will be downloaded to each node on the c...
258
py_executable (str): Specifies the executable used for running the Ray workers. It can include arguments as well. The executable can be located in the working_dir. This runtime environment is useful to run workers in a custom debugger or profiler as well as to run workers in an environment set up by a package manager l...
259
excludes (List[str]): When used with working_dir or py_modules, specifies a list of files or paths to exclude from being uploaded to the cluster. This field uses the pattern-matching syntax used by .gitignore files: see https://git-scm.com/docs/gitignore for details. Note: In accordance with .gitignore syntax, if there...
260
Example: {"working_dir": "/Users/my_working_dir/", "excludes": ["my_file.txt", "/subdir/", "path/to/dir", "*.log"]} pip (dict | List[str] | str): Either (1) a list of pip requirements specifiers, (2) a string containing the path to a local pip “requirements.txt” file, or (3) a python dictionary that has three fields:...
261
Example: ["requests==1.0.0", "aiohttp", "ray[serve]"] Example: "./requirements.txt" Example: {"packages":["tensorflow", "requests"], "pip_check": False, "pip_version": "==22.0.2;python_version=='3.8.11'"} When specifying a path to a requirements.txt file, the file must be present on your local machine and it must be a...
262
uv (dict | List[str] | str): Alpha version feature. This plugin is the uv pip version of the pip plugin above. If you are looking for uv run support with pyproject.toml and uv.lock support, use the uv run runtime environment plugin instead. Either (1) a list of uv requirements specifiers, (2) a string containing the pa...
263
To override the default options and install without any options, use an empty list [] as install option value. The syntax of a requirement specifier is the same as pip requirements. This will be installed in the Ray workers at runtime. Packages in the preinstalled cluster environment will still be available. To use a ...
264
Example: ["requests==1.0.0", "aiohttp", "ray[serve]"] Example: "./requirements.txt" Example: {"packages":["tensorflow", "requests"], "uv_version": "==0.4.0;python_version=='3.8.11'"} When specifying a path to a requirements.txt file, the file must be present on your local machine and it must be a valid absolute path o...
265
conda (dict | str): Either (1) a dict representing the conda environment YAML, (2) a string containing the path to a local conda “environment.yml” file, or (3) the name of a local conda environment already installed on each node in your cluster (e.g., "pytorch_p36") or its absolute path (e.g. "/home/youruser/anaconda3/...
266
Example: {"dependencies": ["pytorch", "torchvision", "pip", {"pip": ["pendulum"]}]} Example: "./environment.yml" Example: "pytorch_p36" Example: "/home/youruser/anaconda3/envs/pytorch_p36" When specifying a path to a environment.yml file, the file must be present on your local machine and it must be a valid absolute p...
267
env_vars (Dict[str, str]): Environment variables to set. Environment variables already set on the cluster will still be visible to the Ray workers; so there is no need to include os.environ or similar in the env_vars field. By default, these environment variables override the same name environment variables on the clu...
268
nsight (Union[str, Dict[str, str]]): specifies the config for the Nsight System Profiler. The value is either (1) “default”, which refers to the default config, or (2) a dict of Nsight System Profiler options and their values. See here for more details on setup and usage. Example: "default" Example: {"stop-on-exit": "...
269
Example: {"setup_timeout_seconds": 10} Example: RuntimeEnvConfig(setup_timeout_seconds=10) (2) eager_install (bool): Indicates whether to install the runtime environment on the cluster at ray.init() time, before the workers are leased. This flag is set to True by default. If set to False, the runtime environment will ...
270
Example: {"eager_install": False} Example: RuntimeEnvConfig(eager_install=False) Caching and Garbage Collection# Runtime environment resources on each node (such as conda environments, pip packages, or downloaded working_dir or py_modules directories) will be cached on the cluster to enable quick reuse across diffe...
271
Runtime Environment Specified by Both Job and Driver# When running an entrypoint script (Driver), the runtime environment can be specified via ray.init(runtime_env=...) or ray job submit --runtime-env (See Specifying a Runtime Environment Per-Job for more details). If the runtime environment is specified by ray job su...
272
Since ray job submit submits a Driver (that calls ray.init), sometimes runtime environments are specified by both of them. When both the Ray Job and Driver specify runtime environments, their runtime environments are merged if there’s no conflict. It means the driver script uses the runtime environment specified by ray...
273
Example: # `ray job submit --runtime_env=...` {"pip": ["requests", "chess"], "env_vars": {"A": "a", "B": "b"}} # ray.init(runtime_env=...) {"env_vars": {"C": "c"}} # Driver's actual `runtime_env` (merged with Job's) {"pip": ["requests", "chess"], "env_vars": {"A": "a", "B": "b", "C": "c"}} Conflict Example: # Examp...
274
# ray.init(runtime_env=...) {"pip": ["torch"]} # Ray raises an exception because "pip" conflicts. You can set an environment variable RAY_OVERRIDE_JOB_RUNTIME_ENV=1 to avoid raising an exception upon a conflict. In this case, the runtime environments are inherited in the same way as Driver and Task and Actor both sp...
275
The runtime_env["env_vars"] field will be merged with the runtime_env["env_vars"] field of the parent. This allows for environment variables set in the parent’s runtime environment to be automatically propagated to the child, even if new environment variables are set in the child’s runtime environment. Every other fiel...
276
# Child's actual `runtime_env` (merged with parent's) {"pip": ["torch", "ray[serve]"], "env_vars": {"A": "a", "B": "new", "C": "c"}} Frequently Asked Questions# Are environments installed on every node?# If a runtime environment is specified in ray.init(runtime_env=...), then the environment will be installed on ...
277
When is the environment installed?# When specified per-job, the environment is installed when you call ray.init() (unless "eager_install": False is set). When specified per-task or per-actor, the environment is installed when the task is invoked or the actor is instantiated (i.e. when you call my_task.remote() or my_ac...
278
How long does it take to install or to load from cache?# The install time usually mostly consists of the time it takes to run pip install or conda create / conda activate, or to upload/download a working_dir, depending on which runtime_env options you’re using. This could take seconds or minutes. On the other hand, loa...
279
What is the relationship between runtime environments and Docker?# They can be used independently or together. A container image can be specified in the Cluster Launcher for large or static dependencies, and runtime environments can be specified per-job or per-task/actor for more dynamic use cases. The runtime environm...
280
Remote URIs# The working_dir and py_modules arguments in the runtime_env dictionary can specify either local path(s) or remote URI(s). A local path must be a directory path. The directory’s contents will be directly accessed as the working_dir or a py_module. A remote URI must be a link directly to a zip file or a whee...
281
Suppose instead you want to host your files in your /some_path/example_dir directory remotely and provide a remote URI. You would need to first compress the example_dir directory into a zip file. There should be no other files or directories at the top level of the zip file, other than example_dir. You can use the foll...
282
Suppose you upload the compressed example_dir directory to AWS S3 at the S3 URI s3://example_bucket/example.zip. Your runtime_env dictionary should contain: runtime_env = {..., "working_dir": "s3://example_bucket/example.zip", ...} Warning Check for hidden files and metadata directories in zipped dependencies. You c...
283
Currently, three types of remote URIs are supported for hosting working_dir and py_modules packages: HTTPS: HTTPS refers to URLs that start with https. These are particularly useful because remote Git providers (e.g. GitHub, Bitbucket, GitLab, etc.) use https URLs as download links for repository archives. This allows...
284
Example: runtime_env = {"working_dir": "https://github.com/example_username/example_respository/archive/HEAD.zip"} S3: S3 refers to URIs starting with s3:// that point to compressed packages stored in AWS S3. To use packages via S3 URIs, you must have the smart_open and boto3 libraries (you can install them using ...
285
Example: runtime_env = {"working_dir": "s3://example_bucket/example_file.zip"} GS: GS refers to URIs starting with gs:// that point to compressed packages stored in Google Cloud Storage. To use packages via GS URIs, you must have the smart_open and google-cloud-storage libraries (you can install them using pip ins...
286
Example: runtime_env = {"working_dir": "gs://example_bucket/example_file.zip"} Note that the smart_open, boto3, and google-cloud-storage packages are not installed by default, and it is not sufficient to specify them in the pip section of your runtime_env. The relevant packages must already be installed on all no...
287
First, create a repository on GitHub to store your working_dir contents or your py_module dependency. By default, when you download a zip file of your repository, the zip file will already contain a single top-level directory that holds the repository contents, so you can directly upload your working_dir contents or yo...
288
Option 1: Download Zip (quicker to implement, but not recommended for production environments)# The first option is to use the remote Git provider’s “Download Zip” feature, which provides an HTTPS link that zips and downloads your repository. This is quick, but it is not recommended because it only allows you to downlo...
289
Now your HTTPS link is copied to your clipboard. You can paste it into your runtime_env dictionary. Warning Using the HTTPS URL from your Git provider’s “Download as Zip” feature is not recommended if the URL always points to the latest commit. For instance, using this method on GitHub generates a link that always poi...
290
Option 2: Manually Create URL (slower to implement, but recommended for production environments)# The second option is to manually create this URL by pattern-matching your specific use case with one of the following examples. This is recommended because it provides finer-grained control over which repository branch and...
291
Here is a list of different use cases and corresponding URLs: Example: Retrieve package from a specific commit hash on a public GitHub repository runtime_env = {"working_dir": ("https://github.com" "/[username]/[repository]/archive/[commit hash].zip")} Example: Retrieve package from ...
292
Example: Retrieve package from a specific commit hash on a public Bitbucket repository runtime_env = {"working_dir": ("https://bitbucket.org" "/[owner]/[repository]/get/[commit hash].tar.gz")} Tip It is recommended to specify a particular commit instead of always using the latest comm...
293
@ray.remote def f(): pass @ray.remote class A: def f(self): pass start = time.time() bad_env = {"conda": {"dependencies": ["this_doesnt_exist"]}} # [Tasks] will raise `RuntimeEnvSetupError`. try: ray.get(f.options(runtime_env=bad_env).remote()) except ray.exceptions.RuntimeEnvSetupError: print("T...
294
Task fails with RuntimeEnvSetupError Actor fails with RuntimeEnvSetupError Full logs can always be found in the file runtime_env_setup-[job_id].log for per-actor, per-task and per-job environments, or in runtime_env_setup-ray_client_server_[port].log for per-job environments when using Ray Client. You can also enable...
295
Resources# Ray allows you to seamlessly scale your applications from a laptop to a cluster without code change. Ray resources are key to this capability. They abstract away physical machines and let you express your computation in terms of resources, while the system manages scheduling and autoscaling based on resource...
296
Physical Resources and Logical Resources# Physical resources are resources that a machine physically has such as physical CPUs and GPUs and logical resources are virtual resources defined by a system. Ray resources are logical and don’t need to have 1-to-1 mapping with physical resources. For example, you can start a R...
297
Resource requirements of tasks or actors do NOT impose limits on actual physical resource usage. For example, Ray doesn’t prevent a num_cpus=1 task from launching multiple threads and using multiple physical CPUs. It’s your responsibility to make sure tasks or actors use no more resources than specified via resource re...
298
Note Ray sets the environment variable OMP_NUM_THREADS=<num_cpus> if num_cpus is set on the task/actor via ray.remote() and task.options()/actor.options(). Ray sets OMP_NUM_THREADS=1 if num_cpus is not specified; this is done to avoid performance degradation with many workers (issue #6998). You can also override this b...
299
Physical resources vs logical resources# Custom Resources# Besides pre-defined resources, you can also specify a Ray node’s custom resources and request them in your tasks or actors. Some use cases for custom resources: Your node has special hardware and you can represent it as a custom resource. Then your tasks o...