Views
No views yet
[!NOTE] zentorch v2.11.0.2 for PyTorch v2.11.0 has to be built from source.
lm_head.1import torch
2from transformers import TorchAoConfig, AutoModelForCausalLM, AutoTokenizer
3from torchao.quantization import Int8DynamicActivationInt8WeightConfig
4from torchao.quantization.quant_primitives import MappingType
5
6MODEL_ID = "meta-llama/Llama-3.3-70B-Instruct"
7OUTPUT_DIR = "amd/Llama-3.3-70B-Instruct-da8w8-torchao-v0.17.0"
8modules_to_skip = [
9 "lm_head",
10 "model.layers.0.self_attn",
11 "model.layers.1.self_attn",
12 "model.layers.3.self_attn",
13]
14
15quantization_config = TorchAoConfig(
16 Int8DynamicActivationInt8WeightConfig(
17 version=2,
18 act_mapping_type=MappingType.SYMMETRIC,
19 ),
20 modules_to_not_convert=modules_to_skip,
21)
22
23model = AutoModelForCausalLM.from_pretrained(
24 MODEL_ID,
25 dtype=torch.bfloat16,
26 device_map="cpu",
27 quantization_config=quantization_config,
28 trust_remote_code=True,
29)
30model.save_pretrained(OUTPUT_DIR)
31
32tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
33tokenizer.save_pretrained(OUTPUT_DIR)
34
35# Smoke test
36inputs = tokenizer("What are we having for dinner?", return_tensors="pt")
37out = model.generate(**inputs, max_new_tokens=30, cache_implementation="static")
38print(tokenizer.decode(out[0], skip_special_tokens=True))1pip install --extra-index-url https://download.pytorch.org/whl/cpu \
2 --extra-index-url https://wheels.vllm.ai/cpu/ \
3 torch==2.11.0+cpu \
4 vllm==0.23.0 \
5 torchao==0.17.0 \
6 "lm-eval[vllm]==0.4.12" \
7 huggingface_hubconda install -c conda-forge gperftools=2.17.2 llvm-openmp=18.1.8 --no-deps -y1# TorchInductor + zentorch
2export TORCHINDUCTOR_FREEZING=1
3export TORCHINDUCTOR_AUTOGRAD_CACHE=0
4export VLLM_USE_AOT_COMPILE=0
5export ZENDNNL_MATMUL_ALGO=1
6
7# Required CPU runtime libraries
8export LD_PRELOAD="<path to lib>/libtcmalloc_minimal.so.4:<path to lib>/libiomp5.so${LD_PRELOAD:+:$LD_PRELOAD}"find / -name 'libtcmalloc_minimal.so.4' and find / -name 'libiomp5.so', then substitute the resulting directory for <path to lib>.| Benchmark | BF16 Baseline | DA8W8 (this model) | Dynamic Quant Difference (baseline: BF16) |
|---|---|---|---|
| GSM8K (5-shot, exact-match flexible) | 0.9477 | 0.9409 | -0.72% |
1lm_eval \
2 --model vllm \
3 --model_args pretrained=amd/Llama-3.3-70B-Instruct-da8w8-torchao-v0.17.0,tokenizer=meta-llama/Llama-3.3-70B-Instruct,dtype=bfloat16 \
4 --tasks gsm8k \
5 --batch_size auto \
6 --trust_remote_code \
7 --num_fewshot 5 \
8 --log_samples \
9 --gen_kwargs "max_gen_toks=2048" \
10 --apply_chat_template \
11 --output_path .