Cerebras¶
在 Cerebras,我们研发了全球最大且最快的人工智能处理器——晶圆级引擎第三代(WSE-3)。搭载 WSE-3 的 Cerebras CS-3 系统代表了一类全新的人工智能超级计算机,以无与伦比的性能和可扩展性,为生成式 AI 训练和推理树立了新标准。
选择 Cerebras 作为推理服务提供商,您将能够:
- 实现前所未有的 AI 推理工作负载速度
- 以高吞吐量进行商业化构建
- 通过我们无缝集群技术轻松扩展 AI 工作负载
我们的 CS-3 系统可快速便捷地组成集群,构建全球最大的人工智能超级计算机,使部署和运行最大规模模型变得简单易行。众多领先企业、研究机构和政府已采用 Cerebras 解决方案开发专有模型,并训练热门的开源模型。
想体验 Cerebras 的强大性能?访问我们的官网获取更多资源,了解通过 Cerebras 云服务或本地部署使用我们技术的方案!
有关 Cerebras 云的更多信息,请访问 cloud.cerebras.ai。API 参考文档详见 inference-docs.cerebras.ai。
安装¶
如果您在 Colab 上打开此 Notebook,可能需要安装 LlamaIndex 🦙。
In [ ]:
Copied!
% pip install llama-index-llms-cerebras
% pip install llama-index-llms-cerebras
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
In [ ]:
Copied!
from llama_index.llms.cerebras import Cerebras
from llama_index.llms.cerebras import Cerebras
从 cloud.cerebras.ai 获取 API 密钥,并将其添加到环境变量中:
export CEREBRAS_API_KEY=<your api key>
或者,您也可以在初始化 LLM 时直接传入 API 密钥:
In [ ]:
Copied!
import os
import getpass
os.environ["CEREBRAS_API_KEY"] = getpass.getpass(
"Enter your Cerebras API key: "
)
llm = Cerebras(model="llama-3.3-70b", api_key=os.environ["CEREBRAS_API_KEY"])
import os
import getpass
os.environ["CEREBRAS_API_KEY"] = getpass.getpass(
"Enter your Cerebras API key: "
)
llm = Cerebras(model="llama-3.3-70b", api_key=os.environ["CEREBRAS_API_KEY"])
Enter your Cerebras API key: ········
可用的 LLM 模型列表可在 inference-docs.cerebras.ai 查阅。
In [ ]:
Copied!
response = llm.complete("What is Generative AI?")
response = llm.complete("What is Generative AI?")
In [ ]:
Copied!
print(response)
print(response)
Generative AI refers to a type of artificial intelligence (AI) that is capable of generating new, original content, such as text, images, music, or videos, based on patterns and structures it has learned from a dataset or a set of examples. This type of AI is designed to create new content that is similar in style, tone, and quality to the original content it was trained on. Generative AI models use various techniques, such as neural networks, to analyze and learn from large datasets, and then generate new content that is similar to the patterns and structures they have learned. These models can be trained on a wide range of data, including text, images, audio, and video, and can be used to generate a variety of content, such as: 1. Text: Generative AI models can generate text that is similar in style and tone to a given text, such as articles, blog posts, or social media updates. 2. Images: Generative AI models can generate images that are similar in style and content to a given image, such as photographs, illustrations, or graphics. 3. Music: Generative AI models can generate music that is similar in style and tone to a given piece of music, such as melodies, harmonies, or beats. 4. Videos: Generative AI models can generate videos that are similar in style and content to a given video, such as animations, movies, or TV shows. Generative AI has many potential applications, including: 1. Content creation: Generative AI can be used to generate content for various industries, such as marketing, advertising, and entertainment. 2. Data augmentation: Generative AI can be used to generate new data that can be used to train and improve machine learning models. 3. Creative collaboration: Generative AI can be used to collaborate with humans in the creative process, such as generating ideas or providing inspiration. 4. Personalization: Generative AI can be used to generate personalized content for individuals, such as customized recommendations or tailored marketing messages. Some examples of generative AI include: 1. Language models like GPT-3, which can generate human-like text based on a prompt. 2. Image generation models like Generative Adversarial Networks (GANs), which can generate realistic images of faces, objects, or scenes. 3. Music generation models like Amper Music, which can generate original music tracks based on a set of parameters. 4. Video generation models like DeepMotion, which can generate realistic videos of human movements and actions. Overall, generative AI has the potential to revolutionize the way we create and interact with content, and has many exciting applications across various industries.
使用消息列表调用 chat 方法¶
In [ ]:
Copied!
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
In [ ]:
Copied!
print(resp)
print(resp)
assistant: Arrrr, me hearty! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty parrot, Polly, have been plunderin' and pillagin' for nigh on 20 years, and me reputation be known from the Caribbean to the coast of Africa! Now, I be a bit of a legend in me own right, with me black beard and me eye patch, and me ship, the "Maverick's Revenge", be the fastest and most feared on the high seas! So, if ye be lookin' for a swashbucklin' adventure, just give ol' Blackbeak Betty a shout, and we'll set sail fer a life o' plunder and pillage! Savvy?
流式传输¶
使用 stream_complete 端点
In [ ]:
Copied!
response = llm.stream_complete("What is Generative AI?")
response = llm.stream_complete("What is Generative AI?")
In [ ]:
Copied!
for r in response:
print(r.delta, end="")
for r in response:
print(r.delta, end="")
Generative AI refers to a type of artificial intelligence (AI) that is capable of generating new, original content, such as text, images, music, or videos, based on patterns and structures it has learned from a dataset or a set of examples. This type of AI is designed to create new content that is similar in style, tone, and quality to the original content it was trained on. Generative AI models use various techniques, such as neural networks, to analyze and learn from large datasets, and then generate new content that is similar to the patterns and structures they have learned. These models can be trained on a wide range of data, including text, images, audio, and video, and can be used to generate a variety of content, such as: 1. Text: Generative AI models can generate text that is similar in style and tone to a given text, such as articles, blog posts, or social media updates. 2. Images: Generative AI models can generate images that are similar in style and content to a given image, such as photographs, illustrations, or graphics. 3. Music: Generative AI models can generate music that is similar in style and tone to a given piece of music, such as melodies, harmonies, or beats. 4. Videos: Generative AI models can generate videos that are similar in style and content to a given video, such as animations, movies, or TV shows. Generative AI has many potential applications, including: 1. Content creation: Generative AI can be used to generate content for various industries, such as marketing, advertising, and entertainment. 2. Data augmentation: Generative AI can be used to generate new data that can be used to train and improve machine learning models. 3. Creative collaboration: Generative AI can be used to collaborate with humans in the creative process, such as generating ideas or providing inspiration. 4. Personalization: Generative AI can be used to generate personalized content for individuals, such as customized recommendations or tailored marketing messages. Some examples of generative AI include: 1. Language models like GPT-3, which can generate human-like text based on a prompt. 2. Image generation models like Generative Adversarial Networks (GANs), which can generate realistic images of faces, objects, or scenes. 3. Music generation models like Amper Music, which can generate original music tracks based on a set of parameters. 4. Video generation models like DeepMotion, which can generate realistic videos of human movements and actions. Overall, generative AI has the potential to revolutionize the way we create and interact with content, and has many exciting applications across various industries.
使用 stream_chat 端点
In [ ]:
Copied!
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
In [ ]:
Copied!
for r in resp:
print(r.delta, end="")
for r in resp:
print(r.delta, end="")
Arrrr, me hearty! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty parrot, Polly, have been plunderin' and pillagin' for nigh on 20 years, and me reputation be known from the Caribbean to the coast of Africa! Now, I be a bit of a legend in me own right, with me black beard and me eye patch, and me ship, the "Maverick's Revenge", be the fastest and most feared on the high seas! So, if ye be lookin' for a swashbucklin' adventure, just give ol' Blackbeak Betty a shout, and we'll set sail fer a life o' plunder and pillage! Savvy?