generated from aniketmaurya/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00ed0ec
commit 60db946
Showing
7 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import requests | ||
from locust import HttpUser, task | ||
|
||
headers = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import uvicorn | ||
|
||
from .base_fastserve import FastServe | ||
|
||
serve = FastServe() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
from typing import List | ||
|
||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
from vllm import LLM, SamplingParams | ||
|
||
tensor_parallel_size = int(os.environ.get("DEVICES", "1")) | ||
print("tensor_parallel_size: ", tensor_parallel_size) | ||
|
||
llm = LLM("meta-llama/Llama-2-7b-hf", tensor_parallel_size=tensor_parallel_size) | ||
|
||
|
||
class PromptRequest(BaseModel): | ||
prompt: str | ||
temperature: float = 1 | ||
max_tokens: int = 200 | ||
stop: List[str] = [] | ||
|
||
|
||
class ResponseModel(BaseModel): | ||
prompt: str | ||
prompt_token_ids: List # The token IDs of the prompt. | ||
outputs: List[str] # The output sequences of the request. | ||
finished: bool # Whether the whole request is finished. | ||
|
||
|
||
app = FastAPI() | ||
|
||
|
||
@app.post("/serve", response_model=ResponseModel) | ||
def serve(request: PromptRequest): | ||
sampling_params = SamplingParams( | ||
max_tokens=request.max_tokens, | ||
temperature=request.temperature, | ||
stop=request.stop, | ||
) | ||
|
||
result = llm.generate(request.prompt, sampling_params=sampling_params)[0] | ||
response = ResponseModel( | ||
prompt=request.prompt, | ||
prompt_token_ids=result.prompt_token_ids, | ||
outputs=result.outputs, | ||
finished=result.finished, | ||
) | ||
return response |