Skip to content

A python package for applying LLM with LangChain and Hugging Face on local CUDA/MPS host

License

Notifications You must be signed in to change notification settings

yingding/applyllm

Repository files navigation

applyllm: python package

This repository contains code of applyllm python PyPI package, for loading and training open source llm models e.g. LlaMA2, Mixtral 8x7B, etc.

Install the package

pip install applyllm

Setup a local venv on Macosx Apple Silicon

python3 -m pip install --upgrade pip
python3 -m pip install --no-cache-dir -r ./llm-examples/setup/requirements310mac.txt

Setup on Kubeflow notebook

python3 -m pip install --upgrade pip
python3 -m pip install --no-cache-dir --user --upgrade -r ./llm-examples/requirements.txt --extra-index-url https://download.pytorch.org/whl/cu118

Build locally

VENV_NAME="llm3.10"
VENV_DIR="$HOME/VENV"
source ${VENV_DIR}/${VENV_NAME}/bin/activate;
make clean && make build && make reload

Publish the test pypi package

VENV_NAME="llm3.10"
VENV_DIR="$HOME/VENV"
source ${VENV_DIR}/${VENV_NAME}/bin/activate;
make clean && make build && make testpypi

Publish the pypi package

VENV_NAME="llm3.10"
VENV_DIR="$HOME/VENV"
source ${VENV_DIR}/${VENV_NAME}/bin/activate;
make clean && make build && make pypi

Add a jupyter notebook kernel to VENV

VENV_NAME="llm3.10"
VENV_DIR="$HOME/VENV"
source ${VENV_DIR}/${VENV_NAME}/bin/activate;
python3 -m pip install --upgrade pip
python3 -m pip install ipykernel
deactivate

We need to reactivate the venv so that the ipython kernel is available after installation.

VENV_NAME="llm3.10"
VENV_DIR="$HOME/VENV"
source ${VENV_DIR}/${VENV_NAME}/bin/activate;
python3 -m ipykernel install --user --name=${VENV_NAME} --display-name ${VENV_NAME}

Note:

  • restart the vs code, to select the venv as jupyter notebook kernel

Reference:

Remove ipykernel

VENV_NAME="llm3.10"
jupyter kernelspec uninstall -y ${VENV_NAME}

Remove all package from venv

python3 -m pip freeze | xargs pip uninstall -y
python3 -m pip list

Sync AIMLflow

aim_repo_path=./aimruns
mlflow_uri=./mlruns
mkdir ${aim_repo_path}
cd ${aim_repo_path}
aim init
cd ..
# start a watch process
aimlflow sync --mlflow-tracking-uri=${mlflow_uri} --aim-repo=${aim_repo_path}
# start a second terminal
aim up --repo=${aim_repo_path}

Restart MLflow UI

If the default port 5000 is used

ps -A | grep gunicorn
pkill -f gunicorn
ps -A | grep gunicorn
# use relative path to set the backend-store-uri, full path with file:///root/sub/mlruns
mlflow ui --backend-store-uri llm-examples/mlruns
# mlflow server --host 127.0.0.1 --port 8080

Reference:

Relevant Tech Info

Makefile **space 4 issue

Makefile need tab as indent, not space 4

Reference: