Override Modal resource options (GPU, scaling) at runtime with Cls.with_options

Cls.with_options lets you override the resource configuration of a Modal Cls at runtime. This is useful when the same code needs to run with different resource allocations — say, with a GPU or with out, or with a large warm pool of containers — at different times — say, when iterating on code and when in production.

Each call to with_options returns a new class handle that scales independently from the original.

Setup 

Defining the class 

We define a simple class with a method that performs a CPU-bound computation. The class is configured with modest defaults.

Using with_options to override configuration 

We can call with_options on the class to get a new handle with different resource settings.