-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from NexaAI/nexa-sdk-upgrade-llama-cpp-python…
…-new Nexa sdk upgrade
- Loading branch information
Showing
26 changed files
with
1,514 additions
and
2,254 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.0.9.5" | ||
__version__ = "0.0.9.6" |
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,2 @@ | ||
from nexa.gguf.llama.llama_cpp import * | ||
from nexa.gguf.llama.llama import * |
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,77 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
import os | ||
import ctypes | ||
import functools | ||
import pathlib | ||
|
||
from typing import ( | ||
Any, | ||
Callable, | ||
List, | ||
Union, | ||
Optional, | ||
TYPE_CHECKING, | ||
TypeVar, | ||
Generic, | ||
) | ||
from typing_extensions import TypeAlias | ||
|
||
|
||
# ctypes sane type hint helpers | ||
# | ||
# - Generic Pointer and Array types | ||
# - PointerOrRef type with a type hinted byref function | ||
# | ||
# NOTE: Only use these for static type checking not for runtime checks | ||
# no good will come of that | ||
|
||
if TYPE_CHECKING: | ||
CtypesCData = TypeVar("CtypesCData", bound=ctypes._CData) # type: ignore | ||
|
||
CtypesArray: TypeAlias = ctypes.Array[CtypesCData] # type: ignore | ||
|
||
CtypesPointer: TypeAlias = ctypes._Pointer[CtypesCData] # type: ignore | ||
|
||
CtypesVoidPointer: TypeAlias = ctypes.c_void_p | ||
|
||
class CtypesRef(Generic[CtypesCData]): | ||
pass | ||
|
||
CtypesPointerOrRef: TypeAlias = Union[ | ||
CtypesPointer[CtypesCData], CtypesRef[CtypesCData] | ||
] | ||
|
||
CtypesFuncPointer: TypeAlias = ctypes._FuncPointer # type: ignore | ||
|
||
F = TypeVar("F", bound=Callable[..., Any]) | ||
|
||
|
||
def ctypes_function_for_shared_library(lib: ctypes.CDLL): | ||
"""Decorator for defining ctypes functions with type hints""" | ||
|
||
def ctypes_function( | ||
name: str, argtypes: List[Any], restype: Any, enabled: bool = True | ||
): | ||
def decorator(f: F) -> F: | ||
if enabled: | ||
func = getattr(lib, name) | ||
func.argtypes = argtypes | ||
func.restype = restype | ||
functools.wraps(f)(func) | ||
return func | ||
else: | ||
return f | ||
|
||
return decorator | ||
|
||
return ctypes_function | ||
|
||
|
||
def _byref(obj: CtypesCData, offset: Optional[int] = None) -> CtypesRef[CtypesCData]: | ||
"""Type-annotated version of ctypes.byref""" | ||
... | ||
|
||
|
||
byref = _byref if TYPE_CHECKING else ctypes.byref |
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 @@ | ||
"""Internal module use at your own risk | ||
This module provides a minimal interface for working with ggml tensors from llama-cpp-python | ||
""" | ||
import os | ||
import pathlib | ||
|
||
from nexa.gguf.lib_utils import load_library | ||
|
||
libggml = load_library("ggml") | ||
|
Oops, something went wrong.