Getting Started#
Prerequisites#
Refer to the Support Matrix to make sure that you have the supported hardware and software stack.
An NGC personal API key. The NIM microservice uses the API key to download models from NVIDIA NGC. Refer to Generating a Personal API Key in the NVIDIA NGC User Guide for more information.
To run the below examples you must have
curl,jq, and the Pythonrequestsmodule installed.When you create an NGC API personal key, select at least the option for NGC Catalog from the Services Included menu. You can specify more services to use the key for additional purposes.
Installing curl, jq, and the Python requests module#
curlis required to send requests from the command line. On Ubuntu and other Debian-based Linux distributions,curlcan be installed with the following command, which may requiresudoaccess:sudo apt-get update && sudo apt-get install curl
jqis used to process and reformat responses from the NIM so they are easier to read.jqcan be installed using the following command, which may requiresudoaccess:sudo apt-get update && sudo apt-get install jq
The Python
requestsmodule facilitates HTTP requests made in many of the examples for this NIM. The Python requests module can be installed usingpip:pip install requests
NGC Authentication#
Generate an API key#
To access NGC resources, you need an NGC API key. You can generate a key here: Generate Personal Key.
When creating an NGC API Personal key, ensure that “NGC Catalog” is selected from the “Services Included” dropdown. You can include more services if you reuse this key for other purposes.
Note
Personal keys allow you to configure an expiration date, revoke, or delete the key using an action button, and rotate the key as needed. For more information about key types, refer to the NGC User Guide.
Export the API key#
Pass the value of the API key to the docker run command in the next section as the NGC_API_KEY environment variable to download the appropriate models and resources when starting the NIM.
If you’re not familiar with how to create the NGC_API_KEY environment variable, the simplest way is to export it in your terminal:
export NGC_API_KEY=<value>
Run one of the following commands to make the key available at startup:
# If using bash
echo "export NGC_API_KEY=<value>" >> ~/.bashrc
# If using zsh
echo "export NGC_API_KEY=<value>" >> ~/.zshrc
Note
Other, more secure options include saving the value in a file, so that you can retrieve with cat $NGC_API_KEY_FILE, or using a password manager.
Docker Login to NGC#
To pull the NIM container image from NGC, first authenticate with the NVIDIA Container Registry with the following command:
echo "$NGC_API_KEY" | docker login nvcr.io --username '$oauthtoken' --password-stdin
Use $oauthtoken as the username and NGC_API_KEY as the password. The $oauthtoken username is a special name that indicates that you will authenticate with an API key and not a username and password.
Starting the NIM Container#
Ensure you have logged in to Docker and set your
NGC_API_KEYenvironment variable as detailed in the preceding section.Create a NIM Cache. If one already exists, you may use the existing one.
export LOCAL_NIM_CACHE=~/.cache/nim mkdir -p ${LOCAL_NIM_CACHE} chmod 777 ${LOCAL_NIM_CACHE}
Start the NIM container:
## Note: these two commands are not required if you have already set the appropiate variables in previous instructions. ## They are provided here as part of a one-click startup sequence. export LOCAL_NIM_CACHE=~/.cache/nim export NGC_API_KEY=<Your NGC API Key> docker run --rm --name boltz2 --runtime=nvidia \ --shm-size=16G \ -e NGC_API_KEY \ -v $LOCAL_NIM_CACHE:/opt/nim/.cache \ -p 8000:8000 \ nvcr.io/nim/mit/boltz2:1.6.0
Note: The
--runtime=nvidiaflag is the legacy approach for GPU access and may require additional Docker daemon configuration. For Docker 19.03+, you can use the--gpusflag instead, which works without additional configuration:# Use all GPUs docker run --rm --name boltz2 --gpus all \ --shm-size=16G \ -e NGC_API_KEY \ -v $LOCAL_NIM_CACHE:/opt/nim/.cache \ -p 8000:8000 \ nvcr.io/nim/mit/boltz2:1.6.0 # Or specify a specific GPU device docker run --rm --name boltz2 --gpus '"device=0"' \ --shm-size=16G \ -e NGC_API_KEY \ -v $LOCAL_NIM_CACHE:/opt/nim/.cache \ -p 8000:8000 \ nvcr.io/nim/mit/boltz2:1.6.0
The preceding command starts the container with the default profile, using all available system GPUs. Note: This will require localizing up to 30 Gigabytes of data to disk. If you have the model cached, the version in the NIM cache specified at
LOCAL_NIM_CACHEwill be used.(Optional) Confirm the service is ready to respond to inference requests:
$ curl -X GET http://localhost:8000/v1/health/ready
Example Output
200 trueSend an inference request:
#!/bin/bash # Define the protein sequence SEQUENCE="MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN" # Create JSON payload for protein structure prediction JSON_DATA='{ "polymers": [ { "id": "A", "molecule_type": "protein", "sequence": "'"$SEQUENCE"'" } ], "recycling_steps": 3, "sampling_steps": 50, "diffusion_samples": 1, "step_scale": 1.638, "output_format": "mmcif" }' echo "Making request..." # Make the POST request # Note: This script requires jq to be installed for JSON processing response=$(curl -s -X POST \ -H "Content-Type: application/json" \ -d "$JSON_DATA" \ http://localhost:8000/biology/mit/boltz2/predict) # Extract and display the structure information # Using jq to parse the JSON response echo "Structure prediction completed" echo "Format: $(echo $response | jq -r '.structures[0].format')" echo "Confidence score: $(echo $response | jq -r '.confidence_scores[0]')" echo "Structure (first 500 chars): $(echo $response | jq -r '.structures[0].structure' | head -c 500)..."import requests import json if __name__ == "__main__": sequence = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN" # Replace with your sequence value of interest headers = { "content-type": "application/json" } data = { "polymers": [ { "id": "A", "molecule_type": "protein", "sequence": sequence } ], "recycling_steps": 3, "sampling_steps": 50, "diffusion_samples": 1, "step_scale": 1.638, "output_format": "mmcif" } print("Making request...") response = requests.post("http://localhost:8000/biology/mit/boltz2/predict", headers=headers, data=json.dumps(data)) result = response.json() print("Structure prediction completed") # Access the first predicted structure if result.get("structures"): structure = result["structures"][0] print(f"Structure format: {structure['format']}") print(f"Confidence score: {result['confidence_scores'][0]}") print(f"Structure (first 500 chars): {structure['structure'][:500]}...")
The description of all API parameters could be found in the Input Parameters section of the Inference Guide.
Runtime Parameters for the Container#
Flags |
Description |
|---|---|
|
|
|
Delete the container after it stops (see Docker docs). |
|
Give a name to the NIM container. Use any preferred value. |
|
(Legacy) Ensure NVIDIA drivers are accessible in the container. Requires additional Docker daemon configuration. For Docker 19.03+, using |
|
(Recommended for Docker 19.03+) Expose all available NVIDIA GPUs inside the container. This is the modern approach for GPU access. |
|
Expose specific NVIDIA GPU(s) inside the container (e.g., device 0). If you are running on a host with multiple GPUs, you can specify which GPU(s) to use. See GPU Enumeration for further information. |
|
Provide the container with the token necessary to download adequate models and resources from NGC. See above. |
|
Specify the profile to use for the NIM. See the Support Matrix section for more information about available profiles. |
|
Specify the port that would be used by NIM inside the container (default is |
|
Forward the port where the NIM HTTP server is published inside the container to access from the host system. The left-hand side of |
Caching Models#
The first time you start the container, the microservice downloads the model from NGC. You can avoid this download step on future runs by caching the model locally.
# Create the cache directory on the host machine.
export LOCAL_NIM_CACHE=~/.cache/nim
mkdir -p "$LOCAL_NIM_CACHE"
chmod 777 $LOCAL_NIM_CACHE
# Run the container with the cache directory as a volume mount.
docker run --rm --name boltz2 --runtime=nvidia \
--shm-size=16G \
-e NGC_API_KEY \
-v $LOCAL_NIM_CACHE:/opt/nim/.cache \
-p 8000:8000 \
nvcr.io/nim/mit/boltz2:1.6.0
Stopping the Container#
The following commands stop the container by stopping and removing the running docker container.
docker stop boltz2
docker rm boltz2
Running on Slurm With Enroot#
This section describes how to run the Boltz2 NIM on a Slurm-based HPC cluster using Enroot to run the NGC container.
Important
NGC_API_KEY: You must export your NGC API key before running the Slurm script so that Enroot can pull the image from NGC. Then run the script (for example, bash boltz2_srun.sh).
Example:
export NGC_API_KEY=<your_NGC_API_key>
bash boltz2_srun.sh
Environment#
Enroot: Version 3.4.1 or newer is supported.
1. Check Enroot is Available#
On the login node, verify Enroot is installed:
enroot version
which enroot
If Enroot is not installed, contact your cluster administrator. Create the Enroot config directory if it does not exist:
mkdir -p ~/.config/enroot
2. Create and Add NGC Credentials#
Create the credentials file so Enroot can pull images from NGC. Replace YOUR_NGC_API_KEY with your NGC API key:
echo 'machine nvcr.io login $oauthtoken password YOUR_NGC_API_KEY' > ~/.config/enroot/.credentials
chmod 600 ~/.config/enroot/.credentials
3. Configure and Run the Slurm Job Script#
Copy the script below to a file, such as boltz2_srun.sh. Set the variables at the top for your cluster and paths:
ACCOUNT: Slurm account name
PARTITION: Slurm partition (for example,
interactiveorgpu)ROOT_DIR: Your working directory on the cluster (for example, Lustre or NFS path)
NGC_API_KEY: Must be exported in your environment before running the script (for example,
export NGC_API_KEY=<your_key>)
Use a shared filesystem path for ROOT_DIR and CACHE_PATH so that the SQSH image and cache are visible from the node where the job runs.
Save the following as boltz2_srun.sh and run it with bash boltz2_srun.sh:
#!/bin/bash
# --- Slurm job configuration (customize for your cluster) ---
ACCOUNT="your_slurm_account"
PARTITION="interactive"
GPUS_PER_NODE=1
MEMORY="32G"
TIME="04:00:00"
# --- Paths (customize for your cluster) ---
ROOT_DIR="/path/to/your/workspace"
CACHE_PATH="${ROOT_DIR}/.nim_cache"
WORKING_CACHE_DIR="/opt/nim/.cache"
WORKING_PATH="${ROOT_DIR}"
MOUNT_PATH="/workspace/data"
TMP_PATH="${ROOT_DIR}/tmp"
MOUNT_TMP_PATH="${MOUNT_PATH}/tmp"
# --- NGC image (use # between registry and image path for Enroot) ---
NGC_IMAGE="docker://nvcr.io#nim/mit/boltz2:1.6.0"
CONTAINER_NAME="boltz2"
ACTIVE_SQSH_PATH="${ROOT_DIR}/boltz2.sqsh"
handle_error() { echo "Error: $1"; exit 1; }
mkdir -p "$(dirname "${ACTIVE_SQSH_PATH}")" || handle_error "Failed to create directory for SQSH file"
mkdir -p "${CACHE_PATH}" || handle_error "Failed to create cache directory"
mkdir -p "${TMP_PATH}" || handle_error "Failed to create tmp directory"
echo "Step 1: Requesting interactive resources..."
srun --account="${ACCOUNT}" \
--partition="${PARTITION}" \
--gpus-per-node="${GPUS_PER_NODE}" \
--mem="${MEMORY}" \
--time="${TIME}" \
--export=ALL \
-o /dev/tty -e /dev/tty \
bash -c "
echo \"Step 2: Importing Docker image\"
if [ ! -f \"${ACTIVE_SQSH_PATH}\" ]; then
mkdir -p \"\$(dirname \"${ACTIVE_SQSH_PATH}\")\" || { echo \"Failed to create directory\"; exit 1; }
enroot import -o \"${ACTIVE_SQSH_PATH}\" ${NGC_IMAGE} || { echo \"Failed to import Docker image\"; exit 1; }
else
echo \"Docker image already exists, skipping import.\"
fi
echo \"Step 3: Creating Enroot container...\"
if enroot list 2>/dev/null | grep -q \"${CONTAINER_NAME}\"; then
enroot remove -f ${CONTAINER_NAME} || true
fi
enroot create --name ${CONTAINER_NAME} \"${ACTIVE_SQSH_PATH}\" || { echo \"Failed to create container\"; exit 1; }
NODE=\$(hostname)
echo \"\$NODE\" > \"${WORKING_PATH}/.boltz2_node\"
echo \"Step 4: Boltz2 container ready.\"
echo \"=====================================\"
echo \"Working directory in container: ${MOUNT_PATH}\"
echo \"From another terminal run: ssh -L 8000:localhost:8000 \$NODE\"
echo \"Node name saved to: ${WORKING_PATH}/.boltz2_node\"
echo \"=====================================\"
cat > \"\${TMPDIR:-/tmp}/rc.local\" << RCEOF
#!/bin/sh
export TMPDIR=${MOUNT_TMP_PATH}
export TEMP=${MOUNT_TMP_PATH}
export TMP=${MOUNT_TMP_PATH}
export HOME=${MOUNT_PATH}
export XDG_CACHE_HOME=${WORKING_CACHE_DIR}
export XDG_DATA_HOME=${MOUNT_PATH}/.local/share
mkdir -p ${MOUNT_TMP_PATH} ${MOUNT_PATH}/.local/share
/opt/nim/start_server.sh &
exec /bin/bash
RCEOF
chmod +x \"\${TMPDIR:-/tmp}/rc.local\"
enroot start \\
--mount ${CACHE_PATH}:${WORKING_CACHE_DIR} \\
--mount ${WORKING_PATH}:${MOUNT_PATH} \\
--mount \"\${TMPDIR:-/tmp}/rc.local:/etc/rc.local\" \\
-e NGC_API_KEY \\
-e TMPDIR=${MOUNT_TMP_PATH} \\
-e TEMP=${MOUNT_TMP_PATH} \\
-e TMP=${MOUNT_TMP_PATH} \\
-e HOME=${MOUNT_PATH} \\
-e XDG_CACHE_HOME=${WORKING_CACHE_DIR} \\
-e XDG_DATA_HOME=${MOUNT_PATH}/.local/share \\
${CONTAINER_NAME} || { echo \"Failed to start container\"; exit 1; }
"
4. Call the API From Your Machine#
After the container is running on a compute node:
Create an SSH tunnel from your machine or the login node:
ssh -L 8000:localhost:8000 $(cat /path/to/your/workspace/.boltz2_node)
In another terminal (with the tunnel open), send an inference request:
curl -s -X POST "http://localhost:8000/biology/mit/boltz2/predict" \ -H "Content-Type: application/json" \ -d '{"polymers":[{"id":"A","molecule_type":"protein","sequence":"MTEYKLVVVGACGVGKSALTIQLIQNHFVDEYDPTIEDSYRKQVVID"}]}' \ --max-time 300
If the request succeeds, you will get a JSON response containing the prediction result.
Next Steps#
Refer to the Deployment section in the Inference Guide for more detailed instructions on how to deploy the NIM.
Refer to Optimization for settings related to optimizing performance of the NIM on your hardware and software stack.