By default, Cerebrium models are executed in Python 3.9 unless the Python version you specified in your cerebrium.toml is different (see here). Note, Cerebrium only supports python from version 3.9 and above.

Dependancies

Traditionally, when working with Python, you will need access to Apt packages, Pip packages and Conda packages. For a deployment to cerebrium, you can specify all of these in your cerebrium.toml file in the following locations:

  • [cerebrium.dependencies.pip] - This is where you define your Pip packages in the form module = version_constraints.

  • [cerebrium.dependencies.conda] - This is where you can define Conda packages you would like to install if you prefer using it for some libraries over pip. You can use both conda and pip in conjunction.

  • [cerebrium.dependencies.apt] - This is where you can define Linux apt packages you would like to install.

Here is an example of the dependencies section of a cerebrium.toml file:


[cerebrium.dependencies.pip]
transformers = ">=4.35.0"
torch = "2.1.0"
accelerate = "latest"

[cerebrium.dependencies.conda]
cuda = ">=11.7"

[cerebrium.dependencies.apt]
ffmpeg = "latest"
"libopenblas-base" = "latest"
"libomp-dev" = "latest"

All the sections above are optional, however, have to contain these file names specifically.

Typically, specifying versions for packages leads to faster builds however, if you ever find you would like to change version numbers or find your library versions aren’t updating, please add the following flag to your deploy command: cerebrium deploy --name <<app-name>> --force-rebuild

Shell Commands

Cerebrium gives you the ability to run shell commands - this is for more complicated use cases of cloning repositories, running install scripts etc.

Please note that shell commands are run last in the build process which means it happens after dependancy installation. If you would like to install a pip package after some shell commands, then run ‘pip install transformers’ in your shell commands

In order to run shell commands you define a list of strings in the [cerebrium.build] section of your cerebrium.toml:


[cerebrium.build]
force_rebuild = false
disable_syntax_check = false
shell_commands = [
    "echo 'Hello, World!'",
    "curl -LsSf https://astral.sh/uv/install.sh | sh",
    "uv venv",
    "uv pip install transformers"
]