forked from abetlen/llama-cpp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'ai_service' parameter to differentiate Prometheus metrics #2
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d9233fc
Launch local llama_cpp server running on zh-service-network
a66c267
Integrates 'ai_service' parameter with the backend
50d5f2b
Allows time_to_first_token to be None
33c022f
ZenHubHQ/devops#2233 - Modified tests to accomodate 'ai_service' para…
b99dbf8
Using correct typing object Tuple
d39c7d9
Removing previous function to detect ai-service based off system message
4b476b9
Removed infer_service_from_prompt from imports
7ea1675
Changes value of 'ai_service' in the unit tests
bfefa26
Added simple test to check health of metrics endpoint
67ae74a
Fixed bug of llama metrics not collecting during streaming
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@ | ||
# Define the image argument and provide a default value | ||
ARG IMAGE=python:3.11.8 | ||
|
||
# Use the image as specified | ||
FROM ${IMAGE} | ||
|
||
# Re-declare the ARG after FROM | ||
ARG IMAGE | ||
|
||
# Update and upgrade the existing packages | ||
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \ | ||
python3 \ | ||
python3-pip \ | ||
ninja-build \ | ||
libopenblas-dev \ | ||
build-essential \ | ||
git | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
COPY . /app | ||
|
||
RUN python3 -m pip install --upgrade pip | ||
|
||
RUN make deps && make build && make clean | ||
|
||
# Set environment variable for the host | ||
ENV GH_TOKEN=$GH_TOKEN | ||
ENV HOST=0.0.0.0 | ||
ENV PORT=8000 | ||
ENV MODEL=/app/models/mistral-7b-openorca.Q5_K_M.gguf | ||
|
||
# # Install depencencies | ||
# RUN python3 -m pip install --upgrade pip pytest cmake scikit-build setuptools fastapi uvicorn sse-starlette pydantic-settings starlette-context psutil prometheus_client | ||
|
||
# # Install llama-cpp-python (build with METAL) | ||
# RUN CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 pip install git+https://${GH_TOKEN}@github.com/ZenHubHQ/llama-cpp-python.git --force-reinstall --upgrade --no-cache-dir --verbose | ||
|
||
# Expose a port for the server | ||
EXPOSE 8000 | ||
|
||
# Run the server start script | ||
CMD ["/bin/sh", "/app/docker/simple/run.sh"] | ||
# CMD python3 -m llama_cpp.server --n_gpu_layers -1 |
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,15 @@ | ||
version: '3' | ||
services: | ||
dev-llama-cpp-python: | ||
build: | ||
context: . | ||
dockerfile: dev.Dockerfile | ||
ports: | ||
- 8000:8000 | ||
volumes: | ||
- ./llama_cpp:/app/llama_cpp | ||
networks: | ||
- zh-service-network | ||
networks: | ||
zh-service-network: | ||
external: 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,4 +1,5 @@ | ||
#!/bin/bash | ||
|
||
make build | ||
uvicorn --factory llama_cpp.server.app:create_app --host $HOST --port $PORT | ||
# uvicorn --factory llama_cpp.server.app:create_app --host $HOST --port $PORT --reload | ||
python3 -m llama_cpp.server --model $MODEL --n_gpu_layers -1 |
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
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 |
---|---|---|
|
@@ -153,7 +153,9 @@ def mock_kv_cache_seq_add( | |
|
||
def test_llama_patch(mock_llama): | ||
n_ctx = 128 | ||
ai_service = "testing" | ||
llama = llama_cpp.Llama(model_path=MODEL, vocab_only=True, n_ctx=n_ctx) | ||
|
||
n_vocab = llama_cpp.llama_n_vocab(llama._model.model) | ||
assert n_vocab == 32000 | ||
|
||
|
@@ -163,32 +165,32 @@ def test_llama_patch(mock_llama): | |
|
||
## Test basic completion from bos until eos | ||
mock_llama(llama, all_text) | ||
completion = llama.create_completion("", max_tokens=36) | ||
completion = llama.create_completion("", max_tokens=36, ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == all_text | ||
assert completion["choices"][0]["finish_reason"] == "stop" | ||
|
||
## Test basic completion until eos | ||
mock_llama(llama, all_text) | ||
completion = llama.create_completion(text, max_tokens=20) | ||
completion = llama.create_completion(text, max_tokens=20, ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == output_text | ||
assert completion["choices"][0]["finish_reason"] == "stop" | ||
|
||
## Test streaming completion until eos | ||
mock_llama(llama, all_text) | ||
chunks = list(llama.create_completion(text, max_tokens=20, stream=True)) | ||
chunks = list(llama.create_completion(text, max_tokens=20, stream=True, ai_service=ai_service)) | ||
assert "".join(chunk["choices"][0]["text"] for chunk in chunks) == output_text | ||
assert chunks[-1]["choices"][0]["finish_reason"] == "stop" | ||
|
||
## Test basic completion until stop sequence | ||
mock_llama(llama, all_text) | ||
completion = llama.create_completion(text, max_tokens=20, stop=["lazy"]) | ||
completion = llama.create_completion(text, max_tokens=20, stop=["lazy"], ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == " jumps over the " | ||
assert completion["choices"][0]["finish_reason"] == "stop" | ||
|
||
## Test streaming completion until stop sequence | ||
mock_llama(llama, all_text) | ||
chunks = list( | ||
llama.create_completion(text, max_tokens=20, stream=True, stop=["lazy"]) | ||
llama.create_completion(text, max_tokens=20, stream=True, stop=["lazy"], ai_service=ai_service) | ||
) | ||
assert ( | ||
"".join(chunk["choices"][0]["text"] for chunk in chunks) == " jumps over the " | ||
|
@@ -197,13 +199,13 @@ def test_llama_patch(mock_llama): | |
|
||
## Test basic completion until length | ||
mock_llama(llama, all_text) | ||
completion = llama.create_completion(text, max_tokens=2) | ||
completion = llama.create_completion(text, max_tokens=2, ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == " jumps" | ||
assert completion["choices"][0]["finish_reason"] == "length" | ||
|
||
## Test streaming completion until length | ||
mock_llama(llama, all_text) | ||
chunks = list(llama.create_completion(text, max_tokens=2, stream=True)) | ||
chunks = list(llama.create_completion(text, max_tokens=2, stream=True, ai_service=ai_service)) | ||
assert "".join(chunk["choices"][0]["text"] for chunk in chunks) == " jumps" | ||
assert chunks[-1]["choices"][0]["finish_reason"] == "length" | ||
|
||
|
@@ -230,15 +232,16 @@ def test_utf8(mock_llama): | |
llama = llama_cpp.Llama(model_path=MODEL, vocab_only=True, logits_all=True) | ||
|
||
output_text = "😀" | ||
ai_service = "testing" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intended for the final PR? |
||
|
||
## Test basic completion with utf8 multibyte | ||
mock_llama(llama, output_text) | ||
completion = llama.create_completion("", max_tokens=4) | ||
completion = llama.create_completion("", max_tokens=4, ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == output_text | ||
|
||
## Test basic completion with incomplete utf8 multibyte | ||
mock_llama(llama, output_text) | ||
completion = llama.create_completion("", max_tokens=1) | ||
completion = llama.create_completion("", max_tokens=1, ai_service=ai_service) | ||
assert completion["choices"][0]["text"] == "" | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended for the final PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Cam. Changing this to a more meaningful value.