MCPcopy Index your code
hub / github.com/llSourcell/Doctor-Dignity

github.com/llSourcell/Doctor-Dignity @main sqlite

repository ↗ · DeepWiki ↗
1,084 symbols 2,521 edges 82 files 114 documented · 11%
README

Doctor Dignity

DISCLAIMER - Do not take any advice from Doctor Dignity seriously yet. This is a work in progress and taking any advice seriously could result in serious injury or even death.

Overview

Doctor Dignity is a Large Language Model that can pass the US Medical Licensing Exam. This is an open-source project with a mission to provide everyone their own private doctor. Doctor Dignity is a version of Meta's Llama2 7 billion parameter Large Language Model that was fine-tuned on a Medical Dialogue Dataset, then further improved using Reinforcement Learning & Constitutional AI. Since the model is only 3 Gigabytes in size, it fits on any local device, so there is no need to pay an API to use it. It's free, made for offline usage which preserves patient confidentiality, and it's available on iOS, Android, and Web. Pull requests for feature additions and improvements are encouraged.

Dependencies

  • Numpy (Use matrix math operations)
  • PyTorch (Build Deep Learning models)
  • Datasets (Access datasets from huggingface hub)
  • Huggingface_hub (access huggingface data & models)
  • Transformers (Access models from HuggingFace hub)
  • Trl (Transformer Reinforcement Learning. And fine-tuning.)
  • Bitsandbytes (makes models smaller, aka 'quantization')
  • Sentencepiece (Byte Pair Encoding scheme aka 'tokenization')
  • OpenAI (Create synthetic fine-tuning and reward model data)
  • TVM (Tensor Virtual Machine, converts onnx model to efficient cross-platform use)
  • Peft (Parameter Efficient Fine Tuning, use low rank adaption (LoRa) to fine-tune)
  • Onnx (Convert trained model to universal format)

Installation

Install all dependencies in one line using pip

pip install numpy torch datasets huggingface_hub transformers trl bitsandbytes sentencepiece openai tvm peft onnx

iOS QuickStart v2

  1. Clone this repository
git clone https://github.com/llSourcell/Doctor-Dignity
  1. Download the Weights
mkdir -p dist/prebuilt
git clone https://github.com/mlc-ai/binary-mlc-llm-libs.git dist/prebuilt/lib
cd dist/prebuilt
git lfs install
wget --no-check-certificate 'https://drive.google.com/file/d/1MLy8BDhuTTcXqagzLFMA07JDzqjQYUTB/view?pli=1'
cd ../..
  1. Build the Tensor Virtual Machine Runtime
git submodule update --init --recursive
pip install apache-tvm
cd ./ios
pip install --pre --force-reinstall mlc-ai-nightly mlc-chat-nightly -f https://mlc.ai/wheels 
./prepare_libs.sh

** Find the right version of MLC LLM for your system here 4. Add Weights to Xcode

cd ./ios
open ./prepare_params.sh # make sure builtin_list only contains "RedPajama-INCITE-Chat-3B-v1-q4f16_1"
./prepare_params.sh
  1. Open Xcode Project and run!

DIY Training

In order to train the model, you can run the training.ipynb notebook locally or remotely via a cloud service like Google Colab Pro. The training process requires a GPU, and if you don't have one then the most accessible option i found was using Google Colab Pro which costs $10/month. The total training time for Doctor Dignity including supervised fine-tuning of the initial LLama model on custom medical data, as well as further improving it via Reinforcement Learning from Constitional AI Feedback took 24 hours on a paid instance of Google Colab. If you're interested in learning more about how this process works, details are in the training.ipynb notebook.

Cloud Training

Open In Colab click here: https://colab.research.google.com/github/llSourcell/Doctor-Dignity/blob/main/llama2.ipynb

Local Training

git clone https://github.com/llSourcell/Doctor-Dignity.git
jupyter training.ipynb

Get jupyter here

Usage https://huggingface.co/llSourcell/medllama2_7b

There are 2 huggingface repos, one which is quantized for mobile and one that is not.

Old iOS app

  • Step 1: Download the iOS Machine Learning Compilation Chat Repository
  • Step 2: Follow the installation steps
  • Step 3: Once the app is running on your iOS device or simulator, tap "add model variant"
  • Step 4: Enter the URL for the latest Doctor Dignity model to download it: [https://huggingface.co/llSourcell/doctorGPT_mini] (https://huggingface.co/llSourcell/doctorGPT_mini)
  • Step 5: Tap 'Add Model' and start chatting locally, inference runs on device. No internet connection needed!

Android app (TODO)

Web (TODO)

As an experiment in Online Learning using actual human feedback, i want to deploy the model as a Flask API with a React front-end. In this case, anyone can chat with the model at this URL. After each query, a human can rate the model's response. This rating is then used to further improve the model's performance through reinforcement learning. to run the app, download flask and then you can run:

flask run

Then visit localhost:3000 to interact with it! You can also deploy to vercel

Credits

Meta, MedAlpaca, Apache, MLC Chat & OctoML

Core symbols most depended-on inside this repo

print
called by 101
examples/rest/nodejs/sample_client.js
get_dict_key
called by 79
mlc_llm/dispatch/llama/main.py
compute
called by 28
mlc_llm/models/llama.py
compute
called by 24
mlc_llm/relax_model/modules.py
get_dict_key
called by 22
mlc_llm/dispatch/dispatch_tir_operator_adreno.py
matmul
called by 17
mlc_llm/dispatch/gpt_neox/redpajama_q4f32.py
register_params
called by 15
mlc_llm/relax_model/param_manager.py
reshape
called by 12
mlc_llm/dispatch/gpt_neox/redpajama_q4f32_mod.py

Shape

Function 467
Method 462
Class 144
Route 11

Languages

Python98%
Java1%
TypeScript1%

Modules by API surface

mlc_llm/dispatch/llama/main.py146 symbols
mlc_llm/relax_model/llama.py54 symbols
mlc_llm/dispatch/dispatch_tir_operator_adreno.py48 symbols
mlc_llm/relax_model/chatglm.py45 symbols
mlc_llm/relax_model/minigpt.py42 symbols
mlc_llm/relax_model/rwkv.py39 symbols
mlc_llm/relax_model/gptj.py38 symbols
mlc_llm/relax_model/gpt_neox.py36 symbols
mlc_llm/dispatch/gpt_neox/redpajama_incite_chat_3b_v1_tune.py36 symbols
mlc_llm/relax_model/gpt_bigcode.py34 symbols
python/mlc_chat/chat_module.py31 symbols
mlc_llm/dispatch/gpt_neox/redpajama_q4f32_tune.py31 symbols

Dependencies from manifests, versioned

@types/node20.4.4 · 1×
dotenv16.3.1 · 1×
langchain0.0.117 · 1×
needle3.2.0 · 1×
openai3.3.0 · 1×
ts-node10.9.1 · 1×
typescript5.1.6 · 1×
sphinx5.2.3 · 1×
sphinx-tabs3.4.1 · 1×
sphinx-toolbox3.4.0 · 1×
sphinxcontrib-napoleon0.7 · 1×
sphinxcontrib_httpdomain1.8.1 · 1×

For agents

$ claude mcp add Doctor-Dignity \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact