nexaai 1.0.21rc5__cp313-cp313-win_arm64.whl → 1.0.21rc16__cp313-cp313-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nexaai might be problematic. Click here for more details.
- nexaai/__init__.py +95 -95
- nexaai/_stub.cp313-win_arm64.pyd +0 -0
- nexaai/_version.py +4 -1
- nexaai/asr.py +68 -65
- nexaai/asr_impl/mlx_asr_impl.py +92 -92
- nexaai/asr_impl/pybind_asr_impl.py +127 -44
- nexaai/base.py +39 -39
- nexaai/binds/__init__.py +6 -5
- nexaai/binds/asr_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/common_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/cpu_gpu/ggml-base.dll +0 -0
- nexaai/binds/cpu_gpu/ggml-cpu.dll +0 -0
- nexaai/binds/cpu_gpu/ggml-opencl.dll +0 -0
- nexaai/binds/cpu_gpu/ggml.dll +0 -0
- nexaai/binds/cpu_gpu/mtmd.dll +0 -0
- nexaai/binds/cpu_gpu/nexa_cpu_gpu.dll +0 -0
- nexaai/binds/cpu_gpu/nexa_plugin.dll +0 -0
- nexaai/binds/embedder_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/libcrypto-3-arm64.dll +0 -0
- nexaai/binds/libssl-3-arm64.dll +0 -0
- nexaai/binds/llm_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/nexa_bridge.dll +0 -0
- nexaai/binds/npu/convnext-sdk.dll +0 -0
- nexaai/binds/npu/embed-gemma-sdk.dll +0 -0
- nexaai/binds/npu/ggml-base.dll +0 -0
- nexaai/binds/npu/ggml-cpu.dll +0 -0
- nexaai/binds/{nexaml → npu}/ggml-opencl.dll +0 -0
- nexaai/binds/npu/ggml.dll +0 -0
- nexaai/binds/npu/granite-nano-sdk.dll +0 -0
- nexaai/binds/npu/granite4-sdk.dll +0 -0
- nexaai/binds/npu/jina-rerank-sdk.dll +0 -0
- nexaai/binds/npu/liquid-sdk.dll +0 -0
- nexaai/binds/npu/llama3-3b-sdk.dll +0 -0
- nexaai/binds/npu/nexa-mm-process.dll +0 -0
- nexaai/binds/npu/nexa-sampling.dll +0 -0
- nexaai/binds/npu/nexa_plugin.dll +0 -0
- nexaai/binds/npu/omni-neural-sdk.dll +0 -0
- nexaai/binds/npu/openblas.dll +0 -0
- nexaai/binds/npu/paddleocr-sdk.dll +0 -0
- nexaai/binds/npu/parakeet-sdk.dll +0 -0
- nexaai/binds/npu/phi3-5-sdk.dll +0 -0
- nexaai/binds/npu/phi4-sdk.dll +0 -0
- nexaai/binds/npu/pyannote-sdk.dll +0 -0
- nexaai/binds/npu/qwen3-4b-sdk.dll +0 -0
- nexaai/binds/npu/qwen3vl-sdk.dll +0 -0
- nexaai/binds/npu/qwen3vl-vision.dll +0 -0
- nexaai/binds/npu/yolov12-sdk.dll +0 -0
- nexaai/binds/npu/zlib1.dll +0 -0
- nexaai/binds/rerank_bind.cp313-win_arm64.pyd +0 -0
- nexaai/binds/vlm_bind.cp313-win_arm64.pyd +0 -0
- nexaai/common.py +105 -105
- nexaai/cv.py +93 -93
- nexaai/cv_impl/mlx_cv_impl.py +89 -89
- nexaai/cv_impl/pybind_cv_impl.py +32 -32
- nexaai/embedder.py +73 -73
- nexaai/embedder_impl/mlx_embedder_impl.py +118 -118
- nexaai/embedder_impl/pybind_embedder_impl.py +96 -96
- nexaai/image_gen.py +141 -141
- nexaai/image_gen_impl/mlx_image_gen_impl.py +292 -292
- nexaai/image_gen_impl/pybind_image_gen_impl.py +85 -85
- nexaai/llm.py +98 -98
- nexaai/llm_impl/mlx_llm_impl.py +271 -271
- nexaai/llm_impl/pybind_llm_impl.py +220 -220
- nexaai/log.py +92 -92
- nexaai/rerank.py +57 -57
- nexaai/rerank_impl/mlx_rerank_impl.py +94 -94
- nexaai/rerank_impl/pybind_rerank_impl.py +136 -136
- nexaai/runtime.py +68 -68
- nexaai/runtime_error.py +24 -24
- nexaai/tts.py +75 -75
- nexaai/tts_impl/mlx_tts_impl.py +94 -94
- nexaai/tts_impl/pybind_tts_impl.py +43 -43
- nexaai/utils/decode.py +17 -17
- nexaai/utils/manifest_utils.py +531 -531
- nexaai/utils/model_manager.py +1562 -1562
- nexaai/utils/model_types.py +49 -49
- nexaai/utils/progress_tracker.py +384 -384
- nexaai/utils/quantization_utils.py +245 -245
- nexaai/vlm.py +129 -129
- nexaai/vlm_impl/mlx_vlm_impl.py +258 -258
- nexaai/vlm_impl/pybind_vlm_impl.py +256 -256
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/METADATA +1 -1
- nexaai-1.0.21rc16.dist-info/RECORD +154 -0
- nexaai/binds/nexaml/FLAC.dll +0 -0
- nexaai/binds/nexaml/fftw3.dll +0 -0
- nexaai/binds/nexaml/fftw3f.dll +0 -0
- nexaai/binds/nexaml/ggml-base.dll +0 -0
- nexaai/binds/nexaml/ggml-cpu.dll +0 -0
- nexaai/binds/nexaml/ggml.dll +0 -0
- nexaai/binds/nexaml/libmp3lame.DLL +0 -0
- nexaai/binds/nexaml/mpg123.dll +0 -0
- nexaai/binds/nexaml/nexa-mm-process.dll +0 -0
- nexaai/binds/nexaml/nexa-sampling.dll +0 -0
- nexaai/binds/nexaml/nexa_plugin.dll +0 -0
- nexaai/binds/nexaml/nexaproc.dll +0 -0
- nexaai/binds/nexaml/ogg.dll +0 -0
- nexaai/binds/nexaml/opus.dll +0 -0
- nexaai/binds/nexaml/qwen3-vl.dll +0 -0
- nexaai/binds/nexaml/qwen3vl-vision.dll +0 -0
- nexaai/binds/nexaml/vorbis.dll +0 -0
- nexaai/binds/nexaml/vorbisenc.dll +0 -0
- nexaai-1.0.21rc5.dist-info/RECORD +0 -162
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/WHEEL +0 -0
- {nexaai-1.0.21rc5.dist-info → nexaai-1.0.21rc16.dist-info}/top_level.txt +0 -0
nexaai/cv.py
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
from typing import List, Optional, Union
|
|
2
|
-
from abc import abstractmethod
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
|
|
5
|
-
from nexaai.base import BaseModel
|
|
6
|
-
from nexaai.common import PluginID
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclass
|
|
10
|
-
class BoundingBox:
|
|
11
|
-
"""Generic bounding box structure."""
|
|
12
|
-
x: float # X coordinate (normalized or pixel, depends on model)
|
|
13
|
-
y: float # Y coordinate (normalized or pixel, depends on model)
|
|
14
|
-
width: float # Width
|
|
15
|
-
height: float # Height
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@dataclass
|
|
19
|
-
class CVResult:
|
|
20
|
-
"""Generic detection/classification result."""
|
|
21
|
-
image_paths: Optional[List[str]] = None # Output image paths
|
|
22
|
-
image_count: int = 0 # Number of output images
|
|
23
|
-
class_id: int = 0 # Class ID (example: ConvNext)
|
|
24
|
-
confidence: float = 0.0 # Confidence score [0.0-1.0]
|
|
25
|
-
bbox: Optional[BoundingBox] = None # Bounding box (example: YOLO)
|
|
26
|
-
text: Optional[str] = None # Text result (example: OCR)
|
|
27
|
-
embedding: Optional[List[float]] = None # Feature embedding (example: CLIP embedding)
|
|
28
|
-
embedding_dim: int = 0 # Embedding dimension
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@dataclass
|
|
32
|
-
class CVResults:
|
|
33
|
-
"""Generic CV inference result."""
|
|
34
|
-
results: List[CVResult] # Array of CV results
|
|
35
|
-
result_count: int # Number of CV results
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class CVCapabilities:
|
|
39
|
-
"""CV capabilities enum."""
|
|
40
|
-
OCR = 0 # OCR
|
|
41
|
-
CLASSIFICATION = 1 # Classification
|
|
42
|
-
SEGMENTATION = 2 # Segmentation
|
|
43
|
-
CUSTOM = 3 # Custom task
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@dataclass
|
|
47
|
-
class CVModelConfig:
|
|
48
|
-
"""CV model preprocessing configuration."""
|
|
49
|
-
capabilities: int # CVCapabilities
|
|
50
|
-
|
|
51
|
-
# MLX-OCR
|
|
52
|
-
det_model_path: Optional[str] = None # Detection model path
|
|
53
|
-
rec_model_path: Optional[str] = None # Recognition model path
|
|
54
|
-
|
|
55
|
-
# QNN
|
|
56
|
-
model_path: Optional[str] = None # Model path
|
|
57
|
-
system_library_path: Optional[str] = None # System library path
|
|
58
|
-
backend_library_path: Optional[str] = None # Backend library path
|
|
59
|
-
extension_library_path: Optional[str] = None # Extension library path
|
|
60
|
-
config_file_path: Optional[str] = None # Config file path
|
|
61
|
-
char_dict_path: Optional[str] = None # Character dictionary path
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class CVModel(BaseModel):
|
|
65
|
-
"""Abstract base class for generic computer vision models."""
|
|
66
|
-
|
|
67
|
-
def __init__(self):
|
|
68
|
-
"""Initialize base CV model class."""
|
|
69
|
-
pass
|
|
70
|
-
|
|
71
|
-
@classmethod
|
|
72
|
-
def _load_from(cls,
|
|
73
|
-
_: str, # TODO: remove this argument, this is a hack to make api design happy
|
|
74
|
-
config: CVModelConfig,
|
|
75
|
-
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
76
|
-
device_id: Optional[str] = None,
|
|
77
|
-
**kwargs
|
|
78
|
-
) -> 'CVModel':
|
|
79
|
-
"""Load CV model from configuration, routing to appropriate implementation."""
|
|
80
|
-
# Check plugin_id value for routing - handle both enum and string
|
|
81
|
-
plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
|
|
82
|
-
|
|
83
|
-
if plugin_value == "mlx":
|
|
84
|
-
from nexaai.cv_impl.mlx_cv_impl import MLXCVImpl
|
|
85
|
-
return MLXCVImpl._load_from(config, plugin_id, device_id)
|
|
86
|
-
else:
|
|
87
|
-
from nexaai.cv_impl.pybind_cv_impl import PyBindCVImpl
|
|
88
|
-
return PyBindCVImpl._load_from(config, plugin_id, device_id)
|
|
89
|
-
|
|
90
|
-
@abstractmethod
|
|
91
|
-
def infer(self, input_image_path: str) -> CVResults:
|
|
92
|
-
"""Perform inference on image."""
|
|
93
|
-
pass
|
|
1
|
+
from typing import List, Optional, Union
|
|
2
|
+
from abc import abstractmethod
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from nexaai.base import BaseModel
|
|
6
|
+
from nexaai.common import PluginID
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class BoundingBox:
|
|
11
|
+
"""Generic bounding box structure."""
|
|
12
|
+
x: float # X coordinate (normalized or pixel, depends on model)
|
|
13
|
+
y: float # Y coordinate (normalized or pixel, depends on model)
|
|
14
|
+
width: float # Width
|
|
15
|
+
height: float # Height
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class CVResult:
|
|
20
|
+
"""Generic detection/classification result."""
|
|
21
|
+
image_paths: Optional[List[str]] = None # Output image paths
|
|
22
|
+
image_count: int = 0 # Number of output images
|
|
23
|
+
class_id: int = 0 # Class ID (example: ConvNext)
|
|
24
|
+
confidence: float = 0.0 # Confidence score [0.0-1.0]
|
|
25
|
+
bbox: Optional[BoundingBox] = None # Bounding box (example: YOLO)
|
|
26
|
+
text: Optional[str] = None # Text result (example: OCR)
|
|
27
|
+
embedding: Optional[List[float]] = None # Feature embedding (example: CLIP embedding)
|
|
28
|
+
embedding_dim: int = 0 # Embedding dimension
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class CVResults:
|
|
33
|
+
"""Generic CV inference result."""
|
|
34
|
+
results: List[CVResult] # Array of CV results
|
|
35
|
+
result_count: int # Number of CV results
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class CVCapabilities:
|
|
39
|
+
"""CV capabilities enum."""
|
|
40
|
+
OCR = 0 # OCR
|
|
41
|
+
CLASSIFICATION = 1 # Classification
|
|
42
|
+
SEGMENTATION = 2 # Segmentation
|
|
43
|
+
CUSTOM = 3 # Custom task
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class CVModelConfig:
|
|
48
|
+
"""CV model preprocessing configuration."""
|
|
49
|
+
capabilities: int # CVCapabilities
|
|
50
|
+
|
|
51
|
+
# MLX-OCR
|
|
52
|
+
det_model_path: Optional[str] = None # Detection model path
|
|
53
|
+
rec_model_path: Optional[str] = None # Recognition model path
|
|
54
|
+
|
|
55
|
+
# QNN
|
|
56
|
+
model_path: Optional[str] = None # Model path
|
|
57
|
+
system_library_path: Optional[str] = None # System library path
|
|
58
|
+
backend_library_path: Optional[str] = None # Backend library path
|
|
59
|
+
extension_library_path: Optional[str] = None # Extension library path
|
|
60
|
+
config_file_path: Optional[str] = None # Config file path
|
|
61
|
+
char_dict_path: Optional[str] = None # Character dictionary path
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class CVModel(BaseModel):
|
|
65
|
+
"""Abstract base class for generic computer vision models."""
|
|
66
|
+
|
|
67
|
+
def __init__(self):
|
|
68
|
+
"""Initialize base CV model class."""
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def _load_from(cls,
|
|
73
|
+
_: str, # TODO: remove this argument, this is a hack to make api design happy
|
|
74
|
+
config: CVModelConfig,
|
|
75
|
+
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
76
|
+
device_id: Optional[str] = None,
|
|
77
|
+
**kwargs
|
|
78
|
+
) -> 'CVModel':
|
|
79
|
+
"""Load CV model from configuration, routing to appropriate implementation."""
|
|
80
|
+
# Check plugin_id value for routing - handle both enum and string
|
|
81
|
+
plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
|
|
82
|
+
|
|
83
|
+
if plugin_value == "mlx":
|
|
84
|
+
from nexaai.cv_impl.mlx_cv_impl import MLXCVImpl
|
|
85
|
+
return MLXCVImpl._load_from(config, plugin_id, device_id)
|
|
86
|
+
else:
|
|
87
|
+
from nexaai.cv_impl.pybind_cv_impl import PyBindCVImpl
|
|
88
|
+
return PyBindCVImpl._load_from(config, plugin_id, device_id)
|
|
89
|
+
|
|
90
|
+
@abstractmethod
|
|
91
|
+
def infer(self, input_image_path: str) -> CVResults:
|
|
92
|
+
"""Perform inference on image."""
|
|
93
|
+
pass
|
nexaai/cv_impl/mlx_cv_impl.py
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
# Note: This code is generated by Cursor, not tested yet.
|
|
2
|
-
|
|
3
|
-
from typing import Optional, Union
|
|
4
|
-
import os
|
|
5
|
-
|
|
6
|
-
from nexaai.common import PluginID
|
|
7
|
-
from nexaai.cv import CVModel, CVModelConfig, CVResults
|
|
8
|
-
from nexaai.mlx_backend.cv.interface import CVModel as MLXCVInterface, create_cv_model
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class MLXCVImpl(CVModel):
|
|
12
|
-
def __init__(self):
|
|
13
|
-
"""Initialize MLX CV implementation."""
|
|
14
|
-
super().__init__()
|
|
15
|
-
self._mlx_cv = None
|
|
16
|
-
|
|
17
|
-
@classmethod
|
|
18
|
-
def _load_from(cls,
|
|
19
|
-
config: CVModelConfig,
|
|
20
|
-
plugin_id: Union[PluginID, str] = PluginID.MLX,
|
|
21
|
-
device_id: Optional[str] = None
|
|
22
|
-
) -> 'MLXCVImpl':
|
|
23
|
-
"""Load CV model from configuration using MLX backend."""
|
|
24
|
-
try:
|
|
25
|
-
# Get MLX config class
|
|
26
|
-
from nexaai.mlx_backend.ml import CVModelConfig as MLXCVModelConfig
|
|
27
|
-
|
|
28
|
-
# Convert our config to MLX format
|
|
29
|
-
mlx_config = MLXCVModelConfig(
|
|
30
|
-
capabilities=config.capabilities,
|
|
31
|
-
det_model_path=config.det_model_path,
|
|
32
|
-
rec_model_path=config.rec_model_path,
|
|
33
|
-
model_path=config.model_path,
|
|
34
|
-
system_library_path=config.system_library_path,
|
|
35
|
-
backend_library_path=config.backend_library_path,
|
|
36
|
-
extension_library_path=config.extension_library_path,
|
|
37
|
-
config_file_path=config.config_file_path,
|
|
38
|
-
char_dict_path=config.char_dict_path
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
# Create instance and load MLX CV model
|
|
42
|
-
instance = cls()
|
|
43
|
-
instance._mlx_cv = create_cv_model(mlx_config, device_id)
|
|
44
|
-
|
|
45
|
-
return instance
|
|
46
|
-
except Exception as e:
|
|
47
|
-
raise RuntimeError(f"Failed to load MLX CV: {str(e)}")
|
|
48
|
-
|
|
49
|
-
def eject(self):
|
|
50
|
-
"""Destroy the model and free resources."""
|
|
51
|
-
if self._mlx_cv:
|
|
52
|
-
self._mlx_cv.destroy()
|
|
53
|
-
self._mlx_cv = None
|
|
54
|
-
|
|
55
|
-
def infer(self, input_image_path: str) -> CVResults:
|
|
56
|
-
"""Perform inference on image."""
|
|
57
|
-
if not self._mlx_cv:
|
|
58
|
-
raise RuntimeError("MLX CV not loaded")
|
|
59
|
-
|
|
60
|
-
try:
|
|
61
|
-
# Use MLX CV inference
|
|
62
|
-
result = self._mlx_cv.infer(input_image_path)
|
|
63
|
-
|
|
64
|
-
# Convert MLX result to our format
|
|
65
|
-
from nexaai.cv import CVResult
|
|
66
|
-
|
|
67
|
-
our_results = []
|
|
68
|
-
for mlx_result in result.results:
|
|
69
|
-
our_result = CVResult(
|
|
70
|
-
image_paths=mlx_result.image_paths,
|
|
71
|
-
image_count=mlx_result.image_count,
|
|
72
|
-
class_id=mlx_result.class_id,
|
|
73
|
-
confidence=mlx_result.confidence,
|
|
74
|
-
bbox=mlx_result.bbox,
|
|
75
|
-
text=mlx_result.text,
|
|
76
|
-
embedding=mlx_result.embedding,
|
|
77
|
-
embedding_dim=mlx_result.embedding_dim
|
|
78
|
-
)
|
|
79
|
-
our_results.append(our_result)
|
|
80
|
-
|
|
81
|
-
return CVResults(
|
|
82
|
-
results=our_results,
|
|
83
|
-
result_count=result.result_count
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
except Exception as e:
|
|
87
|
-
raise RuntimeError(f"Failed to perform CV inference: {str(e)}")
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
# Note: This code is generated by Cursor, not tested yet.
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Union
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from nexaai.common import PluginID
|
|
7
|
+
from nexaai.cv import CVModel, CVModelConfig, CVResults
|
|
8
|
+
from nexaai.mlx_backend.cv.interface import CVModel as MLXCVInterface, create_cv_model
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MLXCVImpl(CVModel):
|
|
12
|
+
def __init__(self):
|
|
13
|
+
"""Initialize MLX CV implementation."""
|
|
14
|
+
super().__init__()
|
|
15
|
+
self._mlx_cv = None
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def _load_from(cls,
|
|
19
|
+
config: CVModelConfig,
|
|
20
|
+
plugin_id: Union[PluginID, str] = PluginID.MLX,
|
|
21
|
+
device_id: Optional[str] = None
|
|
22
|
+
) -> 'MLXCVImpl':
|
|
23
|
+
"""Load CV model from configuration using MLX backend."""
|
|
24
|
+
try:
|
|
25
|
+
# Get MLX config class
|
|
26
|
+
from nexaai.mlx_backend.ml import CVModelConfig as MLXCVModelConfig
|
|
27
|
+
|
|
28
|
+
# Convert our config to MLX format
|
|
29
|
+
mlx_config = MLXCVModelConfig(
|
|
30
|
+
capabilities=config.capabilities,
|
|
31
|
+
det_model_path=config.det_model_path,
|
|
32
|
+
rec_model_path=config.rec_model_path,
|
|
33
|
+
model_path=config.model_path,
|
|
34
|
+
system_library_path=config.system_library_path,
|
|
35
|
+
backend_library_path=config.backend_library_path,
|
|
36
|
+
extension_library_path=config.extension_library_path,
|
|
37
|
+
config_file_path=config.config_file_path,
|
|
38
|
+
char_dict_path=config.char_dict_path
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Create instance and load MLX CV model
|
|
42
|
+
instance = cls()
|
|
43
|
+
instance._mlx_cv = create_cv_model(mlx_config, device_id)
|
|
44
|
+
|
|
45
|
+
return instance
|
|
46
|
+
except Exception as e:
|
|
47
|
+
raise RuntimeError(f"Failed to load MLX CV: {str(e)}")
|
|
48
|
+
|
|
49
|
+
def eject(self):
|
|
50
|
+
"""Destroy the model and free resources."""
|
|
51
|
+
if self._mlx_cv:
|
|
52
|
+
self._mlx_cv.destroy()
|
|
53
|
+
self._mlx_cv = None
|
|
54
|
+
|
|
55
|
+
def infer(self, input_image_path: str) -> CVResults:
|
|
56
|
+
"""Perform inference on image."""
|
|
57
|
+
if not self._mlx_cv:
|
|
58
|
+
raise RuntimeError("MLX CV not loaded")
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
# Use MLX CV inference
|
|
62
|
+
result = self._mlx_cv.infer(input_image_path)
|
|
63
|
+
|
|
64
|
+
# Convert MLX result to our format
|
|
65
|
+
from nexaai.cv import CVResult
|
|
66
|
+
|
|
67
|
+
our_results = []
|
|
68
|
+
for mlx_result in result.results:
|
|
69
|
+
our_result = CVResult(
|
|
70
|
+
image_paths=mlx_result.image_paths,
|
|
71
|
+
image_count=mlx_result.image_count,
|
|
72
|
+
class_id=mlx_result.class_id,
|
|
73
|
+
confidence=mlx_result.confidence,
|
|
74
|
+
bbox=mlx_result.bbox,
|
|
75
|
+
text=mlx_result.text,
|
|
76
|
+
embedding=mlx_result.embedding,
|
|
77
|
+
embedding_dim=mlx_result.embedding_dim
|
|
78
|
+
)
|
|
79
|
+
our_results.append(our_result)
|
|
80
|
+
|
|
81
|
+
return CVResults(
|
|
82
|
+
results=our_results,
|
|
83
|
+
result_count=result.result_count
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
except Exception as e:
|
|
87
|
+
raise RuntimeError(f"Failed to perform CV inference: {str(e)}")
|
|
88
|
+
|
|
89
|
+
|
nexaai/cv_impl/pybind_cv_impl.py
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
from typing import Optional, Union
|
|
2
|
-
|
|
3
|
-
from nexaai.common import PluginID
|
|
4
|
-
from nexaai.cv import CVModel, CVModelConfig, CVResults
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class PyBindCVImpl(CVModel):
|
|
8
|
-
def __init__(self):
|
|
9
|
-
"""Initialize PyBind CV implementation."""
|
|
10
|
-
super().__init__()
|
|
11
|
-
# TODO: Add PyBind-specific initialization
|
|
12
|
-
|
|
13
|
-
@classmethod
|
|
14
|
-
def _load_from(cls,
|
|
15
|
-
config: CVModelConfig,
|
|
16
|
-
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
17
|
-
device_id: Optional[str] = None
|
|
18
|
-
) -> 'PyBindCVImpl':
|
|
19
|
-
"""Load CV model from configuration using PyBind backend."""
|
|
20
|
-
# TODO: Implement PyBind CV loading
|
|
21
|
-
instance = cls()
|
|
22
|
-
return instance
|
|
23
|
-
|
|
24
|
-
def eject(self):
|
|
25
|
-
"""Destroy the model and free resources."""
|
|
26
|
-
# TODO: Implement PyBind CV cleanup
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
def infer(self, input_image_path: str) -> CVResults:
|
|
30
|
-
"""Perform inference on image."""
|
|
31
|
-
# TODO: Implement PyBind CV inference
|
|
32
|
-
raise NotImplementedError("PyBind CV inference not yet implemented")
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
|
|
3
|
+
from nexaai.common import PluginID
|
|
4
|
+
from nexaai.cv import CVModel, CVModelConfig, CVResults
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PyBindCVImpl(CVModel):
|
|
8
|
+
def __init__(self):
|
|
9
|
+
"""Initialize PyBind CV implementation."""
|
|
10
|
+
super().__init__()
|
|
11
|
+
# TODO: Add PyBind-specific initialization
|
|
12
|
+
|
|
13
|
+
@classmethod
|
|
14
|
+
def _load_from(cls,
|
|
15
|
+
config: CVModelConfig,
|
|
16
|
+
plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP,
|
|
17
|
+
device_id: Optional[str] = None
|
|
18
|
+
) -> 'PyBindCVImpl':
|
|
19
|
+
"""Load CV model from configuration using PyBind backend."""
|
|
20
|
+
# TODO: Implement PyBind CV loading
|
|
21
|
+
instance = cls()
|
|
22
|
+
return instance
|
|
23
|
+
|
|
24
|
+
def eject(self):
|
|
25
|
+
"""Destroy the model and free resources."""
|
|
26
|
+
# TODO: Implement PyBind CV cleanup
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
def infer(self, input_image_path: str) -> CVResults:
|
|
30
|
+
"""Perform inference on image."""
|
|
31
|
+
# TODO: Implement PyBind CV inference
|
|
32
|
+
raise NotImplementedError("PyBind CV inference not yet implemented")
|
nexaai/embedder.py
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
from typing import List, Union
|
|
2
|
-
from dataclasses import dataclass
|
|
3
|
-
from abc import abstractmethod
|
|
4
|
-
import numpy as np
|
|
5
|
-
|
|
6
|
-
from nexaai.base import BaseModel
|
|
7
|
-
from nexaai.common import PluginID
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class EmbeddingConfig:
|
|
12
|
-
batch_size: int = 32
|
|
13
|
-
normalize: bool = True
|
|
14
|
-
normalize_method: str = "l2"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Embedder(BaseModel):
|
|
18
|
-
def __init__(self):
|
|
19
|
-
"""
|
|
20
|
-
Internal initializer
|
|
21
|
-
"""
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
@classmethod
|
|
25
|
-
def _load_from(cls, model_path: str, model_name: str = None, tokenizer_file: str = "tokenizer.json", plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP, **kwargs):
|
|
26
|
-
"""
|
|
27
|
-
Load an embedder from model files, routing to appropriate implementation.
|
|
28
|
-
|
|
29
|
-
Args:
|
|
30
|
-
model_path: Path to the model file
|
|
31
|
-
model_name: Name of the model
|
|
32
|
-
tokenizer_file: Path to the tokenizer file (default: "tokenizer.json")
|
|
33
|
-
plugin_id: Plugin ID to use for the model (default: PluginID.LLAMA_CPP)
|
|
34
|
-
|
|
35
|
-
Returns:
|
|
36
|
-
Embedder instance
|
|
37
|
-
"""
|
|
38
|
-
# Check plugin_id value for routing - handle both enum and string
|
|
39
|
-
plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
|
|
40
|
-
|
|
41
|
-
if plugin_value == "mlx":
|
|
42
|
-
from nexaai.embedder_impl.mlx_embedder_impl import MLXEmbedderImpl
|
|
43
|
-
return MLXEmbedderImpl._load_from(model_path, model_name, tokenizer_file, plugin_id)
|
|
44
|
-
else:
|
|
45
|
-
from nexaai.embedder_impl.pybind_embedder_impl import PyBindEmbedderImpl
|
|
46
|
-
return PyBindEmbedderImpl._load_from(model_path, model_name, tokenizer_file, plugin_id)
|
|
47
|
-
|
|
48
|
-
@abstractmethod
|
|
49
|
-
def generate(self, texts: Union[List[str], str] = None, config: EmbeddingConfig = EmbeddingConfig(), input_ids: Union[List[int], List[List[int]]] = None) -> np.ndarray:
|
|
50
|
-
"""
|
|
51
|
-
Generate embeddings for the given texts or input_ids.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
texts: List of strings or single string to embed
|
|
55
|
-
input_ids: Pre-tokenized input as:
|
|
56
|
-
- Single sequence: list of integers [1, 2, 3, 4]
|
|
57
|
-
- Multiple sequences: list of lists [[1, 2, 3], [4, 5, 6]]
|
|
58
|
-
config: Configuration for embedding generation
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
numpy array of embeddings with shape (num_sequences, embedding_dim)
|
|
62
|
-
"""
|
|
63
|
-
pass
|
|
64
|
-
|
|
65
|
-
@abstractmethod
|
|
66
|
-
def get_embedding_dim(self) -> int:
|
|
67
|
-
"""
|
|
68
|
-
Get the embedding dimension of the model
|
|
69
|
-
|
|
70
|
-
Returns:
|
|
71
|
-
The embedding dimension in int
|
|
72
|
-
"""
|
|
73
|
-
pass
|
|
1
|
+
from typing import List, Union
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from abc import abstractmethod
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from nexaai.base import BaseModel
|
|
7
|
+
from nexaai.common import PluginID
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class EmbeddingConfig:
|
|
12
|
+
batch_size: int = 32
|
|
13
|
+
normalize: bool = True
|
|
14
|
+
normalize_method: str = "l2"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Embedder(BaseModel):
|
|
18
|
+
def __init__(self):
|
|
19
|
+
"""
|
|
20
|
+
Internal initializer
|
|
21
|
+
"""
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def _load_from(cls, model_path: str, model_name: str = None, tokenizer_file: str = "tokenizer.json", plugin_id: Union[PluginID, str] = PluginID.LLAMA_CPP, **kwargs):
|
|
26
|
+
"""
|
|
27
|
+
Load an embedder from model files, routing to appropriate implementation.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
model_path: Path to the model file
|
|
31
|
+
model_name: Name of the model
|
|
32
|
+
tokenizer_file: Path to the tokenizer file (default: "tokenizer.json")
|
|
33
|
+
plugin_id: Plugin ID to use for the model (default: PluginID.LLAMA_CPP)
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Embedder instance
|
|
37
|
+
"""
|
|
38
|
+
# Check plugin_id value for routing - handle both enum and string
|
|
39
|
+
plugin_value = plugin_id.value if isinstance(plugin_id, PluginID) else plugin_id
|
|
40
|
+
|
|
41
|
+
if plugin_value == "mlx":
|
|
42
|
+
from nexaai.embedder_impl.mlx_embedder_impl import MLXEmbedderImpl
|
|
43
|
+
return MLXEmbedderImpl._load_from(model_path, model_name, tokenizer_file, plugin_id)
|
|
44
|
+
else:
|
|
45
|
+
from nexaai.embedder_impl.pybind_embedder_impl import PyBindEmbedderImpl
|
|
46
|
+
return PyBindEmbedderImpl._load_from(model_path, model_name, tokenizer_file, plugin_id)
|
|
47
|
+
|
|
48
|
+
@abstractmethod
|
|
49
|
+
def generate(self, texts: Union[List[str], str] = None, config: EmbeddingConfig = EmbeddingConfig(), input_ids: Union[List[int], List[List[int]]] = None) -> np.ndarray:
|
|
50
|
+
"""
|
|
51
|
+
Generate embeddings for the given texts or input_ids.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
texts: List of strings or single string to embed
|
|
55
|
+
input_ids: Pre-tokenized input as:
|
|
56
|
+
- Single sequence: list of integers [1, 2, 3, 4]
|
|
57
|
+
- Multiple sequences: list of lists [[1, 2, 3], [4, 5, 6]]
|
|
58
|
+
config: Configuration for embedding generation
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
numpy array of embeddings with shape (num_sequences, embedding_dim)
|
|
62
|
+
"""
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def get_embedding_dim(self) -> int:
|
|
67
|
+
"""
|
|
68
|
+
Get the embedding dimension of the model
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
The embedding dimension in int
|
|
72
|
+
"""
|
|
73
|
+
pass
|