Views
No views yet



eagenerate function from the EaModel class for accelerated generation, similar to using the generate method from Hugging Face Transformers.1import torch
2from model.ea_model_griffin import EaModel
3from fastchat.model import get_conversation_template
4
5# Ensure base_model_path points to the original LLM and ea_model_path to the GRIFFIN draft model
6base_model_path = "meta-llama/Meta-Llama-3-70B-Instruct"
7EAGLE_model_path = "husj576/GRIFFIN-llama3-instruct-70B" # This model
8
9# Load the GRIFFIN enhanced model
10model = EaModel.from_pretrained(
11 base_model_path=base_model_path,
12 ea_model_path=EAGLE_model_path,
13 torch_dtype=torch.float16,
14 low_cpu_mem_usage=True,
15 device_map="auto",
16 total_token=-1 # Automatically configure total_token
17)
18model.eval()
19
20your_message="Hello, how are you today?"
21
22# Use the correct chat template for the base model (e.g., Llama-3.1-Instruct)
23# The GitHub example uses "vicuna", but "llama-3" would be more appropriate for Llama-3.1-8B-Instruct.
24# Please refer to `fastchat.model.get_conversation_template` for available templates.
25conv = get_conversation_template("llama3")
26conv.append_message(conv.roles[0], your_message)
27conv.append_message(conv.roles[1], None) # Append an empty assistant message to prompt generation
28prompt = conv.get_prompt()
29
30# Tokenize the prompt
31input_ids = model.tokenizer([prompt]).input_ids
32input_ids = torch.as_tensor(input_ids).cuda()
33
34# Generate output using eagenerate
35output_ids = model.eagenerate(input_ids, temperature=0.5, max_new_tokens=512)
36
37# Decode and print the generated text
38output = model.tokenizer.decode(output_ids[0])
39print(output)1@misc{hu2025griffineffectivetokenalignment,
2 title={GRIFFIN: Effective Token Alignment for Faster Speculative Decoding},
3 author={Shijing Hu and Jingyang Li and Xingyu Xie and Zhihui Lu and Kim-Chuan Toh and Pan Zhou},
4 year={2025},
5 eprint={2502.11018},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2502.11018},
9}