Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

mlc

CONTAINERS IMAGES RUN BUILD

Container for MLC LLM project using Apache TVM Unity with CUDA, cuDNN, CUTLASS, FasterTransformer, and FlashAttention-2 kernels.

Model Quantization

First, download the original HF Transformers version of the model that you want to quantize with MLC, and symbolically link it under /data/models/mlc/dist/models so that MLC can find it properly:

./run.sh --env HUGGINGFACE_TOKEN=<YOUR-ACCESS-TOKEN> $(./autotag mlc) /bin/bash -c '\
  ln -s $(huggingface-downloader meta-llama/Llama-2-7b-chat-hf) /data/models/mlc/dist/models/Llama-2-7b-chat-hf'

Note

If you're quantizing Llava, you need to change "model_type": "llava" to "model_type": "llama" in the original model's config.json version of the model (you can patch this locally after it's been downloaded under /data/models/huggingface)

Then perform W4A16 quantization on the model:

./run.sh $(./autotag mlc) \
  python3 -m mlc_llm.build \
    --model Llama-2-7b-chat-hf \
    --quantization q4f16_ft \
    --artifact-path /data/models/mlc/dist \
    --max-seq-len 4096 \
    --target cuda \
    --use-cuda-graph \
    --use-flash-attn-mqa

In this example, the quantized model and its runtime will be saved under /data/models/mlc/dist/Llama-2-7b-chat-hf-q4f16_ft

Benchmarks

To benchmark the quantized model, run the benchmark.py script:

./run.sh $(./autotag mlc) \
  python3 /opt/mlc-llm/benchmark.py \
    --model /data/models/mlc/dist/Llama-2-7b-chat-hf-q4f16_ft/params \
    --prompt /data/prompts/completion_16.json \
    --max-new-tokens 128

The --prompt file used controls the number of input tokens (context length) - there are generated prompt sequences under /data/prompts for up to 4096 tokens. The --max-new-tokens argument specifies how many output tokens the model generates for each prompt.

AVERAGE OVER 10 RUNS:
/data/models/mlc/dist/Llama-2-7b-chat-hf-q4f16_ft/params:  prefill_time 0.027 sec, prefill_rate 582.8 tokens/sec, decode_time 2.986 sec, decode_rate 42.9 tokens/sec

The prefill time is how long the model takes to process the input context before it can start generating output tokens. The decode rate is the speed at which it generates output tokens. These results are averaged over the number of prompts, minus the first prompt as a warm-up.

CONTAINERS
mlc:dev
   Builds mlc-dev_jp60 mlc-dev_jp51
   Requires L4T >=34.1.0
   Dependencies build-essential cuda cudnn python tensorrt numpy cmake onnx pytorch torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Images dustynv/mlc:dev-r35.3.1 (2023-10-30, 9.0GB)
dustynv/mlc:dev-r35.4.1 (2023-12-16, 9.4GB)
dustynv/mlc:dev-r36.2.0 (2023-12-16, 10.6GB)
   Notes mlc-ai/mlc-llm commit SHA b812bb576b6e01a158f4a2d2ebb02ce1ac455d6a
mlc:9bf5723
   Requires L4T ==35.*
   Dependencies build-essential cuda cudnn python tensorrt numpy cmake onnx pytorch torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Notes mlc-ai/mlc-llm commit SHA 9bf5723
mlc:51fb0f4
   Aliases mlc
   Requires L4T >=34.1.0
   Dependencies build-essential cuda cudnn python tensorrt numpy cmake onnx pytorch torchvision huggingface_hub rust transformers
   Dependants local_llm
   Dockerfile Dockerfile
   Notes mlc-ai/mlc-llm commit SHA 51fb0f4
CONTAINER IMAGES
Repository/Tag Date Arch Size
  dustynv/mlc:dev-r35.3.1 2023-10-30 arm64 9.0GB
  dustynv/mlc:dev-r35.4.1 2023-12-16 arm64 9.4GB
  dustynv/mlc:dev-r36.2.0 2023-12-16 arm64 10.6GB
  dustynv/mlc:r35.2.1 2023-12-16 arm64 9.4GB
  dustynv/mlc:r35.3.1 2023-11-05 arm64 8.9GB
  dustynv/mlc:r35.4.1 2024-01-27 arm64 9.4GB
  dustynv/mlc:r36.2.0 2024-01-27 arm64 10.6GB

Container images are compatible with other minor versions of JetPack/L4T:
    • L4T R32.7 containers can run on other versions of L4T R32.7 (JetPack 4.6+)
    • L4T R35.x containers can run on other versions of L4T R35.x (JetPack 5.1+)

RUN CONTAINER

To start the container, you can use the run.sh/autotag helpers or manually put together a docker run command:

# automatically pull or build a compatible container image
./run.sh $(./autotag mlc)

# or explicitly specify one of the container images above
./run.sh dustynv/mlc:r36.2.0

# or if using 'docker run' (specify image and mounts/ect)
sudo docker run --runtime nvidia -it --rm --network=host dustynv/mlc:r36.2.0

run.sh forwards arguments to docker run with some defaults added (like --runtime nvidia, mounts a /data cache, and detects devices)
autotag finds a container image that's compatible with your version of JetPack/L4T - either locally, pulled from a registry, or by building it.

To mount your own directories into the container, use the -v or --volume flags:

./run.sh -v /path/on/host:/path/in/container $(./autotag mlc)

To launch the container running a command, as opposed to an interactive shell:

./run.sh $(./autotag mlc) my_app --abc xyz

You can pass any options to run.sh that you would to docker run, and it'll print out the full command that it constructs before executing it.

BUILD CONTAINER

If you use autotag as shown above, it'll ask to build the container for you if needed. To manually build it, first do the system setup, then run:

./build.sh mlc

The dependencies from above will be built into the container, and it'll be tested during. See ./build.sh --help for build options.