Views
No views yet
<think>...</think> block, the model emits a sequence of latent reasoning
vectors that are consumed internally and never appear in the visible output.
At inference time this lets the model "think" while emitting fewer visible
tokens, trading textual scratchpad for a dense continuous representation.<think> phase it operates on the concatenation of the
current token embedding and the previous-step hidden state; its output is
projected back into the model's hidden space and fed into the frozen Qwen as
the next embedding (replacing the token embedding for that position). When the
model samples </think>, generation switches back to ordinary visible
token-by-token decoding.| file | purpose |
|---|---|
latent_head.safetensors | 16 tensors, bfloat16. The trained adapter weights. |
adapter_config.json | Base-model reference, training metadata, vLLM weight-name remap. |
tensor_index.json | Per-tensor shape/dtype manifest. |
test_inference.py | Minimal smoke-test script (also serves as a usage example). |
embed_tokens matrix is shared with the frozen Qwen and is
intentionally not stored here.feature/latent-mtp-integration branch). The fork
registers the architecture Qwen3_5LatentMTP and accepts the adapter through
several reference forms:/path/to/latent_head.safetensors # local file
/path/to/checkpoint.pt # local .pt (legacy)
junglepy/Qwen3.5-27B-Latent-Reasoning # HF repo (default file)
junglepy/Qwen3.5-27B-Latent-Reasoning:latent_head.safetensors # HF repo + filename
hf://junglepy/Qwen3.5-27B-Latent-Reasoning/latent_head.safetensors # explicit hf:// schemecore.layer.* → model.layers.0.*
core.fc.* → model.fc.*
core.pre_fc_norm_embedding.* → model.pre_fc_norm_embedding.*
core.pre_fc_norm_hidden.* → model.pre_fc_norm_hidden.*
core.norm.* → model.norm.*
to_embed.* → to_embed.*1from transformers import AutoTokenizer
2from vllm import LLM, SamplingParams
3
4base = "Qwen/Qwen3.5-27B"
5adapter = "junglepy/Qwen3.5-27B-Latent-Reasoning:latent_head.safetensors"
6
7tok = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
8llm = LLM(
9 model=base,
10 dtype="bfloat16",
11 trust_remote_code=True,
12 max_model_len=3072,
13 async_scheduling=False,
14)
15
16prompt = tok.apply_chat_template(
17 [{"role": "user", "content": "What is 17 × 23?"}],
18 tokenize=False,
19 add_generation_prompt=True,
20 enable_thinking=True,
21)
22
23params = SamplingParams(
24 temperature=0.0,
25 max_tokens=512,
26 extra_args={
27 "latent_reasoning": {
28 "backend": "qwen35_mtp",
29 "checkpoint": adapter,
30 "think_close_token_id": 248069, # </think>
31 "max_internal_tokens": 320,
32 }
33 },
34)
35
36out = llm.generate([prompt], params)[0].outputs[0]
37print(out.text)
38print("latent steps used:", out.latent_internal_token_count)test_inference.py runs the same path end-to-end on two
example prompts.If you sit behind an HTTP proxy, the first run may needenv -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy -u ALL_PROXY NO_PROXY='*' …to lethuggingface_hubreachhuggingface.cofor the initial download.
embed_tokens matrix stays frozen and equal to the base)w): 8chunk_size = 2): each latent vector is duplicated to two
reasoning positions in the cached sequence.think_tokens_mean 320,
visible_tokens_mean 287, self_exit_rate 0.00, maxed_rate 1.00 — at
max_internal_tokens=320).Qwen/Qwen3.5-27B, you agree to the base
model's license terms as well.