Open dan-homebrew opened 1 month ago
This document outlines the architecture for integrating Python functionality into a C++ application, specifically for running machine learning models. The system uses a proxy approach to connect the C++ application (cortex.cpp) with Python processes, allowing for isolated environments for different models.
cortexcpp/
├── models/
│ cortexso/
│ └── python/
│ └── whisper/
│ ├── model-binary.pth
│ ├── whisper.py
│ ├── main.py
│ └── requirements.txt
├── engines/
│ ├── cortex.llamacpp/
│ └── cortex.python/
│ ├── libengine.so # proxy interface for python model and cortex.cpp
│ └── venv/ # Virtual environments
│ ├── whisper/
│ │ ├── lib/ # python libraries and dependencies for whisper
│ │ └── bin/
│ │ └─ python3.12 # executable python for whisper
│ ├── fish-speech/
│ └── vision/
/path/to/venv/bin/python -m pip install -r requirements.txt
The model pulling step also needs to install the engine
for running python model. engine
or backend
for python model is all libs and deps inside virtual environment.
main.py
in the appropriate virtual environment/ engine/ backend.predict
function (or similar) for each model's specific inference logicmain.py
is the entry point for each modelsys.path
can be modified to locate model-specific modules (e.g., whisper.py
)@nguyenhoangthuan99 @vansangpfiev @namchuai I would like to raise a concern here, and propose a (possibly incorrect) alternative:
This has the following benefits:
I would suggest using uv. It is extremely fast Python package and project manager, written in Rust.
Then you can even do something like this.
uv run --with mlx-lm \
mlx_lm.generate \
--model mlx-community/Qwen2.5-Coder-32B-Instruct-8bit \
--max-tokens 4000 \
--prompt 'write me a python function that renders a mandelbrot fractal as wide as the current terminal'
There are lot of python projects related to LLM, so being able to use those packages directly can easily help.
These might be of interest:
Goal
Tasklist
Previous Discussions