├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── config.yml │ ├── documentation.md │ ├── feature-request.md │ ├── general.md │ ├── model-request.md │ ├── speed-report.md │ └── tracking.md └── workflows │ ├── documentation.yml │ └── update-relax.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CONTRIBUTORS.md ├── LICENSE ├── Machine_Learning_Compilation_for_Beginners.ipynb ├── README.md ├── android ├── .gitignore ├── CMakeLists.txt ├── MLCChat │ ├── .gitignore │ ├── app │ │ ├── .gitignore │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── assets │ │ │ └── app-config.json │ │ │ ├── ic_launcher-playstore.png │ │ │ ├── java │ │ │ └── ai │ │ │ │ └── mlc │ │ │ │ └── mlcchat │ │ │ │ ├── AppViewModel.kt │ │ │ │ ├── ChatView.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── NavView.kt │ │ │ │ ├── StartView.kt │ │ │ │ └── ui │ │ │ │ └── theme │ │ │ │ ├── Color.kt │ │ │ │ ├── Theme.kt │ │ │ │ └── Type.kt │ │ │ └── res │ │ │ ├── drawable │ │ │ ├── ic_android_black_24dp.xml │ │ │ └── mlc_logo_108.xml │ │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── themes.xml │ │ │ └── xml │ │ │ ├── backup_rules.xml │ │ │ └── data_extraction_rules.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── README.md ├── prepare_libs.sh ├── prepare_model_lib.py └── src │ ├── cpp │ └── tvm_runtime.h │ └── java │ └── ai │ └── mlc │ └── mlcllm │ └── ChatModule.java ├── build.py ├── cmake └── gen_cmake_config.py ├── cpp ├── README.md ├── cli_main.cc ├── conv_templates.cc ├── conversation.cc ├── conversation.h ├── image_embed.cc ├── image_embed.h ├── llm_chat.cc └── llm_chat.h ├── docs ├── .gitignore ├── Makefile ├── README.md ├── _static │ └── img │ │ ├── mlc-logo-with-text-landscape.svg │ │ └── project-structure.svg ├── community │ ├── faq.rst │ └── guideline.rst ├── compilation │ ├── compile_models.rst │ ├── configure_quantization.rst │ ├── distribute_compiled_models.rst │ ├── get-vicuna-weight.rst │ └── python.rst ├── conf.py ├── deploy │ ├── android.rst │ ├── cli.rst │ ├── ios.rst │ ├── javascript.rst │ ├── python.rst │ └── rest.rst ├── get_started │ ├── mlc_chat_config.rst │ ├── project_overview.rst │ └── try_out.rst ├── index.rst ├── install │ ├── conda.rst │ ├── emcc.rst │ ├── gpu.rst │ └── tvm.rst ├── make.bat ├── prebuilt_models.rst ├── requirements.txt └── tutorials │ └── customize │ └── define_new_models.rst ├── examples ├── python │ ├── benchmark.py │ └── sample_mlc_chat.py └── rest │ ├── nodejs │ ├── README.MD │ ├── dotenv.example │ ├── package.json │ ├── sample_client.js │ ├── sample_langchain.ts │ ├── sample_openai.js │ └── tsconfig.json │ ├── python │ ├── sample_client.py │ ├── sample_langchain.py │ └── sample_openai.py │ └── resources │ ├── linux.txt │ └── state_of_the_union.txt ├── ios ├── .gitignore ├── MLCChat.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── xcschemes │ │ └── MLCChat.xcscheme ├── MLCChat │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ ├── AppIcon~ios-marketing.png │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Common │ │ ├── Constants.swift │ │ └── Fonts.swift │ ├── Extensions │ │ ├── UIDeviceExtension.swift │ │ └── UIScreenExtension.swift │ ├── Info.plist │ ├── MLCChat.entitlements │ ├── MLCChatApp.swift │ ├── Models │ │ ├── AppConfig.swift │ │ ├── ExampleModelConfig.swift │ │ ├── ModelConfig.swift │ │ └── ParamsConfig.swift │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ ├── States │ │ ├── AppState.swift │ │ ├── ChatState.swift │ │ └── ModelState.swift │ ├── Views │ │ ├── ChatView.swift │ │ ├── ImageProcessing.swift │ │ ├── MessageView.swift │ │ ├── ModelView.swift │ │ └── StartView.swift │ └── app-config.json ├── MLCSwift │ ├── Package.swift │ ├── README.md │ ├── Sources │ │ ├── ObjC │ │ │ ├── LLMChat.mm │ │ │ └── include │ │ │ │ └── LLMChat.h │ │ └── Swift │ │ │ ├── LLMChat.swift │ │ │ └── ThreadWorker.swift │ └── tvm_home ├── README.md ├── prepare_libs.sh ├── prepare_model_lib.py └── prepare_params.sh ├── mlc_llm ├── __init__.py ├── build.py ├── core.py ├── dispatch │ ├── __init__.py │ ├── dispatch_tir_operator.py │ ├── dispatch_tir_operator_adreno.py │ ├── gpt_neox │ │ ├── __init__.py │ │ ├── dolly_v2_3b.py │ │ ├── dolly_v2_3b_mod.py │ │ ├── redpajama_incite_chat_3b_v1.py │ │ ├── redpajama_incite_chat_3b_v1_mod.py │ │ ├── redpajama_incite_chat_3b_v1_tune.py │ │ ├── redpajama_q4f32.py │ │ ├── redpajama_q4f32_mod.py │ │ └── redpajama_q4f32_tune.py │ └── llama │ │ ├── __init__.py │ │ └── main.py ├── models │ ├── __init__.py │ └── llama.py ├── quantization │ ├── __init__.py │ ├── autogptq_quantization.py │ ├── ft_rowwise_quantization.py │ ├── group_quantization.py │ ├── quantization.py │ └── tir_utils.py ├── relax_model │ ├── __init__.py │ ├── chatglm.py │ ├── commons.py │ ├── gpt_bigcode.py │ ├── gpt_neox.py │ ├── gptj.py │ ├── llama.py │ ├── minigpt.py │ ├── modules.py │ ├── param_manager.py │ └── rwkv.py ├── transform │ ├── __init__.py │ ├── clean_up_tir_attrs.py │ ├── decode_matmul_ewise.py │ ├── decode_take.py │ ├── decode_transpose.py │ ├── fuse_split_rotary_embedding.py │ ├── lift_tir_global_buffer_alloc.py │ ├── reorder_transform_func.py │ ├── rewrite_attention.py │ └── transpose_matmul.py └── utils.py ├── pyproject.toml ├── python ├── README.md ├── mlc_chat │ ├── __init__.py │ ├── base.py │ ├── callback.py │ ├── chat_module.py │ ├── embeddings │ │ ├── __init__.py │ │ └── openai.py │ ├── gradio.py │ ├── interface │ │ ├── __init__.py │ │ └── openai_api.py │ ├── libinfo.py │ └── rest.py └── setup.py ├── scripts ├── build_site.sh ├── check_url_validity.py ├── gh_deploy_site.sh ├── local_deploy_site.sh └── prep_emcc_deps.sh ├── setup.py ├── site ├── .gitignore ├── _config.yml ├── gif │ ├── android-demo.gif │ ├── ios-demo.gif │ └── linux-demo.gif ├── img │ ├── android │ │ ├── android-diagram.png │ │ ├── android-studio.png │ │ ├── android-vs-ios.png │ │ └── local-advantage.png │ └── diag.svg ├── index.md └── privacy.md ├── tests ├── cpp │ └── conv_unittest.cc ├── debug │ ├── compare_lib.py │ └── dump_intermediate.py ├── evaluate.py └── python │ ├── test_build_args.py │ ├── test_build_model_from_args.py │ └── test_model_llama.py └── version.py /.clang-format: -------------------------------------------------------------------------------- 1 | # Run the following command to reformat a file: 2 | # clang-format -i -style=Google 3 | # Or use clang-format-diff to only reformat the changed lines: 4 | # https://clang.llvm.org/docs/ClangFormat.html 5 | BasedOnStyle: Google 6 | DerivePointerAlignment: false 7 | ColumnLimit: 100 8 | PointerAlignment: Left 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "🐛 Bug Report" 3 | about: Submit a bug report to help us improve MLC-LLM 4 | title: '[Bug] ' 5 | labels: ['bug'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## 🐛 Bug 11 | 12 | 13 | 14 | ## To Reproduce 15 | 16 | Steps to reproduce the behavior: 17 | 18 | 1. 19 | 1. 20 | 1. 21 | 22 | 23 | 24 | ## Expected behavior 25 | 26 | 27 | 28 | ## Environment 29 | 30 | - Platform (e.g. WebGPU/Vulkan/IOS/Android/CUDA): 31 | - Operating system (e.g. Ubuntu/Windows/MacOS/...): 32 | - Device (e.g. iPhone 12 Pro, PC+RTX 3090, ...) 33 | - How you installed MLC-LLM (`conda`, source): 34 | - How you installed TVM-Unity (`pip`, source): 35 | - Python version (e.g. 3.10): 36 | - GPU driver version (if applicable): 37 | - CUDA/cuDNN version (if applicable): 38 | - TVM Unity Hash Tag (`python -c "import tvm; print('\n'.join(f'{k}: {v}' for k, v in tvm.support.libinfo().items()))"`, applicable if you compile models): 39 | - Any other relevant information: 40 | 41 | ## Additional context 42 | 43 | 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | 3 | contact_links: 4 | - name: Check the MLC-LLM Documentation 5 | url: https://mlc.ai/mlc-llm/docs/ 6 | about: Our documentation might provide answers to your questions. 7 | - name: Chat on Discord 8 | url: https://discord.gg/9Xpy2HGBuD 9 | about: Join the Discord Server to live chat with the community. 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4DA Documentation" 3 | about: Report an issue related to https://mlc.ai/mlc-llm/docs 4 | title: '[Doc] ' 5 | labels: ['documentation'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## 📚 Documentation 11 | 12 | ### Suggestion 13 | 14 | 15 | ### Bug 16 | - Link to the buggy documentation/tutorial: 17 | - Description of the bug: 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature Request" 3 | about: Submit a proposal/request for a new MLC-LLM feature, or an enhancement on existing features. 4 | title: '[Feature Request] ' 5 | labels: ['feature request'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## 🚀 Feature 11 | 12 | 13 | ## Motivation 14 | 15 | 16 | 17 | ## Alternatives 18 | 19 | 20 | 21 | ## Additional context 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/general.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "❓ General Questions" 3 | about: General questions you have about MLC-LLM. 4 | title: '[Question] ' 5 | labels: ['question'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## ❓ General Questions 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/model-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "️️⚙️ Model Request" 3 | about: Request a new model in MLC-LLM 4 | title: '[Model Request] ' 5 | labels: ['new-models'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## ⚙️ Request New Models 11 | 12 | - Link to an existing implementation (e.g. Hugging Face/Github): 13 | - Is this model architecture supported by MLC-LLM? (the list of [supported models](https://mlc.ai/mlc-llm/docs/prebuilt_models.html)) 14 | 15 | ## Additional context 16 | 17 | 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/speed-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: " 🏎️ Speed Report" 3 | about: Submit a speed report of an model running in MLC-LLM 4 | title: '[Speed] ' 5 | labels: ['performance'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | # 🏎️ Speed Report 11 | 12 | 13 | 14 | - The model code: 15 | 16 | 17 | - The model configuration (e.g. quantization mode, running data type, etc.): 18 | - Device (e.g. MacBook Pro M2, PC+RTX 3080): 19 | - OS (if applicable): 20 | - Encode speed (Token/s): 21 | - Decode speed (Token/s): 22 | - Memory usage (if applicable): 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/tracking.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Tracking" 3 | about: A tracking issue that tracks ongoing item in the project 4 | title: '[Tracking] ' 5 | labels: ['status: tracking'] 6 | assignees: '' 7 | 8 | --- 9 | 10 | 24 | 25 | 26 | ## Overview 27 | 28 | 29 | 30 | 31 | ## Action Items 32 | 33 | 34 | - [ ] 35 | 36 | 37 | ## Links to Related Issues and PRs 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Build Docs 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | test_linux: 10 | name: Deploy Docs 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | submodules: recursive 17 | 18 | - name: Configuring build Environment 19 | run: | 20 | sudo apt-get update 21 | python -m pip install -U pip wheel 22 | 23 | - name: Setup Ruby 24 | uses: ruby/setup-ruby@v1 25 | with: 26 | ruby-version: '3.0' 27 | 28 | - name: Installing dependencies 29 | run: | 30 | python -m pip install -r docs/requirements.txt 31 | gem install jekyll jekyll-remote-theme 32 | 33 | - name: Deploying on GitHub Pages 34 | if: github.ref == 'refs/heads/main' 35 | run: | 36 | git remote set-url origin https://x-access-token:${{ secrets.MLC_GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY 37 | git config --global user.email "mlc-gh-actions-bot@nomail" 38 | git config --global user.name "mlc-gh-actions-bot" 39 | ./scripts/gh_deploy_site.sh 40 | -------------------------------------------------------------------------------- /.github/workflows/update-relax.yml: -------------------------------------------------------------------------------- 1 | name: 'Relax Submodule Sync' 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | sync: 8 | name: 'Relax Submodule Sync' 9 | runs-on: ubuntu-latest 10 | 11 | defaults: 12 | run: 13 | shell: bash 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v3 18 | with: 19 | submodules: true 20 | 21 | - name: Git Sumbodule Update 22 | run: | 23 | git submodule update --remote 3rdparty/tvm 24 | 25 | - name: Commit update 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.MLC_GITHUB_TOKEN }} 28 | run: | 29 | git config --global user.name 'Git bot' 30 | git config --global user.email 'bot@noreply.github.com' 31 | git remote set-url origin https://$GITHUB_TOKEN@github.com/mlc-ai/mlc-llm 32 | git commit -am "Auto updated submodule references" && git push || echo "No changes to commit" 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | params/ 3 | *.bak 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | .DS_Store 10 | 11 | *.S 12 | # C extensions 13 | *.so 14 | 15 | build/ 16 | 17 | *.ll 18 | .npm 19 | # Distribution / packaging 20 | .Python 21 | env/ 22 | build/ 23 | build-*/ 24 | develop-eggs/ 25 | dist/ 26 | downloads/ 27 | eggs/ 28 | .eggs/ 29 | lib/ 30 | lib64/ 31 | parts/ 32 | sdist/ 33 | var/ 34 | wheels/ 35 | pip-wheel-metadata/ 36 | share/python-wheels/ 37 | *.egg-info/ 38 | .installed.cfg 39 | *.egg 40 | MANIFEST 41 | 42 | .conda/ 43 | # PyInstaller 44 | # Usually these files are written by a python script from a template 45 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 46 | *.manifest 47 | *.spec 48 | 49 | # Generated by python/gen_requirements.py 50 | python/requirements/*.txt 51 | 52 | # Installer logs 53 | pip-log.txt 54 | pip-delete-this-directory.txt 55 | 56 | # Unit test / coverage reports 57 | htmlcov/ 58 | .tox/ 59 | .nox/ 60 | .coverage 61 | .coverage.* 62 | .cache 63 | nosetests.xml 64 | coverage.xml 65 | *.cover 66 | *.py,cover 67 | .hypothesis/ 68 | .pytest_cache/ 69 | 70 | # Translations 71 | *.mo 72 | *.pot 73 | 74 | # Django stuff: 75 | *.log 76 | local_settings.py 77 | db.sqlite3 78 | db.sqlite3-journal 79 | 80 | # Flask stuff: 81 | instance/ 82 | .webassets-cache 83 | 84 | # Scrapy stuff: 85 | .scrapy 86 | 87 | # Sphinx documentation 88 | docs/_build/ 89 | docs/_staging/ 90 | 91 | # PyBuilder 92 | target/ 93 | /target/ 94 | 95 | # Jupyter Notebook 96 | .ipynb_checkpoints 97 | 98 | # IPython 99 | profile_default/ 100 | ipython_config.py 101 | 102 | # pyenv 103 | .python-version 104 | 105 | # pipenv 106 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 107 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 108 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 109 | # install all needed dependencies. 110 | #Pipfile.lock 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | *~ 138 | *.pyc 139 | *~ 140 | config.mk 141 | config.cmake 142 | Win32 143 | *.dir 144 | perf 145 | *.wasm 146 | .emscripten 147 | 148 | ## IOS 149 | DerivedData/ 150 | 151 | ## Java 152 | *.class 153 | jvm/*/target/ 154 | jvm/*/*/target/ 155 | jvm/native/*/generated 156 | jvm/native/src/main/native/org_apache_tvm_native_c_api.h 157 | *.worksheet 158 | *.idea 159 | *.iml 160 | *.classpath 161 | *.project 162 | *.settings 163 | */node_modules/ 164 | 165 | ## Various settings 166 | *.pbxuser 167 | !default.pbxuser 168 | *.mode1v3 169 | !default.mode1v3 170 | *.mode2v3 171 | !default.mode2v3 172 | *.perspectivev3 173 | !default.perspectivev3 174 | xcuserdata/ 175 | .pkl_memoize_* 176 | 177 | .emscripten* 178 | .m2 179 | 180 | # Compiled Dynamic libraries 181 | *.so 182 | *.dylib 183 | *.dll 184 | 185 | # Compiled Object files 186 | *.slo 187 | *.lo 188 | *.o 189 | *.obj 190 | 191 | # Precompiled Headers 192 | *.gch 193 | *.pch 194 | 195 | # Compiled Static libraries 196 | *.lai 197 | *.la 198 | *.a 199 | *.lib 200 | 201 | # Executables 202 | *.exe 203 | *.out 204 | *.app 205 | 206 | ## Other 207 | *.moved-aside 208 | *.xccheckout 209 | *.xcscmblueprint 210 | .DS_Store 211 | tags 212 | cscope* 213 | *.lock 214 | 215 | # vim temporary files 216 | *.swp 217 | *.swo 218 | 219 | # TVM generated code 220 | perf 221 | .bash_history 222 | # *.json 223 | *.params 224 | *.ro 225 | *.onnx 226 | *.h5 227 | synset.txt 228 | cat.jpg 229 | cat.png 230 | docs.tgz 231 | cat.png 232 | *.mlmodel 233 | tvm_u.* 234 | tvm_t.* 235 | # Mac OS X 236 | .DS_Store 237 | 238 | # Jetbrain 239 | .idea 240 | .ipython 241 | .jupyter 242 | .nv 243 | .pylint.d 244 | .python_history 245 | .pytest_cache 246 | .local 247 | cmake-build-debug 248 | 249 | # Visual Studio 250 | .vs 251 | 252 | # Visual Studio Code 253 | .vscode 254 | 255 | # tmp file 256 | .nfs* 257 | 258 | # keys 259 | *.pem 260 | *.p12 261 | *.pfx 262 | *.cer 263 | *.crt 264 | *.der 265 | 266 | # patch sentinel 267 | patched.txt 268 | 269 | # Python type checking 270 | .mypy_cache/ 271 | .pyre/ 272 | 273 | # pipenv files 274 | Pipfile 275 | Pipfile.lock 276 | 277 | # conda package artifacts 278 | conda/Dockerfile.cuda* 279 | conda/pkg 280 | .node_repl_history 281 | # nix files 282 | .envrc 283 | *.nix 284 | 285 | # Docker files 286 | .sudo_as_admin_successful 287 | 288 | # Downloaded models/datasets 289 | .tvm_test_data 290 | .dgl 291 | .caffe2 292 | 293 | # Local docs build 294 | _docs/ 295 | jvm/target 296 | .config/configstore/ 297 | .ci-py-scripts/ 298 | 299 | # Generated Hexagon files 300 | src/runtime/hexagon/rpc/hexagon_rpc.h 301 | src/runtime/hexagon/rpc/hexagon_rpc_skel.c 302 | src/runtime/hexagon/rpc/hexagon_rpc_stub.c 303 | 304 | # Local tvm-site checkout 305 | tvm-site/ 306 | 307 | # Generated docs files 308 | gallery/how_to/work_with_microtvm/micro_tvmc.py 309 | 310 | # Test sample data files 311 | !tests/python/ci/sample_prs/*.json 312 | 313 | # Used in CI to communicate between Python and Jenkins 314 | .docker-image-names/ 315 | 316 | # Printed TIR code on disk 317 | *.tir 318 | 319 | # GDB history file 320 | .gdb_history 321 | 322 | dist 323 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rdparty/argparse"] 2 | path = 3rdparty/argparse 3 | url = https://github.com/p-ranav/argparse 4 | [submodule "3rdparty/tokenizers-cpp"] 5 | path = 3rdparty/tokenizers-cpp 6 | url = https://github.com/mlc-ai/tokenizers-cpp 7 | [submodule "3rdparty/googletest"] 8 | path = 3rdparty/googletest 9 | url = https://github.com/google/googletest.git 10 | [submodule "3rdparty/tvm"] 11 | path = 3rdparty/tvm 12 | url = https://github.com/mlc-ai/relax.git 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | project(mlc_llm C CXX) 3 | 4 | include(CheckCXXCompilerFlag) 5 | if(NOT MSVC) 6 | check_cxx_compiler_flag("-std=c++17" SUPPORT_CXX17) 7 | set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}") 8 | set(CMAKE_CUDA_STANDARD 17) 9 | else() 10 | check_cxx_compiler_flag("/std:c++17" SUPPORT_CXX17) 11 | set(CMAKE_CXX_FLAGS "/std:c++17 ${CMAKE_CXX_FLAGS}") 12 | set(CMAKE_CUDA_STANDARD 17) 13 | endif() 14 | 15 | if(EXISTS ${CMAKE_BINARY_DIR}/config.cmake) 16 | include(${CMAKE_BINARY_DIR}/config.cmake) 17 | else() 18 | if(EXISTS ${CMAKE_SOURCE_DIR}/config.cmake) 19 | include(${CMAKE_SOURCE_DIR}/config.cmake) 20 | endif() 21 | endif() 22 | 23 | if(NOT CMAKE_BUILD_TYPE) 24 | set( 25 | CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE 26 | ) 27 | message(STATUS "Setting default build type to " ${CMAKE_BUILD_TYPE}) 28 | endif(NOT CMAKE_BUILD_TYPE) 29 | 30 | option(MLC_HIDE_PRIVATE_SYMBOLS "Hide private symbols" ON) 31 | 32 | if (MLC_LLM_INSTALL_STATIC_LIB) 33 | set(BUILD_STATIC_RUNTIME ON) 34 | endif() 35 | 36 | set(MLC_VISIBILITY_FLAG "") 37 | if (MLC_HIDE_PRIVATE_SYMBOLS) 38 | set(HIDE_PRIVATE_SYMBOLS ON) 39 | if (NOT MSVC) 40 | set(MLC_VISIBILITY_FLAG "-fvisibility=hidden") 41 | endif() 42 | message(STATUS "Hide private symbols") 43 | endif() 44 | 45 | option(BUILD_CPP_TEST "Build cpp unittests" OFF) 46 | 47 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 48 | 49 | # tvm runtime config: minimize runtime components 50 | set(USE_RPC OFF) 51 | set(USE_MICRO OFF) 52 | set(USE_GRAPH_EXECUTOR OFF) 53 | set(USE_GRAPH_EXECUTOR_DEBUG OFF) 54 | set(USE_AOT_EXECUTOR OFF) 55 | set(USE_PROFILER OFF) 56 | set(USE_GTEST OFF) 57 | set(USE_LIBBACKTRACE OFF) 58 | set(BUILD_DUMMY_LIBTVM ON) 59 | if (NOT DEFINED TVM_HOME) 60 | set(TVM_HOME 3rdparty/tvm) 61 | endif (NOT DEFINED TVM_HOME) 62 | message(STATUS "TVM_HOME: ${TVM_HOME}") 63 | add_subdirectory(${TVM_HOME} tvm EXCLUDE_FROM_ALL) 64 | 65 | set(MLC_LLM_RUNTIME_LINKER_LIB "") 66 | set(TOKENZIER_CPP_PATH 3rdparty/tokenizers-cpp) 67 | add_subdirectory(${TOKENZIER_CPP_PATH} tokenizers EXCLUDE_FROM_ALL) 68 | 69 | 70 | tvm_file_glob(GLOB_RECURSE MLC_LLM_SRCS cpp/*.cc) 71 | tvm_file_glob(GLOB_RECURSE MLC_CLI_SRCS cpp/cli_main.cc) 72 | list(REMOVE_ITEM MLC_LLM_SRCS ${MLC_CLI_SRCS}) 73 | 74 | add_library(mlc_llm_objs OBJECT ${MLC_LLM_SRCS}) 75 | add_library(mlc_cli_objs OBJECT ${MLC_CLI_SRCS}) 76 | 77 | set( 78 | MLC_LLM_INCLUDES 79 | ${TVM_HOME}/include 80 | ${TVM_HOME}/3rdparty/dlpack/include 81 | ${TVM_HOME}/3rdparty/dmlc-core/include 82 | ${TVM_HOME}/3rdparty/picojson 83 | ) 84 | 85 | set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS} DMLC_USE_LOGGING_LIBRARY=) 86 | 87 | target_include_directories(mlc_llm_objs PRIVATE ${MLC_LLM_INCLUDES}) 88 | target_compile_definitions(mlc_llm_objs PRIVATE ${MLC_LLM_COMPILE_DEFS}) 89 | target_include_directories(mlc_llm_objs PRIVATE ${TOKENZIER_CPP_PATH}/include) 90 | target_compile_definitions(mlc_llm_objs PRIVATE -DMLC_LLM_EXPORTS) 91 | 92 | add_library(mlc_llm SHARED $) 93 | add_library(mlc_llm_static STATIC $) 94 | add_dependencies(mlc_llm_static tokenizers_cpp sentencepiece-static tokenizers_c tvm_runtime) 95 | set_target_properties(mlc_llm_static PROPERTIES OUTPUT_NAME mlc_llm) 96 | 97 | target_link_libraries(mlc_llm PUBLIC tvm_runtime) 98 | target_link_libraries(mlc_llm PRIVATE tokenizers_cpp) 99 | 100 | if (BUILD_CPP_TEST) 101 | message(STATUS "Building cpp unittests") 102 | add_subdirectory(3rdparty/googletest) 103 | file(GLOB_RECURSE MLC_LLM_TEST_SRCS ${PROJECT_SOURCE_DIR}/tests/cpp/*unittest.cc) 104 | add_executable(mlc_llm_cpp_tests ${MLC_LLM_TEST_SRCS}) 105 | target_include_directories(mlc_llm_cpp_tests PRIVATE ${MLC_LLM_INCLUDES}) 106 | target_include_directories(mlc_llm_cpp_tests PRIVATE ${PROJECT_SOURCE_DIR}/cpp) 107 | target_include_directories(mlc_llm_cpp_tests PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) 108 | target_link_libraries(mlc_llm_cpp_tests PUBLIC mlc_llm gtest gtest_main) 109 | endif(BUILD_CPP_TEST) 110 | 111 | # Example app that may depends on mlc_llm 112 | add_executable(mlc_chat_cli $) 113 | target_include_directories(mlc_cli_objs PRIVATE ${MLC_LLM_INCLUDES}) 114 | target_include_directories(mlc_cli_objs PRIVATE 3rdparty/argparse/include) 115 | target_compile_definitions(mlc_cli_objs PRIVATE ${MLC_LLM_COMPILE_DEFS}) 116 | 117 | if (CMAKE_SYSTEM_NAME STREQUAL "Android") 118 | target_link_libraries(mlc_llm PRIVATE log) 119 | target_link_libraries(mlc_chat_cli PRIVATE log) 120 | endif() 121 | 122 | if (MLC_LLM_INSTALL_STATIC_LIB) 123 | target_link_libraries( 124 | mlc_chat_cli PRIVATE mlc_llm_static tokenizers_cpp sentencepiece-static tokenizers_c) 125 | target_link_libraries( 126 | mlc_chat_cli PRIVATE "$") 127 | else() 128 | target_link_libraries(mlc_chat_cli PUBLIC mlc_llm) 129 | endif() 130 | 131 | add_library(mlc_llm_module SHARED $) 132 | target_link_libraries(mlc_llm_module PUBLIC tvm) 133 | target_link_libraries(mlc_llm_module PRIVATE tokenizers_cpp) 134 | 135 | 136 | set_property(TARGET mlc_llm_module APPEND PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}") 137 | set_property(TARGET mlc_llm APPEND PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}") 138 | 139 | find_program(CARGO_EXECUTABLE cargo) 140 | 141 | if(NOT CARGO_EXECUTABLE) 142 | message(FATAL_ERROR "Cargo is not found! Please install cargo.") 143 | endif() 144 | 145 | # when this option is on, 146 | # we install all static lib deps into lib 147 | if (MLC_LLM_INSTALL_STATIC_LIB) 148 | install(TARGETS 149 | mlc_llm_static 150 | tokenizers_cpp 151 | sentencepiece-static 152 | tvm_runtime 153 | LIBRARY DESTINATION lib${LIB_SUFFIX} 154 | ) 155 | # tokenizers need special handling as it builds from rust 156 | if(MSVC) 157 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tokenizers/libtokenizers_c.lib 158 | DESTINATION lib${LIB_SUFFIX} 159 | ) 160 | else() 161 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tokenizers/libtokenizers_c.a 162 | DESTINATION lib${LIB_SUFFIX} 163 | ) 164 | endif() 165 | else() 166 | install(TARGETS mlc_chat_cli tvm_runtime mlc_llm mlc_llm_module 167 | mlc_llm_static 168 | tokenizers_cpp 169 | sentencepiece-static 170 | RUNTIME_DEPENDENCY_SET tokenizers_c 171 | RUNTIME DESTINATION bin 172 | LIBRARY DESTINATION lib${LIB_SUFFIX} 173 | ) 174 | endif() 175 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | MLC LLM Contributors 2 | ==================== 3 | 4 | 5 | ## List of Contributors 6 | - [Full List of Contributors](https://github.com/mlc-ai/mlc-llm/graphs/contributors) 7 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | MLCChat/app/src/main/jni/*.h 2 | MLCChat/app/src/main/jni/*.cc 3 | MLCChat/app/src/main/obj 4 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | 3 | project(mlc-chat C CXX) 4 | 5 | set(ANDROID_DIR ${CMAKE_CURRENT_LIST_DIR}) 6 | set(ANDROID_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}) 7 | 8 | set(MLC_LLM_DIR ${ANDROID_DIR}/..) 9 | set(MLC_LLM_BINARY_DIR mlc_llm) 10 | set(MLC_LLM_COMPILE_DEFS TVM_LOG_CUSTOMIZE=1) 11 | add_subdirectory(${MLC_LLM_DIR} ${MLC_LLM_BINARY_DIR} EXCLUDE_FROM_ALL) 12 | 13 | if (NOT DEFINED TVM_HOME) 14 | set(TVM_HOME ${MLC_LLM_DIR}/3rdparty/tvm) 15 | endif (NOT DEFINED TVM_HOME) 16 | message(STATUS "TVM_HOME: ${TVM_HOME}") 17 | 18 | find_package(Java REQUIRED) 19 | find_package(JNI REQUIRED) 20 | if (JNI_FOUND) 21 | message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") 22 | message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}") 23 | endif() 24 | include(UseJava) 25 | 26 | 27 | file(GLOB_RECURSE javasources 28 | ${TVM_HOME}/jvm/core/src/main/java/org/apache/tvm/*.java 29 | ${ANDROID_DIR}/src/java/*.java 30 | ) 31 | set(JNI_HEADER ${CMAKE_BINARY_DIR}/jni_header) 32 | add_jar(tvm4j_core ${javasources} GENERATE_NATIVE_HEADERS tvm4jheaders DESTINATION ${JNI_HEADER}) 33 | 34 | add_custom_command( 35 | TARGET tvm4j_core POST_BUILD 36 | COMMAND ${CMAKE_COMMAND} -E rename ${JNI_HEADER}/org_apache_tvm_LibInfo.h ${JNI_HEADER}/org_apache_tvm_native_c_api.h 37 | ) 38 | 39 | add_library(model_android STATIC IMPORTED) 40 | set_target_properties(model_android PROPERTIES IMPORTED_LOCATION ${ANDROID_BIN_DIR}/model_lib/libmodel_android.a) 41 | 42 | add_library(tvm4j_runtime_packed SHARED ${TVM_HOME}/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc) 43 | 44 | target_include_directories(tvm4j_runtime_packed PUBLIC 45 | ${JNI_INCLUDE_DIRS} 46 | ${JNI_HEADER} 47 | ${ANDROID_DIR}/src/cpp 48 | ${TVM_HOME}/3rdparty/dlpack/include 49 | ${TVM_HOME}/3rdparty/dmlc-core/include 50 | ${TVM_HOME}/include 51 | ) 52 | 53 | target_link_libraries(tvm4j_runtime_packed 54 | sentencepiece-static 55 | tokenizers_c 56 | tokenizers_cpp 57 | log 58 | -Wl,--whole-archive 59 | tvm_runtime 60 | mlc_llm_static 61 | model_android 62 | -Wl,--no-whole-archive 63 | ) 64 | 65 | target_compile_definitions(tvm4j_runtime_packed PUBLIC TVM4J_ANDROID) 66 | add_dependencies(tvm4j_runtime_packed tvm4j_core) 67 | 68 | install_jar(tvm4j_core output) 69 | install(TARGETS tvm4j_runtime_packed LIBRARY DESTINATION output/${ANDROID_ABI}) -------------------------------------------------------------------------------- /android/MLCChat/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /android/MLCChat/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /src/main/libs -------------------------------------------------------------------------------- /android/MLCChat/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | namespace 'ai.mlc.mlcchat' 8 | compileSdk 33 9 | 10 | defaultConfig { 11 | applicationId "ai.mlc.mlcchat" 12 | minSdk 26 13 | targetSdk 33 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | vectorDrawables { 19 | useSupportLibrary true 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | sourceSets { 30 | main { 31 | jni.srcDirs = [] 32 | jniLibs.srcDirs = ['src/main/libs'] 33 | } 34 | } 35 | compileOptions { 36 | sourceCompatibility JavaVersion.VERSION_1_8 37 | targetCompatibility JavaVersion.VERSION_1_8 38 | } 39 | kotlinOptions { 40 | jvmTarget = '1.8' 41 | } 42 | buildFeatures { 43 | compose true 44 | } 45 | composeOptions { 46 | kotlinCompilerExtensionVersion '1.4.3' 47 | } 48 | packagingOptions { 49 | resources { 50 | excludes += '/META-INF/{AL2.0,LGPL2.1}' 51 | } 52 | } 53 | } 54 | 55 | dependencies { 56 | 57 | implementation 'androidx.core:core-ktx:1.10.1' 58 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' 59 | implementation 'androidx.activity:activity-compose:1.7.1' 60 | implementation platform('androidx.compose:compose-bom:2022.10.00') 61 | implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1' 62 | implementation 'androidx.compose.ui:ui' 63 | implementation 'androidx.compose.ui:ui-graphics' 64 | implementation 'androidx.compose.ui:ui-tooling-preview' 65 | implementation 'androidx.compose.material3:material3:1.1.0' 66 | implementation 'androidx.compose.material:material-icons-extended' 67 | implementation 'androidx.appcompat:appcompat:1.6.1' 68 | implementation 'androidx.navigation:navigation-compose:2.5.3' 69 | implementation 'com.google.code.gson:gson:2.10.1' 70 | implementation fileTree(dir: 'src/main/libs', include: ['*.aar', '*.jar'], exclude: []) 71 | testImplementation 'junit:junit:4.13.2' 72 | androidTestImplementation 'androidx.test.ext:junit:1.1.5' 73 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 74 | androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00') 75 | androidTestImplementation 'androidx.compose.ui:ui-test-junit4' 76 | debugImplementation 'androidx.compose.ui:ui-tooling' 77 | debugImplementation 'androidx.compose.ui:ui-test-manifest' 78 | 79 | } -------------------------------------------------------------------------------- /android/MLCChat/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 10 | 11 | 21 | 24 | 25 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/assets/app-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "model_libs": [ 3 | "Llama-2-7b-chat-hf-q4f16_1", 4 | "RedPajama-INCITE-Chat-3B-v1-q4f16_1" 5 | ], 6 | "model_list": [ 7 | { 8 | "model_url": "https://huggingface.co/mlc-ai/mlc-chat-Llama-2-7b-chat-hf-q4f16_1/", 9 | "local_id": "Llama-2-7b-chat-hf-q4f16_1" 10 | }, 11 | { 12 | "model_url": "https://huggingface.co/mlc-ai/mlc-chat-RedPajama-INCITE-Chat-3B-v1-q4f16_1/", 13 | "local_id": "RedPajama-INCITE-Chat-3B-v1-q4f16_1" 14 | } 15 | ], 16 | "add_model_samples": [] 17 | } 18 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/Doctor-Dignity/3f2ffb6c892f13b50a708d05900d3227acb40ded/android/MLCChat/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/java/ai/mlc/mlcchat/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package ai.mlc.mlcchat 2 | 3 | import ai.mlc.mlcchat.ui.theme.MLCChatTheme 4 | import android.os.Bundle 5 | import androidx.activity.ComponentActivity 6 | import androidx.activity.compose.setContent 7 | import androidx.compose.foundation.layout.fillMaxSize 8 | import androidx.compose.material3.ExperimentalMaterial3Api 9 | import androidx.compose.material3.Surface 10 | import androidx.compose.ui.Modifier 11 | 12 | 13 | class MainActivity : ComponentActivity() { 14 | 15 | @ExperimentalMaterial3Api 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | setContent { 19 | Surface( 20 | modifier = Modifier 21 | .fillMaxSize() 22 | ) { 23 | MLCChatTheme { 24 | NavView() 25 | } 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/java/ai/mlc/mlcchat/NavView.kt: -------------------------------------------------------------------------------- 1 | package ai.mlc.mlcchat 2 | 3 | import androidx.compose.material3.ExperimentalMaterial3Api 4 | import androidx.compose.runtime.Composable 5 | import androidx.lifecycle.viewmodel.compose.viewModel 6 | import androidx.navigation.compose.NavHost 7 | import androidx.navigation.compose.composable 8 | import androidx.navigation.compose.rememberNavController 9 | 10 | @ExperimentalMaterial3Api 11 | @Composable 12 | fun NavView(appViewModel: AppViewModel = viewModel()) { 13 | val navController = rememberNavController() 14 | NavHost(navController = navController, startDestination = "home") { 15 | composable("home") { StartView(navController, appViewModel) } 16 | composable("chat") { ChatView(navController, appViewModel.chatState) } 17 | } 18 | } -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package ai.mlc.mlcchat.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Blue10 = Color(0xFF000F5E) 6 | val Blue20 = Color(0xFF001E92) 7 | val Blue30 = Color(0xFF002ECC) 8 | val Blue40 = Color(0xFF1546F6) 9 | val Blue80 = Color(0xFFB8C3FF) 10 | val Blue90 = Color(0xFFDDE1FF) 11 | 12 | val DarkBlue10 = Color(0xFF00036B) 13 | val DarkBlue20 = Color(0xFF000BA6) 14 | val DarkBlue30 = Color(0xFF1026D3) 15 | val DarkBlue40 = Color(0xFF3648EA) 16 | val DarkBlue80 = Color(0xFFBBC2FF) 17 | val DarkBlue90 = Color(0xFFDEE0FF) 18 | 19 | val Yellow10 = Color(0xFF261900) 20 | val Yellow20 = Color(0xFF402D00) 21 | val Yellow30 = Color(0xFF5C4200) 22 | val Yellow40 = Color(0xFF7A5900) 23 | val Yellow80 = Color(0xFFFABD1B) 24 | val Yellow90 = Color(0xFFFFDE9C) 25 | 26 | val Red10 = Color(0xFF410001) 27 | val Red20 = Color(0xFF680003) 28 | val Red30 = Color(0xFF930006) 29 | val Red40 = Color(0xFFBA1B1B) 30 | val Red80 = Color(0xFFFFB4A9) 31 | val Red90 = Color(0xFFFFDAD4) 32 | 33 | val Grey10 = Color(0xFF191C1D) 34 | val Grey20 = Color(0xFF2D3132) 35 | val Grey80 = Color(0xFFC4C7C7) 36 | val Grey90 = Color(0xFFE0E3E3) 37 | val Grey95 = Color(0xFFEFF1F1) 38 | val Grey99 = Color(0xFFFBFDFD) 39 | 40 | val BlueGrey30 = Color(0xFF45464F) 41 | val BlueGrey50 = Color(0xFF767680) 42 | val BlueGrey60 = Color(0xFF90909A) 43 | val BlueGrey80 = Color(0xFFC6C5D0) 44 | val BlueGrey90 = Color(0xFFE2E1EC) -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package ai.mlc.mlcchat.ui.theme 2 | 3 | import android.app.Activity 4 | import android.os.Build 5 | import androidx.compose.foundation.isSystemInDarkTheme 6 | import androidx.compose.material3.MaterialTheme 7 | import androidx.compose.material3.darkColorScheme 8 | import androidx.compose.material3.dynamicDarkColorScheme 9 | import androidx.compose.material3.dynamicLightColorScheme 10 | import androidx.compose.material3.lightColorScheme 11 | import androidx.compose.runtime.Composable 12 | import androidx.compose.runtime.SideEffect 13 | import androidx.compose.ui.graphics.Color 14 | import androidx.compose.ui.graphics.toArgb 15 | import androidx.compose.ui.platform.LocalContext 16 | import androidx.compose.ui.platform.LocalView 17 | import androidx.core.view.WindowCompat 18 | 19 | private val DarkColorScheme = darkColorScheme( 20 | primary = Blue80, 21 | onPrimary = Blue20, 22 | primaryContainer = Blue30, 23 | onPrimaryContainer = Blue90, 24 | inversePrimary = Blue40, 25 | secondary = DarkBlue80, 26 | onSecondary = DarkBlue20, 27 | secondaryContainer = DarkBlue30, 28 | onSecondaryContainer = DarkBlue90, 29 | tertiary = Yellow80, 30 | onTertiary = Yellow20, 31 | tertiaryContainer = Yellow30, 32 | onTertiaryContainer = Yellow90, 33 | error = Red80, 34 | onError = Red20, 35 | errorContainer = Red30, 36 | onErrorContainer = Red90, 37 | background = Grey10, 38 | onBackground = Grey90, 39 | surface = Grey10, 40 | onSurface = Grey80, 41 | inverseSurface = Grey90, 42 | inverseOnSurface = Grey20, 43 | surfaceVariant = BlueGrey30, 44 | onSurfaceVariant = BlueGrey80, 45 | outline = BlueGrey60 46 | ) 47 | 48 | private val LightColorScheme = lightColorScheme( 49 | primary = Blue40, 50 | onPrimary = Color.White, 51 | primaryContainer = Blue90, 52 | onPrimaryContainer = Blue10, 53 | inversePrimary = Blue80, 54 | secondary = DarkBlue40, 55 | onSecondary = Color.White, 56 | secondaryContainer = DarkBlue90, 57 | onSecondaryContainer = DarkBlue10, 58 | tertiary = Yellow40, 59 | onTertiary = Color.White, 60 | tertiaryContainer = Yellow90, 61 | onTertiaryContainer = Yellow10, 62 | error = Red40, 63 | onError = Color.White, 64 | errorContainer = Red90, 65 | onErrorContainer = Red10, 66 | background = Grey99, 67 | onBackground = Grey10, 68 | surface = Grey99, 69 | onSurface = Grey10, 70 | inverseSurface = Grey20, 71 | inverseOnSurface = Grey95, 72 | surfaceVariant = BlueGrey90, 73 | onSurfaceVariant = BlueGrey30, 74 | outline = BlueGrey50 75 | ) 76 | 77 | @Composable 78 | fun MLCChatTheme( 79 | darkTheme: Boolean = isSystemInDarkTheme(), 80 | // Dynamic color is available on Android 12+ 81 | dynamicColor: Boolean = true, 82 | content: @Composable () -> Unit 83 | ) { 84 | val colorScheme = when { 85 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { 86 | val context = LocalContext.current 87 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) 88 | } 89 | 90 | darkTheme -> DarkColorScheme 91 | else -> LightColorScheme 92 | } 93 | val view = LocalView.current 94 | if (!view.isInEditMode) { 95 | SideEffect { 96 | val window = (view.context as Activity).window 97 | window.statusBarColor = colorScheme.primary.toArgb() 98 | WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme 99 | } 100 | } 101 | 102 | MaterialTheme( 103 | colorScheme = colorScheme, 104 | typography = Typography, 105 | content = content 106 | ) 107 | } -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package ai.mlc.mlcchat.ui.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | bodyLarge = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp, 15 | lineHeight = 24.sp, 16 | letterSpacing = 0.5.sp 17 | ) 18 | /* Other default text styles to override 19 | titleLarge = TextStyle( 20 | fontFamily = FontFamily.Default, 21 | fontWeight = FontWeight.Normal, 22 | fontSize = 22.sp, 23 | lineHeight = 28.sp, 24 | letterSpacing = 0.sp 25 | ), 26 | labelSmall = TextStyle( 27 | fontFamily = FontFamily.Default, 28 | fontWeight = FontWeight.Medium, 29 | fontSize = 11.sp, 30 | lineHeight = 16.sp, 31 | letterSpacing = 0.5.sp 32 | ) 33 | */ 34 | ) -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/res/drawable/ic_android_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/res/drawable/mlc_logo_108.xml: -------------------------------------------------------------------------------- 1 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MLCChat 3 | -------------------------------------------------------------------------------- /android/MLCChat/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |