Skip to main content
Open In ColabOpen on GitHub

Beam

调用Beam API包装器以在云部署中部署并随后调用gpt2 LLM的实例。需要安装Beam库并注册Beam客户端ID和客户端密钥。通过调用包装器,创建并运行模型的实例,返回与提示相关的文本。然后可以通过直接调用Beam API进行额外的调用。

创建一个账户,如果你还没有的话。从仪表板获取你的API密钥。

安装Beam CLI

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

注册API密钥并设置您的beam客户端ID和密钥环境变量:

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}

安装Beam SDK:

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

直接从langchain部署和调用Beam!

请注意,冷启动可能需要几分钟才能返回响应,但后续调用会更快!

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:Beam

这个页面有帮助吗?