Reserving CPU and memory

Modal jobs are reserved 100 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 go above the limit.

CPU cores

If you have code that you want to ensure receives a larger minimum number of cores, you can request it using the cpu argument. This expects a float number of CPU cores:

import modal

stub = modal.Stub()

@stub.function(cpu=2.0)
def my_function():
    # code here will have access to at least 2.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=2048)
def my_function():
    # code here will have access to at least 2048 MiB
    ...

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. We plan to support large larger requests in the future.

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.