Skip to main content
This guide demonstrates how to run the Meta Llama 3.1 8B Instruct model on Beam.
You need an access token from Huggingface to run this example. You can sign up for Huggingface and access your token on the settings page, and store it in the Beam Secrets Manager.

View the Code

See the code for this example on Github.

Prerequisites

  1. Request Access: Request access to the model here.
  2. Retrieve HF Token: Get your Huggingface token from this page.
  3. Save HF Token on Beam: Use the command beam secret create HF_TOKEN [TOKEN] to save your token.

Setup Remote Environment

The first thing we’ll do is set up an Image with the Python packages required for this app. We use the if env.is_remote() flag to conditionally import the Python packages only when the script is running remotely on Beam.

Inference Function

Here’s the inference function. By adding the @endpoint decorator to it, we can expose this function as a RESTful API. Note the secrets argument which ensures the Huggingface token is loaded into the environment.

Deploy to Production

The following command deploys our code to Beam, and hosts it as a REST API:

Invoking the API

Once the API is running, you can invoke it using the following cURL command:
Replace [ENDPOINT-ID] with your actual endpoint ID and [AUTH-TOKEN] with your authentication token. You’ll see a response from the API, like this:

Summary

You’ve successfully set up a highly performant serverless API for generating text using the Meta Llama 3.1 8B Instruct model on Beam.