Llama-3-8B (Chatbot)¶
Overview¶
This tutorial explains how to compile and deploy the Llama 3 model from HuggingFace on a single Rebel100™ (RBLN-CR13) NPU. This guide uses the meta-llama/Meta-Llama-3-8B-Instruct model.
Serving on Rebel100™
On Rebel100™, use RBLN vLLM (vllm serve) as the main way to serve LLMs. It compiles the model and exposes an OpenAI-compatible API in one step; see the Meta-Llama-3-8B-Instruct recipe. This tutorial covers the optimum-rbln Python API, which is useful for checking compilation and running inference directly.
Note
Rebel100™ does not support RSD (see the version matrix), and every Rebel100™ example in the Model Zoo compiles for one NPU, so rbln_num_devices is set to 1 in this tutorial.
Note
Llama 3 is licensed under the LLAMA Community License, Copyright (c) Meta Platforms, Inc. All Rights Reserved.
Setup & Installation¶
Before you begin, ensure that your system environment is properly configured and that all required packages are installed. This includes:
- System Requirements:
- Python: 3.10–3.14
- RBLN Driver
- Package Requirements:
- Installation Command:
Note
rebel-compilerrequires an RBLN Portal account.- The commands above are intended for a default pip install on Debian-based Linux such as Ubuntu. For all other configurations, refer to the Installation Guide for the supported install matrix and the applicable commands.
Note
The meta-llama/Meta-Llama-3-8B-Instruct model on HuggingFace has restricted access. Once access is granted, you can log in using the hf (huggingface-cli) command as shown below:
Using RBLN Optimum¶
This step demonstrates how to compile the meta-llama/Meta-Llama-3-8B-Instruct model to run on a single Rebel100™ NPU.
Model Compilation¶
To begin, import the RBLNLlamaForCausalLM class from optimum-rbln. This class's from_pretrained() method downloads the Llama 3 model from the HuggingFace Hub and compiles it using the RBLN Compiler. When exporting the model, specify the following parameters:
export: Must beTrueto compile the model.rbln_batch_size: Defines the batch size for compilation.rbln_max_seq_len: Defines the maximum sequence length.rbln_num_devices: Defines the number of NPUs to be used for inference. Set it to1on Rebel100™.
After compilation, save the model artifacts to disk using the save_pretrained() method. This creates a directory (e.g., rbln-Llama-3-8B-Instruct) containing the compiled model.
Load the Compiled RBLN Model¶
Load the compiled RBLN model using RBLNLlamaForCausalLM.from_pretrained(). Pass the saved directory path as model_id and set the export parameter to False.
Prepare Inputs¶
Use the AutoTokenizer from the transformers library to tokenize the input sequences. For instruction-tuned models such as Llama 3, apply the chat template.
Model Inference¶
You can now generate a response using the generate() method.
Example Output: