-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Showing
17 changed files
with
238 additions
and
23 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
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,8 @@ | ||
clients: | ||
- type: openai-compatible | ||
name: ktransformers | ||
api_base: http://ktransformers:12456/v1 | ||
api_key: sk-ktransformers | ||
models: | ||
- name: ${HARBOR_AICHAT_MODEL} | ||
|
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,4 @@ | ||
openai-api-base: http://ktransformers:12456/v1 | ||
openai-api-key: sk-ktransformers | ||
model: openai/${HARBOR_AIDER_MODEL} | ||
verify-ssl: false |
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,25 @@ | ||
services: | ||
ktransformers: | ||
container_name: ${HARBOR_CONTAINER_PREFIX}.ktransformers | ||
env_file: | ||
- ./.env | ||
- ./ktransformers/override.env | ||
ipc: host | ||
build: | ||
context: ./ktransformers | ||
dockerfile: Dockerfile | ||
ports: | ||
- ${HARBOR_KTRANSFORMERS_HOST_PORT}:12456 | ||
volumes: | ||
- ${HARBOR_HF_CACHE}:/root/.cache/huggingface | ||
- ${HARBOR_LLAMACPP_CACHE}:/root/.cache/llama.cpp | ||
# Monkey-patch to make compatible with Open WebUI | ||
- ./ktransformers/chat.py:/opt/conda/lib/python3.10/site-packages/ktransformers/server/api/openai/endpoints/chat.py | ||
environment: | ||
- HF_TOKEN=${HARBOR_HF_TOKEN} | ||
networks: | ||
- harbor-network | ||
command: > | ||
--model_path ${HARBOR_KTRANSFORMERS_MODEL} | ||
--gguf_path ${HARBOR_KTRANSFORMERS_GGUF} | ||
${HARBOR_KTRANSFORMERS_EXTRA_ARGS} |
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,4 @@ | ||
services: | ||
aichat: | ||
volumes: | ||
- ./aichat/configs/aichat.ktransformers.yml:/app/configs/ktransformers.yml |
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,4 @@ | ||
services: | ||
aider: | ||
volumes: | ||
- ./aider/configs/aider.ktransformers.yml:/root/.aider/ktransformers.yml |
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,9 @@ | ||
services: | ||
ktransformers: | ||
deploy: | ||
resources: | ||
reservations: | ||
devices: | ||
- driver: nvidia | ||
count: all | ||
capabilities: [gpu] |
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,4 @@ | ||
services: | ||
webui: | ||
volumes: | ||
- ./open-webui/configs/config.ktransformers.json:/app/configs/config.ktransformers.json |
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,18 @@ | ||
@host = http://localhost:34121 | ||
|
||
### | ||
|
||
curl {{host}}/v1/models | ||
|
||
### | ||
|
||
curl {{host}}/v1/chat/completions -H 'Content-Type: application/json' -H "Authorization: Bearer sk-fake" -d '{ | ||
"model": "anything", | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": "Bobby was born in Paris. How old is Bobby?" | ||
} | ||
], | ||
"max_tokens": 30 | ||
}' |
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,16 @@ | ||
# Base image for some other Harbor services, reusing | ||
ARG HARBOR_KTRANSFORMERS_IMAGE=pytorch/pytorch:2.3.1-cuda12.1-cudnn8-devel | ||
|
||
FROM ${HARBOR_KTRANSFORMERS_IMAGE} | ||
|
||
ARG HARBOR_KTRANSFORMERS_VERSION="0.1.4" | ||
ENV CUDA_HOME /usr/local/cuda | ||
|
||
WORKDIR /app | ||
RUN apt-get update && apt-get install -y git | ||
RUN pip install numpy cpufeature | ||
RUN pip install flash_attn | ||
RUN pip install https://github.com/kvcache-ai/ktransformers/releases/download/v${HARBOR_KTRANSFORMERS_VERSION}/ktransformers-${HARBOR_KTRANSFORMERS_VERSION}+cu121torch23avx2-cp310-cp310-linux_x86_64.whl --no-build-isolation | ||
RUN ldconfig /usr/local/cuda-$(echo $CUDA_VERSION | cut -d. -f1,2)/compat/ | ||
|
||
ENTRYPOINT [ "ktransformers" ] |
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,51 @@ | ||
# Monkey-patch to include "/v1/models" endpoint to make it complatible | ||
# with the Open WebUI | ||
|
||
import json | ||
from time import time | ||
from uuid import uuid4 | ||
from fastapi import APIRouter | ||
from fastapi.requests import Request | ||
from ktransformers.server.utils.create_interface import get_interface | ||
from ktransformers.server.schemas.assistants.streaming import chat_stream_response | ||
from ktransformers.server.schemas.endpoints.chat import ChatCompletionCreate,ChatCompletionChunk,ChatCompletionObject | ||
from ktransformers.server.backend.base import BackendInterfaceBase | ||
|
||
router = APIRouter() | ||
|
||
@router.get('/models', tags=['openai']) | ||
async def models(): | ||
return { | ||
"object": "list", | ||
"data": [ | ||
{ | ||
"id": "ktransformers", | ||
"object": "model", | ||
"created": 1234567890, | ||
"owned_by": "organization", | ||
"permission": [] | ||
} | ||
] | ||
} | ||
|
||
@router.post('/chat/completions',tags=['openai']) | ||
async def chat_completion(request:Request,create:ChatCompletionCreate): | ||
id = str(uuid4()) | ||
|
||
interface: BackendInterfaceBase = get_interface() | ||
# input_ids = interface.format_and_tokenize_input_ids(id,messages=create.get_tokenizer_messages()) | ||
|
||
input_message = [json.loads(m.model_dump_json()) for m in create.messages] | ||
|
||
if create.stream: | ||
async def inner(): | ||
chunk = ChatCompletionChunk(id=id,object='chat.completion.chunk',created=int(time())) | ||
async for token in interface.inference(input_message,id): | ||
chunk.set_token(token) | ||
yield chunk | ||
return chat_stream_response(request,inner()) | ||
else: | ||
comp = ChatCompletionObject(id=id,object='chat.completion.chunk',created=int(time())) | ||
async for token in interface.inference(input_message,id): | ||
comp.append_token(token) | ||
return comp |
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,2 @@ | ||
# You can provide additional | ||
# environment variables here |
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,4 @@ | ||
open-webui/configs/config.airllm.json{ | ||
{ | ||
"openai": { | ||
"api_base_urls": [ | ||
"http://airllm:5000/v1" | ||
|
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,11 @@ | ||
{ | ||
"openai": { | ||
"api_base_urls": [ | ||
"http://ktransformers:12456/v1" | ||
], | ||
"api_keys": [ | ||
"sk-ktransformers" | ||
], | ||
"enabled": true | ||
} | ||
} |
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,6 +1,6 @@ | ||
{ | ||
"name": "@av/harbor", | ||
"version": "0.1.24", | ||
"version": "0.1.25", | ||
"bin": { | ||
"harbor": "./bin/harbor" | ||
} | ||
|
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