Views
No views yet

| LongBench suite | Llama-3.1-8B-Instruct | Llama-3-CBHybridM-8B | Llama-3-CBHybridL-8B |
|---|---|---|---|
| KV cache memory*, GB | 2.147 | 1.275 | 1.376 |
| Single-doc QA | 54.197 | 54.507 | 56.187 |
| Multi-doc QA | 41.455 | 41.022 | 43.082 |
| Summarization | 26.1275 | 25.607 | 25.357 |
| Few-shot learning | 63.4075 | 64.42 | 65.183 |
| Synthetic | 97.29 | 96.75 | 98.0 |
| Code completion | 59.745 | 66.865 | 66.49 |
| Macro-mean (EN & ZH) | 57.037 | 58.195 | 59.05 |
| Macro-mean (EN) | 58.606 | 60.485 | 60.937 |
| HELMET suite (seq. len. 16K) | Llama-3.1-8B-Instruct | Llama-3-CBHybridM-8B | Llama-3-CBHybridL-8B |
|---|---|---|---|
| KV cache memory, GB | 2.147 | 1.275 | 1.376 |
| Recall | 99.6875 | 87.5625 | 95.1875 |
| Rerank | 52.6671 | 42.7879 | 45.5175 |
| RAG | 69.0417 | 68.625 | 69.4583 |
| LongdocQA | 32.061 | 34.419 | 35.2879 |
| ICL | 76 | 81.6 | 82.2 |
| Summarization | 26.278 | 22.4353 | 23.7324 |
| Macro-mean | 59.2892 | 56.2382 | 58.564 |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "cerebras/Llama-3-CBHybridM-8B"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11 trust_remote_code=True
12)
13
14messages = [
15 {"role": "system", "content": "You are a wafer-scale chatbot who always responds in wafer speak!"},
16 {"role": "user", "content": "Who are you?"},
17]
18
19input_ids = tokenizer.apply_chat_template(
20 messages,
21 add_generation_prompt=True,
22 return_tensors="pt"
23).to(model.device)
24
25outputs = model.generate(
26 input_ids,
27 max_new_tokens=256,
28)
29response = outputs[0][input_ids.shape[-1]:]
30print(tokenizer.decode(response, skip_special_tokens=True))tokenizer.insert_memory_tokens() method as shown below:1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "cerebras/Llama-3-CBHybridM-8B"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11 trust_remote_code=True
12)
13
14messages = [
15 {"role": "system", "content": "You are a wafer-scale chatbot who always responds in wafer speak!"},
16 {"role": "user", "content": "Who are you?"},
17]
18
19input_ids = tokenizer.apply_chat_template(
20 messages,
21 add_generation_prompt=True,
22 return_tensors="pt"
23).to(model.device)
24
25# Inserting 8 memory tokens per 256 tokens of original input:
26input_ids = tokenizer.insert_memory_tokens(
27 input_ids,
28 episode_length=256,
29 num_memory_tokens_per_episode=8
30)
31
32outputs = model.generate(
33 input_ids,
34 max_new_tokens=256,
35)
36response = outputs[0][input_ids.shape[-1]:]
37print(tokenizer.decode(response, skip_special_tokens=True))
38Llama-3-CBHybrid model series is from the LM-Infinite work of Han et al. See our blog post for the full list of references.1@misc{cerebras2025cb-hybrid-llama,
2 author = {Lazarevich, Ivan and Hassanpour, Mohammad and Venkatesh, Ganesh},
3 title = {Compressing KV cache memory by half with sparse attention},
4 month = {March},
5 year = {2025},
6 howpublished = {\url{https://www.cerebras.ai/blog/compressing-kv-cache-memory-by-half-with-sparse-attention}}
7}