Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .scripts/build_steps.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions .scripts/run_osx_build.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .scripts/run_win_build.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions conda-forge.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build_platform:
osx_arm64: osx_64
conda_build_tool: rattler-build
conda_build:
error_overlinking: true
conda_forge_output_validation: true
Expand Down
80 changes: 0 additions & 80 deletions recipe/meta.yaml

This file was deleted.

98 changes: 98 additions & 0 deletions recipe/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
schema_version: 1

context:
name: llama-cpp-python
version: "0.3.32"
# NOTE: VERIFY llama_cpp_version before merging!
llama_cpp_version: "9851"

package:
name: ${{ name|lower }}
version: ${{ version }}

source:
url: https://pypi.org/packages/source/${{ name[0] }}/${{ name }}/llama_cpp_python-${{ version }}.tar.gz
sha256: b06502361770f82eb08b7f1a192eb084b9ead2b88fe32cda8c397a2782eabde6
patches:
# Asks cdll to look for the library in the path as well.
- 0001-Adapt-shared-library-relocation.patch

build:
number: 1
script:
- if: win
then:
- set "CMAKE_ARGS=%CMAKE_ARGS% -DLLAMA_BUILD=OFF -DLLAVA_BUILD=OFF"
- ${{ PYTHON }} -m pip install . -vv
else:
- export CMAKE_ARGS="${CMAKE_ARGS} -DLLAMA_BUILD=OFF -DLLAVA_BUILD=OFF"
- ${{ PYTHON }} -m pip install . -vv

requirements:
build:
- if: build_platform != target_platform
then:
- python
- cross-python_${{ target_platform }}
- ${{ compiler('c') }}
- ${{ stdlib('c') }}
- ${{ compiler('cxx') }}
- cmake
- make
- pkgconfig
host:
- python
- scikit-build-core >=0.5.1
- pip
run:
- python
- typing-extensions >=4.5.0
- numpy >=1.20.0
- diskcache >=5.6.1
- pyyaml >=5.1
- llama.cpp ==${{ llama_cpp_version }}
# Split into llama-cpp-python-server
- uvicorn >=0.22.0
- fastapi >=0.100.0
- pydantic-settings >=2.0.1
- sse-starlette >=1.6.1
- starlette-context >=0.3.6,<0.4

tests:
- python:
imports:
- llama_cpp
pip_check: true
- script:
# Exercises the bindings and calls into libllama.
- python test.py
# Downloads a tiny GGUF model and runs a full load/tokenize/inference/embed check.
- if: win
then:
- curl.exe -L --retry 3 -o tinystories.gguf https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf
else:
- curl -L --retry 3 -o tinystories.gguf https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf
- python test_gguf.py tinystories.gguf
requirements:
run:
- curl
files:
recipe:
- test.py
- test_gguf.py

about:
homepage: https://github.com/abetlen/llama-cpp-python
summary: Python bindings for the llama.cpp library
license: MIT
license_file:
- LICENSE.md

extra:
recipe-maintainers:
- JohanMabille
- jjerphan
- jonashaag
- YYYasin19
- sodre
- toniher
4 changes: 4 additions & 0 deletions recipe/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import llama_cpp
print(llama_cpp.__version__)
print(llama_cpp.llama_backend_init()) # calls into libllama
llama_cpp.llama_backend_free()
51 changes: 51 additions & 0 deletions recipe/test_gguf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import sys
import time

def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <path/to/model.gguf>", file=sys.stderr)
sys.exit(1)

model_path = sys.argv[1]

print("1. Importing llama_cpp ...", end=" ", flush=True)
from llama_cpp import Llama
print("OK")

print(f"2. Loading model: {model_path} ...", end=" ", flush=True)
t0 = time.time()
llm = Llama(model_path=model_path, n_ctx=512, verbose=False)
print(f"OK ({time.time() - t0:.1f}s)")

print("3. Tokenization ...", end=" ", flush=True)
tokens = llm.tokenize(b"Hello, world!")
assert len(tokens) > 0
print(f"OK ({len(tokens)} tokens)")

print("4. Inference ...", end=" ", flush=True)
t0 = time.time()
output = llm(
"Q: What is the capital of France? A:",
max_tokens=16,
stop=["Q:", "\n"],
echo=False,
)
elapsed = time.time() - t0
text = output["choices"][0]["text"].strip()
print(f"OK ({elapsed:.1f}s)")
print(f" Response: {text!r}")

print("5. Embedding ...", end=" ", flush=True)
try:
emb_llm = Llama(model_path=model_path, embedding=True, n_ctx=64, verbose=False)
vec = emb_llm.embed("test sentence")
assert len(vec) > 0
print(f"OK (dim={len(vec)})")
except Exception as e:
print(f"SKIP ({e})")

print("\nAll checks passed.")

if __name__ == "__main__":
main()
Loading