modal.Cls

class Cls(modal.object.Object)

Cls adds method pooling and lifecycle hook behavior to modal.Function.

Generally, you will not construct a Cls directly. Instead, use the @app.cls() decorator on the App object.

def __init__(self, *args, **kwargs):

from_name

@classmethod
@renamed_parameter((2024, 12, 18), "tag", "name")
def from_name(
    cls: type["_Cls"],
    app_name: str,
    name: str,
    namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
    environment_name: Optional[str] = None,
    workspace: Optional[str] = None,
) -> "_Cls":

Reference a Cls from a deployed App by its name.

In contrast to modal.Cls.lookup, this is a lazy method that defers hydrating the local object with metadata from Modal servers until the first time it is actually used.

Model = modal.Cls.from_name("other-app", "Model")

with_options

def with_options(
    self: "_Cls",
    cpu: Optional[Union[float, tuple[float, float]]] = None,
    memory: Optional[Union[int, tuple[int, int]]] = None,
    gpu: GPU_T = None,
    secrets: Collection[_Secret] = (),
    volumes: dict[Union[str, os.PathLike], _Volume] = {},
    retries: Optional[Union[int, Retries]] = None,
    timeout: Optional[int] = None,
    concurrency_limit: Optional[int] = None,
    allow_concurrent_inputs: Optional[int] = None,
    container_idle_timeout: Optional[int] = None,
) -> "_Cls":

Beta: Allows for the runtime modification of a modal.Cls’s configuration.

This is a beta feature and may be unstable.

Usage:

Model = modal.Cls.lookup("my_app", "Model")
ModelUsingGPU = Model.with_options(gpu="A100")
ModelUsingGPU().generate.remote(42)  # will run with an A100 GPU

lookup

@staticmethod
@renamed_parameter((2024, 12, 18), "tag", "name")
def lookup(
    app_name: str,
    name: str,
    namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
    client: Optional[_Client] = None,
    environment_name: Optional[str] = None,
    workspace: Optional[str] = None,
) -> "_Cls":

Lookup a Cls from a deployed App by its name.

In contrast to modal.Cls.from_name, this is an eager method that will hydrate the local object with metadata from Modal servers.

Model = modal.Cls.lookup("other-app", "Model")
model = Model()
model.inference(...)