Skip to content

Commit

Permalink
Upstream merge oct31 (#41)
Browse files Browse the repository at this point in the history
* [API] Add GenerationConfig (mlc-ai#1024)

* Fix two bugs in kv-cache backtrack loop (mlc-ai#856)

Fix two bugs in kv-cache pop loop

Bug 1: old code would stop early because output_ids was shortened in-place during the loop

Bug 2: off-by-one in backoff size due to break

* [Build] Added --pdb flag to build.py, drop into pdb on error (mlc-ai#1017)

This commit adds an optional `--pdb` flag to the `build.py` script. If
passed, any exception raised that would otherwise terminate the script
will first enter a pdb post-mortem, allowing the error to be
inspected.

* [Android] Use `AlertDialog` instead of `Toast` (mlc-ai#1039)

* Add doc for ChatConfig, ConvConfig, GenerationConfig, BuildArgs (mlc-ai#1040)

Add doc for ChatConfig, ConvConfig, GenerationConfig, BuildArgs, build model

* [Android] Add Llama2 q4f16_0 (mlc-ai#1041)

llama2 q4f160

* [Docs] Model prebuilts tracking page revamp (mlc-ai#1000)

* Update compile_models.rst (mlc-ai#1038)

fix permission issue

* Support for the Stable LM 3B model (mlc-ai#1008)

Support for the stablelm-3b-4e1t model

* [Docs] Iterate model prebuilts docs (mlc-ai#1043)

* Iterate model prebuilts docs

* small fix

* Update README.md

* [CPP] Separate common utils out from llm_chat.cc (mlc-ai#1044)

This PR separates out the tokenizer creation function, the
random number generator out from `llm_chat.cc` as a preparation
step for batching inference support, since these functions/modules
are also used in the same way in batching inference.

* Update README.md (mlc-ai#1045)

Update README.md

* add verbose stats to mlc-chat REST API (mlc-ai#1049)

* add verbose stats to mlc-chat REST API

* update docs

* [Transform] Apply split_rotary optimization on prefill (mlc-ai#1033)

* [Transform] Apply split_rotary optimization on prefill

Prior to this commit, the `transform.fuse_split_rotary_embedding`
function was only applicable to the `decode` function of a Llama-type
model.  This was due to the sequence length being restricted to one,
both in the pattern-match rule and in the `split_rotary` function, and
the function being restricted to operate only on the `decode`
function.

This commit updates the `transform.fuse_split_rotary_embedding` pass
to be a `tvm.ir.transform.Pass`, operating on all applicable matched
in the `IRModule`.  The `split_rotary` function is now produced as a
fully-generic function, with static parameters substituted in
afterwards.  At this stage, the sequence length is retained as a
dynamic parameter, such that it can be used by the `prefill` function.

* Avoid multiple kernel launches for split_rotary

* [Docs] Add `mlc.ai/package` to `DEPENDENCY INSTALLATION` group (mlc-ai#1055)

Co-authored-by: Junru Shao <[email protected]>

* Revert "[Transform] Apply split_rotary optimization on prefill (mlc-ai#1033)" (mlc-ai#1058)

This reverts commit b9179cf as elaborated here mlc-ai#1033 (comment)

* [BugFix] Set the right `max_sequence_length` for both Llama-1 and Llama-2 families (mlc-ai#1032)

* fix

* reflect feedback

---------

Co-authored-by: “Sunghyun <[email protected]>

* [Doc] Use -U instead of --force-reinstall (mlc-ai#1062)

`--force-reinstall` will reinstall all dependencies to a python package,
which is unnecessary. `-U` is a better choice in this case.

* [Model] Initial batching support for Llama (mlc-ai#1048)

This PR introduces the initial batched input support for llama
models. To make the code managable, we keep both the single-sequence
handling flow and the batching handling flow in the Llama modeling.

Now, with `--enable-batching` as a build argument, we build Llama
for the batched version.

NOTE: The paged attention kernel/TIR func are not included in this PR,
so currently the built library with batching enabled is not runnable.
We will follow up with the attention kernel in the future.

This PR guarantees that the existing single-sequence inference (Python
API, CLI, etc.) is not broken.

P.S.. The batching flow is subject to bug fixes as we integrate with
the attention function and run the e2e flow in the future.

* Fix Stable LM 3B build (mlc-ai#1061)

* [stablelm 3b] Rename dynamic vocab size from "v" to "vocab_size"

* Add get_num_key_value_heads method to StableLM3bConfig

* [Core] Remove duplication in MODEL.get_model calls (mlc-ai#1054)

This commit removes the `if`/`elif` chain in `core.py`, where the body
of each conditional assigns the same `mod, param_manager, params,
model_config`, and is identical except for the choice of model being
built.

* [ParamManager] Cleanup creation of quantization IRModule (mlc-ai#1053)

This commit replaces the single-parameter
`relax_model.param_manager.create_quantize_func` function with a
method on the `ParamManager`, `create_parameter_transformation`.  This
avoids potential typos between `param_manager` as the imported Python
module `mlc_llm.relax_model.param_manager` and an instance of the
`ParamManager` class named `param_manager`, and makes the
functionality easier to find.

This function also takes an optional `optimize_parameter_order` flag,
defaulting to `True`, which applies the `ReorderTransformFunc` pass.
Since the `ReorderTransformFunc` is intended to be used with several
configuration objects owned by `ParamManager`, this simplifies the
common path of producing an optimally-ordered parameter transformation
module.

* Minor typo fix (mlc-ai#1064)

* Add links to Python API Reference (mlc-ai#1068)

* [Fix] ChatModule incorrect temperature buffer shape (mlc-ai#1070)

PR mlc-ai#1048 updated the signature of softmax in the built model library
and changed the temperature buffer shape in ChatModule. This causes
some existing demo unable to run since we did not do a round of model
library update.

This PR reverts the ChatModule change, and adds back the softmax
function in non-batching case. With this PR, the regression should
be fixed.

* [ParamManager] Added progress bar for get_item/set_item (mlc-ai#1063)

* [Python] Extract common device str parse function in ChatModule (mlc-ai#1074)

This PR lifts the device string parsing (just a few of lines)
to a standalone function, so that on the serving side the serving
can make use of this function as well.

Tested Python API and it does not seem to incur regression.

* [Bugfix] Compilation Error in q4f32_1 (mlc-ai#1078)

The pass `fuse-split-rotary` assumes the compute dtype is fp16, which
usually is, but in certain cases, e.g. `q0f32` and `q4f32_1`, the
compute is based on fp32 instead. This PR strengthens the check guard.

* Establish `mlc_chat.compiler` (mlc-ai#1082)

This PR establishes the compiler components in MLC-Chat Python API,
which currently includes two primary components: models and parameters.

The models are `nn.Module`-based definition of an LLM, which, as the
very first stab, contains only `LlamaForCasualLM`. It is decomposed into
three files:
- `llama_config.py`: common configurations for Llama, where we define
  relevant configurations of its architecture, as well as include
  standard config file for Llama2-7B/13B/70B for convenient testing;
- `llama.py`: the model architecture of Llama, based on the PyTorch-like
`nn.Module` API;
- `llama_parameter.py`: defines the mapping between MLC parameters and
  pytorch parameters.

The parameters contains the basic functionality of parameter mapping,
and the loaders that effectively convert parameters from PyTorch to MLC
according to the mapping specified. Currently, only `HFTorchLoader` is
implemented, but loaders like SafeTensor, GPTQ or AWQ should be quite
straightforward according to the existing design.

On top of this PR, on-the-fly quantization could be defined as a loading
time transformation on MLC parameters, while pre-quantized parameter
loading is effectively parameter loading after MLC's `nn.Module` is
quantized.

Two unittests examplify how the infrastructure works:
- `./tests/python/model/test_llama.py` shows how to create an `nn.Module`
using the new infra, and then convert it to TVM IRModule;
- `./tests/python/parameter/hf_torch_loader.py` shows how to load
parameters from HuggingFace PyTorch format.

Besides, `mlc_chat.support` is established for utility functions, which
now contains two utils:
- `config.py` which supports reading configurations into dataclasses
from JSON file or Python dict. On top of Python dataclass, it throws
irrelevant fields into `cls.kwargs`, which is helpful when loading
HuggingFace configuration file;
- `tqdm.py` which contains tqdm-related utilities, primarily redirecting
logging and printing to work nicely with tqdm.

* Update README.md for Multi-GPU (mlc-ai#1090)

* Support lib_path override in C++. Improvements on docs and error messages (mlc-ai#1086)

* Support lib_path option in C++ CLI. Disable ChatConfig.model_lib override in Python API. Improvements on helper messages and error messages

* Update docs

* Rename lib_path -> model_lib_path

* StreamIterator (mlc-ai#1057)

Co-authored-by: Varshith <[email protected]>

* Update `benchmark.py` according to mlc-ai#1086 (mlc-ai#1091)

Update `benchmark.py`

* Disable Disco for q4f16_ft and q8f16_ft quantization (mlc-ai#1094)

* [Format] Apply isort and black for `python/` (mlc-ai#1097)

[Format] Apply isort and black on `python/`

The commands I am using are:

```
isort --profile black python/
black python/
```

It is always recommended to format the code before submission, given we
don't have a linter CI yet.

* More formatting (mlc-ai#1099)

* Enable Python Linter (mlc-ai#1098)

This PR enables two Python formatters "black" and "isort" on the following directory:
- `./python/`
- `./tests/python/`

Enabling pylint and mypy is left for future work

* Add Basic Pylint and Mypy Tooling (mlc-ai#1100)

Add pylint/mypy tooling into pyproject.toml

This PR establishes the initial Python tooling infra with Pylint and
Mypy. Currently only the newest modules, i.e. `mlc_chat.support` and
`mlc_chat.compiler` are covered, and we expect to cover the entire
package, as being tracked in mlc-ai#1101.

* [CI] Add clang-format (mlc-ai#1103)

* [Slim-LM] Smart path finding for config and weight (mlc-ai#1088)

* [Transform] Provide IRModule transform for rewrite_attention (mlc-ai#1052)

Prior to this commit, `mlc_llm.transform.rewrite_attention` updated a
single function.  This commit modifies it to instead be a transform
operating on any pattern matches within an `IRModule`.

* [ParamManager] Use BundleModelParams for transform_dequantize (mlc-ai#1056)

* [ParamManager] Use BundleModelParams for transform_quantize

Prior to this commit, `ParamManager.transform_quantize` function took
as input functions with separate parameters for each weight tensor,
and produced output functions with a tuple parameter for all weights.
Because `LiftTransformParams` had the same convention, neither could
be applied as part of the same build flow.

This commit updates `ParamManager.transform_quantize` pass to produce
outputs with separate tensor parameters, using the `BundleModelParams`
transform to later combine them into a single tuple parameter.  The
analogous change was also performed for `LiftTransformParams` as part
of apache/tvm#15657.

In addition, prior to this commit, the
`ParamManager.transform_dequantize` function operated directly on a
`IRModule` object.  As a result, any debug instrumentation
(e.g. before/after printouts for each pass, before/after verification
with `relax.analysis.well_formed`, etc.) did not apply to this
`transform_dequantize`.  This commit updates
`ParamManager.transform_dequantize` to return a `ir.transform.Pass`.

* Correct type annotation

* [Slim-LM] Introduce HFLoad for loading Pytorch and SafeTensor weights (mlc-ai#1113)

* [WINDOWS] reduce noise in windows build (mlc-ai#1115)

* Add CLI commands for compilation (mlc-ai#1109)

* Auto updated submodule references

* fix mismatched argument name (mlc-ai#1117)

fix error introduced by recent code changes

fixes mlc-ai#1116

* [Docs] Add doc for max and mean gen len, shift factor; and buildArgs (mlc-ai#1119)

* Add doc for max and mean gen len, shift factor

* Update python docs for BuildArgs

* Revert "[ParamManager] Use BundleModelParams for transform_dequantize" (mlc-ai#1120)

Revert "[ParamManager] Use BundleModelParams for transform_dequantize (mlc-ai#1056)"

This reverts commit e5927ce.

This causes a regression impacting all MLC LLM nightlies as it violates the existing calling convention in MLC Chat runtime. An example: mlc-ai#1060 (comment)

* Remove inaccurate warning message (mlc-ai#1121)

This PR removes an inaccurate warning from mlc-ai#1086, which warns about
`model_lib` overriding regardless of whether or not it's actually
overridden. With this commit, we only warn if its value is not None.

* [REST] OpenAI compatible Rest API (mlc-ai#1107)

* add presence and frequency penalty

* Added support for passing conversation history in /v1/chat/completions endpoint

* Added support for RestAPI parameters max_gen_len, n, and stop_str

* * add presence and frequency penalty to generation config
* refactor generation config

* Added documentation for parameters

* replace lib_path with model_lib_path in rest.py

* fixed black isort issues

* fix lib_path

* Add --opt flag parsing to CLI (mlc-ai#1123)

* [ParamManager][Redo] Use BundleModelParams for transform_dequantize (mlc-ai#1127)

Prior to this commit, `ParamManager.transform_quantize` function took
as input functions with separate parameters for each weight tensor,
and produced output functions with a tuple parameter for all weights.
Because `LiftTransformParams` had the same convention, neither could
be applied as part of the same build flow.

This commit updates `ParamManager.transform_quantize` pass to produce
outputs with separate tensor parameters, using the `BundleModelParams`
transform to later combine them into a single tuple parameter.  The
analogous change was also performed for `LiftTransformParams` as part
of apache/tvm#15657.

In addition, prior to this commit, the
`ParamManager.transform_dequantize` function operated directly on a
`IRModule` object.  As a result, any debug instrumentation
(e.g. before/after printouts for each pass, before/after verification
with `relax.analysis.well_formed`, etc.) did not apply to this
`transform_dequantize`.  This commit updates
`ParamManager.transform_dequantize` to return a `ir.transform.Pass`.

This commit is a repeat of the reverted PR
mlc-ai#1056.  This PR resolves the bug
in the earlier implementation by removing the call to
`.without_attr("num_input")` in `ParamReplacer.rewrite_func`.  This
follows an analogous update in `LiftTransformParams`, preserving the
`"num_input"` attribute for use in `BundleModelParams`.

* added details to windows installation (mlc-ai#1133)

32bit version of the zstd.dll library was causing issues, so updated the doc to be more specific and download the 64bit version.

* Grammatical and Typographical improvements (mlc-ai#1139)

* Update faq.rst

* Update guideline.rst

* Update compile_models.rst

* Update distribute_compiled_models.rst

* Update get-vicuna-weight.rst

* Update python.rst

* Update android.rst

* Update cli.rst

* Update ios.rst

* Update javascript.rst

* Update python.rst

* Update rest.rst

* Minor enhancements to `ChatModule` (mlc-ai#1132)

Some minor enhancements to `ChatModule`, mainly handle the device parsing solely in `_parse_device_str` instead of handling it both in the member function and the `__init__` function to avoid redundancy; and some type annotation fix.

* Updating tvm install docs (mlc-ai#1143)

Updating the tvm install docs to assist a user in finding and copying zstd.dll to the correct folder.

* Make the help info consistent with program name (mlc-ai#1137)

When user use command `mlc_chat_cli --help`, the output will be
something like

Usage: mlc_chat [--help] ...

That's because the program name specified in `cli_main.cc` is "mlc_chat".
It will be less confusing if the output of help info shows

Usage: mlc_chat_cli [--help] ...

* Support parameter packing (mlc-ai#1146)

* [Slim-LM] Enable Group Quant (mlc-ai#1129)

* Enable group quant via new interface.

* Minor fix.

* Linting.

* Fix isort.

* Fix mypy.

* TE compute working.

* Skip embed.

* Support cpu+gpu quantization.

* Add target option to tests.

* Linting.

* Enable Mypy and Pylint in mlc_chat Python Package (mlc-ai#1149)

* Migrate Compiler Passes (mlc-ai#1150)

* Compile Model Preset without External `config.json` (mlc-ai#1151)

This PR adds support for compiling a preset of models without
having to provide a `config.json` on disk using the commands below:

```diff
python -m mlc_chat.cli.compile \
       --quantization q4f16_1 -o /tmp/1.so \
-       --config /models/Llama-2-7b-chat-hf
+       --config llama2_7b
```

This allows easier testing and binary distribution without having to
depend on external model directory.

* Update attention layer (mlc-ai#1153)

Existing dlight optimization only works for NT matmul, but not NN. As a
result, the new `nn.Module`-based implementation, which uses NN matmul,
fails compilation at HEAD for now. This PR fixes this issue by tweaking
`k` to the preferred layout.

The following commands now work with the new compilation pipeline:

```bash
python -m mlc_chat.cli.compile --config llama2_7b  --quantization q4f16_1 -o /tmp/1.so
python -m mlc_chat.cli.compile --config llama2_13b --quantization q4f16_1 -o /tmp/1.so
python -m mlc_chat.cli.compile --config llama2_70b --quantization q4f16_1 -o /tmp/1.so
```

Note that the quantization algorithm per se, `q4f16_1`, has not been
implemented yet, meaning this code path is not yet ready for use so far.

* Add batched Llama model definition using vLLM paged attention (mlc-ai#1134)

* Add batched Llama model with vllm paged attention

* update core.py

* doc

* minor

* add e2e test

* mv file

* clean

* Check if TVM has been built with USE_VLLM

* update BuildArgs docstring

* [Transform][Redo] Apply split_rotary optimization on prefill (mlc-ai#1125)

Prior to this commit, the `transform.fuse_split_rotary_embedding`
function was only applicable to the `decode` function of a Llama-type
model.  This was due to the sequence length being restricted to one,
both in the pattern-match rule and in the `split_rotary` function, and
the function being restricted to operate only on the `decode`
function.

This commit updates the `transform.fuse_split_rotary_embedding` pass
to be a `tvm.ir.transform.Pass`, operating on all applicable matched
in the `IRModule`.  The `split_rotary` function is now produced as a
fully-generic function, with static parameters substituted in
afterwards.  At this stage, the sequence length is retained as a
dynamic parameter, such that it can be used by the `prefill` function.

This commit reapplies the reverted commit
mlc-ai#1033.  The error in the
previous implementation was in the definition of
`rotary_embedding_offset`, which provided the `query_sequence_length`
instead of `kv_sequence_length`.  This was able to pass the validity
tests described
[here](mlc-ai#1058 (comment)),
as these two sequence lengths are identical for the first call.

* Apply rewrite for normal attention and MQA (mlc-ai#1138)

Fixes a bug introduced in mlc-ai#1052,
where use of the `--use-flash-attn-mqa` flag on a model that doesn't
use MQA would prevent the use of CUTLASS attention at all.

* [Rest] Fix emoji handling in Rest API. (mlc-ai#1142)

* [Utility] Check for isinstance(exc, Exception) before entering pdb (mlc-ai#1095)

This is a follow-up to mlc-ai#1017, which added a `--pdb` flag to enter a
debugger on exit.  This commit checks the type of the raised
exception, and only enters the debugger if it is a subclass of
`Exception`.  This ensures that implementation-details, such as a
thrown `SystemExit` or `KeyboardInterrupt`, do not cause an erroneous
entry to pdb.

* [Utils] Remove conversion to numpy array in utils.save_params (mlc-ai#1083)

Prior to this commit, each parameter was converted to a numpy-owned
array as part of a total size computation.  This commit computes the
size directly, removing the conversion.

* [Fix][REST] Use lowered-cased "app" (mlc-ai#1159)

* sync llama def

* fi

---------

Co-authored-by: David Pissarra <[email protected]>
Co-authored-by: Roee Shenberg <[email protected]>
Co-authored-by: Eric Lunderberg <[email protected]>
Co-authored-by: Yaxing Cai <[email protected]>
Co-authored-by: Charlie Ruan <[email protected]>
Co-authored-by: Bohan Hou <[email protected]>
Co-authored-by: yongjer <[email protected]>
Co-authored-by: Jeethu Rao <[email protected]>
Co-authored-by: Junru Shao <[email protected]>
Co-authored-by: Ruihang Lai <[email protected]>
Co-authored-by: Denise Kutnick <[email protected]>
Co-authored-by: Lesheng Jin <[email protected]>
Co-authored-by: Junru Shao <[email protected]>
Co-authored-by: Sunghyun Park <[email protected]>
Co-authored-by: “Sunghyun <[email protected]>
Co-authored-by: Rick Zhou <[email protected]>
Co-authored-by: Varshith Bathini <[email protected]>
Co-authored-by: Varshith <[email protected]>
Co-authored-by: Tianqi Chen <[email protected]>
Co-authored-by: Git bot <[email protected]>
Co-authored-by: SingLi <[email protected]>
Co-authored-by: Kartik Khandelwal <[email protected]>
Co-authored-by: Goutham Tamilselvan <[email protected]>
Co-authored-by: S A G A R <[email protected]>
Co-authored-by: Yuchen Jin <[email protected]>
Co-authored-by: DavidSharma <[email protected]>
Co-authored-by: fennecJ <[email protected]>
Co-authored-by: Xiyou Zhou <[email protected]>
  • Loading branch information
1 parent 70902d8 commit ba6d4ea
Show file tree
Hide file tree
Showing 124 changed files with 8,943 additions and 2,078 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Lint
on: [push, pull_request]
env:
IMAGE: 'mlcaidev/ci-cpu:caab922'

jobs:
isort:
name: Python / isort
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ''
- name: Version
run: |
wget https://raw.githubusercontent.com/mlc-ai/package/main/docker/bash.sh -O ./ci/bash.sh
chmod u+x ./ci/bash.sh
./ci/bash.sh $IMAGE "conda env export --name ci-lint"
- name: Lint
run: |
./ci/bash.sh $IMAGE bash ./ci/task/isort.sh
black:
name: Python / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ''
- name: Version
run: |
wget https://raw.githubusercontent.com/mlc-ai/package/main/docker/bash.sh -O ./ci/bash.sh
chmod u+x ./ci/bash.sh
./ci/bash.sh $IMAGE "conda env export --name ci-lint"
- name: Lint
run: |
./ci/bash.sh $IMAGE bash ./ci/task/black.sh
mypy:
name: Python / mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ''
- name: Version
run: |
wget https://raw.githubusercontent.com/mlc-ai/package/main/docker/bash.sh -O ./ci/bash.sh
chmod u+x ./ci/bash.sh
./ci/bash.sh $IMAGE "conda env export --name ci-lint"
- name: Lint
run: |
./ci/bash.sh $IMAGE bash ./ci/task/mypy.sh
pylint:
name: Python / pylint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ''
- name: Version
run: |
wget https://raw.githubusercontent.com/mlc-ai/package/main/docker/bash.sh -O ./ci/bash.sh
chmod u+x ./ci/bash.sh
./ci/bash.sh $IMAGE "conda env export --name ci-lint"
- name: Lint
run: |
./ci/bash.sh $IMAGE bash ./ci/task/pylint.sh
clang-format:
name: C++ / clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ''
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Version
run: |
wget https://raw.githubusercontent.com/mlc-ai/package/main/docker/bash.sh -O ./ci/bash.sh
chmod u+x ./ci/bash.sh
./ci/bash.sh $IMAGE "conda env export --name ci-lint"
- name: Lint
run: |
./ci/bash.sh $IMAGE bash ./ci/task/clang-format.sh
2 changes: 1 addition & 1 deletion 3rdparty/tvm
Submodule tvm updated 134 files
90 changes: 76 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

[Documentation](https://llm.mlc.ai/docs) | [Blog](https://blog.mlc.ai/) | [Discord][discord-url]

Machine Learning Compilation for Large Language Models (MLC LLM) is a high-performance universal deployment solution that allows native deployment of any large language models with native APIs with compiler acceleration. The mission of this project is to enable everyone to develop, optimize and deploy AI models natively on everyone's devices with ML compilation techniques.
**M**achine **L**earning **C**ompilation for **L**arge **L**anguage **M**odels (MLC LLM) is a high-performance universal deployment solution that allows native deployment of any large language models with native APIs with compiler acceleration. The mission of this project is to enable everyone to develop, optimize and deploy AI models natively on everyone's devices with ML compilation techniques.

**Universal deployment.** MLC LLM supports the following platforms and hardware:

<table style="width:100%">
<thead>
<tr>
<th style="width:16%"> </th>
<th style="width:21%">AMD GPU</th>
<th style="width:21%">NVIDIA GPU</th>
<th style="width:21%">Apple M1/M2 GPU</th>
<th style="width:21%">Intel GPU</th>
<th style="width:15%"> </th>
<th style="width:20%">AMD GPU</th>
<th style="width:20%">NVIDIA GPU</th>
<th style="width:20%">Apple GPU</th>
<th style="width:24%">Intel GPU</th>
</tr>
</thead>
<tbody>
Expand All @@ -28,21 +28,18 @@ Machine Learning Compilation for Large Language Models (MLC LLM) is a high-perfo
</tr>
<tr>
<td>macOS</td>
<td>✅ Metal</td>
<td>✅ Metal (dGPU)</td>
<td>N/A</td>
<td>✅ Metal</td>
<td>✅ Metal</td>
<td>✅ Metal (iGPU)</td>
</tr>
<tr>
<td>Web Browser</td>
<td>✅ WebGPU</td>
<td>✅ WebGPU</td>
<td>✅ WebGPU</td>
<td>✅ WebGPU</td>
<td colspan=4>✅ WebGPU and WASM </td>
</tr>
<tr>
<td>iOS / iPadOS</td>
<td colspan=4>✅ Metal on Apple M1/M2 GPU</td>
<td colspan=4>✅ Metal on Apple A-series GPU</td>
</tr>
<tr>
<td>Android</td>
Expand All @@ -52,8 +49,25 @@ Machine Learning Compilation for Large Language Models (MLC LLM) is a high-perfo
</tbody>
</table>


**Scalable.** MLC LLM scales universally on NVIDIA and AMD GPUs, cloud and gaming GPUs. Below
showcases our single batch decoding performance with prefilling = 1 and decoding = 256.

Performance of 4-bit CodeLlama-34B and Llama2-70B on two NVIDIA RTX 4090 and two AMD Radeon 7900 XTX:
<p float="left">
<img src="site/img/multi-gpu/figure-1.svg" width="40%"/>
<img src="site/img/multi-gpu/figure-3.svg" width="30%"/>
</p>

Scaling of fp16 and 4-bit CodeLlama-34 and Llama2-70B on A100-80G-PCIe and A10G-24G-PCIe, up to 8 GPUs:
<p float="center">
<img src="site/img/multi-gpu/figure-2.svg" width="100%"/>
</p>

## News

* [10/18/2023] [[Post]](https://blog.mlc.ai/2023/10/19/Scalable-Language-Model-Inference-on-Multiple-NVDIA-AMD-GPUs) Scalable multi-GPU support for CUDA and ROCm are official.
* [09/02/2023] Prebuilt ROCm 5.7 and CUDA 12.2 package is [available](https://llm.mlc.ai/docs/install/tvm.html#option-1-prebuilt-package).
* [08/25/2023] CodeLlama support is up.
* [08/14/2023] [[Post]](https://blog.mlc.ai/2023/08/09/GPU-Accelerated-LLM-on-Orange-Pi) Mali GPU support is up on Orange Pi.
* [08/09/2023] [[Post]](https://blog.mlc.ai/2023/08/09/Making-AMD-GPUs-competitive-for-LLM-inference) ROCm backend is mature to use.
Expand All @@ -66,7 +80,55 @@ Machine Learning Compilation for Large Language Models (MLC LLM) is a high-perfo

## Getting Started

Please visit our [this page](https://llm.mlc.ai/docs/index.html#getting-started) for detailed instructions.
Please visit our [documentation](https://llm.mlc.ai/docs/index.html#getting-started) for detailed instructions.

## Model Support

MLC LLM supports a wide range of model architectures and variants. We have the following prebuilts which you can
use off-the-shelf. Visit [Prebuilt Models](https://llm.mlc.ai/docs/prebuilt_models.html) to see the full list, and [Compile Models via MLC](https://llm.mlc.ai/docs/compilation/compile_models.html) to see how to use models not on this list.

<table style="width:100%">
<thead>
<tr>
<th style="width:40%">Architecture</th>
<th style="width:60%">Prebuilt Model Variants</th>
</tr>
</thead>
<tbody>
<tr>
<td>Llama</td>
<td>Llama-2, Code Llama, Vicuna, WizardLM, WizardMath, OpenOrca Platypus2, FlagAlpha Llama-2 Chinese, georgesung Llama-2 Uncensored</td>
</tr>
<tr>
<td>GPT-NeoX</td>
<td>RedPajama</td>
</tr>
<tr>
<td>GPT-J</td>
<td></td>
</tr>
<tr>
<td>RWKV</td>
<td>RWKV-raven</td>
</tr>
<tr>
<td>MiniGPT</td>
<td></td>
</tr>
<tr>
<td>GPTBigCode</td>
<td>WizardCoder</td>
</tr>
<tr>
<td>ChatGLM</td>
<td></td>
</tr>
<tr>
<td>StableLM</td>
<td></td>
</tr>
</tbody>
</table>

## Universal Deployment APIs

Expand Down
5 changes: 5 additions & 0 deletions android/MLCChat/app/src/main/assets/app-config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"model_libs": [
"Llama-2-7b-chat-hf-q4f16_0",
"Llama-2-7b-chat-hf-q4f16_1",
"RedPajama-INCITE-Chat-3B-v1-q4f16_1"
],
"model_list": [
{
"model_url": "https://huggingface.co/mlc-ai/mlc-chat-Llama-2-7b-chat-hf-q4f16_0/",
"local_id": "Llama-2-7b-chat-hf-q4f16_0"
},
{
"model_url": "https://huggingface.co/mlc-ai/mlc-chat-Llama-2-7b-chat-hf-q4f16_1/",
"local_id": "Llama-2-7b-chat-hf-q4f16_1"
Expand Down
70 changes: 40 additions & 30 deletions android/MLCChat/app/src/main/java/ai/mlc/mlcchat/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package ai.mlc.mlcchat

import ai.mlc.mlcllm.ChatModule
import android.app.Application
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Environment
import android.widget.Toast
import androidx.compose.runtime.mutableStateOf
Expand All @@ -23,6 +26,8 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
val modelList = emptyList<ModelState>().toMutableStateList()
val chatState = ChatState()
val modelSampleList = emptyList<ModelRecord>().toMutableStateList()
private var showAlert = mutableStateOf(false)
private var alertMessage = mutableStateOf("")
private var appConfig = AppConfig(
emptyList(),
emptyList<ModelRecord>().toMutableList(),
Expand All @@ -44,25 +49,46 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
loadAppConfig()
}

fun supportedModelLibs(): List<String> {
return appConfig.modelLibs
}

fun isShowingAlert(): Boolean {
return showAlert.value
}

fun errorMessage(): String {
return alertMessage.value
}

fun dismissAlert() {
require(showAlert.value)
showAlert.value = false
}

fun copyError() {
require(showAlert.value)
val clipboard =
application.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText("MLCChat", errorMessage()))
}

private fun issueAlert(error: String) {
showAlert.value = true
alertMessage.value = error
}

fun requestAddModel(url: String, localId: String?) {
if (localId != null && localIdSet.contains(localId)) {
Toast.makeText(
application,
"localId: $localId has been occupied",
Toast.LENGTH_SHORT
).show()
issueAlert("localId: $localId has been occupied")
} else {
downloadModelConfig(if (url.endsWith("/")) url else "$url/", localId, false)
}
}

fun requestDeleteModel(localId: String) {
deleteModel(localId)
Toast.makeText(
application,
"Model: $localId has been deleted",
Toast.LENGTH_SHORT
).show()
issueAlert("Model: $localId has been deleted")
}


Expand Down Expand Up @@ -133,11 +159,7 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
private fun isModelConfigAllowed(modelConfig: ModelConfig): Boolean {
if (appConfig.modelLibs.contains(modelConfig.modelLib)) return true;
viewModelScope.launch {
Toast.makeText(
application,
"Model lib ${modelConfig.modelLib} is not supported.",
Toast.LENGTH_SHORT
).show()
issueAlert("Model lib ${modelConfig.modelLib} is not supported.")
}
return false
}
Expand Down Expand Up @@ -169,11 +191,7 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
}
if (localIdSet.contains(modelConfig.localId)) {
tempFile.delete()
Toast.makeText(
application,
"${modelConfig.localId} has been used, please consider another local ID",
Toast.LENGTH_SHORT
).show()
issueAlert("${modelConfig.localId} has been used, please consider another local ID")
return@launch
}
if (!isModelConfigAllowed(modelConfig)) {
Expand All @@ -188,21 +206,13 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
addModelConfig(modelConfig, modelUrl, isBuiltin)
} catch (e: Exception) {
viewModelScope.launch {
Toast.makeText(
application,
"Add model failed: ${e.localizedMessage}",
Toast.LENGTH_SHORT
).show()
issueAlert("Add model failed: ${e.localizedMessage}")
}
}
}
} catch (e: Exception) {
viewModelScope.launch {
Toast.makeText(
application,
"Download model config failed: ${e.localizedMessage}",
Toast.LENGTH_SHORT
).show()
issueAlert("Download model config failed: ${e.localizedMessage}")
}
}

Expand Down
Loading

0 comments on commit ba6d4ea

Please sign in to comment.