Skip to main content

Beam

Calls the Beam API wrapper to deploy and make subsequent calls to an instance of the gpt2 LLM in a cloud deployment. Requires installation of the Beam library and registration of Beam Client ID and Client Secret. By calling the wrapper an instance of the model is created and run, with returned text relating to the prompt. Additional calls can then be made by directly calling the Beam API.

Create an account, if you don't have one already. Grab your API keys from the dashboard.

Install the Beam CLI

!curl https://raw.githubusercontent.com/slai-labs/get-beam/main/get-beam.sh -sSfL | sh

Register API Keys and set your beam client id and secret environment variables:

import os

beam_client_id = "<Your beam client id>"
beam_client_secret = "<Your beam client secret>"

# Set the environment variables
os.environ["BEAM_CLIENT_ID"] = beam_client_id
os.environ["BEAM_CLIENT_SECRET"] = beam_client_secret

# Run the beam configure command
!beam configure --clientId={beam_client_id} --clientSecret={beam_client_secret}

Install the Beam SDK:

%pip install --upgrade --quiet  beam-sdk

Deploy and call Beam directly from langchain!

Note that a cold start might take a couple of minutes to return the response, but subsequent calls will be faster!

from langchain_community.llms.beam import Beam

llm = Beam(
model_name="gpt2",
name="langchain-gpt2-test",
cpu=8,
memory="32Gi",
gpu="A10G",
python_version="python3.8",
python_packages=[
"diffusers[torch]>=0.10",
"transformers",
"torch",
"pillow",
"accelerate",
"safetensors",
"xformers",
],
max_length="50",
verbose=False,
)

llm._deploy()

response = llm._call("Running machine learning on a remote GPU")

print(response)

API Reference:


Help us out by providing feedback on this documentation page: