Views
No views yet
Qwen/Qwen3-8B.Qwen/Qwen3-8B, then apply the adapter in
this repository.modeling_speed.pymodeling_speed_qwen3.pyspeed_inference.pyspeed_decoder_modeling.pyspeed_modeling_common.pytrust_remote_code=True.| Setting | Value |
|---|---|
| Base model | Qwen/Qwen3-8B |
| Adapter type | LoRA |
| Lower SPEED layers | 24 |
| Prompt prefill mode | lower layers only |
| Upper prompt targets | bos,assistant |
| Prefill attention | causal |
| Decode tokens | full-depth |
lower_k=24 and speed_upper_targets=("bos", "assistant").pip install "transformers==4.57.6" "peft==0.19.1" huggingface_hub accelerate safetensors1import sys
2import torch
3from huggingface_hub import snapshot_download
4
5model_id = "jeongseokoh/Qwen3-8B_SPEED-24-BoS"
6repo_dir = snapshot_download(model_id)
7sys.path.insert(0, repo_dir)
8
9from speed_inference import load_speed_model
10
11model, tokenizer = load_speed_model(
12 repo_dir,
13 dtype=torch.bfloat16,
14 device_map="auto",
15 speed_generate=True,
16 speed_layers=24,
17 speed_attn="causal",
18 speed_upper_targets=("bos", "assistant"),
19)
20model.eval()
21
22messages = [
23 {"role": "system", "content": "You are a helpful assistant."},
24 {"role": "user", "content": "What is the capital of France?"},
25]
26
27with torch.inference_mode():
28 outputs = model.generate(
29 speed_generate=True,
30 messages=messages,
31 lower_k=24,
32 speed_upper_targets=("bos", "assistant"),
33 max_new_tokens=256,
34 do_sample=True,
35 temperature=0.6,
36 top_p=0.95,
37 top_k=20,
38 return_dict_in_generate=True,
39 )
40
41prompt_len = outputs["prompt_lengths"][0]
42generated_ids = outputs["sequences"][0, prompt_len:]
43print(tokenizer.decode(generated_ids, skip_special_tokens=True))messages and an optional context. The
context span is processed as prompt context according to the SPEED prefill rule.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=24,
15 speed_upper_targets=("bos", "assistant"),
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))return_dict_in_generate=True so the prompt length is handled correctly.1text = model.generate(
2 speed_generate=True,
3 messages=[
4 {"role": "system", "content": "You are a helpful assistant."},
5 {"role": "user", "content": "Give me a short answer."},
6 ],
7 lower_k=24,
8 max_new_tokens=128,
9 return_dict_in_generate=True,
10 return_text=True,
11)
12print(text)speed_generate directly to AutoModelForCausalLM.from_pretrained(model_id, ...); Transformers/PEFT may route that call through the base Qwen3ForCausalLM
class, which does not accept those arguments.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=True for SPEED inference. Calling ordinary
generate() without speed_generate=True uses the normal generation path.Qwen/Qwen3-8B must be downloadable
from the inference server.pipeline("text-generation", ...) is not recommended because the SPEED API
needs structured arguments such as messages, context, and lower_k.