Titan Takeoff
TitanML
帮助企业通过我们的训练、压缩和推理优化平台构建和部署更好、更小、更便宜、更快的NLP模型。
我们的推理服务器,Titan Takeoff 使您能够通过一条命令在本地硬件上部署LLMs。支持大多数生成模型架构,如Falcon、Llama 2、GPT2、T5等。如果您在使用特定模型时遇到问题,请通过hello@titanml.co联系我们。
示例用法
这里有一些有用的示例,帮助您开始使用Titan Takeoff Server。在运行这些命令之前,您需要确保Takeoff Server已在后台启动。更多信息请参见启动Takeoff的文档页面。
import time
# Note importing TitanTakeoffPro instead of TitanTakeoff will work as well both use same object under the hood
from langchain_community.llms import TitanTakeoff
from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler
from langchain_core.prompts import PromptTemplate
示例 1
基本使用假设Takeoff正在您的机器上使用其默认端口(即localhost:3000)运行。
llm = TitanTakeoff()
output = llm.invoke("What is the weather in London in August?")
print(output)
示例 2
指定端口和其他生成参数
llm = TitanTakeoff(port=3000)
# A comprehensive list of parameters can be found at https://docs.titanml.co/docs/next/apis/Takeoff%20inference_REST_API/generate#request
output = llm.invoke(
"What is the largest rainforest in the world?",
consumer_group="primary",
min_new_tokens=128,
max_new_tokens=512,
no_repeat_ngram_size=2,
sampling_topk=1,
sampling_topp=1.0,
sampling_temperature=1.0,
repetition_penalty=1.0,
regex_string="",
json_schema=None,
)
print(output)
示例 3
使用generate处理多个输入
llm = TitanTakeoff()
rich_output = llm.generate(["What is Deep Learning?", "What is Machine Learning?"])
print(rich_output.generations)
示例 4
流式输出
llm = TitanTakeoff(
streaming=True, callback_manager=CallbackManager([StreamingStdOutCallbackHandler()])
)
prompt = "What is the capital of France?"
output = llm.invoke(prompt)
print(output)
示例 5
使用LCEL
llm = TitanTakeoff()
prompt = PromptTemplate.from_template("Tell me about {topic}")
chain = prompt | llm
output = chain.invoke({"topic": "the universe"})
print(output)
示例 6
开始使用TitanTakeoff Python包装器的读者。如果您在首次启动Takeoff时没有创建任何读者,或者您想添加另一个,您可以在初始化TitanTakeoff对象时这样做。只需将您想要启动的模型配置列表作为models
参数传递。
# Model config for the llama model, where you can specify the following parameters:
# model_name (str): The name of the model to use
# device: (str): The device to use for inference, cuda or cpu
# consumer_group (str): The consumer group to place the reader into
# tensor_parallel (Optional[int]): The number of gpus you would like your model to be split across
# max_seq_length (int): The maximum sequence length to use for inference, defaults to 512
# max_batch_size (int_: The max batch size for continuous batching of requests
llama_model = {
"model_name": "TheBloke/Llama-2-7b-Chat-AWQ",
"device": "cuda",
"consumer_group": "llama",
}
llm = TitanTakeoff(models=[llama_model])
# The model needs time to spin up, length of time need will depend on the size of model and your network connection speed
time.sleep(60)
prompt = "What is the capital of France?"
output = llm.invoke(prompt, consumer_group="llama")
print(output)
相关
- LLM 概念指南
- LLM how-to guides