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:0.1.0
   Requires L4T ['>=36']
   Dependencies build-essential cuda cudnn python numpy cmake onnx pytorch:2.2 torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Notes mlc-ai/mlc-llm commit SHA 607dc5a
mlc:0.1.0-builder
   Requires L4T ['>=36']
   Dependencies build-essential cuda cudnn python numpy cmake onnx pytorch:2.2 torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Notes mlc-ai/mlc-llm commit SHA 607dc5a
mlc:0.1.1
   Requires L4T ['>=36']
   Dependencies build-essential cuda cudnn python numpy cmake onnx pytorch:2.2 torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Images dustynv/mlc:0.1.1-r36.2.0 (2024-04-18, 7.4GB)
   Notes mlc-ai/mlc-llm commit SHA 3403a4e
mlc:0.1.1-builder
   Requires L4T ['>=36']
   Dependencies build-essential cuda cudnn python numpy cmake onnx pytorch:2.2 torchvision huggingface_hub rust transformers
   Dockerfile Dockerfile
   Notes mlc-ai/mlc-llm commit SHA 3403a4e
CONTAINER IMAGES
Repository/Tag Date Arch Size
  dustynv/mlc:0.1.1-r36.2.0 2024-04-18 arm64 7.4GB
  dustynv/mlc:3feed05-builder-r36.2.0 2024-02-16 arm64 10.8GB
  dustynv/mlc:3feed05-r36.2.0 2024-02-16 arm64 9.6GB
  dustynv/mlc:51fb0f4-builder-r35.4.1 2024-02-16 arm64 9.5GB
  dustynv/mlc:51fb0f4-builder-r36.2.0 2024-02-16 arm64 10.6GB
  dustynv/mlc:5584cac-r36.2.0 2024-02-22 arm64 9.6GB
  dustynv/mlc:607dc5a-r36.2.0 2024-02-27 arm64 9.6GB
  dustynv/mlc:c30348a-r36.2.0 2024-02-20 arm64 9.6GB
  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-03-09 arm64 9.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 jetson-containers run and autotag, or manually put together a docker run command:

# automatically pull or build a compatible container image
jetson-containers run $(autotag mlc)

# or explicitly specify one of the container images above
jetson-containers run dustynv/mlc:0.1.1-r36.2.0

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

jetson-containers run 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:

jetson-containers run -v /path/on/host:/path/in/container $(autotag mlc)

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

jetson-containers run $(autotag mlc) my_app --abc xyz

You can pass any options to it 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:

jetson-containers build mlc

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