Views
No views yet
meta-llama/Llama-3.1-8B-Instruct.meta-llama/Llama-3.1-8B-Instruct, then applies the adapter in this repository.trust_remote_code=True is required because the checkpoint bundles custom
SPEED modeling code.| Setting | Value |
|---|---|
| Base model | meta-llama/Llama-3.1-8B-Instruct |
| Model family | llama |
| Adapter checkpoint | true |
| Lower SPEED layers | 24 |
| Prompt prefill mode | lower |
| Upper prompt targets | bos,query,assistant |
| Context mode | 0 |
| Prefill attention | causal |
| Decode tokens | full-depth |
pip install "transformers>=4.57,<5" "peft>=0.19,<1" huggingface_hub accelerate safetensors1import sys
2import torch
3from huggingface_hub import snapshot_download
4
5model_id = "jeongseokoh/Llama-3.1-8B-Instruct_SPEED-24-BoS-Query"
6LOWER_K = 24
7SPEED_UPPER_TARGETS = ('bos', 'query', 'assistant')
8
9repo_dir = snapshot_download(model_id)
10sys.path.insert(0, repo_dir)
11
12from speed_inference import load_speed_model
13
14model, tokenizer = load_speed_model(
15 repo_dir,
16 dtype=torch.bfloat16,
17 device_map="auto",
18 speed_generate=True,
19 speed_layers=LOWER_K,
20 speed_attn='causal',
21 speed_upper_targets=SPEED_UPPER_TARGETS,
22)
23model.eval()
24
25messages = [
26 {"role": "system", "content": "You are a helpful assistant."},
27 {"role": "user", "content": "What is the capital of France?"},
28]
29
30with torch.inference_mode():
31 outputs = model.generate(
32 speed_generate=True,
33 messages=messages,
34 lower_k=LOWER_K,
35 speed_upper_targets=SPEED_UPPER_TARGETS,
36 max_new_tokens=256,
37 do_sample=True,
38 temperature=0.6,
39 top_p=0.95,
40 top_k=20,
41 return_dict_in_generate=True,
42 )
43
44prompt_len = outputs["prompt_lengths"][0]
45generated_ids = outputs["sequences"][0, prompt_len:]
46print(tokenizer.decode(generated_ids, skip_special_tokens=True))1question = "What are the key claims in the document?"
2document = "..." # long document text
3
4messages = [
5 {"role": "system", "content": "You are a helpful assistant."},
6 {"role": "user", "content": question},
7]
8
9with torch.inference_mode():
10 outputs = model.generate(
11 speed_generate=True,
12 messages=messages,
13 context=document,
14 lower_k=LOWER_K,
15 speed_upper_targets=SPEED_UPPER_TARGETS,
16 max_new_tokens=512,
17 do_sample=False,
18 return_dict_in_generate=True,
19 )
20
21prompt_len = outputs["prompt_lengths"][0]
22print(tokenizer.decode(outputs["sequences"][0, prompt_len:], skip_special_tokens=True))snapshot_download() and the bundled speed_inference.load_speed_model()
entrypoint as shown above. The original SPEED source repository is not needed
on the inference server.speed_generate directly to AutoModelForCausalLM.from_pretrained(model_id, ...); Transformers/PEFT may route that call through the base model class,
which does not accept those arguments.speed_generate=True for SPEED inference. Ordinary generate()
uses the normal generation path.meta-llama/Llama-3.1-8B-Instruct must be downloadable
from the inference server.pipeline("text-generation", ...) is not recommended because SPEED needs
structured arguments such as messages, context, and lower_k.llama are bundled:modeling_speed_llama.py