Skip to main content

Running Friendli Container


Friendli Containers enable you to effortlessly deploy your generative AI model on your own machine. This tutorial will guide you through the process of running a Friendli Container. The current version of Friendli Containers supports most of major generative language models.


  • Before you begin, make sure you have signed up for Friendli Suite. You can use Friendli Containers free of charge for 60 days.
  • Friendli Container currently only supports NVIDIA GPUs, so please prepare proper GPUs and a compatible driver by referring to our required CUDA compatibility guide.
  • Prepare a Personal Access Token following this guide.
  • Prepare a Friendli Container Secret following this guide.

Preparing Personal Access Token

PAT (Personal Access Token) is the user credentials for logging into our container registry.

  1. Sign in Friendli Suite.
  2. Go to User Settings > Tokens and click 'Create new token'.
  3. Save your created token value and export it as FRIENDLI_PAT.

Preparing Container Secret

Container secret is a secret code that is used to activate Friendli Container. You should pass the container secret as an environment variable to run the container image.

  1. Sign in Friendli Suite.
  2. Go to Container > Container Secrets and click 'Create secret'.
  3. Save your created secret value and export it as FRIENDLI_CONTAINER_SECRET.

🔑 Secret Rotation

You can rotate the container secret for security reasons. If you rotate the container secret, a new secret will be created and the previous secret will be revoked automatically in 30 minutes.

Pulling Friendli Container Image

  1. Log in to the Docker client using the personal access token created as outlined in Preparing Personal Access Token.

    docker login -u $FRIENDLI_EMAIL -p $FRIENDLI_PAT
  2. Pull image

    docker pull[your_repository]:[your_tag]

💰 60-Days Free Trial

During the 60-days free trial period, you can use image only, which can be pulled with docker pull

Running Friendli Container with Hugging Face Models

If your model is in a safetensors format, which is compatible with Hugging Face transformers, you can serve the model directly with Friendli Containers.

The current version of Friendli Containers supports direct loading of safetensors checkpoints for the following models (and corresponding Hugging Face transformers classes):

  • GPT (GPT2LMHeadModel)
  • GPT-J (GPTJForCausalLM)
  • MPT (MPTForCausalLM)
  • OPT (OPTForCausalLM)
  • BLOOM (BloomForCausalLM)
  • GPT-NeoX (GPTNeoXForCausalLM)
  • Llama (LlamaForCausalLM)
  • Falcon (FalconForCausalLM)
  • Mistral (MistralForCausalLM)
  • Mixtral (MixtralForCausalLM)
  • Qwen2 (Qwen2ForCausalLM)
  • Gemma (GemmaForCausalLM)
  • Starcoder2 (Starcoder2ForCausalLM)
  • Cohere (CohereForCausalLM)
  • DBRX (DbrxForCausalLM)
  • Phi (PhiForCausalLM)
  • Phi3 (Phi3ForCausalLM)
  • T5 (T5ForConditionalGeneration)
  • MT5 (MT5ForConditionalGeneration)

If your model does not belong to one of the above model types, please ask for support by sending an email to Support.

Here are the instructions to run Friendli Container to serve a Hugging Face model:

# Fill the values of following variables.
export HF_MODEL_NAME="" # Hugging Face model name (e.g., "meta-llama/Meta-Llama-3-8B-Instruct")
export FRIENDLI_CONTAINER_SECRET="" # Friendli container secret
export FRIENDLI_CONTAINER_IMAGE="" # Friendli container image (e.g., "")
export GPU_ENUMERATION="" # GPUs (e.g., '"device=0,1"')

docker run \
-p 8000:8000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--hf-model-name $HF_MODEL_NAME \

The [LAUNCH_OPTIONS] should be replaced with Launch Options for Friendli Container.

By running the above command, you will have a running Docker container that exports an HTTP endpoint for handling inference requests.

Examples: Deploying the Llama 3 8B Instruct model

This is an example running Llama3-8B-Instruct model with a single GPU.

export FRIENDLI_CONTAINER_SECRET=""  # Friendli container secret (leave it if it's already set in your environment)
export HF_TOKEN="" # Access token from HuggingFace (see the caution below)
export HF_MODEL_NAME="meta-llama/Meta-Llama-3-8B-Instruct"
export GPU_ENUMERATION="device=0"

docker run \
-p 8000:8000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--hf-model-name meta-llama/Meta-Llama-3-8B-Instruct

Since downloading meta-llama/Meta-Llama-3-8B-Instruct is allowed only for authorized users, you need to provide your Hugging Face User Access Token through HF_TOKEN environment variable. It works the same for all private repositories.

Multi-GPU Serving

Friendli Container supports tensor parallelism and pipeline parallelism for multi-GPU inference.

Tensor Parallelism

