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 Python requests module 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#

  1. curl is required to send requests from the command line. On Ubuntu and other Debian-based Linux distributions, curl can be installed with the following command, which may require sudo access:

    sudo apt-get update && sudo apt-get install curl
    
  2. jq is used to process and reformat responses from the NIM so they are easier to read. jq can be installed using the following command, which may require sudo access:

    sudo apt-get update && sudo apt-get install jq
    
  3. The Python requests module facilitates HTTP requests made in many of the examples for this NIM. The Python requests module can be installed using pip:

    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 this key is to be reused 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#

  1. Ensure you have logged in to Docker and set your NGC_API_KEY environment variable as detailed in the preceding section.

  2. 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}
    
  3. 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 msa-search --runtime=nvidia \
    -e NGC_API_KEY \
    -v $LOCAL_NIM_CACHE:/opt/nim/.cache \
    -p 8000:8000 \
    nvcr.io/nim/colabfold/msa-search:1.0.0
    

    The preceding command starts the container with the default profile, using all available system GPUs. Note: This will require localizing 1.3 Terabytes of data to the disk. This process may take up to 10 hours, depending on the speed of your internet connection. If you have the model cached, the version in the NIM cache specified at LOCAL_NIM_CACHE will be used.

  4. Optional: Confirm the service is ready to respond to inference requests:

    $ curl -X GET http://localhost:8000/v1/health/ready
    

    Example Output

     200 OK
    
  5. Send an inference request:

#!/bin/bash

# Define the protein sequence
SEQUENCE="MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"

# Create JSON payload
JSON_DATA='{
"sequence": "'"$SEQUENCE"'",
"e_value": 0.0001,
"iterations": 1,
"databases": ["Uniref30_2302", "colabfold_envdb_202108", "PDB70_220313"],
"search_type": "alphafold2",
"output_alignment_formats": ["fasta", "a3m"],
"max_msa_sequences": 1000
}'

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/colabfold/msa-search/predict)

# Extract and display the A3M format and alignment
# Using jq to parse the JSON response
echo "Format: $(echo $response | jq -r '.alignments.Uniref30_2302.a3m.format')"
echo "Alignment:"
echo "$response" | jq -r '.alignments.Uniref30_2302.a3m.alignment'
import requests
import json


if __name__ == "__main__":
    sequence = "MALWMRLLPLLALLALWGPDPAAAFVNQHLCGSHLVEALYLVCGERGFFYTPKTRREAEDLQVGQVELGGGPGAGSLQPLALEGSLQKRGIVEQCCTSICSLYQLENYCN"  # Replace with your sequence value of interest
    headers = {
        "content-type": "application/json"
        }
    data = {
        "sequence": sequence,
        "e_value": 0.0001,
        "iterations": 1,
        "databases": ["Uniref30_2302", "colabfold_envdb_202108", "PDB70_220313"],
        "search_type": "alphafold2",
        "output_alignment_formats" : ["fasta", "a3m"],
        "max_msa_sequences" : 1000
        }
    print("Making request...")
    response = requests.post("http://localhost:8000/biology/colabfold/msa-search/predict",headers=headers, data=json.dumps(data))
    ## Get the fasta formatted record
    record = response.json()["alignments"]["Uniref30_2302"]["a3m"]
    print(record["format"]) ## prints "a3m"
    print(record["alignment"]) ## prints the full A3M-formatted alignment file, which may be very large.

The description of all API parameters could be found in API Reference.

Runtime Parameters for the Container#

Flags

Description

-it

--interactive + --tty (see Docker docs)

--rm

Delete the container after it stops (see Docker docs).

--name=<container-name

Give a name to the NIM container. Use any preferred value.

--runtime=nvidia

Ensure NVIDIA drivers are accessible in the container.

--gpus '"device=0"'

Expose NVIDIA GPU 0 inside the container. If you are running on a host with multiple GPUs, you need to specify which GPU to use. See GPU Enumeration for further information on for mounting specific GPUs.

-e NGC_API_KEY=$NGC_API_KEY

Provide the container with the token necessary to download adequate models and resources from NGC. See [above](# NGC Authentication).

-e NIM_MODEL_PROFILE=<profile>

Specify the profile to use for the NIM. See the Support Matrix section for more information about available profiles.

-e NIM_HTTP_API_PORT=8000

Specify the port that would be used by NIM inside the container (default is 8000).

-p 8000:8000

Forward the port where the NIM HTTP server is published inside the container to access from the host system. The left-hand side of : is the host system ip:port (8000 here), while the right-hand side is the container port where the NIM HTTP server is published.

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 msa-search --runtime=nvidia \
-e NGC_API_KEY \
-v $LOCAL_NIM_CACHE:/opt/nim/.cache \
-p 8000:8000 \
nvcr.io/nim/colabfold/msa-search:1.0.0

Stopping the Container#

The following commands stop the container by stopping and removing the running docker container.

docker stop msa-search
docker rm msa-search

Next Steps#

  • See Deploy Using Docker for more detailed instructions on how to deploy the NIM.

  • See Optimization for settings related to optimizing performance of the NIM on your hardware and software stack.