Advanced Usage
Multi-GPU Support
MAISI Nim supports multi-GPU configurations to enhance performance and speed up processing. The logic for utilizing multiple GPUs is as follows:
- If the
num_output_samplesparameter is set toNand there areNvisible GPUs, thenNimages will be processed in parallel, with each GPU handling one image. - If the
num_output_samplesparameter is larger than the number of GPUs, for example, if the number of GPUs isMandN > M, thenMimages will be processed in parallel. The remaining images will be queued and processed as GPUs become available.
Please note that the number of GPUs available on your system is correctly configured and visible. For example, you can set the CUDA visible devices when running a Docker container to specify which GPUs should be used:
If you use --gpus "device=2,3" instead of --gpus "all", be aware that the GPUs are renumbered inside the container. Specifically, GPU 2 on the host becomes GPU 0 in the container, and GPU 3 on the host becomes GPU 1 in the container. Therefore, you should still set CUDA_VISIBLE_DEVICES=0,1 to correctly map the GPUs.
Writing Data to Blob Storage
To write generated images and masks to a blob storage, the pre_signed_url parameter should be specified.
The pre_signed_url parameter is a pre-signed URL that allows you to securely upload files to a blob storage service, such as AWS S3, without requiring direct access to your storage credentials. This URL is generated with specific permissions and an expiration time, ensuring that the upload can only occur within a defined time frame and with the specified permissions.
Generate Pre-Signed URL Example
Different cloud providers have different ways to produce pre-signed URLs. Please check their official documentation for details. Here we use AWS S3 as an example.
You can generate a pre-signed URL for an S3 bucket using the boto3 library in Python. If you are using AWS CloudShell, boto3 is pre-installed and credentials are automatically configured. For local environments, ensure that your AWS credentials are properly configured. Please refer to the official documentation for more details.
Here is an example of how to generate a pre-signed URL for uploading an object to an S3 bucket using boto3 in Python:
Specify pre-signed URL in Payload
After having a valid pre-signed URL, you can specify the pre_signed_url in the request payload, for example:
Writing Data to Local Mounted Directory
To write generated images and masks to a local mounted directory, the local_working_dir parameter should be specified in the request payload. To enable this feature, the local directory must be mounted when running the NIM container:
please ensure that the directory has the correct permissions to allow the Docker container to write to it (for example, do sudo chmod -R 777 to it). If the directory is /path/on/host/results/, then in the inference request payload, local_working_dir should be /path/in/container/results/.
Set timeout
Set a custom timeout for image generation (default is 1800 seconds):
Change Port
The default port for the FastAPI app is 8000, and adding an environment variable NIM_HTTP_API_PORT when running the container can change it. For example:
Some ports, such as 8001, 8002, and 8080, may already be in use by other services inside the container. Avoid setting NIM_HTTP_API_PORT to these ports to prevent conflicts.