Tensor parallelism is employed when serving large models that exceed the memory capacity of a single GPU, by distributing parts of the model's weights across multiple GPUs. To leverage tensor parallelism with the Friendli Container:

  1. Specify multiple GPUs for $GPU_ENUMERATION (e.g., '"device=0,1,2,3"').
  2. Use --num-devices (or -d) option to specify the tensor parallelism degree (e.g., --num-devices 4).

Pipeline Parallelism

Pipeline parallelism splits a model into multiple segments to be processed across different GPU, enabling the deployment of larger models that would not otherwise fit on a single GPU. To exploit pipeline parallelism with the Friendli Container:

  1. Specify multiple GPUs for $GPU_ENUMERATION (e.g., '"device=0,1,2,3"').
  2. Use --num-workers (or -n) option to specify the pipeline parallelism degree (e.g., --num-workers 4).

🆚 Choosing between Tensor Parallelism and Pipeline Parallelism

When deploying models with the Friendli Container, you have the flexibility to combine tensor parallelism and pipeline parallelism. We recommend exploring a balance between the two, based on their distinct characteristics. While tensor parallelism involves "expensive" all-reduce operations to aggregate partial results across all devices, pipeline parallelism relies on "cheaper" peer-to-peer communication. Thus, in limited network setup, such as PCIe networks, leveraging pipeline parallelism is preferable. Conversely, in rich network setup like NVLink, tensor parallelism is recommended due to its superior parallel computation efficiency.

Advanced: Serving AWQ Models

Running quantized models requires an additional step to search execution policy. See Serving AWQ Models to learn how to create an inference endpoint for the AWQ model.

Advanced: Serving MoE Models

Running MoE (Mixture of Experts) models requires an additional step to search execution policy. See Serving MoE Models to learn how to create an inference endpoint for the AWQ model.

Sending Inference Requests

We can now send inference requests to the running Friendli Container. For information on all parameters that can be used in an inference request, please refer to this document.


export ENDPOINT_URL=""

curl -X POST http://$ENDPOINT_URL:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Python is a popular"}], "max_tokens": 30, "stream": true}'

Options for Running Friendli Container

General Options

--version-Print Friendli Container version.-
--help-Print Friendli Container help message.-

Launch Options

--web-server-portINTWeb server port.8000
--metrics-portINTPrometheus metrics export port.8281
--hf-model-nameTEXTHugging Face model name to serve (e.g., meta-llama/Meta-Llama-3-8B-Instruct). Friendli Container will download the model from the Hugging Face Models Hub before creating the inference endpoint. This option is available only for models with safetensors format.-
--ckpt-pathTEXTAbsolute path of model checkpoint. If not specified, use uninitialized (garbage) values for model parameters.-
--ckpt-typeTEXTCheckpoint file type. Choose one of {hdf5|safetensors|hf_safetensors}. If not specified, guess the type from the filename extension of the ckpt, or use HDF5.hdf5
--tokenizer-file-pathTEXTAbsolute path of tokenizer file. This option is not needed when tokenizer.json is located under the path specified at --ckpt-path.-
--tokenizer-add-special-tokensBOOLEANWhether or not to add special tokens in tokenization. Equivalent to Hugging Face Tokenizer's add_special_tokens argument.false
--tokenizer-skip-special-tokensBOOLEANWhether or not to remove special tokens in detokenization. Equivalent to Hugging Face Tokenizer's skip_special_tokens argument.true
--dtypeCHOICE: [bf16, fp16, fp32]Data type of weights and activations. Choose one of {fp16|bf16|fp32}. This argument applies to non-quantized weights and activations. If not specified, Friendli Container follows the value of torch_dtype in config.json file or assumes fp16.fp16
--bad-stop-file-pathTEXTJSON file path that contains stop sequences or bad words/tokens.-
--num-request-threadsINTThread pool size for handling HTTP requests.4
--timeout-microsecondsINTServer-side timeout for client requests, in microseconds.0 (no timeout)
--ignore-nan-errorBOOLEANIf set to True, ignore NaN error. Otherwise, respond with a 400 status code if NaN values are detected while processing a request.-
--max-batch-sizeINTMax number of sequences that can be processed in a batch.384
--num-devices, -dINTNumber of devices to use in tensor parallelism degree.1
--num-workers, -nINTNumber of workers to use in a pipeline (i.e., pipeline parallelism degree).1
--search-policyBOOLEANSearch best engine policy for the given combination of model, hardware, parallelism degree. Learn more about policy search at Optimizing Inference with Policy Search.-
--algo-policy-dirTEXTPath to directory containing the policy file. Learn more about policy search at Optimizing Inference with Policy Search.-

Model Specific Options


--max-input-lengthINTMaximum input length.-
--max-output-lengthINTMaximum output length.-