Reserving CPU and memory
Modal jobs are reserved 128 MiB of memory and 0.1 CPU cores by default. However, if there is free memory or CPU capacity on a worker, containers are free to spike above these limits.
CPU cores
If you have code that you want to run on a larger number of cores, you can
request that using the cpu
argument. This allows you to specify a
floating-point number of CPU cores:
import modal
stub = modal.Stub()
@stub.function(cpu=8.0)
def my_function():
# code here will have access to at least 8.0 cores
...
Memory
If you have code that needs more guaranteed memory, you can request it using the
memory
argument. This expects an integer number of megabytes:
import modal
stub = modal.Stub()
@stub.function(memory=32768)
def my_function():
# code here will have access to at least 32 GiB of RAM
...
How much can I request?
For both CPU and memory, a maximum is enforced at function creation time to
ensure your application can be scheduled for execution. Requests exceeding the
maximum will be rejected with an
InvalidError
.
As the platform grows, we plan to support larger CPU and memory reservations.
Resource limits
We currently don’t support setting a hard limit on the resource usage of a function. But we do plan to add this feature so that users have more control over the resource consumption of their Modal applications.