Code Monkey home page Code Monkey logo

Comments (3)

CrazyBoyM avatar CrazyBoyM commented on July 28, 2024

当前没有使用vllm和你设置的超参数去尝试,关于API部署可以尝试按以下文档中的方案不会重复:https://github.com/CrazyBoyM/llama3-Chinese-chat/tree/main/deploy/API

代码:

import uvicorn
import torch
from transformers import pipeline, AutoTokenizer
from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/")
async def create_item(request: Request):
    global pipe
    data = await request.json()
    prompt = data.get('prompt')
    print(prompt)

    messages = [
            {
                "role": "system",
                "content": "你是一个超级智者,名字叫shareAI-llama3,拥有优秀的问题解答能力。",
            },
            {"role": "user", "content": prompt}
    ]
    
    response = pipe(messages)
    # breakpoint()
    print(response)
    answer = {
        "response": response[-1]["content"],
        "status": 200,
    }
    return answer


if __name__ == '__main__':
    model_name_or_path = '/openbayes/home/baicai003/Llama3-Chinese-instruct-DPO-beta0___5'
    # 这里的模型路径替换为你本地的完整模型存储路径 (一般从huggingface或者modelscope上下载到)
    tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=False)
    pipe = pipeline(
        "conversational", 
        model_name_or_path, 
        torch_dtype=torch.float16, 
        device_map="auto", 
        max_new_tokens=512, 
        do_sample=True,
        top_p=0.9, 
        temperature=0.6, 
        repetition_penalty=1.1,
        eos_token_id=tokenizer.encode('<|eot_id|>')[0]
    )
    # 如果是base+sft模型需要替换<|eot_id|>为<|end_of_text|>,因为llama3 base模型里没有训练<|eot_id|>这个token

    uvicorn.run(app, host='0.0.0.0', port=9009) # 这里的端口替换为你实际想要监听的端口

from llama3-chinese-chat.

CrazyBoyM avatar CrazyBoyM commented on July 28, 2024

可以尝试设置一下repetition_penalty系数

from llama3-chinese-chat.

james-yw avatar james-yw commented on July 28, 2024

好的,谢谢~

from llama3-chinese-chat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.