langchain 与 llama2 本地慢速推理

问题描述 投票:0回答:1

我正在使用 Langchainllama-2-13B。我已在具有 240GB RAM 和 4x16GB Tesla V100 GPU 的 AWS 计算机上设置了 llama2。大约需要 20 秒才能做出推断。我想让它更快,达到8-10秒左右,使其实时。而且产量很差。 如果我问一个问题:“嗨,你好吗?”它将生成一个 500 字的段落。 如何改善输出结果?我目前正在使用这个配置:

LlamaCpp(model_path= path,
                temperature=0.7,
                max_tokens=800,
                top_p=0.1,
                top_k=40,
                n_threads=4,
                callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]),
                verbose=True,
                n_ctx=2000,
                n_gpu_layers=80,
                n_batch=2048)
langchain llamacpp
1个回答
0
投票

我会首先使用 llama-2-13B-**chat**** 而不是 llama-2-13B

聊天模型针对对话用例进行了优化,并且没有聊天后缀的模型经过训练以预测下一个标记。因此,通过生成 500 字的段落,您的模型就完全完成了它应该做的事情。

此外,提示对于 LLaMa 模型至关重要。您可以使用序列开始 (BOS)序列结束 (EOS) 令牌,其看起来像这样:

template = """
    [INST] <<SYS>>
    You are a helpful, respectful and honest assistant. 
    Always answer as helpfully as possible, while being safe.  
    Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. 
    Please ensure that your responses are socially unbiased and positive in nature.
    If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. 
    If you don't know the answer to a question, please don't share false information.
    <</SYS>>
    {INSERT_PROMPT_HERE} [/INST]
    """

prompt = 'Your actual question to the model'
prompt = template.replace('INSERT_PROMPT_HERE', prompt)
© www.soinside.com 2019 - 2024. All rights reserved.