Skip to navigation

Environment Variables for AlphaFold2

View as MarkdownOpen in Claude

You can use environment variables to configure the AlphaFold2 NIM at runtime. Pass these variables to the container with the -e option in the docker run command. Runtime configuration lets you tune NIM performance, take advantage of your unique hardware, and modify runtime behavior, such as the location of the NIM cache. For the first-run procedure, refer to the Quickstart Guide.

General Environment Variables

The following table describes the environment variables you can set to configure the AlphaFold2 NIM.

NameTypeValid ValuesDefault ValueDescription
NIM_CACHE_PATHStringContainer path/opt/nim/.cacheThe cache path inside the container. Must match the destination of the volume mount (-v) used for the NIM cache.
NIM_HTTP_API_PORTIntegerPort number8000The HTTP API port the NIM listens on inside the container. Set this together with the -p option when running multiple services.
NIM_PARALLEL_MSA_RUNNERSInteger1 to 43Controls the coarse-grained parallelism of the MSA process (the number of concurrent MSA runners). Do not use more than 4.
NIM_PARALLEL_THREADS_PER_MSAInteger8 to 168Controls the number of threads used by each MSA process.

The product of NIM_PARALLEL_MSA_RUNNERS and NIM_PARALLEL_THREADS_PER_MSA should be less than or equal to the number of CPU cores available to the NIM. The default values of NIM_PARALLEL_MSA_RUNNERS=3 and NIM_PARALLEL_THREADS_PER_MSA=8 work well for most machines, and most users do not need to modify these variables.

The host environment variable LOCAL_NIM_CACHE sets the NIM cache location on the host file system, and CUDA_VISIBLE_DEVICES controls which GPU devices are visible to the container.

Review How to Start the NIM

The following command starts the NIM. The examples in this page build on it.

export LOCAL_NIM_CACHE=~/.cache/nim
docker run --rm --name alphafold2 --runtime=nvidia \
-e CUDA_VISIBLE_DEVICES=0 \
-e NGC_API_KEY \
-v $LOCAL_NIM_CACHE:/opt/nim/.cache \
-p 8000:8000 \
nvcr.io/nim/deepmind/alphafold2:2.1.0

In this command:

  • The -p option sets the port for the NIM.
  • The -e options define environment variables, which are passed into the NIM’s container at runtime.
  • --rm removes the container when it exits.
  • -it allows interacting with the container directly at the CLI.

Configure the Location of the NIM Cache

The location of the NIM cache can be changed on both the local file system and within the NIM. This is useful when a larger drive is needed to store the model weights, for example.

To change the NIM cache location on the host file system, change the source mount in the preceding command, which is set in the environment variable LOCAL_NIM_CACHE:

export LOCAL_NIM_CACHE=/mount/largedisk/nim/.cache
docker run --rm --name alphafold2 --runtime=nvidia \
-e CUDA_VISIBLE_DEVICES=0 \
-e NGC_API_KEY \
-v $LOCAL_NIM_CACHE:/opt/nim/.cache \
-p 8000:8000 \
nvcr.io/nim/deepmind/alphafold2:2.1.0

This affects only the location outside the container. To change the location of the cache inside the container, you must:

  1. Mount the new destination path.
  2. Provide the new path in the NIM_CACHE_PATH environment variable.

The following example moves the cache within the container to /workdir/cache/af2/:

export LOCAL_NIM_CACHE=/mount/largedisk/nim/.cache
docker run --rm --name alphafold2 --runtime=nvidia \
-e CUDA_VISIBLE_DEVICES=0 \
-e NGC_API_KEY \
-e NIM_CACHE_PATH=/workdir/cache/af2 \ ## Note: we must set this environment variable...
-v $LOCAL_NIM_CACHE:/workdir/cache/af2 \ ## and provide the destination mount.
-p 8000:8000 \
nvcr.io/nim/deepmind/alphafold2:2.1.0

Use an Alternative Port for NIM Requests

If you have other HTTP or gRPC servers running (for example, other NIMs), you might need to make the 8000 port available by using another port for your NIM. To do so:

  1. Change the exposed port by setting the -p option.
  2. Set the NIM_HTTP_API_PORT environment variable to the new port.

The following example sets the NIM to run on port 7979:

export LOCAL_NIM_CACHE=/mount/largedisk/nim/.cache
docker run --rm --name alphafold2 --runtime=nvidia \
-e CUDA_VISIBLE_DEVICES=0 \
-e NGC_API_KEY \
-e NIM_HTTP_API_PORT=7979 \ ## We must set the NIM_HTTP_API_PORT environment variable...
-e NIM_CACHE_PATH=/workdir/cache/af2 \
-v $LOCAL_NIM_CACHE:/workdir/cache/af2 \
-p 7979:7979 \ ## as well as forward the port to host.
nvcr.io/nim/deepmind/alphafold2:2.1.0

Configure MSA Runners and Threads

The AlphaFold2 NIM has been optimized in many ways. One such optimization is the ability to tune the MSA process for better performance on your machine, based on the number of available CPU cores, the number of available GPUs, and your SSD speed.

Do not run the AlphaFold2 NIM on a machine that uses a hard disk drive for storage, as it significantly decreases the performance of the NIM.

There are two layers of tunable parallelism for MSA within the AlphaFold2 NIM, set by two different environment variables:

  1. NIM_PARALLEL_MSA_RUNNERS controls the coarse-grained parallelism of the MSA process.
  2. NIM_PARALLEL_THREADS_PER_MSA controls the number of threads used by each MSA process.

The product of NIM_PARALLEL_MSA_RUNNERS and NIM_PARALLEL_THREADS_PER_MSA should be less than or equal to the number of CPU cores available to the NIM.

For example, on a machine with 48 CPU cores, an appropriate setting would be:

NIM_PARALLEL_MSA_RUNNERS=3
NIM_PARALLEL_THREADS_PER_MSA=12

This allocates three runners, each with 12 threads.

We do not recommend using more than four runners, and the number of threads per MSA should generally be between eight and 16.

To modify these variables at runtime, pass them as environment variables in the NIM startup command. For example, on a 32-core machine, you could set NIM_PARALLEL_MSA_RUNNERS to three and reduce NIM_PARALLEL_THREADS_PER_MSA to 10 so that the workloads fit the machine well:

docker run --rm --name alphafold2 --runtime=nvidia \
-e CUDA_VISIBLE_DEVICES=0 \
-e NGC_API_KEY \
-e NIM_PARALLEL_MSA_RUNNERS=3 \ ## We set the number of parallel runners to 6, perhaps because we have used many MSA databases...
-e NIM_PARALLEL_THREADS_PER_MSA=10 \ ## and we set the number of threads per MSA to 12, to
-v $LOCAL_NIM_CACHE:/opt/nim/.cache \
-p 8000:8000 \
nvcr.io/nim/deepmind/alphafold2:2.1.0

Explore the following related topics: