Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_id = "lsm0729/llama-1b-w8a8-quantized"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(
6 model_id,
7 device_map="cuda",
8 dtype="auto"
9)
10
11# Generate
12messages = [
13 {"role": "system", "content": "You are a helpful assistant."},
14 {"role": "user", "content": "What is the capital of South Korea?"}
15]
16
17input_ids = tokenizer.apply_chat_template(
18 messages,
19 add_generation_prompt=True,
20 return_tensors="pt"
21).to("cuda")
22
23outputs = model.generate(
24 input_ids,
25 max_new_tokens=256,
26 temperature=0.6,
27 top_p=0.9,
28 do_sample=True
29)
30
31response = tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True)
32print(response)1import os
2os.environ["TORCHAO_AUTOTUNER_ENABLE"] = "1"
3
4from transformers import AutoTokenizer, AutoModelForCausalLM
5from utils import replace_CompressedLinear_with_QLinear, replace_attention_with_fused_qkv
6
7model_id = "lsm0729/llama-1b-w8a8-quantized"
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", dtype="auto")
10
11# Replace with optimized layers
12replace_CompressedLinear_with_QLinear(model) # INT8 Triton kernels
13replace_attention_with_fused_qkv(model) # Fused QKV projection
14
15# Now use the model (same as above)| Metric | Value |
|---|---|
| Memory Usage | ~2.5 GB |
| Inference Speed | ~180 tokens/sec |
| Latency (first token) | ~50ms |
| Batch Size 1 | Supported |
1quant_stage:
2 quant_modifiers:
3 GPTQModifier:
4 sequential_update: true
5 dampening_frac: 0.01
6 block_size: 128
7 scheme:
8 input_activations:
9 num_bits: 8
10 symmetric: true
11 strategy: token
12 weights:
13 num_bits: 8
14 symmetric: true
15 strategy: channel1@article{llama32,
2 title={Llama 3.2: Revolutionizing edge AI and vision with open, customizable models},
3 author={Meta AI},
4 year={2024},
5 url={https://ai.meta.com/blog/llama-3-2-connect-2024-vision-edge-mobile-devices/}
6}
7
8@software{llmcompressor,
9 title={LLM Compressor},
10 author={Neural Magic, Inc.},
11 year={2024},
12 url={https://github.com/vllm-project/llm-compressor}
13}