Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ray project Ray Serve ReplicaConfig

From Leeroopedia
Revision as of 13:48, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ray_project_Ray_Serve_ReplicaConfig.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Model_Serving, Distributed_Computing
Last Updated 2026-02-13 16:00 GMT

Overview

ReplicaConfig is a configuration class that defines how a Ray Serve deployment replica actor is created and what resources it requires.

Description

ReplicaConfig holds the deployment class definition name, constructor initialization arguments, and Ray actor options such as CPU, GPU, memory, and runtime environment settings. During construction, it validates actor options against an allow-list, defaults num_cpus to 1.0 if unset, and computes a normalized resource requirements map from the provided actor options. The class supports protobuf serialization via toProtoBytes() and deserialization via fromProto(), using MessagePack for init args and JSON for actor options.

Usage

Use ReplicaConfig when creating or updating a deployment to specify the replica's class definition, constructor arguments, and resource requirements (CPU, GPU, memory, accelerator type). It is typically constructed by the deployment API and passed along with DeploymentConfig inside DeploymentInfo.

Code Reference

Source Location

  • Repository: Ray
  • File: java/serve/src/main/java/io/ray/serve/config/ReplicaConfig.java

Signature

public class ReplicaConfig {

    public ReplicaConfig(
        String deploymentDef, Object[] initArgs, Map<String, Object> rayActorOptions)

    public byte[] toProtoBytes()

    public static ReplicaConfig fromProto(io.ray.serve.generated.ReplicaConfig proto)
}

Import

import io.ray.serve.config.ReplicaConfig;

I/O Contract

Constructor Parameters

Parameter Type Description
deploymentDef String Fully qualified class name of the deployment implementation
initArgs Object[] Constructor arguments for the deployment class (defaults to empty array if null)
rayActorOptions Map<String, Object> Ray actor options controlling resource allocation (defaults to empty map if null)

Allowed Ray Actor Options

Option Key Description
accelerator_type Type of accelerator required
memory Memory requirement in bytes
num_cpus Number of CPUs (defaults to 1.0)
num_gpus Number of GPUs
object_store_memory Object store memory requirement
resources Custom resource requirements
runtime_env Runtime environment specification

Key Methods

Method Return Type Description
getDeploymentDef() String Returns the deployment class definition name
getInitArgs() Object[] Returns the constructor initialization arguments
getRayActorOptions() Map<String, Object> Returns the Ray actor options map
getResources() Map<String, Object> Returns the computed resource requirements
toProtoBytes() byte[] Serializes the config to protobuf bytes
fromProto(proto) ReplicaConfig Static factory that deserializes from a protobuf message

Usage Examples

// Create a ReplicaConfig with resource requirements
Map<String, Object> actorOptions = new HashMap<>();
actorOptions.put("num_cpus", 2.0);
actorOptions.put("num_gpus", 1.0);
actorOptions.put("memory", 1024 * 1024 * 512L);

ReplicaConfig config = new ReplicaConfig(
    "com.example.MyModelDeployment",
    new Object[]{"model-path", 128},
    actorOptions
);

// Access computed resources
Map<String, Object> resources = config.getResources();
// resources: {"CPU": 2.0, "GPU": 1.0, "memory": 536870912}

// Serialize to protobuf bytes for transmission
byte[] protoBytes = config.toProtoBytes();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment